Skip to content

Commit e7a7657

Browse files
committed
Get rid of setRelation - it was simply broken as the various edges might be in Set or Map, and changing the relation would change the hash key
1 parent e3e01a5 commit e7a7657

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

src/edu/stanford/nlp/naturalli/NaturalLogicAnnotator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private void addNegationToDependencyGraph(SemanticGraph tree) {
394394
while (matcher.find()) {
395395
IndexedWord gov = matcher.getNode("gov");
396396
IndexedWord dep = matcher.getNode("quantifier");
397-
tree.getEdge(gov, dep).setRelation(UniversalEnglishGrammaticalRelations.NEGATION_MODIFIER);
397+
tree.updateEdge(tree.getEdge(gov, dep), UniversalEnglishGrammaticalRelations.NEGATION_MODIFIER);
398398
}
399399
// System.out.println("becomes");
400400
// System.out.println(tree);

src/edu/stanford/nlp/semgraph/SemanticGraph.java

+9
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ public boolean removeVertex(IndexedWord vertex) {
133133
return graph.removeVertex(vertex);
134134
}
135135

136+
public boolean updateEdge(SemanticGraphEdge edge, GrammaticalRelation reln) {
137+
boolean removed = removeEdge(edge);
138+
if (removed) {
139+
SemanticGraphEdge newEdge = new SemanticGraphEdge(edge.getSource(), edge.getTarget(), reln, edge.getWeight(), edge.isExtra());
140+
addEdge(newEdge);
141+
}
142+
return removed;
143+
}
144+
136145
/**
137146
* This returns an ordered list of vertices (based upon their
138147
* indices in the sentence). This creates and sorts a list, so

src/edu/stanford/nlp/semgraph/SemanticGraphEdge.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SemanticGraphEdge
2020

2121
public static boolean printOnlyRelation = false; // a hack for displaying SemanticGraph in JGraph. Should be redone better.
2222

23-
private GrammaticalRelation relation;
23+
private final GrammaticalRelation relation;
2424
private final double weight;
2525

2626
private final boolean isExtra;
@@ -63,10 +63,6 @@ public GrammaticalRelation getRelation() {
6363
return relation;
6464
}
6565

66-
public void setRelation(GrammaticalRelation relation) {
67-
this.relation = relation;
68-
}
69-
7066
public IndexedWord getSource() {
7167
return source;
7268
}

src/edu/stanford/nlp/trees/UniversalEnglishGrammaticalStructure.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ private static void addPassiveAgentToReln(SemanticGraph sg,
404404
IndexedWord gov, IndexedWord mod, IndexedWord caseMarker) {
405405

406406
SemanticGraphEdge edge = sg.getEdge(gov, mod);
407-
edge.setRelation(UniversalEnglishGrammaticalRelations.AGENT);
407+
sg.updateEdge(edge, UniversalEnglishGrammaticalRelations.AGENT);
408408
}
409409

410410

@@ -446,7 +446,7 @@ private static void addCaseMarkersToReln(SemanticGraph sg, IndexedWord gov, Inde
446446
lastCaseMarkerIndex = cm.index();
447447
}
448448
GrammaticalRelation reln = getCaseMarkedRelation(edge.getRelation(), sb.toString().toLowerCase());
449-
edge.setRelation(reln);
449+
sg.updateEdge(edge, reln);
450450
}
451451

452452
private static final SemgrexPattern PREP_CONJP_PATTERN = SemgrexPattern.compile("{} >/(case|mark)/ ({}=gov >conj ({} >cc {}=cc) >conj {}=conj)" +
@@ -752,7 +752,7 @@ private static void addConjToReln(SemanticGraph sg,
752752
for (IndexedWord conjDep : conjDeps) {
753753
SemanticGraphEdge edge = sg.getEdge(gov, conjDep);
754754
if (edge.getRelation() == CONJUNCT || conjDep.index() > ccDep.index()) {
755-
edge.setRelation(conjValue(ccDep, sg));
755+
sg.updateEdge(edge, conjValue(ccDep, sg));
756756
}
757757
}
758758
}
@@ -876,23 +876,23 @@ private static void convertRel(SemanticGraph sg) {
876876
if (nmod.getGovernor().tag().startsWith("NN")
877877
|| nmod.getGovernor().tag().startsWith("PRN")
878878
|| nmod.getGovernor().tag().startsWith("DT")) {
879-
nmod.setRelation(NOMINAL_MODIFIER);
879+
sg.updateEdge(nmod, NOMINAL_MODIFIER);
880880
} else {
881-
nmod.setRelation(OBLIQUE_MODIFIER);
881+
sg.updateEdge(nmod, OBLIQUE_MODIFIER);
882882
}
883883
}
884884

885885
break;
886886
}
887887

888-
if ( ! changedPrep) {
889-
prep.setRelation(OBLIQUE_MODIFIER);
888+
if (!changedPrep) {
889+
sg.updateEdge(prep, OBLIQUE_MODIFIER);
890890
}
891891
}
892892

893893
/* Rename remaining "rel" relations. */
894894
for (SemanticGraphEdge edge : sg.findAllRelns(RELATIVE)) {
895-
edge.setRelation(DIRECT_OBJECT);
895+
sg.updateEdge(edge, DIRECT_OBJECT);
896896
}
897897
}
898898

src/edu/stanford/nlp/trees/ud/UniversalGrammaticalStructure.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public static void addCaseMarkerForConjunctions(SemanticGraph sg) {
411411

412412
if (edge1.getRelation().toString().startsWith(relnName) && edge1.getRelation().getSpecific() != null) {
413413
changed = true;
414-
sg.getEdge(edge.getGovernor(), edge.getDependent(), edge.getRelation()).setRelation(edge1.getRelation());
414+
sg.updateEdge(edge, edge1.getRelation());
415415
break;
416416
}
417417
}
@@ -442,7 +442,7 @@ private static void addCaseMarkersToReln(SemanticGraph sg, IndexedWord gov, Inde
442442
//GrammaticalRelation reln = getCaseMarkedRelation(edge.getRelation(), relnName.toLowerCase() + ":ENH_CASE");
443443
GrammaticalRelation reln = getCaseMarkedRelation(edge.getRelation(), relnName.toLowerCase());
444444

445-
edge.setRelation(reln);
445+
sg.updateEdge(edge, reln);
446446
}
447447

448448
/**
@@ -538,7 +538,7 @@ private static void addConjToReln(SemanticGraph sg,
538538
if (relnName.matches("[^a-zA-Z_]")) {
539539
continue;
540540
}
541-
edge.setRelation(UniversalGrammaticalRelations.getConj(relnName));
541+
sg.updateEdge(edge, UniversalGrammaticalRelations.getConj(relnName));
542542
}
543543
}
544544
}

0 commit comments

Comments
 (0)