Skip to content

Commit 86b6a03

Browse files
committed
Move oldest Klein parseCommandLineArguments out of CoreNLP
1 parent 61e4ae1 commit 86b6a03

File tree

1 file changed

+8
-68
lines changed

1 file changed

+8
-68
lines changed

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

+8-68
Original file line numberDiff line numberDiff line change
@@ -1285,67 +1285,6 @@ public static void printToFile(String filename, String message) {
12851285
printToFile(new File(filename), message, false);
12861286
}
12871287

1288-
/**
1289-
* A simpler form of command line argument parsing.
1290-
* Dan thinks this is highly superior to the overly complexified code that
1291-
* comes before it.
1292-
* Parses command line arguments into a Map. Arguments of the form
1293-
* -flag1 arg1 -flag2 -flag3 arg3
1294-
* will be parsed so that the flag is a key in the Map (including the hyphen)
1295-
* and the
1296-
* optional argument will be its value (if present).
1297-
*
1298-
* @return A Map from keys to possible values (String or null)
1299-
*/
1300-
@SuppressWarnings("unchecked")
1301-
public static Map<String, String> parseCommandLineArguments(String[] args) {
1302-
return (Map)parseCommandLineArguments(args, false);
1303-
}
1304-
1305-
/**
1306-
* A simpler form of command line argument parsing.
1307-
* Dan thinks this is highly superior to the overly complexified code that
1308-
* comes before it.
1309-
* Parses command line arguments into a Map. Arguments of the form
1310-
* -flag1 arg1 -flag2 -flag3 arg3
1311-
* will be parsed so that the flag is a key in the Map (including the hyphen)
1312-
* and the
1313-
* optional argument will be its value (if present).
1314-
* In this version, if the argument is numeric, it will be a Double value
1315-
* in the map, not a String.
1316-
*
1317-
* @return A Map from keys to possible values (String or null)
1318-
*/
1319-
public static Map<String, Object> parseCommandLineArguments(String[] args, boolean parseNumbers) {
1320-
Map<String, Object> result = Generics.newHashMap();
1321-
for (int i = 0; i < args.length; i++) {
1322-
String key = args[i];
1323-
if (key.charAt(0) == '-') {
1324-
if (i + 1 < args.length) {
1325-
String value = args[i + 1];
1326-
if (value.charAt(0) != '-') {
1327-
if (parseNumbers) {
1328-
Object numericValue = value;
1329-
try {
1330-
numericValue = Double.parseDouble(value);
1331-
} catch (NumberFormatException e2) {
1332-
// ignore
1333-
}
1334-
result.put(key, numericValue);
1335-
} else {
1336-
result.put(key, value);
1337-
}
1338-
i++;
1339-
} else {
1340-
result.put(key, null);
1341-
}
1342-
} else {
1343-
result.put(key, null);
1344-
}
1345-
}
1346-
}
1347-
return result;
1348-
}
13491288

13501289
public static String stripNonAlphaNumerics(String orig) {
13511290
StringBuilder sb = new StringBuilder();
@@ -1367,7 +1306,7 @@ public static String stripSGML(String orig) {
13671306
public static void printStringOneCharPerLine(String s) {
13681307
for (int i = 0; i < s.length(); i++) {
13691308
int c = s.charAt(i);
1370-
System.out.println(c + " \'" + (char) c + "\' ");
1309+
System.out.println(c + " '" + (char) c + "' ");
13711310
}
13721311
}
13731312

@@ -1675,7 +1614,7 @@ public static <T> T columnStringToObject(Class objClass, String str, String deli
16751614
public static <T> T columnStringToObject(Class<?> objClass, String str, Pattern delimiterPattern, String[] fieldNames)
16761615
throws InstantiationException, IllegalAccessException, NoSuchMethodException, NoSuchFieldException, InvocationTargetException {
16771616
String[] fields = delimiterPattern.split(str);
1678-
T item = ErasureUtils.uncheckedCast(objClass.newInstance());
1617+
T item = ErasureUtils.uncheckedCast(objClass.getDeclaredConstructor().newInstance());
16791618
for (int i = 0; i < fields.length; i++) {
16801619
try {
16811620
Field field = objClass.getDeclaredField(fieldNames[i]);
@@ -1955,7 +1894,7 @@ public static String toAscii(String s) {
19551894
} else if (c >= 0x00fd && c <= 0x00ff) {
19561895
result = "y";
19571896
} else if (c >= 0x2018 && c <= 0x2019) {
1958-
result = "\'";
1897+
result = "'";
19591898
} else if (c >= 0x201c && c <= 0x201e) {
19601899
result = "\"";
19611900
} else if (c >= 0x0213 && c <= 0x2014) {
@@ -2316,7 +2255,8 @@ public static Collection<String> getCharacterNgrams(String s, int minSize, int m
23162255
return ngrams;
23172256
}
23182257

2319-
private static Pattern diacriticalMarksPattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}");
2258+
private static final Pattern diacriticalMarksPattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}");
2259+
23202260
public static String normalize(String s) {
23212261
// Normalizes string and strips diacritics (map to ascii) by
23222262
// 1. taking the NFKD (compatibility decomposition -
@@ -2711,12 +2651,12 @@ public static Map<String, String> decodeMap(String encoded){
27112651
i += 1;
27122652
}else{
27132653
//(case: normal)
2714-
if(chars[i] == '"'){
2654+
if (chars[i] == '"') {
27152655
quoteCloseChar = '"';
2716-
} else if(chars[i] == '\''){
2656+
} else if(chars[i] == '\'') {
27172657
quoteCloseChar = '\'';
27182658
} else if (chars[i] == '\n' && current.length() == 0) {
2719-
current.append(""); // do nothing
2659+
// current.append(""); // do nothing
27202660
} else if(chars[i] == ',' || chars[i] == ';' || chars[i] == '\t' || chars[i] == '\n'){
27212661
// case: end a value
27222662
if (onKey) {

0 commit comments

Comments
 (0)