Java Code Examples for de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency#setDependencyType()
The following examples show how to use
de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency#setDependencyType() .
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: Mate2StanfordDepConverter.java From ambiverse-nlu with Apache License 2.0 | 6 votes |
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { for (Dependency d : JCasUtil.select(jCas, Dependency.class)) { if (!d.getDependencyType().equals("--")) { GrammaticalRelation rel = relmaps.get(d.getDependencyType()); String s = rel.toString(); d.setDependencyType(s); } else { if (d.getDependencyType().equals("--") && d.getDependent().getBegin() == d.getGovernor().getBegin() && d.getDependent().getEnd() == d.getGovernor().getEnd()) { d.setDependencyType(GrammaticalRelation.ROOT.toString()); } } } }
Example 2
Source File: Tsv3XSerializerTest.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testRelation() throws Exception { // Create test document JCas cas = makeJCasOneSentence("This is a test ."); List<Token> tokens = new ArrayList<>(select(cas, Token.class)); Dependency dep = new Dependency(cas); dep.setGovernor(tokens.get(0)); dep.setDependent(tokens.get(1)); dep.setDependencyType("dep"); dep.setBegin(dep.getDependent().getBegin()); dep.setEnd(dep.getDependent().getEnd()); dep.addToIndexes(); // Set up TSV schema TsvSchema schema = new TsvSchema(); Type dependencyType = cas.getCasType(Dependency.type); schema.addColumn(new TsvColumn(dependencyType, LayerType.RELATION, "DependencyType", FeatureType.PRIMITIVE)); schema.addColumn(new TsvColumn(dependencyType, LayerType.RELATION, "Governor", FeatureType.RELATION_REF)); // Convert test document content to TSV model TsvDocument doc = Tsv3XCasDocumentBuilder.of(schema, cas); doc.getSentences().get(0).getTokens().get(1).addUimaAnnotation(dep, false); assertEquals( join(asList("1-1\t0-4\tThis\t_\t_\t", "1-2\t5-7\tis\tdep\t1-1\t"), "\n"), join(asList(doc.getToken(0, 0), doc.getToken(0, 1)), "\n")); String expectedSentence = "#Text=This is a test .\n" + "1-1\t0-4\tThis\t_\t_\t\n" + "1-2\t5-7\tis\tdep\t1-1\t\n" + "1-3\t8-9\ta\t_\t_\t\n" + "1-4\t10-14\ttest\t_\t_\t\n" + "1-5\t15-16\t.\t_\t_\t\n"; assertEquals(expectedSentence, doc.getSentences().get(0).toString()); }
Example 3
Source File: WebannoTsv1Reader.java From webanno with Apache License 2.0 | 4 votes |
/** * add dependency parsing to CAS */ private void createDependency(JCas aJCas, Map<Integer, String> tokens, Map<Integer, String> dependencyFunction, Map<Integer, Integer> dependencyDependent, Map<String, Token> tokensStored) { for (int i = 1; i <= tokens.size(); i++) { if (dependencyFunction.get(i) != null) { Dependency outDependency = new Dependency(aJCas); outDependency.setDependencyType(dependencyFunction.get(i)); // if span A has (start,end)= (20, 26) and B has (start,end)= (30, 36) // arc drawn from A to B, dependency will have (start, end) = (20, 36) // arc drawn from B to A, still dependency will have (start, end) = (20, 36) int begin = 0, end = 0; // if not ROOT if (dependencyDependent.get(i) != 0) { begin = tokensStored.get("t_" + i).getBegin() > tokensStored.get( "t_" + dependencyDependent.get(i)).getBegin() ? tokensStored.get( "t_" + dependencyDependent.get(i)).getBegin() : tokensStored.get( "t_" + i).getBegin(); end = tokensStored.get("t_" + i).getEnd() < tokensStored.get( "t_" + dependencyDependent.get(i)).getEnd() ? tokensStored.get( "t_" + dependencyDependent.get(i)).getEnd() : tokensStored .get("t_" + i).getEnd(); } else { begin = tokensStored.get("t_" + i).getBegin(); end = tokensStored.get("t_" + i).getEnd(); } outDependency.setBegin(begin); outDependency.setEnd(end); outDependency.setDependent(tokensStored.get("t_" + i)); if (dependencyDependent.get(i) == 0) { outDependency.setGovernor(tokensStored.get("t_" + i)); } else { outDependency.setGovernor(tokensStored.get("t_" + dependencyDependent.get(i))); } outDependency.addToIndexes(); } } }
Example 4
Source File: ConstraintsGeneratorTest.java From webanno with Apache License 2.0 | 4 votes |
@Test public void testSimplePath() throws Exception { ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream( "src/test/resources/rules/10.rules")); Parse p = parser.Parse(); ParsedConstraints constraints = p.accept(new ParserVisitor()); JCas jcas = JCasFactory.createJCas(); jcas.setDocumentText("The sun."); // Add token annotations Token t_the = new Token(jcas, 0, 3); t_the.addToIndexes(); Token t_sun = new Token(jcas, 0, 3); t_sun.addToIndexes(); // Add POS annotations and link them to the tokens POS p_the = new POS(jcas, t_the.getBegin(), t_the.getEnd()); p_the.setPosValue("DET"); p_the.addToIndexes(); t_the.setPos(p_the); POS p_sun = new POS(jcas, t_sun.getBegin(), t_sun.getEnd()); p_sun.setPosValue("NN"); p_sun.addToIndexes(); t_sun.setPos(p_sun); // Add dependency annotations Dependency dep_the_sun = new Dependency(jcas); dep_the_sun.setGovernor(t_sun); dep_the_sun.setDependent(t_the); dep_the_sun.setDependencyType("det"); dep_the_sun.setBegin(dep_the_sun.getGovernor().getBegin()); dep_the_sun.setEnd(dep_the_sun.getGovernor().getEnd()); dep_the_sun.addToIndexes(); Evaluator constraintsEvaluator = new ValuesGenerator(); List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues( dep_the_sun, "DependencyType", constraints); List<PossibleValue> expectedOutput = new LinkedList<>(); expectedOutput.add(new PossibleValue("det", false)); assertEquals(expectedOutput, possibleValues); }