/** * Gets the name of this resource, for use in logging and trace messages. * * @return the name of this resource */ protected String getResourceName() { return getMetaData().getName(); } }
protected String getNameFromMetadata() { return super.getMetaData().getName(); }
@Override protected Iterable<Resource> getResources(UimaContext ctx) throws IOException, ResourceInitializationException { // if input directory does not exist or is not a directory, throw exception if (!inputDir.isDirectory()) { throw new ResourceInitializationException( ResourceConfigurationException.DIRECTORY_NOT_FOUND, new Object[] { PARAM_INPUTDIR, this.getMetaData().getName(), inputDir.getPath() }); } // get list of .xmi files in the specified directory Collection<File> mFiles = FileUtils.listFiles(inputDir, suffixFileFilter(".xmi"), trueFileFilter()); xmiResources = Collections2.transform(mFiles, file2Resource); return xmiResources; }
/** * @see org.apache.uima.collection.CollectionReader_ImplBase#initialize() */ public void initialize() throws ResourceInitializationException { mFailOnUnknownType = (Boolean) getConfigParameterValue(PARAM_FAILUNKNOWN); if (null == mFailOnUnknownType) { mFailOnUnknownType = true; // default to true if not specified } File directory = new File(((String) getConfigParameterValue(PARAM_INPUTDIR)).trim()); mCurrentIndex = 0; // if input directory does not exist or is not a directory, throw exception if (!directory.exists() || !directory.isDirectory()) { throw new ResourceInitializationException(ResourceConfigurationException.DIRECTORY_NOT_FOUND, new Object[] { PARAM_INPUTDIR, this.getMetaData().getName(), directory.getPath() }); } // get list of .xmi files in the specified directory mFiles = new ArrayList(); File[] files = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (!files[i].isDirectory() && files[i].getName().endsWith(".xmi")) { mFiles.add(files[i]); } } }
public void initialize() throws ResourceInitializationException { File directory = new File(((String) getConfigParameterValue(PARAM_INPUTDIR)).trim()); // if input directory does not exist or is not a directory, throw exception if (!directory.exists() || !directory.isDirectory()) { throw new ResourceInitializationException(ResourceConfigurationException.DIRECTORY_NOT_FOUND, new Object[]{PARAM_INPUTDIR, this.getMetaData().getName(), directory.getPath()}); } Object para = getConfigParameterValue(PARAM_READ_TYPES); if (para != null && para instanceof String && ((String) para).trim().length() > 0) { readTypes = ((String) para).trim(); } mRecursive = false; mFiles = new ArrayList<>(); mFiles = UIMATypeFunctions.addFilesFromDir(directory, "txt", true); mCurrentIndex = 0; mEncoding = "UTF-8"; UIMATypeFunctions.getTypes(readTypes, typeClasses, typeConstructors, typeSetMethods); String typeDescriptorFile = "desc/type/customized"; if (!new File(typeDescriptorFile + ".xml").exists()) { typeDescriptorFile = "desc/type/All_Types"; } }
/** * @see org.apache.uima.collection.CollectionReader_ImplBase#initialize() */ public void initialize() throws ResourceInitializationException { logger = getUimaContext().getLogger(); logger.log(Level.INFO, "initialize() - Initializing ACETern-Reader..."); annotateDCT = (Boolean) getConfigParameterValue(PARAM_DCT); File directory = new File(((String) getConfigParameterValue(PARAM_INPUTDIR)).trim()); currentIndex = 0; // if input directory does not exist or is not a directory, throw exception if (!directory.exists() || !directory.isDirectory()) { throw new ResourceInitializationException(ResourceConfigurationException.DIRECTORY_NOT_FOUND, new Object[] { PARAM_INPUTDIR, this.getMetaData().getName(), directory.getPath() }); } // get list of files (without subdirectories) in the specified directory mFiles = new ArrayList<File>(); File[] files = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (!files[i].isDirectory()) { mFiles.add(files[i]); } } }
private PipelineBuilder build(PipelineBuilder builder) throws InvalidXMLException, IOException, SAXException, CpeDescriptorException { Set<String> cpeNames = newHashSet(); for (AnalysisEngineDescription aed : this.aeds) { // workaround to use multiple cpe with the same name String name = aed.getMetaData().getName(); if (cpeNames.contains(name)) { ResourceMetaData metaData = aed.getMetaData(); String newName = name + System.currentTimeMillis(); metaData.setName(newName); aed.setMetaData(metaData); cpeNames.add(newName); } else { cpeNames.add(name); } builder.add(aed); } return builder; }
/** * @see org.apache.uima.collection.CollectionReader_ImplBase#initialize() */ public void initialize() throws ResourceInitializationException { File directory = new File(((String) getConfigParameterValue(PARAM_INPUTDIR)).trim()); mEncoding = (String) getConfigParameterValue(PARAM_ENCODING); mLanguage = (String) getConfigParameterValue(PARAM_LANGUAGE); mRecursive = (Boolean) getConfigParameterValue(PARAM_SUBDIR); if (null == mRecursive) { // could be null if not set, it is optional mRecursive = Boolean.FALSE; } mCurrentIndex = 0; // if input directory does not exist or is not a directory, throw exception if (!directory.exists() || !directory.isDirectory()) { throw new ResourceInitializationException(ResourceConfigurationException.DIRECTORY_NOT_FOUND, new Object[]{PARAM_INPUTDIR, this.getMetaData().getName(), directory.getPath()}); } // get list of files in the specified directory, and subdirectories if the // parameter PARAM_SUBDIR is set to True mFiles = new ArrayList<File>(); addFilesFromDir(directory, null); }
/** * Checks for duplicate parameter names and throws an exception if any are found. * * @param aParams * an array of ConfigurationParameters * * @throws ResourceInitializationException * if there is a duplicate parameter name in the arrays */ protected void checkForDuplicateParameterNames(ConfigurationParameter[] aParams) throws ResourceInitializationException { Set<String> paramNames = new HashSet<String>(); for (int i = 0; i < aParams.length; i++) { if (!paramNames.add(aParams[i].getName())) { throw new ResourceInitializationException( ResourceInitializationException.DUPLICATE_CONFIGURATION_PARAMETER_NAME, new Object[] { aParams[i].getName(), getMetaData().getName(), aParams[i].getSourceUrlString() }); } } }
/** * @see org.apache.uima.resource.Resource#destroy() */ public void destroy() { if (mAnnotator != null) mAnnotator.destroy(); getLogger().logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_destroyed__CONFIG", getMetaData().getName()); super.destroy(); }
/** * @see org.apache.uima.resource.Resource#destroy() */ public void destroy() { if (mASB != null) mASB.destroy(); getLogger().logrb(Level.CONFIG, CLASS_NAME.getName(), "destroy", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_destroyed__CONFIG", getMetaData().getName()); super.destroy(); }
/** * @see AnalysisEngine#processAndOutputNewCASes(CAS) */ public CasIterator processAndOutputNewCASes(CAS aCAS) throws AnalysisEngineProcessException { // logging and instrumentation String resourceName = getMetaData().getName(); Logger logger = getLogger(); logger.logrb(Level.FINE, CLASS_NAME.getName(), "process", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_process_begin__FINE", resourceName); try { CasIterator iterator = _getASB().process(aCAS); // log end of event logger.logrb(Level.FINE, CLASS_NAME.getName(), "process", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_process_end__FINE", resourceName); return iterator; } catch (Exception e) { // log and rethrow exception logger.log(Level.SEVERE, "", e); if (e instanceof AnalysisEngineProcessException) throw (AnalysisEngineProcessException) e; else throw new AnalysisEngineProcessException(e); } }
private String setupName() { String svcName = null; if (!(resourceSpecifier instanceof CustomResourceSpecifier)) { svcName = ((ResourceCreationSpecifier) resourceSpecifier).getMetaData().getName(); } if (svcName == null || svcName.trim().length() == 0) { if (isTopLevelComponent()) { svcName = getTopLevelServiceName(); } else { svcName = getDelegateServiceName(); } } if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, CLASS_NAME.getName(), "setupName", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_using_generated_name_INFO", new Object[] { svcName }); } return svcName; } /**
/** * @see org.apache.uima.resource.Resource#destroy() */ public void destroy() { if (mAnalysisComponent != null) { UimaContext prevContext = UimaContextHolder.setContext(getUimaContext()); // for use by POJOs try { mAnalysisComponent.destroy(); } finally { UimaContextHolder.setContext(prevContext); } getLogger().logrb(Level.CONFIG, CLASS_NAME.getName(), "destroy", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_destroyed__CONFIG", getMetaData().getName()); } super.destroy(); }
@Test public void testValid1() throws Exception { String yaml = Files.asCharSource(getFile("jobConfig.yaml"), Charset.defaultCharset()).read(); JobBuilder jb = new JobBuilder("Test Job", new YamlPipelineConfiguration(yaml)); BaleenJob job = (BaleenJob) jb.createNewPipeline(); assertEquals("Test Job", job.getName()); assertEquals(yaml, job.originalConfig()); assertEquals(yaml, job.orderedConfig()); CollectionReader cr = job.collectionReader(); assertEquals("uk.gov.dstl.baleen.schedules.Other", cr.getMetaData().getName()); assertEquals("Foo", cr.getConfigParameterValue("key")); List<AnalysisEngine> annotators = job.annotators(); assertEquals(2, annotators.size()); AnalysisEngine ann0 = annotators.get(0); assertEquals("uk.gov.dstl.baleen.testing.DummyTask", ann0.getMetaData().getName()); assertEquals("Foo", ann0.getConfigParameterValue("key")); AnalysisEngine ann1 = annotators.get(1); assertEquals("uk.gov.dstl.baleen.testing.DummyTaskParams", ann1.getMetaData().getName()); assertEquals("Bar", ann1.getConfigParameterValue("key")); List<AnalysisEngine> consumers = job.consumers(); assertEquals(0, consumers.size()); }
@Test public void testValid2() throws Exception { String yaml = Files.asCharSource(getFile("jobConfig2.yaml"), Charset.defaultCharset()).read(); JobBuilder jb = new JobBuilder("Test Job", new YamlPipelineConfiguration(yaml)); BaleenJob job = (BaleenJob) jb.createNewPipeline(); assertEquals("Test Job", job.getName()); assertEquals(yaml, job.originalConfig()); assertEquals(yaml, job.orderedConfig()); CollectionReader cr = job.collectionReader(); assertEquals(BaleenDefaults.DEFAULT_SCHEDULER, cr.getMetaData().getName()); assertEquals("Foo", cr.getConfigParameterValue("key")); List<AnalysisEngine> annotators = job.annotators(); assertEquals(2, annotators.size()); AnalysisEngine ann0 = annotators.get(0); assertEquals("uk.gov.dstl.baleen.testing.DummyTask", ann0.getMetaData().getName()); assertEquals("Foo", ann0.getConfigParameterValue("key")); AnalysisEngine ann1 = annotators.get(1); assertEquals("uk.gov.dstl.baleen.testing.DummyTaskParams", ann1.getMetaData().getName()); assertEquals("Bar", ann1.getConfigParameterValue("key")); List<AnalysisEngine> consumers = job.consumers(); assertEquals(0, consumers.size()); }
@Test public void testValid3() throws Exception { String yaml = Files.asCharSource(getFile("jobConfig3.yaml"), Charset.defaultCharset()).read(); JobBuilder jb = new JobBuilder("Test Job", new YamlPipelineConfiguration(yaml)); BaleenJob job = (BaleenJob) jb.createNewPipeline(); assertEquals("Test Job", job.getName()); assertEquals(yaml, job.originalConfig()); assertEquals(yaml, job.orderedConfig()); CollectionReader cr = job.collectionReader(); assertEquals("uk.gov.dstl.baleen.schedules.Other", cr.getMetaData().getName()); assertEquals("Foo", cr.getConfigParameterValue("key")); List<AnalysisEngine> annotators = job.annotators(); assertEquals(2, annotators.size()); AnalysisEngine ann0 = annotators.get(0); assertEquals("uk.gov.dstl.baleen.testing.DummyTask", ann0.getMetaData().getName()); assertEquals("Foo", ann0.getConfigParameterValue("key")); AnalysisEngine ann1 = annotators.get(1); assertEquals("uk.gov.dstl.baleen.testing.DummyTaskParams", ann1.getMetaData().getName()); assertEquals("Bar", ann1.getConfigParameterValue("key")); List<AnalysisEngine> consumers = job.consumers(); assertEquals(0, consumers.size()); }
@Test public void testErrorNoClass() throws Exception { String yaml = Files.asCharSource(getFile("errorNoClassConfig.yaml"), StandardCharsets.UTF_8).read(); PipelineBuilder pb = new PipelineBuilder("Test Pipeline", new YamlPipelineConfiguration(yaml)); BaleenPipeline pipeline = pb.createNewPipeline(); CollectionReader cr = pipeline.collectionReader(); assertEquals("uk.gov.dstl.baleen.testing.DummyCollectionReader", cr.getMetaData().getName()); List<AnalysisEngine> annotators = pipeline.annotators(); assertEquals(0, annotators.size()); }
/** * Gets the name. * * @return the name */ public String getName() { if (editor.isLocalProcessingDescriptor()) return editor.getAeDescription().getMetaData().getName(); if (editor.isTypeSystemDescriptor()) return editor.getTypeSystemDescription().getName(); if (editor.isTypePriorityDescriptor()) return editor.getTypePriorities().getName(); if (editor.isFsIndexCollection()) return editor.getFsIndexCollection().getName(); if (editor.isExtResAndBindingsDescriptor()) return editor.getExtResAndBindings().getName(); throw new InternalErrorCDE("invalid state"); }
@Test public void testErrorNotFound() throws Exception { String yaml = Files.asCharSource(getFile("errorNotFoundConfig.yaml"), StandardCharsets.UTF_8).read(); PipelineBuilder pb = new PipelineBuilder("Test Pipeline", new YamlPipelineConfiguration(yaml)); BaleenPipeline pipeline = pb.createNewPipeline(); CollectionReader cr = pipeline.collectionReader(); assertEquals("uk.gov.dstl.baleen.testing.DummyCollectionReader", cr.getMetaData().getName()); List<AnalysisEngine> annotators = pipeline.annotators(); assertEquals(0, annotators.size()); }