Skip to content

Commit

Permalink
Get rid of setRelation - it was simply broken as the various edges mi…
Browse files Browse the repository at this point in the history
…ght be in Set or Map, and changing the relation would change the hash key
  • Loading branch information
AngledLuffa committed Mar 5, 2023
1 parent e3e01a5 commit e7a7657
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/edu/stanford/nlp/naturalli/NaturalLogicAnnotator.java
Expand Up @@ -394,7 +394,7 @@ private void addNegationToDependencyGraph(SemanticGraph tree) {
while (matcher.find()) {
IndexedWord gov = matcher.getNode("gov");
IndexedWord dep = matcher.getNode("quantifier");
tree.getEdge(gov, dep).setRelation(UniversalEnglishGrammaticalRelations.NEGATION_MODIFIER);
tree.updateEdge(tree.getEdge(gov, dep), UniversalEnglishGrammaticalRelations.NEGATION_MODIFIER);
}
// System.out.println("becomes");
// System.out.println(tree);
Expand Down
9 changes: 9 additions & 0 deletions src/edu/stanford/nlp/semgraph/SemanticGraph.java
Expand Up @@ -133,6 +133,15 @@ public boolean removeVertex(IndexedWord vertex) {
return graph.removeVertex(vertex);
}

public boolean updateEdge(SemanticGraphEdge edge, GrammaticalRelation reln) {
boolean removed = removeEdge(edge);
if (removed) {
SemanticGraphEdge newEdge = new SemanticGraphEdge(edge.getSource(), edge.getTarget(), reln, edge.getWeight(), edge.isExtra());
addEdge(newEdge);
}
return removed;
}

/**
* This returns an ordered list of vertices (based upon their
* indices in the sentence). This creates and sorts a list, so
Expand Down
6 changes: 1 addition & 5 deletions src/edu/stanford/nlp/semgraph/SemanticGraphEdge.java
Expand Up @@ -20,7 +20,7 @@ public class SemanticGraphEdge

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

private GrammaticalRelation relation;
private final GrammaticalRelation relation;
private final double weight;

private final boolean isExtra;
Expand Down Expand Up @@ -63,10 +63,6 @@ public GrammaticalRelation getRelation() {
return relation;
}

public void setRelation(GrammaticalRelation relation) {
this.relation = relation;
}

public IndexedWord getSource() {
return source;
}
Expand Down
Expand Up @@ -404,7 +404,7 @@ private static void addPassiveAgentToReln(SemanticGraph sg,
IndexedWord gov, IndexedWord mod, IndexedWord caseMarker) {

SemanticGraphEdge edge = sg.getEdge(gov, mod);
edge.setRelation(UniversalEnglishGrammaticalRelations.AGENT);
sg.updateEdge(edge, UniversalEnglishGrammaticalRelations.AGENT);
}


Expand Down Expand Up @@ -446,7 +446,7 @@ private static void addCaseMarkersToReln(SemanticGraph sg, IndexedWord gov, Inde
lastCaseMarkerIndex = cm.index();
}
GrammaticalRelation reln = getCaseMarkedRelation(edge.getRelation(), sb.toString().toLowerCase());
edge.setRelation(reln);
sg.updateEdge(edge, reln);
}

private static final SemgrexPattern PREP_CONJP_PATTERN = SemgrexPattern.compile("{} >/(case|mark)/ ({}=gov >conj ({} >cc {}=cc) >conj {}=conj)" +
Expand Down Expand Up @@ -752,7 +752,7 @@ private static void addConjToReln(SemanticGraph sg,
for (IndexedWord conjDep : conjDeps) {
SemanticGraphEdge edge = sg.getEdge(gov, conjDep);
if (edge.getRelation() == CONJUNCT || conjDep.index() > ccDep.index()) {
edge.setRelation(conjValue(ccDep, sg));
sg.updateEdge(edge, conjValue(ccDep, sg));
}
}
}
Expand Down Expand Up @@ -876,23 +876,23 @@ private static void convertRel(SemanticGraph sg) {
if (nmod.getGovernor().tag().startsWith("NN")
|| nmod.getGovernor().tag().startsWith("PRN")
|| nmod.getGovernor().tag().startsWith("DT")) {
nmod.setRelation(NOMINAL_MODIFIER);
sg.updateEdge(nmod, NOMINAL_MODIFIER);
} else {
nmod.setRelation(OBLIQUE_MODIFIER);
sg.updateEdge(nmod, OBLIQUE_MODIFIER);
}
}

break;
}

if ( ! changedPrep) {
prep.setRelation(OBLIQUE_MODIFIER);
if (!changedPrep) {
sg.updateEdge(prep, OBLIQUE_MODIFIER);
}
}

/* Rename remaining "rel" relations. */
for (SemanticGraphEdge edge : sg.findAllRelns(RELATIVE)) {
edge.setRelation(DIRECT_OBJECT);
sg.updateEdge(edge, DIRECT_OBJECT);
}
}

Expand Down
Expand Up @@ -411,7 +411,7 @@ public static void addCaseMarkerForConjunctions(SemanticGraph sg) {

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

edge.setRelation(reln);
sg.updateEdge(edge, reln);
}

/**
Expand Down Expand Up @@ -538,7 +538,7 @@ private static void addConjToReln(SemanticGraph sg,
if (relnName.matches("[^a-zA-Z_]")) {
continue;
}
edge.setRelation(UniversalGrammaticalRelations.getConj(relnName));
sg.updateEdge(edge, UniversalGrammaticalRelations.getConj(relnName));
}
}
}
Expand Down

0 comments on commit e7a7657

Please sign in to comment.