List of usage examples for edu.stanford.nlp.trees GrammaticalRelation toString
@Override public final String toString()
From source file:be.fivebyfive.lingua.stanfordcorenlp.PipelineDependency.java
License:Open Source License
public PipelineDependency(PipelineToken governor, PipelineToken dependent, int govIndex, int depIndex, GrammaticalRelation relation) { this.governor = governor; this.dependent = dependent; this.govIndex = govIndex; this.depIndex = depIndex; this.relation = relation.toString(); this.longRelation = relation.getLongName(); }
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.util.StanfordAnnotator.java
License:Open Source License
/** * Writes dependency annotations to the JCas * //from w w w .ja v a 2 s . c o m * @param jCas * a CAS. * @param aDependencyType * the dependency type * @param aGovernor * the governing-word * @param aDependent * the dependent-word */ public static void createDependencyAnnotation(JCas jCas, GrammaticalRelation aDependencyType, Token aGovernor, Token aDependent) { // create the necessary objects and methods String dependencyTypeName = DEPPACKAGE + aDependencyType.getShortName().toUpperCase(); Type type = jCas.getTypeSystem().getType(dependencyTypeName); if (type == null) { // Fall back to generic type. If we used a mapping provider, we'd do that too. type = JCasUtil.getType(jCas, Dependency.class); // throw new IllegalStateException("Type [" + dependencyTypeName + "] mapped to tag [" // + dependencyType + "] is not defined in type system"); } Dependency dep = (Dependency) jCas.getCas().createFS(type); dep.setDependencyType(aDependencyType.toString()); dep.setGovernor(aGovernor); dep.setDependent(aDependent); dep.setBegin(dep.getDependent().getBegin()); dep.setEnd(dep.getDependent().getEnd()); dep.addToIndexes(); }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
public String getRelation() { if (headIndexedWord == null) return null; if (dependency.getRoots().isEmpty()) return null; // root relation if (dependency.getFirstRoot().equals(headIndexedWord)) return "root"; if (!dependency.vertexSet().contains(dependency.getParent(headIndexedWord))) return null; GrammaticalRelation relation = dependency.reln(dependency.getParent(headIndexedWord), headIndexedWord); // adjunct relations if (relation.toString().startsWith("prep") || relation == EnglishGrammaticalRelations.PREPOSITIONAL_OBJECT || relation == EnglishGrammaticalRelations.TEMPORAL_MODIFIER || relation == EnglishGrammaticalRelations.ADV_CLAUSE_MODIFIER || relation == EnglishGrammaticalRelations.ADVERBIAL_MODIFIER || relation == EnglishGrammaticalRelations.PREPOSITIONAL_COMPLEMENT) return "adjunct"; // subject relations if (relation == EnglishGrammaticalRelations.NOMINAL_SUBJECT || relation == EnglishGrammaticalRelations.CLAUSAL_SUBJECT || relation == EnglishGrammaticalRelations.CONTROLLING_SUBJECT) return "subject"; if (relation == EnglishGrammaticalRelations.NOMINAL_PASSIVE_SUBJECT || relation == EnglishGrammaticalRelations.CLAUSAL_PASSIVE_SUBJECT) return "subject"; // verbal argument relations if (relation == EnglishGrammaticalRelations.ADJECTIVAL_COMPLEMENT || relation == EnglishGrammaticalRelations.CLAUSAL_COMPLEMENT || relation == EnglishGrammaticalRelations.XCLAUSAL_COMPLEMENT || relation == EnglishGrammaticalRelations.AGENT || relation == EnglishGrammaticalRelations.DIRECT_OBJECT || relation == EnglishGrammaticalRelations.INDIRECT_OBJECT) return "verbArg"; // noun argument relations if (relation == EnglishGrammaticalRelations.RELATIVE_CLAUSE_MODIFIER || relation == EnglishGrammaticalRelations.NOUN_COMPOUND_MODIFIER || relation == EnglishGrammaticalRelations.ADJECTIVAL_MODIFIER || relation == EnglishGrammaticalRelations.APPOSITIONAL_MODIFIER || relation == EnglishGrammaticalRelations.POSSESSION_MODIFIER) return "nounArg"; return null;//w w w . j a va 2s . c o m }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
public int getModifiers(Dictionaries dict) { if (headIndexedWord == null) return 0; int count = 0; List<Pair<GrammaticalRelation, IndexedWord>> childPairs = dependency.childPairs(headIndexedWord); for (Pair<GrammaticalRelation, IndexedWord> childPair : childPairs) { GrammaticalRelation gr = childPair.first; IndexedWord word = childPair.second; if (gr == EnglishGrammaticalRelations.ADJECTIVAL_MODIFIER || gr == EnglishGrammaticalRelations.VERBAL_MODIFIER || gr == EnglishGrammaticalRelations.RELATIVE_CLAUSE_MODIFIER || gr.toString().startsWith("prep_")) { count++;// w w w.j a v a 2 s.c o m } // add noun modifier when the mention isn't a NER if (nerString.equals("O") && gr == EnglishGrammaticalRelations.NOUN_COMPOUND_MODIFIER) { count++; } // add possessive if not a personal determiner if (gr == EnglishGrammaticalRelations.POSSESSION_MODIFIER && !dict.determiners.contains(word.lemma())) { count++; } } return count; }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
public int getNegation(Dictionaries dict) { if (headIndexedWord == null) return 0; // direct negation in a child Collection<IndexedWord> children = dependency.getChildren(headIndexedWord); for (IndexedWord child : children) { if (dict.negations.contains(child.lemma())) return 1; }//from w w w . ja v a2 s .c o m // or has a sibling Collection<IndexedWord> siblings = dependency.getSiblings(headIndexedWord); for (IndexedWord sibling : siblings) { if (dict.negations.contains(sibling.lemma()) && !dependency.hasParentWithReln(headIndexedWord, EnglishGrammaticalRelations.NOMINAL_SUBJECT)) return 1; } // check the parent List<Pair<GrammaticalRelation, IndexedWord>> parentPairs = dependency.parentPairs(headIndexedWord); if (!parentPairs.isEmpty()) { Pair<GrammaticalRelation, IndexedWord> parentPair = parentPairs.get(0); GrammaticalRelation gr = parentPair.first; // check negative prepositions if (dict.neg_relations.contains(gr.toString())) return 1; } return 0; }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
public int getCoordination() { if (headIndexedWord == null) return 0; Set<GrammaticalRelation> relations = dependency.childRelns(headIndexedWord); for (GrammaticalRelation rel : relations) { if (rel.toString().startsWith("conj_")) { return 1; }/*from ww w . ja v a2 s . c o m*/ } Set<GrammaticalRelation> parent_relations = dependency.relns(headIndexedWord); for (GrammaticalRelation rel : parent_relations) { if (rel.toString().startsWith("conj_")) { return 1; } } return 0; }
From source file:me.aatma.languagetologic.graph.pattern.KBNLPatternStateNsubj.java
public static List<Relation> check(KBNLNodeCloud from, IndexedWord i, GrammaticalRelation r) { List<Relation> semEdgePossibilities = new ArrayList<Relation>(); if (from instanceof KBNLStateNodeCloud && (r.toString().equals("agent") // Passive voice || r.toString().equals("nsubj") // Active voice - Unverified; Could be "agent" )) {// w ww . ja v a2 s .com // TODO: Check if the Constants.isa() replace is of correct argument signature // (type inst class) semEdgePossibilities.add(RDF_S.type); return semEdgePossibilities; } else { return null; } }