Skip to content

Commit

Permalink
update scoref to use enhanced UD
Browse files Browse the repository at this point in the history
  • Loading branch information
sebschu authored and Stanford NLP committed Jul 4, 2016
1 parent c066d09 commit 97208fd
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/edu/stanford/nlp/dcoref/Mention.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ public ArrayList<ArrayList<IndexedWord>> getPremodifiers(){
if(child.second().index() < headWord.index() if(child.second().index() < headWord.index()
&& !child.second.tag().equals("DT") && !child.second.tag().equals("WRB") && !child.second.tag().equals("DT") && !child.second.tag().equals("WRB")
&& !function.endsWith("det") && !function.equals("nummod") && !function.endsWith("det") && !function.equals("nummod")
&& !function.startsWith("acl") && !function.equals("advcl") && !function.startsWith("acl") && !function.startsWith("advcl")
&& !function.equals("punct")){ && !function.equals("punct")){
ArrayList<IndexedWord> phrase = new ArrayList<>(dependency.descendants(child.second())); ArrayList<IndexedWord> phrase = new ArrayList<>(dependency.descendants(child.second()));
Collections.sort(phrase); Collections.sort(phrase);
Expand Down
20 changes: 10 additions & 10 deletions src/edu/stanford/nlp/hcoref/Preprocessor.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ private static void fillMentionInfo(Document doc, Dictionaries dict,
m.contextParseTree = sentence.get(TreeAnnotation.class); m.contextParseTree = sentence.get(TreeAnnotation.class);
// m.sentenceWords = sentence.get(TokensAnnotation.class); // m.sentenceWords = sentence.get(TokensAnnotation.class);
m.basicDependency = sentence.get(BasicDependenciesAnnotation.class); m.basicDependency = sentence.get(BasicDependenciesAnnotation.class);
m.collapsedDependency = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class); m.enhancedDependency = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
if (m.collapsedDependency == null) { if (m.enhancedDependency == null) {
m.collapsedDependency = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class); m.enhancedDependency = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
} }


// mentionSubTree (highest NP that has the same head) if constituency tree available // mentionSubTree (highest NP that has the same head) if constituency tree available
Expand Down Expand Up @@ -345,7 +345,7 @@ private static void fillMentionInfo(Document doc, Dictionaries dict,
private static void findSyntacticRelationsFromDependency(List<Mention> orderedMentions) { private static void findSyntacticRelationsFromDependency(List<Mention> orderedMentions) {
if(orderedMentions.size()==0) return; if(orderedMentions.size()==0) return;
markListMemberRelation(orderedMentions); markListMemberRelation(orderedMentions);
SemanticGraph dependency = orderedMentions.get(0).collapsedDependency; SemanticGraph dependency = orderedMentions.get(0).enhancedDependency;


// apposition // apposition
Set<Pair<Integer, Integer>> appos = Generics.newHashSet(); Set<Pair<Integer, Integer>> appos = Generics.newHashSet();
Expand Down Expand Up @@ -708,9 +708,9 @@ private static boolean findSpeaker(Document doc, int utterNum, int sentNum, List
String word = cl.word(); String word = cl.word();
if(dict.reportVerb.contains(lemma) && cl.tag().startsWith("V")) { if(dict.reportVerb.contains(lemma) && cl.tag().startsWith("V")) {
// find subject // find subject
SemanticGraph dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class); SemanticGraph dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
if (dependency == null) { if (dependency == null) {
dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class); dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
} }
IndexedWord w = dependency.getNodeByWordPattern(word); IndexedWord w = dependency.getNodeByWordPattern(word);


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


Expand Down Expand Up @@ -861,10 +861,10 @@ public static boolean isSpeaker(Mention m, Mention ant, Dictionaries dict) {
} }
if(countQuotationMark!=1) return false; if(countQuotationMark!=1) return false;


IndexedWord w = m.collapsedDependency.getNodeByWordPattern(m.sentenceWords.get(m.headIndex).get(CoreAnnotations.TextAnnotation.class)); IndexedWord w = m.enhancedDependency.getNodeByWordPattern(m.sentenceWords.get(m.headIndex).get(CoreAnnotations.TextAnnotation.class));
if(w== null) return false; if(w== null) return false;


for(Pair<GrammaticalRelation,IndexedWord> parent : m.collapsedDependency.parentPairs(w)){ for(Pair<GrammaticalRelation,IndexedWord> parent : m.enhancedDependency.parentPairs(w)){
if(parent.first().getShortName().equals("nsubj") if(parent.first().getShortName().equals("nsubj")
&& dict.reportVerb.contains(parent.second().get(CoreAnnotations.LemmaAnnotation.class))) { && dict.reportVerb.contains(parent.second().get(CoreAnnotations.LemmaAnnotation.class))) {
return true; return true;
Expand Down
4 changes: 2 additions & 2 deletions src/edu/stanford/nlp/hcoref/SingletonPredictor.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public GeneralDataset<String, String> generateFeatureVectors(Properties props) t
// Ignore verbal mentions // Ignore verbal mentions
if(mention.headWord.tag().startsWith("V")) continue; if(mention.headWord.tag().startsWith("V")) continue;


IndexedWord head = mention.collapsedDependency. IndexedWord head = mention.enhancedDependency.
getNodeByIndexSafe(mention.headWord.index()); getNodeByIndexSafe(mention.headWord.index());
if(head == null) continue; if(head == null) continue;
ArrayList<String> feats = mention.getSingletonFeatures(dict); ArrayList<String> feats = mention.getSingletonFeatures(dict);
Expand All @@ -103,7 +103,7 @@ public GeneralDataset<String, String> generateFeatureVectors(Properties props) t
gold_heads.add(gold_men.headWord); gold_heads.add(gold_men.headWord);
} }
for(Mention predicted_men : document.predictedMentionsByID.values()){ for(Mention predicted_men : document.predictedMentionsByID.values()){
SemanticGraph dep = predicted_men.collapsedDependency; SemanticGraph dep = predicted_men.enhancedDependency;
IndexedWord head = dep.getNodeByIndexSafe(predicted_men.headWord.index()); IndexedWord head = dep.getNodeByIndexSafe(predicted_men.headWord.index());
if(head == null || !dep.vertexSet().contains(head)) continue; if(head == null || !dep.vertexSet().contains(head)) continue;


Expand Down
Loading

0 comments on commit 97208fd

Please sign in to comment.