@Test public void testApply() throws Exception { URL typePrioritiesUrl = RutaTestUtils.class.getResource("TypePriorities.xml"); URL tsUrl = RutaTestUtils.class.getResource("BasicTypeSystem.xml"); Object descriptor = UIMAFramework.getXMLParser().parse(new XMLInputSource(tsUrl)); TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor; tsDesc.addType("uima.ruta.T1", "", "uima.tcas.Annotation"); tsDesc.addType("uima.ruta.T2", "", "uima.tcas.Annotation"); tsDesc.addType("uima.ruta.T3", "", "uima.tcas.Annotation"); tsDesc.resolveImports(); TypePriorities typePriorities = UIMAFramework.getXMLParser() .parseTypePriorities(new XMLInputSource(typePrioritiesUrl)); CAS cas = CasCreationUtils.createCas(tsDesc, typePriorities, new FsIndexDescription[0]); cas.setDocumentText("Some document."); Ruta.apply(cas, "CW{-> MARK(T1)} SW;"); AnnotationIndex<AnnotationFS> ai = null; FSIterator<AnnotationFS> iterator = null; ai = cas.getAnnotationIndex(cas.getTypeSystem().getType("uima.ruta.T1")); iterator = ai.iterator(); assertEquals(1, ai.size()); assertEquals("Some", iterator.next().getCoveredText()); Ruta.apply(cas, "T1 SW{-> MARK(T2)};"); ai = cas.getAnnotationIndex(cas.getTypeSystem().getType("uima.ruta.T2")); iterator = ai.iterator(); assertEquals(1, ai.size()); assertEquals("document", iterator.next().getCoveredText()); Ruta.apply(cas, "T1{-> MARK(T3,1,2,3)} T2 PERIOD;"); ai = cas.getAnnotationIndex(cas.getTypeSystem().getType("uima.ruta.T3")); iterator = ai.iterator(); assertEquals(1, ai.size()); assertEquals("Some document.", iterator.next().getCoveredText()); cas.release(); }
public static void apply(CAS cas, String script, Map<String, Object> parameters) throws IOException, InvalidXMLException, ResourceInitializationException, ResourceConfigurationException, AnalysisEngineProcessException, URISyntaxException { String viewName = cas.getViewName(); URL aedesc = RutaEngine.class.getResource("BasicEngine.xml"); AnalysisEngine ae = wrapAnalysisEngine(aedesc, viewName, null); File scriptFile = File.createTempFile("Ruta", RutaEngine.SCRIPT_FILE_EXTENSION); scriptFile.deleteOnExit(); FileUtils.saveString2File(script, scriptFile, "UTF-8"); ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile.getParentFile().getAbsolutePath() }); String name = scriptFile.getName().substring(0, scriptFile.getName().length() - 5); ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name); if (parameters != null) { for (Map.Entry<String, Object> parameter : parameters.entrySet()) { ae.setConfigParameterValue(parameter.getKey(), parameter.getValue()); } } ae.reconfigure(); ae.process(cas); scriptFile.delete(); ae.destroy(); }
Ruta { public static void apply(CAS cas, String script, Map<String, Object> parameters) throws IOException, InvalidXMLException, ResourceInitializationException, ResourceConfigurationException, AnalysisEngineProcessException, URISyntaxException { String viewName = cas.getViewName(); URL aedesc = RutaEngine.class.getResource("BasicEngine.xml"); AnalysisEngine ae = wrapAnalysisEngine(aedesc, viewName, null); File scriptFile = File.createTempFile("Ruta", RutaEngine.SCRIPT_FILE_EXTENSION); scriptFile.deleteOnExit(); FileUtils.saveString2File(script, scriptFile, "UTF-8"); ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile.getParentFile().getAbsolutePath() }); String name = scriptFile.getName().substring(0, scriptFile.getName().length() - 5); ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name); if (parameters != null) { for (Map.Entry<String, Object> parameter : parameters.entrySet()) { ae.setConfigParameterValue(parameter.getKey(), parameter.getValue()); } } ae.reconfigure(); ae.process(cas); scriptFile.delete(); ae.destroy(); } }
Ruta { public static void apply(CAS cas, String script, Map<String, Object> parameters) throws IOException, InvalidXMLException, ResourceInitializationException, ResourceConfigurationException, AnalysisEngineProcessException, URISyntaxException { String viewName = cas.getViewName(); URL aedesc = RutaEngine.class.getResource("BasicEngine.xml"); AnalysisEngine ae = wrapAnalysisEngine(aedesc, viewName, null); File scriptFile = File.createTempFile("Ruta", RutaEngine.SCRIPT_FILE_EXTENSION); scriptFile.deleteOnExit(); FileUtils.saveString2File(script, scriptFile, "UTF-8"); ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile.getParentFile().getAbsolutePath() }); String name = scriptFile.getName().substring(0, scriptFile.getName().length() - 5); ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name); if (parameters != null) { for (Map.Entry<String, Object> parameter : parameters.entrySet()) { ae.setConfigParameterValue(parameter.getKey(), parameter.getValue()); } } ae.reconfigure(); ae.process(cas); scriptFile.delete(); ae.destroy(); }  }
Ruta { public static void apply(CAS cas, String script, Map<String, Object> parameters) throws IOException, InvalidXMLException, ResourceInitializationException, ResourceConfigurationException, AnalysisEngineProcessException, URISyntaxException { String viewName = cas.getViewName(); URL aedesc = RutaEngine.class.getResource("BasicEngine.xml"); AnalysisEngine ae = wrapAnalysisEngine(aedesc, viewName, null); File scriptFile = File.createTempFile("Ruta", RutaEngine.SCRIPT_FILE_EXTENSION); scriptFile.deleteOnExit(); FileUtils.saveString2File(script, scriptFile, "UTF-8"); ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile.getParentFile().getAbsolutePath() }); String name = scriptFile.getName().substring(0, scriptFile.getName().length() - 5); ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name); if (parameters != null) { for (Map.Entry<String, Object> parameter : parameters.entrySet()) { ae.setConfigParameterValue(parameter.getKey(), parameter.getValue()); } } ae.reconfigure(); ae.process(cas); scriptFile.delete(); ae.destroy(); }  static void applyRule(JCas jcas, String rule, Object... configurationData); static void apply(CAS cas, String script, Map<String, Object> parameters); static void apply(CAS cas, String script); static void removeDebugInformation(JCas jcas); static String inject(String script, String placeholder, int[] addresses); static String inject(String script, FeatureStructureImpl... annotations); static List<Annotation> select(JCas jcas, String rule, Object... configurationData); static boolean matches(JCas jcas, String rule, Object... configurationData); static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String viewName,
          ResourceManager resourceManager); static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String viewName,
          boolean rutaEngine, String encoding, ResourceManager resourceManager); @Deprecated static AnalysisEngineDescription createAnalysisEngineDescription(String script); @Deprecated static AnalysisEngineDescription createAnalysisEngineDescription(String script,
          TypeSystemDescription... tsds); }
