Skip to content

Commit ec5d719

Browse files
committed
Morphological features need to be in a TreeMap to keep them sorted by key
1 parent 27c6703 commit ec5d719

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.Map;
1010
import java.util.SortedSet;
11+
import java.util.TreeMap;
1112

1213
/**
1314
* Set of common annotations for {@link CoreMap}s. The classes
@@ -580,10 +581,10 @@ public Class<HashMap<String,String>> getType() {
580581
/**
581582
* CoNLL-U dep parsing - List of morphological features
582583
*/
583-
public static class CoNLLUFeats implements CoreAnnotation<HashMap<String,String>> {
584+
public static class CoNLLUFeats implements CoreAnnotation<TreeMap<String,String>> {
584585
@Override
585-
public Class<HashMap<String,String>> getType() {
586-
return ErasureUtils.uncheckedCast(HashMap.class);
586+
public Class<TreeMap<String,String>> getType() {
587+
return ErasureUtils.uncheckedCast(TreeMap.class);
587588
}
588589
}
589590

src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ public CoreLabel fromProto(CoreNLPProtos.Token proto) {
14531453
if (proto.hasSpan()) { word.set(SpanAnnotation.class, new IntPair(proto.getSpan().getBegin(), proto.getSpan().getEnd())); }
14541454
if (proto.hasSentiment()) { word.set(SentimentCoreAnnotations.SentimentClass.class, proto.getSentiment()); }
14551455
if (proto.hasQuotationIndex()) { word.set(QuotationIndexAnnotation.class, proto.getQuotationIndex()); }
1456-
if (proto.hasConllUFeatures()) { word.set(CoNLLUFeats.class, fromProto(proto.getConllUFeatures())); }
1456+
if (proto.hasConllUFeatures()) { word.set(CoNLLUFeats.class, new TreeMap<>(fromProto(proto.getConllUFeatures()))); }
14571457
if (proto.hasConllUMisc()) { word.set(CoNLLUMisc.class, proto.getConllUMisc()); }
14581458
if (proto.hasCoarseTag()) { word.set(CoarseTagAnnotation.class, proto.getCoarseTag()); }
14591459
if (proto.hasConllUTokenSpan()) { word.set(CoNLLUTokenSpanAnnotation.class, new IntPair(proto.getConllUTokenSpan().getBegin(), proto.getSpan().getEnd())); }

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/EditNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package edu.stanford.nlp.semgraph.semgrex.ssurgeon;
22

33
import java.util.Collections;
4-
import java.util.HashMap;
54
import java.util.Map;
65
import java.util.TreeMap;
76

@@ -94,10 +93,10 @@ public boolean evaluate(SemanticGraph sg, SemgrexMatcher sm) {
9493
}
9594

9695
for (String key : updateMorphoFeatures.keySet()) {
97-
HashMap<String, String> features = word.get(CoreAnnotations.CoNLLUFeats.class);
96+
TreeMap<String, String> features = word.get(CoreAnnotations.CoNLLUFeats.class);
9897
if (features == null) {
9998
changed = true;
100-
features = new HashMap<>();
99+
features = new TreeMap<>();
101100
word.set(CoreAnnotations.CoNLLUFeats.class, features);
102101
}
103102

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public IndexedWord apply(String line) {
245245

246246

247247
/* Parse features. */
248-
HashMap<String, String> features = CoNLLUUtils.parseFeatures(bits[5]);
248+
TreeMap<String, String> features = CoNLLUUtils.parseFeatures(bits[5]);
249249
word.set(CoreAnnotations.CoNLLUFeats.class, features);
250250

251251

@@ -268,7 +268,7 @@ public IndexedWord apply(String line) {
268268
word.setValue(bits[1]);
269269

270270
/* Parse features. */
271-
HashMap<String, String> features = CoNLLUUtils.parseFeatures(bits[5]);
271+
TreeMap<String, String> features = CoNLLUUtils.parseFeatures(bits[5]);
272272
word.set(CoreAnnotations.CoNLLUFeats.class, features);
273273

274274
/* Parse extra dependencies. */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class CoNLLUUtils {
1717
* @param featureString
1818
* @return A {@code HashMap<String,String>} with the feature values.
1919
*/
20-
public static HashMap<String,String> parseFeatures(String featureString) {
21-
HashMap<String, String> features = new LinkedHashMap<>();
20+
public static TreeMap<String,String> parseFeatures(String featureString) {
21+
TreeMap<String, String> features = new TreeMap<>();
2222
if (! featureString.equals("_")) {
2323
String[] featValPairs = featureString.split("\\|");
2424
for (String p : featValPairs) {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import java.util.HashSet;
88
import java.util.Iterator;
99
import java.util.List;
10+
import java.util.Map;
1011
import java.util.Properties;
1112
import java.util.Set;
13+
import java.util.TreeMap;
1214

1315
import edu.stanford.nlp.io.IOUtils;
1416
import edu.stanford.nlp.io.RuntimeIOException;
@@ -51,8 +53,8 @@ public class UniversalDependenciesFeatureAnnotator {
5153

5254

5355
private static final String FEATURE_MAP_FILE = "edu/stanford/nlp/models/ud/feature_map.txt";
54-
private HashMap<String,HashMap<String,String>> posFeatureMap;
55-
private HashMap<String,HashMap<String,String>> wordPosFeatureMap;
56+
private HashMap<String,TreeMap<String,String>> posFeatureMap;
57+
private Map<String,TreeMap<String,String>> wordPosFeatureMap;
5658

5759
private final Morphology morphology = new Morphology();
5860

@@ -390,10 +392,10 @@ public void addFeatures(SemanticGraph sg, Tree tree, boolean addLemma, boolean a
390392
String posTag = word.get(CoreAnnotations.PartOfSpeechAnnotation.class);
391393
String token = word.get(CoreAnnotations.TextAnnotation.class);
392394
Integer index = word.get(CoreAnnotations.IndexAnnotation.class);
393-
HashMap<String, String> wordFeatures = word.get(CoreAnnotations.CoNLLUFeats.class);
395+
TreeMap<String, String> wordFeatures = word.get(CoreAnnotations.CoNLLUFeats.class);
394396

395397
if (wordFeatures == null) {
396-
wordFeatures = new HashMap<>();
398+
wordFeatures = new TreeMap<>();
397399
word.set(CoreAnnotations.CoNLLUFeats.class, wordFeatures);
398400
}
399401

0 commit comments

Comments
 (0)