Skip to content

Commit

Permalink
Fix spelling mistake, make some methods static.
Browse files Browse the repository at this point in the history
  • Loading branch information
manning authored and Stanford NLP committed Jun 11, 2016
1 parent 8b56a5b commit 84c4040
Show file tree
Hide file tree
Showing 29 changed files with 157 additions and 688 deletions.
7 changes: 6 additions & 1 deletion itest/src/edu/stanford/nlp/naturalli/OpenIEITest.java
Expand Up @@ -126,6 +126,12 @@ public void testExtractionsObamaWikiOne() {
add("Barack Hussein Obama II\tis\tPresident");
// add("Barack Hussein Obama II\tis\tcurrent President");
add("Barack Hussein Obama II\tis\t44th President");
// These are a bit fishy...
add("first African American\thold\toffice");
add("first American\thold\toffice");
add("African American\thold\toffice");
add("American\thold\toffice");
// End odd extractions
}}, "Barack Hussein Obama II is the 44th and current President of the United States, and the first African American to hold the office.");
}

Expand All @@ -145,7 +151,6 @@ public void testExtractionsObamaWikiTwo() {
}

@Test
@Ignore // TODO(gabor) why does this fail? [2016-06-07]
public void testExtractionsObamaWikiThree() {
assertExtracted(new HashSet<String>() {{
add("He\twas\tcommunity organizer in Chicago");
Expand Down
3 changes: 0 additions & 3 deletions src/edu/stanford/nlp/dcoref/ACEMentionExtractor.java
Expand Up @@ -177,9 +177,6 @@ private void extractGoldMentions(CoreMap s, List<List<Mention>> allGoldMentions,
for(EntityMention e : treeForSortGoldMentions){
Mention men = new Mention();
men.dependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (men.dependency == null) {
men.dependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}
men.startIndex = e.getExtentTokenStart();
men.endIndex = e.getExtentTokenEnd();

Expand Down
9 changes: 0 additions & 9 deletions src/edu/stanford/nlp/hcoref/Preprocessor.java
Expand Up @@ -302,9 +302,6 @@ private static void fillMentionInfo(Document doc, Dictionaries dict,
// m.sentenceWords = sentence.get(TokensAnnotation.class);
m.basicDependency = sentence.get(BasicDependenciesAnnotation.class);
m.collapsedDependency = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (m.collapsedDependency == null) {
m.collapsedDependency = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}

// mentionSubTree (highest NP that has the same head) if constituency tree available
if (m.contextParseTree != null) {
Expand Down Expand Up @@ -709,9 +706,6 @@ private static boolean findSpeaker(Document doc, int utterNum, int sentNum, List
if(dict.reportVerb.contains(lemma) && cl.tag().startsWith("V")) {
// find subject
SemanticGraph dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (dependency == null) {
dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}
IndexedWord w = dependency.getNodeByWordPattern(word);

if (w != null) {
Expand Down Expand Up @@ -826,9 +820,6 @@ private static String findNextParagraphSpeaker(Document doc, List<CoreMap> parag
if(w.get(CoreAnnotations.LemmaAnnotation.class).equals("report") || w.get(CoreAnnotations.LemmaAnnotation.class).equals("say")) {
String word = w.get(CoreAnnotations.TextAnnotation.class);
SemanticGraph dependency = lastSent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (dependency == null) {
dependency = lastSent.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}
IndexedWord t = dependency.getNodeByWordPattern(word);

for(Pair<GrammaticalRelation,IndexedWord> child : dependency.childPairs(t)){
Expand Down
14 changes: 2 additions & 12 deletions src/edu/stanford/nlp/hcoref/md/CorefMentionFinder.java
Expand Up @@ -66,9 +66,6 @@ protected static void extractPremarkedEntityMentions(CoreMap s, List<Mention> me
List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsedDependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsedDependency == null) {
collapsedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}
int beginIndex = -1;
for (CoreLabel w : sent) {
MultiTokenTag t = w.get(CoreAnnotations.MentionTokenAnnotation.class);
Expand Down Expand Up @@ -107,9 +104,6 @@ protected static void extractEnumerations(CoreMap s, List<Mention> mentions, Set
Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class);
SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsedDependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsedDependency == null) {
collapsedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}

TregexPattern tgrepPattern = enumerationsMentionPattern;
TregexMatcher matcher = tgrepPattern.matcher(tree);
Expand Down Expand Up @@ -352,9 +346,7 @@ protected static void extractNamedEntityModifiers(List<CoreMap> sentences, List<
int dummyMentionId = -1;
Mention m = new Mention(dummyMentionId, beginIndex, endIndex, tokens,
sent.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class),
sent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class) != null
? sent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class)
: sent.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class),
sent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class),
new ArrayList<>(tokens.subList(beginIndex, endIndex)));
mentions.add(m);
mentionSpanSet.add(span);
Expand Down Expand Up @@ -397,9 +389,7 @@ protected static void addGoldMentions(List<CoreMap> sentences,
int dummyMentionId = -1;
Mention m = new Mention(dummyMentionId, g.startIndex, g.endIndex, tokens,
sent.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class),
sent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class) != null
? sent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class)
: sent.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class),
sent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class),
new ArrayList<>(tokens.subList(g.startIndex, g.endIndex)));
mentions.add(m);
mentionSpanSet.add(pair);
Expand Down
Expand Up @@ -142,10 +142,7 @@ private void extractMentionForHeadword(IndexedWord headword, SemanticGraph dep,
List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
SemanticGraph basic = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsed = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsed == null) {
collapsed = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}


// pronoun
if(headword.tag().startsWith("PRP")) {
extractPronounForHeadword(headword, dep, s, mentions, mentionSpanSet, namedEntitySpanSet);
Expand Down Expand Up @@ -263,9 +260,6 @@ private void extractPronounForHeadword(IndexedWord headword, SemanticGraph dep,
List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
SemanticGraph basic = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsed = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsed == null) {
collapsed = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}
int beginIdx = headword.index()-1;
int endIdx = headword.index();

Expand Down
6 changes: 0 additions & 6 deletions src/edu/stanford/nlp/hcoref/md/HybridCorefMentionFinder.java
Expand Up @@ -80,9 +80,6 @@ protected static void extractNamedEntityMentions(CoreMap s, List<Mention> mentio
List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsedDependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsedDependency == null) {
collapsedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}
String preNE = "O";
int beginIndex = -1;
for(CoreLabel w : sent) {
Expand Down Expand Up @@ -165,9 +162,6 @@ private static void extractNPorPRP(CoreMap s, List<Mention> mentions, Set<IntPai
tree.indexLeaves();
SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsedDependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsedDependency == null) {
collapsedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}

TregexPattern tgrepPattern = npOrPrpMentionPattern;
TregexMatcher matcher = tgrepPattern.matcher(tree);
Expand Down
Expand Up @@ -118,9 +118,6 @@ public void extractNPorPRP(CoreMap s, List<Mention> mentions, Set<IntPair> menti
tree.indexLeaves();
SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsedDependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsedDependency == null) {
collapsedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}

TregexPattern tgrepPattern = npOrPrpMentionPattern;
TregexMatcher matcher = tgrepPattern.matcher(tree);
Expand Down Expand Up @@ -154,9 +151,6 @@ protected static void extractNamedEntityMentions(CoreMap s, List<Mention> mentio
List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
SemanticGraph collapsedDependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
if (collapsedDependency == null) {
collapsedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
}
String preNE = "O";
int beginIndex = -1;
for(CoreLabel w : sent) {
Expand Down Expand Up @@ -197,7 +191,7 @@ protected static void extractNamedEntityMentions(CoreMap s, List<Mention> mentio
}

/** Filter out all spurious mentions
*/
* @param goldMentionsByID */
@Override
public void removeSpuriousMentionsEn(Annotation doc, List<List<Mention>> predictedMentions, Dictionaries dict) {

Expand Down
2 changes: 1 addition & 1 deletion src/edu/stanford/nlp/ie/KBPSemgrexExtractor.java
Expand Up @@ -67,7 +67,7 @@ public Pair<String, Double> classify(KBPInput input) {
CoreMap sentence = input.sentence.asCoreMap(Sentence::nerTags, Sentence::dependencyGraph);
boolean matches
= matches(sentence, rulesForRel, input,
sentence.get(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class)) ||
sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class)) ||
matches(sentence, rulesForRel, input,
sentence.get(SemanticGraphCoreAnnotations.AlternativeDependenciesAnnotation.class));
if (matches) {
Expand Down
2 changes: 1 addition & 1 deletion src/edu/stanford/nlp/naturalli/ClauseSplitter.java
Expand Up @@ -113,7 +113,7 @@ static ClauseSplitter train(
CoreMap sentence = rawExample.first;
Collection<Pair<Span, Span>> spans = rawExample.second;
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
SemanticGraph tree = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
SemanticGraph tree = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
// Create raw clause searcher (no classifier)
ClauseSplitterSearchProblem problem = new ClauseSplitterSearchProblem(tree, true);

Expand Down
Expand Up @@ -80,10 +80,6 @@ public class ClauseSplitterSearchProblem {
add("clone_nsubj");
add("simple");
}});
put("advcl:*", new ArrayList<String>() {{
add("clone_nsubj");
add("simple");
}});
put("conj:*", new ArrayList<String>() {{
add("clone_nsubj");
add("clone_dobj");
Expand Down
4 changes: 2 additions & 2 deletions src/edu/stanford/nlp/naturalli/CreateClauseDataset.java
Expand Up @@ -325,8 +325,8 @@ private static List<Pair<CoreMap, Collection<Pair<Span, Span>>>> processDirector
CoreMap sentence = new ArrayCoreMap(4) {{
set(CoreAnnotations.TokensAnnotation.class, tokens);
set(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class, graph);
set(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class, graph);
set(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class, graph);
set(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class, graph);
set(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class, graph);
}};
natlog.doOneSentence(null, sentence);

Expand Down
37 changes: 19 additions & 18 deletions src/edu/stanford/nlp/naturalli/NaturalLogicAnnotator.java
@@ -1,4 +1,4 @@
package edu.stanford.nlp.naturalli;
package edu.stanford.nlp.naturalli;
import edu.stanford.nlp.util.logging.Redwood;

import edu.stanford.nlp.ie.machinereading.structure.Span;
Expand Down Expand Up @@ -254,10 +254,10 @@ private static Pair<Integer, Integer> excludeFromSpan(Pair<Integer, Integer> spa
* <li>If we have a one-place quantifier, the object is allowed to absorb only prepositions from the pivot.</li>
* </ul>
*/
private OperatorSpec computeScope(SemanticGraph tree, Operator operator,
IndexedWord pivot, Pair<Integer, Integer> quantifierSpan,
IndexedWord subject, boolean isProperNounSubject, IndexedWord object,
int sentenceLength) {
private static OperatorSpec computeScope(SemanticGraph tree, Operator operator,
IndexedWord pivot, Pair<Integer, Integer> quantifierSpan,
IndexedWord subject, boolean isProperNounSubject, IndexedWord object,
int sentenceLength) {
Pair<Integer, Integer> subjSpan;
Pair<Integer, Integer> objSpan;
if (subject == null && object == null) {
Expand Down Expand Up @@ -306,7 +306,7 @@ private OperatorSpec computeScope(SemanticGraph tree, Operator operator,
* @param quantifier The word at which we matched a quantifier.
* @return An optional triple consisting of the particular quantifier we matched, as well as the span of that quantifier in the sentence.
*/
private Optional<Triple<Operator,Integer,Integer>> validateQuantiferByHead(CoreMap sentence, IndexedWord quantifier) {
private static Optional<Triple<Operator,Integer,Integer>> validateQuantifierByHead(CoreMap sentence, IndexedWord quantifier) {
// Some useful variables
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
Function<CoreLabel, String> glossFn = (label) -> "CD".equals(label.tag()) ? "--NUM--" : label.lemma();
Expand Down Expand Up @@ -341,7 +341,7 @@ private void annotateOperators(CoreMap sentence) {
SemanticGraph tree = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
if (tree == null) {
tree = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
tree = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
}
for (SemgrexPattern pattern : PATTERNS) {
SemgrexMatcher matcher = pattern.matcher(tree);
Expand Down Expand Up @@ -370,7 +370,7 @@ private void annotateOperators(CoreMap sentence) {
quantifierInfo = Optional.of(Triple.makeTriple(Operator.IMPLICIT_NAMED_ENTITY, quantifier.index(), quantifier.index())); // note: empty quantifier span given
} else {
// find the quantifier, and return some info about it.
quantifierInfo = validateQuantiferByHead(sentence, quantifier);
quantifierInfo = validateQuantifierByHead(sentence, quantifier);
}

// Awful hacks to regularize the subject of things like "one of" and "there are"
Expand Down Expand Up @@ -438,11 +438,11 @@ private void annotateOperators(CoreMap sentence) {
* Annotate any unary quantifiers that weren't found in the main {@link NaturalLogicAnnotator#annotateOperators(CoreMap)} method.
* @param sentence The sentence to annotate.
*/
private void annotateUnaries(CoreMap sentence) {
private static void annotateUnaries(CoreMap sentence) {
// Get tree and tokens
SemanticGraph tree = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
if (tree == null) {
tree = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
tree = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
}
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);

Expand Down Expand Up @@ -470,7 +470,7 @@ private void annotateUnaries(CoreMap sentence) {
IndexedWord subject = matcher.getNode("subject");
// ... If there is not already an operator there
if (!isOperator[quantifier.index() - 1]) {
Optional<Triple<Operator, Integer, Integer>> quantifierInfo = validateQuantiferByHead(sentence, quantifier);
Optional<Triple<Operator, Integer, Integer>> quantifierInfo = validateQuantifierByHead(sentence, quantifier);
// ... and if we found a quantifier span
if (quantifierInfo.isPresent()) {
// Then add the unary operator!
Expand Down Expand Up @@ -506,7 +506,7 @@ private void annotateUnaries(CoreMap sentence) {
*
* @param sentence As in {@link edu.stanford.nlp.naturalli.NaturalLogicAnnotator#doOneSentence(edu.stanford.nlp.pipeline.Annotation, edu.stanford.nlp.util.CoreMap)}
*/
private void annotatePolarity(CoreMap sentence) {
private static void annotatePolarity(CoreMap sentence) {
// Collect all the operators in this sentence
List<OperatorSpec> operators = new ArrayList<>();
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
Expand All @@ -527,13 +527,13 @@ private void annotatePolarity(CoreMap sentence) {
token.set(PolarityAnnotation.class, Polarity.DEFAULT);
}
}
if (sentence.containsKey(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class)) {
for (IndexedWord token : sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class).vertexSet()) {
if (sentence.containsKey(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class)) {
for (IndexedWord token : sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class).vertexSet()) {
token.set(PolarityAnnotation.class, Polarity.DEFAULT);
}
}
if (sentence.containsKey(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class)) {
for (IndexedWord token : sentence.get(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class).vertexSet()) {
if (sentence.containsKey(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class)) {
for (IndexedWord token : sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class).vertexSet()) {
token.set(PolarityAnnotation.class, Polarity.DEFAULT);
}
}
Expand Down Expand Up @@ -643,8 +643,9 @@ public Set<Class<? extends CoreAnnotation>> requires() {
CoreAnnotations.PartOfSpeechAnnotation.class,
CoreAnnotations.LemmaAnnotation.class,
SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class,
SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class,
SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class
SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class,
SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class
)));
}

}

0 comments on commit 84c4040

Please sign in to comment.