@Test public void testTypeUsageInformation() throws Exception { String script = "TYPE typeVar;\n"; script += "CW{-> FalsePositive};\n"; script += "RETAINTYPE(WS);\n"; script += "DECLARE Type1;\n"; script += "org.apache.uima.ruta.type.FalseNegative;\n"; script += "BLOCK(block) Document{}{\n"; script += "DECLARE Type2;\n"; script += "SW.ct==\"a\"{-> CREATE(RutaAnnotation, \"score\"= W.begin)};\n"; script += "}\n"; AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, RutaEngine.PARAM_VAR_NAMES, new String[] { "typeVar" }, RutaEngine.PARAM_VAR_VALUES, new String[] { "TruePositive" }, RutaEngine.PARAM_RULES, script, RutaEngine.PARAM_INDEX_ONLY_MENTIONED_TYPES, Boolean.valueOf(true), RutaEngine.PARAM_INDEX_ADDITONALLY, new String[] { "COMMA" }); RutaEngine engine = (RutaEngine) FieldUtils.readField(ae, "mAnalysisComponent", true); TypeUsageInformation typeUsageInformation = (TypeUsageInformation) FieldUtils.readField(engine, "typeUsageInformation", true); List<String> mentionedTypes = typeUsageInformation.getMentionedTypes(); Collections.sort(mentionedTypes); Assert.assertEquals( Arrays.asList("COMMA", "CW", "Document", "Document", "SW", "SW.ct", "TruePositive", "W", "W.begin", "WS", "org", "org.apache", "org.apache.uima", "org.apache.uima.ruta", "org.apache.uima.ruta.type", "org.apache.uima.ruta.type.BREAK", "org.apache.uima.ruta.type.FalseNegative", "org.apache.uima.ruta.type.MARKUP", "org.apache.uima.ruta.type.SPACE", "uima.tcas.DocumentAnnotation"), mentionedTypes); CAS cas = RutaTestUtils.getCAS("This is a test."); JCas jcas = cas.getJCas(); ae.process(jcas); Collection<String> usedTypes = typeUsageInformation.getUsedTypes(); List<String> usedTypesList = new ArrayList<>(usedTypes); Collections.sort(usedTypesList); Assert.assertEquals(Arrays.asList("org.apache.uima.ruta.type.BREAK", "org.apache.uima.ruta.type.COMMA", "org.apache.uima.ruta.type.CW", "org.apache.uima.ruta.type.FalseNegative", "org.apache.uima.ruta.type.MARKUP", "org.apache.uima.ruta.type.SPACE", "org.apache.uima.ruta.type.SW", "org.apache.uima.ruta.type.TruePositive", "org.apache.uima.ruta.type.W", "org.apache.uima.ruta.type.WS", "uima.tcas.DocumentAnnotation"), usedTypesList); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { CAS cas = jcas.getCas(); if (reloadScript || (!initialized && !cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) { initializeScript(cas.getViewName()); } else { resetEnvironments(cas); initializeVariableValues(); } boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem(); if (!initialized || reloadScript || typeSystemChanged) { initializeTypes(script, cas, new ArrayList<String>()); if (typeUsageInformation != null) { typeUsageInformation.resolveTypes(script, cas.getTypeSystem()); } initialized = true; lastTypeSystem = cas.getTypeSystem(); } InferenceCrowd crowd = initializeCrowd(); RutaStream stream = initializeStream(cas, crowd); stream.setDynamicAnchoring(dynamicAnchoring); stream.setGreedyRuleElement(greedyRuleElement); stream.setGreedyRule(greedyRule); stream.setMaxRuleMatches(maxRuleMatches); stream.setMaxRuleElementMatches(maxRuleElementMatches); try { script.apply(stream, crowd); } catch (Throwable e) { throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, new Object[] {}, e); } crowd.finished(stream); if (removeBasics) { jcas.removeAllIncludingSubtypes(RutaBasic.type); jcas.removeAllIncludingSubtypes(TokenSeed.type); List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>(); for (Type seedType : seedTypes) { AnnotationIndex<AnnotationFS> seedIndex = cas.getAnnotationIndex(seedType); for (AnnotationFS fs : seedIndex) { toRemove.add(fs); } } for (AnnotationFS annotationFS : toRemove) { cas.removeFsFromIndexes(annotationFS); } } }
RutaEngine extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { CAS cas = jcas.getCas(); if (reloadScript || (!initialized && !cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) { initializeScript(cas.getViewName()); } else { resetEnvironments(cas); initializeVariableValues(); } boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem(); if (!initialized || reloadScript || typeSystemChanged) { initializeTypes(script, cas, new ArrayList<String>()); if (typeUsageInformation != null) { typeUsageInformation.resolveTypes(script, cas.getTypeSystem()); } initialized = true; lastTypeSystem = cas.getTypeSystem(); } InferenceCrowd crowd = initializeCrowd(); RutaStream stream = initializeStream(cas, crowd); stream.setDynamicAnchoring(dynamicAnchoring); stream.setGreedyRuleElement(greedyRuleElement); stream.setGreedyRule(greedyRule); stream.setMaxRuleMatches(maxRuleMatches); stream.setMaxRuleElementMatches(maxRuleElementMatches); try { script.apply(stream, crowd); } catch (Throwable e) { throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, new Object[] {}, e); } crowd.finished(stream); if (removeBasics) { jcas.removeAllIncludingSubtypes(RutaBasic.type); jcas.removeAllIncludingSubtypes(TokenSeed.type); List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>(); for (Type seedType : seedTypes) { AnnotationIndex<AnnotationFS> seedIndex = cas.getAnnotationIndex(seedType); for (AnnotationFS fs : seedIndex) { toRemove.add(fs); } } for (AnnotationFS annotationFS : toRemove) { cas.removeFsFromIndexes(annotationFS); } } } }
RutaEngine extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { CAS cas = jcas.getCas(); if (reloadScript || (!initialized && !cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) { initializeScript(cas.getViewName()); } else { resetEnvironments(cas); initializeVariableValues(); } boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem(); if (!initialized || reloadScript || typeSystemChanged) { initializeTypes(script, cas, new ArrayList<String>()); if (typeUsageInformation != null) { typeUsageInformation.resolveTypes(script, cas.getTypeSystem()); } initialized = true; lastTypeSystem = cas.getTypeSystem(); } InferenceCrowd crowd = initializeCrowd(); RutaStream stream = initializeStream(cas, crowd); stream.setDynamicAnchoring(dynamicAnchoring); stream.setGreedyRuleElement(greedyRuleElement); stream.setGreedyRule(greedyRule); stream.setMaxRuleMatches(maxRuleMatches); stream.setMaxRuleElementMatches(maxRuleElementMatches); try { script.apply(stream, crowd); } catch (Throwable e) { throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, new Object[] {}, e); } crowd.finished(stream); if (removeBasics) { jcas.removeAllIncludingSubtypes(RutaBasic.type); jcas.removeAllIncludingSubtypes(TokenSeed.type); List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>(); for (Type seedType : seedTypes) { AnnotationIndex<AnnotationFS> seedIndex = cas.getAnnotationIndex(seedType); for (AnnotationFS fs : seedIndex) { toRemove.add(fs); } } for (AnnotationFS annotationFS : toRemove) { cas.removeFsFromIndexes(annotationFS); } } }  }
RutaEngine extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { CAS cas = jcas.getCas(); if (reloadScript || (!initialized && !cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) { initializeScript(cas.getViewName()); } else { resetEnvironments(cas); initializeVariableValues(); } boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem(); if (!initialized || reloadScript || typeSystemChanged) { initializeTypes(script, cas, new ArrayList<String>()); if (typeUsageInformation != null) { typeUsageInformation.resolveTypes(script, cas.getTypeSystem()); } initialized = true; lastTypeSystem = cas.getTypeSystem(); } InferenceCrowd crowd = initializeCrowd(); RutaStream stream = initializeStream(cas, crowd); stream.setDynamicAnchoring(dynamicAnchoring); stream.setGreedyRuleElement(greedyRuleElement); stream.setGreedyRule(greedyRule); stream.setMaxRuleMatches(maxRuleMatches); stream.setMaxRuleElementMatches(maxRuleElementMatches); try { script.apply(stream, crowd); } catch (Throwable e) { throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, new Object[] {}, e); } crowd.finished(stream); if (removeBasics) { jcas.removeAllIncludingSubtypes(RutaBasic.type); jcas.removeAllIncludingSubtypes(TokenSeed.type); List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>(); for (Type seedType : seedTypes) { AnnotationIndex<AnnotationFS> seedIndex = cas.getAnnotationIndex(seedType); for (AnnotationFS fs : seedIndex) { toRemove.add(fs); } } for (AnnotationFS annotationFS : toRemove) { cas.removeFsFromIndexes(annotationFS); } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas); static void addSourceDocumentInformation(CAS cas, File each); static void removeSourceDocumentInformation(CAS cas); @Override void batchProcessComplete(); @Override void collectionProcessComplete(); @Override void destroy(); }
RutaEngine extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { CAS cas = jcas.getCas(); if (reloadScript || (!initialized && !cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) { initializeScript(cas.getViewName()); } else { resetEnvironments(cas); initializeVariableValues(); } boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem(); if (!initialized || reloadScript || typeSystemChanged) { initializeTypes(script, cas, new ArrayList<String>()); if (typeUsageInformation != null) { typeUsageInformation.resolveTypes(script, cas.getTypeSystem()); } initialized = true; lastTypeSystem = cas.getTypeSystem(); } InferenceCrowd crowd = initializeCrowd(); RutaStream stream = initializeStream(cas, crowd); stream.setDynamicAnchoring(dynamicAnchoring); stream.setGreedyRuleElement(greedyRuleElement); stream.setGreedyRule(greedyRule); stream.setMaxRuleMatches(maxRuleMatches); stream.setMaxRuleElementMatches(maxRuleElementMatches); try { script.apply(stream, crowd); } catch (Throwable e) { throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, new Object[] {}, e); } crowd.finished(stream); if (removeBasics) { jcas.removeAllIncludingSubtypes(RutaBasic.type); jcas.removeAllIncludingSubtypes(TokenSeed.type); List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>(); for (Type seedType : seedTypes) { AnnotationIndex<AnnotationFS> seedIndex = cas.getAnnotationIndex(seedType); for (AnnotationFS fs : seedIndex) { toRemove.add(fs); } } for (AnnotationFS annotationFS : toRemove) { cas.removeFsFromIndexes(annotationFS); } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas); static void addSourceDocumentInformation(CAS cas, File each); static void removeSourceDocumentInformation(CAS cas); @Override void batchProcessComplete(); @Override void collectionProcessComplete(); @Override void destroy(); static final String SCRIPT_FILE_EXTENSION; static final String SEPARATOR_VAR_VALUES; static final String SOURCE_DOCUMENT_INFORMATION; static final String BASIC_TYPE; static final String OPTIONAL_TYPE; static final String FRAME_TYPE; static final String PARAM_RULES; static final String PARAM_RULES_SCRIPT_NAME; static final String PARAM_MAIN_SCRIPT; static final String PARAM_SCRIPT_ENCODING; static final String PARAM_SCRIPT_PATHS; static final String PARAM_DESCRIPTOR_PATHS; static final String PARAM_RESOURCE_PATHS; static final String PARAM_ADDITIONAL_SCRIPTS; static final String PARAM_ADDITIONAL_ENGINES; static final String PARAM_ADDITIONAL_UIMAFIT_ENGINES; static final String PARAM_ADDITIONAL_EXTENSIONS; static final String PARAM_RELOAD_SCRIPT; static final String PARAM_SEEDERS; static final String PARAM_DEFAULT_FILTERED_TYPES; static final String PARAM_REMOVE_BASICS; static final String PARAM_DYNAMIC_ANCHORING; static final String PARAM_LOW_MEMORY_PROFILE; static final String PARAM_SIMPLE_GREEDY_FOR_COMPOSED; static final String PARAM_GREEDY_RULE_ELEMENT; static final String PARAM_GREEDY_RULE; static final String PARAM_DEBUG; static final String PARAM_DEBUG_WITH_MATCHES; static final String PARAM_DEBUG_ONLY_FOR; static final String PARAM_PROFILE; static final String PARAM_STATISTICS; static final String PARAM_CREATED_BY; static final String PARAM_STRICT_IMPORTS; static final String PARAM_DICT_REMOVE_WS; static final String PARAM_CSV_SEPARATOR; static final String PARAM_VAR_NAMES; static final String PARAM_VAR_VALUES; static final String PARAM_REINDEX_ONLY; static final String PARAM_REINDEX_ONLY_MENTIONED_TYPES; static final String PARAM_INDEX_ONLY_MENTIONED_TYPES; static final String PARAM_INDEX_ADDITONALLY; static final String PARAM_EMPTY_IS_INVISIBLE; static final String PARAM_MODIFY_DATAPATH; static final String PARAM_INFERENCE_VISITORS; static final String PARAM_MAX_RULE_MATCHES; static final String PARAM_MAX_RULE_ELEMENT_MATCHES; }