Skip to content

Commit d9083ce

Browse files
committed
Print out EmptyIndex in the CoNLLUDocumentWriter if needed on enhanced dependency graphs. Currently, no special technique to separate copy nodes from empty nodes - presumably no conllu file will ever have both
1 parent d4162c6 commit d9083ce

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/edu/stanford/nlp/ling/IndexedWord.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,14 @@ public String toPrimes() {
370370
return StringUtils.repeat('\'', copyCount);
371371
}
372372

373-
public String toCopyIndex() {
373+
public String toCopyOrEmptyIndex() {
374+
// TODO: if there's ever a CoNLLU or other situation that has both
375+
// copy & empty indices, no idea what to do with such an abomination
374376
if (copyCount == 0) {
375-
if (Double.isNaN(this.pseudoPosition)) {
377+
Integer empty = this.get(CoreAnnotations.EmptyIndexAnnotation.class);
378+
if (empty != null) {
379+
return this.index() + "." + empty;
380+
} else if (Double.isNaN(this.pseudoPosition)) {
376381
return String.valueOf(this.index());
377382
} else {
378383
return String.valueOf(this.pseudoPosition);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public String printSemanticGraph(SemanticGraph basicSg, SemanticGraph enhancedSg
8181

8282
// Try to find main governor and additional dependencies
8383
IndexedWord gov = basicSg.containsVertex(token) ? basicSg.getParent(token) : null;
84-
String govIdx = gov != null ? gov.toCopyIndex() : null;
84+
String govIdx = gov != null ? gov.toCopyOrEmptyIndex() : null;
8585
GrammaticalRelation reln = gov != null ? basicSg.getEdge(gov, token).getRelation() : null;
8686

8787
HashMap<String, String> enhancedDependencies = new HashMap<>();
@@ -99,7 +99,7 @@ public String printSemanticGraph(SemanticGraph basicSg, SemanticGraph enhancedSg
9999
//} else if (edge.getWeight() == 5.0) {
100100
// relationString = relationString + ":ENH_CONJ_PROP";
101101
//}
102-
enhancedDependencies.put(parent.toCopyIndex(), relationString);
102+
enhancedDependencies.put(parent.toCopyOrEmptyIndex(), relationString);
103103
}
104104
} else {
105105
// add enhanced ones stored with token
@@ -165,7 +165,7 @@ public String printSemanticGraph(SemanticGraph basicSg, SemanticGraph enhancedSg
165165
lemma = lemma.replaceAll(RRB_PATTERN, ")");
166166
}
167167

168-
sb.append(String.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s%n", token.toCopyIndex(), word,
168+
sb.append(String.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s%n", token.toCopyOrEmptyIndex(), word,
169169
lemma, upos, pos, featuresString, govIdx, relnName, additionalDepsString, misc));
170170
}
171171
sb.append(System.lineSeparator());

0 commit comments

Comments
 (0)