@Test public void segmentAndTokenizeTest() throws Exception { TreexServerExecution tse = new TreexServerExecution(); tse.start(); TreexServerConnection conn = tse.getConnection(); conn.initScenario("cs", "W2A::Segment", "W2A::Tokenize"); Object ret = conn.analyzeText("Ahoj světe! Hallo world! Nula se píše jako 0 ."); conn.terminateServer(); List<Map<String, Object>> treexRet = Utils.objectArrayToGenericList(ret); Assert.assertEquals(treexRet.size(), 3); List<Object> nodes1 = Utils.objectArrayToGenericList(treexRet.get(0).get("nodes")); Assert.assertEquals(nodes1.size(), 3); List<Object> nodes2 = Utils.objectArrayToGenericList(treexRet.get(1).get("nodes")); Assert.assertEquals(nodes2.size(), 3); List<Object> nodes3 = Utils.objectArrayToGenericList(treexRet.get(2).get("nodes")); Assert.assertEquals(nodes3.size(), 6); @SuppressWarnings("unchecked") Map<String, Object> toc = (Map<String, Object>) nodes3.get(4); Assert.assertEquals(toc.get("ord"), "5"); Assert.assertEquals(toc.get("form"), "0"); }
@Override public void execute() throws ExecutionException { initBeforeExecute(); AnnotationSet tokensAndDependenciesAS = inputAS; TreeIndex index = new GateAwareTreeIndex( tokensAndDependenciesAS.get(null, Utils.setFromArray(new String[] {"args"}))); QueryData data = new QueryData(index, new GateAnnotationsNodeAttributes(tokensAndDependenciesAS)); Iterable<QueryMatch> results = queryObject.evaluate(data); int queryMatchOrd = 0; for (QueryMatch result : results) { queryMatchOrd++; for (NodeMatch match : result.getMatchingNodes()) { String name = match.getQueryNode().getName(); if (name != null) { Annotation matchingAnnot = tokensAndDependenciesAS.get(match.getNodeId()); FeatureMap fm = Factory.newFeatureMap(); fm.put("matchingNodeId", match.getNodeId()); fm.put( "queryMatchId", String.format("%s_%03d", buildQueryStringHash(getQueryString()), queryMatchOrd)); outputAS.add(matchingAnnot.getStartNode(), matchingAnnot.getEndNode(), name, fm); } } } }
@SuppressWarnings("unchecked") public static AnnotationDiffer computeDiffWithDocFeatures( Document document, List<String> featureNames, AnnotationSet responsesAnnotations) { FeatureMap doc_fm = document.getFeatures(); // Logger log = Logger.getLogger(DocumentFeaturesDiff.class); int correct = 0; int missing = 0; int spurious = 0; for (String feature_name : featureNames) { // int cur_correct = 0; List<String> f = (List<String>) doc_fm.get(feature_name); if (f == null) { f = (List<String>) doc_fm.get(feature_name + "s"); } AnnotationDiffer diff = computeDiffWithGoldStandardDataForSingleFeature( feature_name, Utils.setFromList(f), responsesAnnotations); spurious += diff.getSpurious(); correct += diff.getCorrectMatches(); missing += diff.getMissing(); } return new AnnotationDifferDocumentFeaturesImpl(correct, missing, spurious); }
@Test(groups = "slow") public void morceTest() throws Exception { TreexServerExecution tse = new TreexServerExecution(); tse.show_treex_output = true; tse.start(); TreexServerConnection conn = tse.getConnection(); conn.initScenario("en", "W2A::EN::Segment", "W2A::EN::Tokenize", "W2A::EN::TagMorce"); logger.debug("Before first sentence."); Object ret = conn.analyzeText("Hallo world!"); logger.debug("Before second sentence."); ret = conn.analyzeText("Life is great, isn't it?"); logger.debug("Second sentence finished!"); Object ret3 = conn.analyzeText("Zero is written as 0 ."); logger.debug("Third sentence finished!"); conn.terminateServer(); List<Map<String, Object>> treexRet = Utils.objectArrayToGenericList(ret); Assert.assertEquals(treexRet.size(), 1); List<Object> nodes1 = Utils.objectArrayToGenericList(treexRet.get(0).get("nodes")); Assert.assertEquals(nodes1.size(), 8); List<Map<String, Object>> treexRet3 = Utils.objectArrayToGenericList(ret3); Assert.assertEquals(treexRet.size(), 1); List<Object> nodes3 = Utils.objectArrayToGenericList(treexRet3.get(0).get("nodes")); Assert.assertEquals(nodes3.size(), 6); @SuppressWarnings("unchecked") Map<String, Object> toc = (Map<String, Object>) nodes3.get(4); Assert.assertEquals(toc.get("ord"), "5"); Assert.assertEquals(toc.get("form"), "0"); }
@BeforeClass public static void initLogger() { Utils.loggerSetup(Level.ALL); }