List of usage examples for edu.stanford.nlp.trees EnglishGrammaticalRelations NOMINAL_SUBJECT
GrammaticalRelation NOMINAL_SUBJECT
To view the source code for edu.stanford.nlp.trees EnglishGrammaticalRelations NOMINAL_SUBJECT.
Click Source Link
From source file:featureExtractor.NLPFeatures.java
static void processLine(String text, int lineId) throws IOException { bw_root.write(Integer.toString(lineId)); bw_subj.write(Integer.toString(lineId)); bw_underRoot.write(Integer.toString(lineId)); bw_nerType.write(Integer.toString(lineId)); //text = "A gigantic Hong Kong set was constructed in downtown Detroit. The set was so big that the Detroit People Mover track ended up becoming part of the set and shooting had to be adjusted to allow the track to move through the set. ";//"One of three new television series scheduled for release in 2014 based on DC Comics characters. The others being Constantine (2014) and The Flash (2014). "; HashMap<String, Integer> nerCount = new HashMap<>(); int superlativePOS = 0; try {/*from w w w. j a v a2 s. c om*/ Annotation document = new Annotation(text); pipeline.annotate(document); List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { SemanticGraph dependencies = sentence .get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class); // getting root words for (IndexedWord rword : dependencies.getRoots()) { //System.out.println(rword.lemma()); //System.out.println(rword.ner()); if (rword.ner().equals("O")) bw_root.write("\t" + rword.ner() + ":" + rword.lemma()); //else if(rword.ner().equals("PERSON")) else bw_root.write("\t" + rword.ner() + ":" + rword.originalText()); /* else bw_root.write(" entity_" + rword.ner()); */ // under root for (IndexedWord child : dependencies.getChildren(rword)) { //System.out.println("here: " + child.originalText()); /* if(child.ner().equals("PERSON")) bw_underRoot.write(" " + child.originalText()); else*/ if (!child.ner().equals("O")) bw_underRoot.write("\t" + child.ner() + ":" + child.originalText()); } // nsubj | nsubpass words GrammaticalRelation[] subjects = { EnglishGrammaticalRelations.NOMINAL_SUBJECT, EnglishGrammaticalRelations.NOMINAL_PASSIVE_SUBJECT }; for (IndexedWord current : dependencies.descendants(rword)) for (IndexedWord nsubWord : dependencies.getChildrenWithRelns(current, Arrays.asList(subjects))) { //System.out.println("wow: " + nsubWord.originalText()); if (!nsubWord.ner().equals("O")) bw_subj.write("\t" + nsubWord.ner() + ":" + nsubWord.originalText()); else { //System.out.println(nsubWord.lemma()); bw_subj.write("\t" + nsubWord.ner() + ":" + nsubWord.lemma()); } /* else bw_subj.write(" entity_"+nsubWord.ner()); */ } } // NER Types frequency for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class); if (pos.equals("JJS") || pos.equals("RBS")) superlativePOS++; nerCount.putIfAbsent(ne, 0); nerCount.put(ne, nerCount.get(ne) + 1); } //System.out.println("dependency graph:\n" + dependencies); } } catch (Exception e) { System.out.println("IGNORED:"); } bw_nerType.write("\t" + Integer.toString(superlativePOS)); for (String ne : ners) { if (nerCount.containsKey(ne)) bw_nerType.write("\t" + nerCount.get(ne).toString()); else bw_nerType.write("\t0"); } bw_root.write("\n"); bw_underRoot.write("\n"); bw_nerType.write("\n"); bw_subj.write("\n"); if (lineId % 25 == 0) { bw_root.flush(); bw_underRoot.flush(); bw_nerType.flush(); bw_subj.flush(); } }
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 v a 2s. c om*/ }
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. j ava2s.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 getModal(Dictionaries dict) { if (headIndexedWord == null) return 0; // direct modal in a child Collection<IndexedWord> children = dependency.getChildren(headIndexedWord); for (IndexedWord child : children) { if (dict.modals.contains(child.lemma())) return 1; }//w ww . j a va2 s . c o m // check the parent IndexedWord parent = dependency.getParent(headIndexedWord); if (parent != null) { if (dict.modals.contains(parent.lemma())) return 1; // check the children of the parent (that is needed for modal auxiliaries) IndexedWord child = dependency.getChildWithReln(parent, EnglishGrammaticalRelations.AUX_MODIFIER); if (!dependency.hasParentWithReln(headIndexedWord, EnglishGrammaticalRelations.NOMINAL_SUBJECT) && child != null && dict.modals.contains(child.lemma())) return 1; } // look at the path to root List<IndexedWord> path = dependency.getPathToRoot(headIndexedWord); if (path == null) return 0; for (IndexedWord word : path) { if (dict.modals.contains(word.lemma())) return 1; } return 0; }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
public int getReportEmbedding(Dictionaries dict) { if (headIndexedWord == null) return 0; // check adverbial clause with marker "as" Collection<IndexedWord> siblings = dependency.getSiblings(headIndexedWord); for (IndexedWord sibling : siblings) { if (dict.reportVerb.contains(sibling.lemma()) && dependency.hasParentWithReln(sibling, EnglishGrammaticalRelations.ADV_CLAUSE_MODIFIER)) { IndexedWord marker = dependency.getChildWithReln(sibling, EnglishGrammaticalRelations.MARKER); if (marker != null && marker.lemma().equals("as")) { return 1; }/*from w w w . j a va 2s . c o m*/ } } // look at the path to root List<IndexedWord> path = dependency.getPathToRoot(headIndexedWord); if (path == null) return 0; boolean isSubject = false; // if the node itself is a subject, we will not take into account its parent in the path if (dependency.hasParentWithReln(headIndexedWord, EnglishGrammaticalRelations.NOMINAL_SUBJECT)) isSubject = true; for (IndexedWord word : path) { if (!isSubject && (dict.reportVerb.contains(word.lemma()) || dict.reportNoun.contains(word.lemma()))) { return 1; } // check how to put isSubject isSubject = dependency.hasParentWithReln(word, EnglishGrammaticalRelations.NOMINAL_SUBJECT); } return 0; }