Refine search
public static AnalysisEngineDescription getDescription() throws ResourceInitializationException { String modelPath = String.format("/models/%s-token.bin", "en"); return AnalysisEngineFactory.createEngineDescription(ConcurrentTokenizer.class, opennlp.uima.util.UimaUtil.MODEL_PARAMETER, ExternalResourceFactory.createExternalResourceDescription(TokenizerModelResourceImpl.class, ConcurrentTokenizer.class.getResource(modelPath).toString()), opennlp.uima.util.UimaUtil.SENTENCE_TYPE_PARAMETER, Sentence.class.getName(), opennlp.uima.util.UimaUtil.TOKEN_TYPE_PARAMETER, Token.class.getName()); }
/** * Scan the given resource specifier for external resource dependencies and whenever a dependency * is encounter that has the specified key, the resource will be bound. * <p> * <b>Caveat</b>: If you use this method, you may expect that {@link DataResource#getUrl()} or * {@link DataResource#getUri()} will return the same URL that you have specified here. This may * <b>NOT</b> be the case. UIMA will internally try to resolve the URL via a * {@link ResourceManager}. If it cannot resolve a remove URL, this mechanism will think it may be * a local file and will return some local path - or it may redirect it to some location as though * fit by the {@link ResourceManager}. * * @param aDesc * a description. * @param aKey * the key to bind to. * @param aUrl * a URL. * @throws InvalidXMLException * if import resolution failed * @see FileResourceSpecifier */ public static void bindResource(ResourceSpecifier aDesc, String aKey, URL aUrl) throws InvalidXMLException { bindResource(aDesc, aKey, aUrl.toString()); }
public static AnalysisEngineDescription createChineseSegmenterAE(String annotationType) { try { AnalysisEngineDescription ae = AnalysisEngineFactory.createEngineDescription( ChineseSegmenter.class, ChineseSegmenter.ANNOTATION_TYPE, annotationType ); ExternalResourceFactory.createDependencyAndBind( ae, ChineseSegmenter.CHINESE_WORD_SEGMENTS, ChineseSegmentResource.class, ChineseSegmenterResourceHelper.getChineseWordSegments()); ExternalResourceFactory.createDependencyAndBind( ae, ChineseSegmenter.CHINESE_FOREIGN_NAME_SEGMENTS, ChineseSegmentResource.class, ChineseSegmenterResourceHelper.getForeignNameSegments()); ExternalResourceFactory.createDependencyAndBind( ae, ChineseSegmenter.CHINESE_NUMBER_SEGMENTS, ChineseSegmentResource.class, ChineseSegmenterResourceHelper.getNumberSegments()); return ae; } catch(Exception e) { throw new RuntimeException(e); } } }
/** * Scan the given resource specifier for external resource dependencies and whenever a dependency * is encounter that has the specified key, the resource will be bound. * <p> * <b>Caveat</b>: If you use this method, you may expect that {@link DataResource#getUrl()} or * {@link DataResource#getUri()} will return the same URL that you have specified here. This is * may <b>NOT</b> be the case. UIMA will internally try to resolve the URL via a * {@link ResourceManager}. If it cannot resolve a remove URL, this mechanism will think it may be * a local file and will return some local path - or it may redirect it to some location as though * fit by the {@link ResourceManager}. * * @param aDesc * a description. * @param aKey * the key to bind to. * @param aUrl * a URL. * @throws InvalidXMLException * if import resolution failed * @see FileResourceSpecifier */ public static void bindResource(ResourceSpecifier aDesc, String aKey, String aUrl) throws InvalidXMLException { ExternalResourceDescription extRes = createExternalResourceDescription(aKey, aUrl); bindResource(aDesc, aKey, extRes); }
/** * Create a new dependency for the specified resource and bind it. This method is helpful for UIMA * components that do not use the uimaFIT {@link ExternalResource} annotation, because no external * resource dependencies can be automatically generated by uimaFIT for such components. * * @param aDesc * a description. * @param aKey * the key to bind to. * @param aImpl * the resource implementation. * @param aApi * the resource interface * @param aParams * additional parameters supported by the resource. * @throws InvalidXMLException * if import resolution failed */ public static void createDependencyAndBind(ResourceSpecifier aDesc, String aKey, Class<? extends Resource> aImpl, Class<?> aApi, String... aParams) throws InvalidXMLException { createDependency(aDesc, aKey, aApi); bindResource(aDesc, aKey, aImpl, aParams); }
/** * Scan the given resource specifier for external resource dependencies and whenever a dependency * with a compatible type is found, the resource will be bound. * * @param aDesc * a description. * @param aApi * the resource interface. * @param aRes * the resource to bind. * @param aParams * parameters passed to the resource when it is created. * @throws InvalidXMLException * if import resolution failed * @throws ClassNotFoundException * if the resource implementation class or interface class could not be accessed * @see CustomResourceSpecifier */ public static void bindResource(ResourceSpecifier aDesc, Class<?> aApi, Class<? extends Resource> aRes, String... aParams) throws InvalidXMLException, ClassNotFoundException { // Appending a disambiguation suffix it possible to have multiple instances of the same // resource with different settings to different keys. ExternalResourceDescription extRes = createExternalResourceDescription( uniqueResourceKey(aRes.getName()), aRes, (Object[]) aParams); bindResource(aDesc, extRes); }
ExternalResourceFactory.createExternalResourceDescription( "tokens", SharedOpenNLPModel.class); ExternalResourceDescription sentencesDesc = ExternalResourceFactory.createExternalResourceDescription( "sentences", SharedOpenNLPModel.class); ExternalResourceDescription posDesc = ExternalResourceFactory.createExternalResourceDescription( "posTags", SharedOpenNLPModel.class); ExternalResourceDescription chunksDesc = ExternalResourceFactory.createExternalResourceDescription( "phraseChunks", SharedOpenNLPModel.class); AnalysisEngineFactory.createEngineDescription( uk.gov.dstl.baleen.annotators.language.OpenNLP.class, "tokens", "phraseChunks", chunksDesc); aeLanguage = AnalysisEngineFactory.createEngine(descLanguage); jCas.setDocumentText(text);
/** * Create an external resource description for a {@link SharedResourceObject}. * * @param aInterface * the interface the resource should implement. * @param aUrl * the URL from which the resource is initialized. * @param aParams * parameters passed to the resource when it is created. * @return the description. * @see ConfigurableDataResourceSpecifier * @see SharedResourceObject */ public static ExternalResourceDescription createExternalResourceDescription( Class<? extends SharedResourceObject> aInterface, URL aUrl, Object... aParams) { return createExternalResourceDescription(uniqueResourceKey(aInterface.getName()), aInterface, aUrl.toString(), aParams); }
java.net.URL url = LvgAnnotator.class.getClassLoader().getResource(lvgProperties); if (url!=null) { logger.info("URL for lvg.properties =" + url.getFile()); } else { String absolutePath = "/tmp/"; return AnalysisEngineFactory.createEngineDescription(LvgAnnotator.class, LvgAnnotator.PARAM_USE_CMD_CACHE, false, false, LvgAnnotator.PARAM_LVGCMDAPI_RESRC_KEY, ExternalResourceFactory.createExternalResourceDescription( LvgCmdApiResourceImpl.class, url));
public ExternalResourceDescription getDefaultLvgCmdApi() throws IOException { synchronized ( LOCK ) { if ( _lvgCmdApi != null ) { return _lvgCmdApi; } URL url = LvgAnnotator.class.getClassLoader().getResource( PROPERTIES_PATH ); if (url!=null) { LOGGER.info("URL for lvg.properties =" + url.getFile()); } else { String absolutePath = "/tmp/"; LOGGER.info("URL==null"); LOGGER.info("Unable to find " + PROPERTIES_PATH + "."); LOGGER.info("Copying files and directories to under " + absolutePath); File lvgFile = new File(LvgAnnotator.copyLvgFiles(absolutePath)); url = lvgFile.toURI().toURL(); } _lvgCmdApi = ExternalResourceFactory.createExternalResourceDescription( LvgCmdApiResourceImpl.class, url ); return _lvgCmdApi; } }
ExternalResourceFactory.createExternalResourceDescription( SharedMongoResource.RESOURCE_KEY, SharedFongoResource.class, RENOUN_PATTERNS, PARAM_MODEL_PATH, Paths.get(MODEL_URL.toURI()).toString(), PARAM_BIN_FOLDER, tempDirectory.toString()); ae.getUimaContext().getResourceObject(SharedMongoResource.RESOURCE_KEY); patternsCollection = sfr.getDB().getCollection(RENOUN_PATTERNS); scoredFactsCollection = sfr.getDB().getCollection(RENOUN_SCORED_FACTS);
@Before public void setUp() throws ResourceInitializationException, ResourceAccessException { // Create a description of an external resource - a fongo instance, in the same way we would // have created a shared mongo resource final ExternalResourceDescription erd = ExternalResourceFactory.createExternalResourceDescription( SharedFongoResource.class, "fongo.collection", "test", "fongo.data", "[]"); // Create the analysis engine final AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( MongoPatternSaver.class, MongoPatternSaver.KEY_MONGO, erd, "collection", "test"); ae = AnalysisEngineFactory.createEngine(aed); ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap()); sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MongoPatternSaver.KEY_MONGO); }
@Override public void beforeTest() throws UIMAException { super.beforeTest(); ExternalResourceDescription stopwordsDesc = ExternalResourceFactory.createExternalResourceDescription( PatternExtractor.KEY_STOPWORDS, SharedStopwordResource.class); final AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription( PatternExtractor.class, PatternExtractor.KEY_STOPWORDS, stopwordsDesc); ae = AnalysisEngineFactory.createEngine(desc); }
ExternalResourceFactory.createExternalResourceDescription( "country", SharedCountryResource.class); SharedCountryResource scr = new SharedCountryResource(); jCas.reset(); jCas.setDocumentText(cca3); l.addToIndexes(); ae.process(jCas);
bindResource(analysisDesc, TaskContext.class, TaskContextProvider.class, TaskContextProvider.PARAM_FACTORY_NAME, contextFactory.getId(), TaskContextProvider.PARAM_CONTEXT_ID, ctx.getId()); addReaderParam.put(Resource.PARAM_UIMA_CONTEXT, uimaCtx); addReaderParam.put(Resource.PARAM_RESOURCE_MANAGER, resMgr); engine.initialize(analysisDesc, addEngineParam); metaData.add(engine.getMetaData()); CAS cas = CasCreationUtils.createCas(metaData); engine.process(cas); cas.reset();
@Before public void setUp() throws Exception { jCas.reset(); elasticsearch = new EmbeddedElasticsearch5(); ExternalResourceDescription erd = ExternalResourceFactory.createExternalResourceDescription( RESOURCE_KEY, SharedElasticsearchResource.class, PARAM_PORT, Integer.toString(elasticsearch.getTransportPort()), PARAM_CLUSTER, elasticsearch.getClusterName()); AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( LocationElasticsearch.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), RESOURCE_KEY, erd, PARAM_INDEX, LOCATION_INDEX); ae = AnalysisEngineFactory.createEngine(aed); }
@Test public void testHasNextLooping() throws Exception { ExternalResourceDescription contentExtractor = ExternalResourceFactory.createExternalResourceDescription( KEY_CONTENT_EXTRACTOR, FakeBaleenContentExtractor.class); DummyBaleenCollectionReader cr = (DummyBaleenCollectionReader) CollectionReaderFactory.createReader( DummyBaleenCollectionReader.class, BaleenCollectionReader.KEY_CONTENT_EXTRACTOR, contentExtractor); while (cr.hasNext()) { JCas jCas = JCasSingleton.getJCasInstance(); cr.getNext(jCas.getCas()); } cr.destroy(); }
@Override public ExternalResourceDescription getActualValue() { return ExternalResourceFactory.createExternalResourceDescription(classOfFeat, params); }
@Test public void testNewFile() throws ResourceInitializationException, AnalysisEngineProcessException, IOException { // Due to limitations in the shared fongo resource we only test document count here! ExternalResourceDescription erd = ExternalResourceFactory.createExternalResourceDescription( "mongo", SharedFongoResource.class, SharedFongoResource.PARAM_FONGO_COLLECTION, "documents", SharedFongoResource.PARAM_FONGO_DATA, objectMapper.writeValueAsString(DATA)); File tempFile = File.createTempFile("test", "mongostats"); tempFile.delete(); try { AnalysisEngine task = create(MongoStats.class, "mongo", erd, "file", tempFile.getAbsolutePath()); execute(task); task.destroy(); List<String> lines = Files.readAllLines(tempFile.toPath()); assertEquals(2, lines.size()); assertEquals("timestamp,documents,entities,relations", lines.get(0)); String[] split = lines.get(1).split(","); assertEquals("3", split[1]); assertEquals("0", split[2]); assertEquals("0", split[3]); } finally { tempFile.delete(); } }
/** * Scan the given resource specifier for external resource dependencies and whenever a dependency * with the given key is encountered, the given resource is bound to it. * * @param aDesc * a description. * @param aKey * the key to bind to. * @param aRes * the resource to bind. * @param aParams * parameters passed to the resource when it is created. * @throws InvalidXMLException * if import resolution failed * @see CustomResourceSpecifier */ public static void bindResource(ResourceSpecifier aDesc, String aKey, Class<? extends Resource> aRes, String... aParams) throws InvalidXMLException { if (ParameterizedDataResource.class.isAssignableFrom(aRes)) { createDependency(aDesc, aKey, DataResource.class); } // Appending a disambiguation suffix it possible to have multiple instances of the same // resource with different settings to different keys. ExternalResourceDescription extRes = createExternalResourceDescription( uniqueResourceKey(aRes.getName()), aRes, (Object[]) aParams); bindResource(aDesc, aKey, extRes); }