Ruta { public static void apply(CAS cas, String script, Map<String, Object> parameters) throws IOException, InvalidXMLException, ResourceInitializationException, ResourceConfigurationException, AnalysisEngineProcessException, URISyntaxException { String viewName = cas.getViewName(); URL aedesc = RutaEngine.class.getResource("BasicEngine.xml"); AnalysisEngine ae = wrapAnalysisEngine(aedesc, viewName, null); File scriptFile = File.createTempFile("Ruta", RutaEngine.SCRIPT_FILE_EXTENSION); scriptFile.deleteOnExit(); FileUtils.saveString2File(script, scriptFile, "UTF-8"); ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile.getParentFile().getAbsolutePath() }); String name = scriptFile.getName().substring(0, scriptFile.getName().length() - 5); ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name); if (parameters != null) { for (Map.Entry<String, Object> parameter : parameters.entrySet()) { ae.setConfigParameterValue(parameter.getKey(), parameter.getValue()); } } ae.reconfigure(); ae.process(cas); scriptFile.delete(); ae.destroy(); }  static void applyRule(JCas jcas, String rule, Object... configurationData); static void apply(CAS cas, String script, Map<String, Object> parameters); static void apply(CAS cas, String script); static void removeDebugInformation(JCas jcas); static String inject(String script, String placeholder, int[] addresses); static String inject(String script, FeatureStructureImpl... annotations); static List<Annotation> select(JCas jcas, String rule, Object... configurationData); static boolean matches(JCas jcas, String rule, Object... configurationData); static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String viewName,
          ResourceManager resourceManager); static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String viewName,
          boolean rutaEngine, String encoding, ResourceManager resourceManager); @Deprecated static AnalysisEngineDescription createAnalysisEngineDescription(String script); @Deprecated static AnalysisEngineDescription createAnalysisEngineDescription(String script,
          TypeSystemDescription... tsds);  }