Skip to content

Commit 6550188

Browse files
committed
LinkedHashMap instead of Properties. Addresses #1289
1 parent 0d2f495 commit 6550188

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

src/edu/stanford/nlp/process/PTBLexer.flex

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ package edu.stanford.nlp.process;
2828

2929
import java.io.Reader;
3030
import java.text.Normalizer;
31+
import java.util.LinkedHashMap;
3132
import java.util.Locale;
3233
import java.util.Map;
33-
import java.util.Properties;
3434
import java.util.Set;
3535
import java.util.regex.Pattern;
3636

@@ -139,11 +139,11 @@ import edu.stanford.nlp.util.logging.Redwood;
139139
if (options == null) {
140140
options = "";
141141
}
142-
Properties prop = StringUtils.stringToProperties(options);
143-
Set<Map.Entry<Object,Object>> props = prop.entrySet();
144-
for (Map.Entry<Object,Object> item : props) {
145-
String key = (String) item.getKey();
146-
String value = (String) item.getValue();
142+
LinkedHashMap<String, String> prop = StringUtils.stringToPropertiesMap(options);
143+
Set<Map.Entry<String, String>> props = prop.entrySet();
144+
for (Map.Entry<String, String> item : props) {
145+
String key = item.getKey();
146+
String value = item.getValue();
147147
boolean val = Boolean.parseBoolean(value);
148148
if ("".equals(key)) {
149149
// allow an empty item

src/edu/stanford/nlp/process/PTBLexer.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232

3333
import java.io.Reader;
3434
import java.text.Normalizer;
35+
import java.util.LinkedHashMap;
3536
import java.util.Locale;
3637
import java.util.Map;
37-
import java.util.Properties;
3838
import java.util.Set;
3939
import java.util.regex.Pattern;
4040

@@ -60954,11 +60954,11 @@ public PTBLexer(Reader r, LexedTokenFactory<?> tf, String options) {
6095460954
if (options == null) {
6095560955
options = "";
6095660956
}
60957-
Properties prop = StringUtils.stringToProperties(options);
60958-
Set<Map.Entry<Object,Object>> props = prop.entrySet();
60959-
for (Map.Entry<Object,Object> item : props) {
60960-
String key = (String) item.getKey();
60961-
String value = (String) item.getValue();
60957+
LinkedHashMap<String, String> prop = StringUtils.stringToPropertiesMap(options);
60958+
Set<Map.Entry<String, String>> props = prop.entrySet();
60959+
for (Map.Entry<String, String> item : props) {
60960+
String key = item.getKey();
60961+
String value = item.getValue();
6096260962
boolean val = Boolean.parseBoolean(value);
6096360963
if ("".equals(key)) {
6096460964
// allow an empty item

src/edu/stanford/nlp/util/StringUtils.java

+29
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,35 @@ public static Properties stringToProperties(String str, Properties props) {
11361136
return props;
11371137
}
11381138

1139+
/**
1140+
* This method updates a LinkedHashMap based on
1141+
* a comma-separated String (with whitespace
1142+
* optionally allowed after the comma) representing properties
1143+
* to a Properties object. Each property is "property=value". The value
1144+
* for properties without an explicitly given value is set to "true".
1145+
*
1146+
* TODO: remove the stringToProperties version
1147+
*/
1148+
public static LinkedHashMap<String, String> stringToPropertiesMap(String str) {
1149+
LinkedHashMap<String, String> props = new LinkedHashMap<>();
1150+
1151+
String[] propsStr = str.trim().split(",\\s*");
1152+
for (String term : propsStr) {
1153+
int divLoc = term.indexOf('=');
1154+
String key;
1155+
String value;
1156+
if (divLoc >= 0) {
1157+
key = term.substring(0, divLoc).trim();
1158+
value = term.substring(divLoc + 1).trim();
1159+
} else {
1160+
key = term.trim();
1161+
value = "true";
1162+
}
1163+
props.put(key, value);
1164+
}
1165+
return props;
1166+
}
1167+
11391168
/**
11401169
* If any of the given list of properties are not found, returns the
11411170
* name of that property. Otherwise, returns null.

0 commit comments

Comments
 (0)