org.apache.uima.resource.ResourceSpecifier Java Examples
The following examples show how to use
org.apache.uima.resource.ResourceSpecifier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExternalResourceFactory.java From uima-uimafit with Apache License 2.0 | 6 votes |
/** * 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 aApi * the resource API. */ public static void createDependency(ResourceSpecifier aDesc, String aKey, Class<?> aApi) { ExternalResourceDependency[] deps = getResourceDependencies(aDesc); if (deps == null) { deps = new ExternalResourceDependency[] {}; } // Check if the resource dependency is already present boolean found = false; for (ExternalResourceDependency dep : deps) { if (dep.getKey().equals(aKey)) { found = true; break; } } // If not, create one if (!found) { setResourceDependencies( aDesc, ArrayUtils.add(deps, createResourceDependency(aKey, aApi, false, null))); } }
Example #2
Source File: SharedElasticsearchResource.java From baleen with Apache License 2.0 | 6 votes |
@Override protected boolean doInitialize(ResourceSpecifier specifier, Map<String, Object> additionalParams) throws ResourceInitializationException { int esPort = ConfigUtils.stringToInteger(esPortString, 9300); // Use the transport client Settings.Builder settings = Settings.builder(); settings.put("cluster.name", esCluster); client = new PreBuiltTransportClient(settings.build()); client.addTransportAddress( new InetSocketTransportAddress(new InetSocketAddress(esHost, esPort))); return client != null; }
Example #3
Source File: ResourceDependencySection.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Adds the delegate to GUI. * * @param keys the keys * @param newKey the new key * @param o the o */ private void addDelegateToGUI(String keys, String newKey, ResourceSpecifier o) { if (o instanceof AnalysisEngineDescription) { AnalysisEngineDescription aeDescription = (AnalysisEngineDescription) o; if (aeDescription.isPrimitive()) addPrimitiveToGUI(keys + newKey + "/", aeDescription); else { for (Iterator it = editor.getDelegateAEdescriptions(aeDescription).entrySet().iterator(); it .hasNext();) { Map.Entry item = (Map.Entry) it.next(); addDelegateToGUI(keys + newKey + "/", (String) item.getKey(), (ResourceSpecifier) item .getValue()); } FlowControllerDeclaration fcd = getFlowControllerDeclaration(); if (null != fcd) { addPrimitiveToGUI(keys + fcd.getKey() + "/", ((ResourceCreationSpecifier) editor .getResolvedFlowControllerDeclaration().getSpecifier())); } } } }
Example #4
Source File: SofaMapSection.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Adds the sofas to all component sofa map. * * @param allComponentSofas the all component sofas * @param key the key * @param delegate the delegate * @param isInput the is input */ private void addSofasToAllComponentSofaMap(Map allComponentSofas, String key, ResourceSpecifier delegate, boolean isInput) { // delegates can be AnalysisEngines, CasConsmers, flowControllers, or remotes if (delegate instanceof AnalysisEngineDescription || delegate instanceof CasConsumerDescription || delegate instanceof FlowControllerDescription) { Set[] inAndOut = getCapabilitySofaNames((ResourceCreationSpecifier) delegate, key); Set inOut = inAndOut[isInput ? 0 : 1]; if (!isInput) { // Aggr "output" can be mapped to delegate "input" inOut.addAll(inAndOut[0]); } if (inOut.size() == 0) { // no sofas defined in this delegate // create default sofa allComponentSofas.put(key, null); } for (Iterator i2 = inOut.iterator(); i2.hasNext();) { allComponentSofas.put(i2.next(), null); } } }
Example #5
Source File: ConceptProximityAnswerScorer.java From bioasq with Apache License 2.0 | 6 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { boolean ret = super.initialize(aSpecifier, aAdditionalParams); String stoplistFile = (String) getParameterValue("stoplist"); try { stoplist = Resources.readLines(getClass().getResource(stoplistFile), Charsets.UTF_8).stream() .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } windowSize = (int) getParameterValue("window-size"); infinity = (double) getParameterValue("infinity"); smoothing = (double) getParameterValue("smoothing"); return ret; }
Example #6
Source File: ElasticsearchResource.java From newsleak with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; } // setup elasticsearch connection this.logger = this.getLogger(); Settings settings = Settings.builder().put("cluster.name", mClustername).build(); try { client = TransportClient.builder().settings(settings).build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(mHost), mPort)); if (createIndex) { createIndex(); } } catch (Exception e) { e.printStackTrace(); System.exit(0); } // initialize fields autoincrementValue = new AtomicCounter(); documentIdMapping = new HashMap<Integer, ArrayList<Integer>>(); metadataFile = new File(mMetadata + ".id-map"); return true; }
Example #7
Source File: BaleenContentExtractor.java From baleen with Apache License 2.0 | 6 votes |
@Override public final boolean initialize(ResourceSpecifier specifier, Map<String, Object> additionalParams) throws ResourceInitializationException { boolean result = super.initialize(specifier, additionalParams); UimaContext context = getUimaContext(); String pipelineName = UimaUtils.getPipelineName(context); monitor = createMonitor(pipelineName); support = createSupport(pipelineName, context); monitor.startFunction("initialize"); doInitialize(context, additionalParams); monitor.finishFunction("initialize"); return result; }
Example #8
Source File: InstallationTester.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks if a given CPE specifier file can be used to produce an instance of CPE. Returns * <code>true</code>, if a CPE can be instantiated, <code>false</code> otherwise. * * @param specifier the resource specifier * @param resource_manager a new resource_manager * @param status the place where to put the results * * @throws IOException * If an I/O exception occurred while creating <code>XMLInputSource</code>. * @throws InvalidXMLException * If the XML parser failed to parse the given input file. * @throws ResourceInitializationException * If the specified CPE cannot be instantiated. */ private void testCpeCongifuration(ResourceSpecifier specifier, ResourceManager resource_manager, TestStatus status) throws IOException, InvalidXMLException, ResourceInitializationException { CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine( (CpeDescription) specifier, resource_manager, null); if (cpe != null) { status.setRetCode(TestStatus.TEST_SUCCESSFUL); } else { status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL); status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE, "installation_verification_cpe_not_created", new Object[] { this.pkgBrowser .getInstallationDescriptor().getMainComponentId() }, null)); } }
Example #9
Source File: FlowControllerDeclaration_impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
public synchronized void resolveImports(ResourceManager aResourceManager) throws InvalidXMLException { Import theImport = getImport(); if (theImport != null) { URL url = theImport.findAbsoluteUrl(aResourceManager); InputStream stream = null; try { stream = url.openStream(); XMLInputSource input = new XMLInputSource(url); ResourceSpecifier spec = UIMAFramework.getXMLParser().parseResourceSpecifier(input); setSpecifier(spec); setImport(null); } catch (IOException e) { throw new InvalidXMLException(e); } finally { try { if (stream != null) { stream.close(); } } catch (IOException e1) { UIMAFramework.getLogger(this.getClass()).log(Level.SEVERE, "", e1); } } } }
Example #10
Source File: SharedActiveMQResource.java From baleen with Apache License 2.0 | 6 votes |
@Override protected boolean doInitialize( ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { try { connection = createConnection( activeMQProtocol, activeMQHost, activeMQPortString, activeMQBrokerArgs, activeMQUser, activeMQPass); connection.start(); session = createSession(connection); messageProducer = createMessageProducer(session); } catch (JMSException jmsException) { throw new ResourceInitializationException( new BaleenException("Error connecting to ActiveMQ", jmsException)); } getMonitor().info("Initialised shared ActiveMQ resource"); return true; }
Example #11
Source File: ProcessingContainer_Impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams) throws ResourceInitializationException { try { if (aSpecifier instanceof CasConsumerDescription_impl) { CasConsumerDescription_impl mDescription = (CasConsumerDescription_impl) aSpecifier; configParams = mDescription.getMetaData().getConfigurationParameterSettings(); if (aAdditionalParams != null) { Set aKeySet = aAdditionalParams.keySet(); Iterator it = aKeySet.iterator(); while (it.hasNext()) { String aKey = (String) it.next(); setConfigParameterValue(aKey, aAdditionalParams.get(aKey)); } } } } catch (Exception fnfe) { fnfe.printStackTrace(); } return true; }
Example #12
Source File: MetaMapConceptProvider.java From bioasq with Apache License 2.0 | 6 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { boolean ret = super.initialize(aSpecifier, aAdditionalParams); String version = String.class.cast(getParameterValue("version")); String username = String.class.cast(getParameterValue("username")); String password = String.class.cast(getParameterValue("password")); String email = String.class.cast(getParameterValue("email")); conf = createConf(version, username, password, email, false, 0); xmlInputFactory = XMLInputFactory.newFactory(); try { transformer = new TransformerFactoryImpl().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "no"); unmarshaller = JAXBContext.newInstance(MetaMapObject.class).createUnmarshaller(); } catch (TransformerConfigurationException | JAXBException e) { throw new ResourceInitializationException(); } return ret; }
Example #13
Source File: LuceneInMemoryPassageScorer.java From bioasq with Apache License 2.0 | 6 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { super.initialize(aSpecifier, aAdditionalParams); hits = Integer.class.cast(getParameterValue("hits")); // query constructor String stoplistPath = String.class.cast(getParameterValue("stoplist-path")); try { stoplist = Resources.readLines(getClass().getResource(stoplistPath), UTF_8).stream() .map(String::trim).collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } analyzer = new StandardAnalyzer(); parser = new QueryParser("text", analyzer); return true; }
Example #14
Source File: JndiResourceLocator.java From uima-uimafit with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @Override public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; } try { InitialContext ctx = new InitialContext(); resource = ctx.lookup(jndiName); } catch (NamingException e) { throw new ResourceInitializationException(e); } return true; }
Example #15
Source File: PickOverrideKeysAndParmName.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Fill parameter candidates. */ private void fillParameterCandidates() { paramsUI.setRedraw(false); paramsUI.removeAll(); TableItem selectedItem = keysUI.getSelection()[0]; Map.Entry entry = (Map.Entry) selectedItem.getData(); String keyName = (String) entry.getKey(); // support CasConsumers also // support Flow Controllers too // and skip remote service descriptors ResourceSpecifier rs = (ResourceSpecifier) entry.getValue(); if (rs instanceof AnalysisEngineDescription || rs instanceof CasConsumerDescription || rs instanceof FlowControllerDescription) { ConfigurationParameterDeclarations delegateCpd = ((ResourceCreationSpecifier) rs) .getMetaData().getConfigurationParameterDeclarations(); addSelectedParms(delegateCpd, keyName); } if (0 < paramsUI.getItemCount()) { paramsUI.setSelection(0); } paramsUI.setRedraw(true); }
Example #16
Source File: CPEFactory.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Replace component's parameters. Its parameter values will be changed to match those defined in * the CPE descriptor. * * @param aResourceSpecifier - * component's descriptor containing parameters to override * @param aCpe_cps the a cpe cps * @param aComponentName the a component name * @throws Exception - * failure during processing */ private void overrideParameterSettings(ResourceSpecifier aResourceSpecifier, CasProcessorConfigurationParameterSettings aCpe_cps, String aComponentName) throws Exception { if (aCpe_cps != null && aCpe_cps.getParameterSettings() != null) { // Extract new parameters from the CPE descriptor // Parameters are optional, so test and do the override if necessary org.apache.uima.collection.metadata.NameValuePair[] nvp = aCpe_cps.getParameterSettings(); for (int i = 0; i < nvp.length; i++) { // Next parameter to overridde if (nvp[i] != null) { overrideParameterIfExists(aResourceSpecifier, nvp[i], aComponentName); } } } }
Example #17
Source File: DeployFactory.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Retrieve protocol from the service descriptor * * @param aCasProcessorConfig Cas Processor configuration * @param aResourceManager needed to resolve import by name * @return - protocol as string (vinci, socket) * * @throws ResourceConfigurationException wraps Exception */ public static String getProtocol(CpeCasProcessor aCasProcessorConfig, ResourceManager aResourceManager) throws ResourceConfigurationException { try { URL clientServiceDescriptor = aCasProcessorConfig.getCpeComponentDescriptor().findAbsoluteUrl(aResourceManager); ResourceSpecifier resourceSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier( new XMLInputSource(clientServiceDescriptor)); if (resourceSpecifier instanceof URISpecifier) { return ((URISpecifier) resourceSpecifier).getProtocol(); } } catch (Exception e) { throw new ResourceConfigurationException(e); } return null; }
Example #18
Source File: AnalysisEngineDescription_implTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testGetAllComponentSpecifiers() throws Exception { try { Map<String, ResourceSpecifier> allSpecs = aggregateDesc.getAllComponentSpecifiers(null); FlowControllerDescription fcDesc = (FlowControllerDescription) allSpecs .get("TestFlowController"); assertNotNull(fcDesc); assertEquals("MyTestFlowController", fcDesc.getMetaData().getName()); AnalysisEngineDescription aeDesc = (AnalysisEngineDescription) allSpecs.get("Test"); assertNotNull(aeDesc); assertEquals("Test TAE", aeDesc.getMetaData().getName()); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example #19
Source File: SharedStopwordResource.java From baleen with Apache License 2.0 | 5 votes |
@Override protected boolean doInitialize(ResourceSpecifier specifier, Map<String, Object> additionalParams) throws ResourceInitializationException { try { stopwords = loadStoplist("SmartStoplist.txt"); } catch (IOException ioe) { getMonitor().error("Unable to read default stop words from SmartStoplist.txt", ioe); throw new ResourceInitializationException(ioe); } return true; }
Example #20
Source File: AnalysisEngineDescription_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public Map<String, ResourceSpecifier> getAllComponentSpecifiers(ResourceManager aResourceManager) throws InvalidXMLException { if (aResourceManager == null) { aResourceManager = UIMAFramework.newDefaultResourceManager(); } resolveImports(aResourceManager); Map<String, ResourceSpecifier> map = new LinkedHashMap<>(mDelegateAnalysisEngineSpecifiers); if (getFlowControllerDeclaration() != null) { map.put(getFlowControllerDeclaration().getKey(), getFlowControllerDeclaration() .getSpecifier()); } return Collections.unmodifiableMap(map); }
Example #21
Source File: CasConsumerFactory_impl.java From uima-uimafit with Apache License 2.0 | 5 votes |
@Override public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams); return initResource(resource, applicationContext); }
Example #22
Source File: DocumentAnalyzer.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Creates a CAS from an descriptor. Supports both local AE descriptors and remote service * specifiers. In the latter case the service is contacted to obtain its type system. * * @param aDescriptorFile the a descriptor file * @return the cas * @throws ResourceInitializationException - * @throws InvalidXMLException - * @throws IOException - */ protected CAS createCasFromDescriptor(String aDescriptorFile) // JMP throws ResourceInitializationException, InvalidXMLException, IOException { ResourceSpecifier spec = UIMAFramework.getXMLParser().parseResourceSpecifier( new XMLInputSource(aDescriptorFile)); if (spec instanceof AnalysisEngineDescription) { return CasCreationUtils.createCas((AnalysisEngineDescription) spec); } else { AnalysisEngine currentAe = UIMAFramework.produceAnalysisEngine(spec); return CasCreationUtils.createCas(currentAe.getAnalysisEngineMetaData()); } }
Example #23
Source File: SharedRedisResource.java From baleen with Apache License 2.0 | 5 votes |
@Override protected boolean doInitialize( final ResourceSpecifier specifier, final Map<String, Object> additionalParams) throws ResourceInitializationException { jedisPool = new JedisPool(redisServer, redisPort); getMonitor().info("Initialised Jedis resources"); return true; }
Example #24
Source File: CasDataInitializer_ImplBase.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Called by the framework to initialize this CAS Initializer. Subclasses should NOT override this * method; instead they should override the zero-argument {@link #initialize()} method and access * metadata via the {@link #getProcessingResourceMetaData()} method. This method is non-final only * for legacy reasons. * * @see org.apache.uima.resource.Resource#initialize(org.apache.uima.resource.ResourceSpecifier, * java.util.Map) */ public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { // aSpecifier must be a CasInitializerDescription if (aSpecifier instanceof CasInitializerDescription) { // do framework intitialiation if (super.initialize(aSpecifier, aAdditionalParams)) { // do user initialization initialize(); return true; } } return false; }
Example #25
Source File: CollectionReaderFactory_impl.java From uima-uimafit with Apache License 2.0 | 5 votes |
@Override public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams); return initResource(resource, applicationContext); }
Example #26
Source File: StringSubtypeTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
protected void setUp() throws Exception { super.setUp(); File specifierFile = JUnitExtension.getFile(specifier); XMLInputSource in = new XMLInputSource(specifierFile); ResourceSpecifier resourceSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in); this.ae = UIMAFramework.produceAnalysisEngine(resourceSpecifier); this.jcas = this.ae.newJCas(); }
Example #27
Source File: ClassTypeProbabilityBmeow.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { boolean init = super.initialize(aSpecifier, aAdditionalParams); try { String language = (String) aAdditionalParams.get(LocalFeaturesTcAnnotator.PARAM_LANGUAGE); populateLanguage(language); } catch (IOException e) { throw new ResourceInitializationException(e); } return init; }
Example #28
Source File: LanguageDetectorResource.java From newsleak with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; } model = new LanguageDetectorModelLoader().load(new File(mModelfile)); languageCounter = new HashMap<String, Integer>(); return true; }
Example #29
Source File: CachedTmToolConceptProvider.java From bioasq with Apache License 2.0 | 5 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { boolean ret = super.initialize(aSpecifier, aAdditionalParams); // initialize mapdb File file = new File((String) getParameterValue("db-file")); db = DBMaker.newFileDB(file).compressionEnable().commitFileSyncDisable().cacheSize(1) .closeOnJvmShutdown().make(); String map = (String) getParameterValue("map-name"); trigger2text2denotations = triggers.stream() .collect(toMap(Function.identity(), trigger -> db.getHashMap(map + "/" + trigger))); return ret; }
Example #30
Source File: VinciCasProcessorDeployer.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Parses given service descriptor and returns initialized ResourceSpecifier. * * @param aUrl - * URL of the descriptor * @return - ResourceSpecifier parsed from descriptor * @throws ResourceConfigurationException wraps Exception */ private ResourceSpecifier getSpecifier(URL aUrl) throws ResourceConfigurationException { try { XMLInputSource in = new XMLInputSource(aUrl); return UIMAFramework.getXMLParser().parseResourceSpecifier(in); } catch (Exception e) { e.printStackTrace(); throw new ResourceConfigurationException(CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_invalid_deployment__SEVERE", new Object[] { Thread.currentThread().getName(), aUrl, null }); } }