From 086d45d9f7ceb34a815f443f70d1e79eb6fc1e53 Mon Sep 17 00:00:00 2001 From: dannima Date: Fri, 20 Apr 2018 18:03:22 -0400 Subject: [PATCH] Remove join function in utilities/StringUtils.java, use StringUtils.join in Apache common --- .../cogcomp/comma/datastructures/Comma.java | 13 ++++--- .../datastructures/CommaSRLSentence.java | 5 ++- .../cogcomp/core/utilities/StringUtils.java | 38 +++++++++---------- .../corpusutils/CorpusSplitConfigurator.java | 5 ++- .../features/helpers/FeatureNGramUtility.java | 7 ++-- .../ner/TestBrownClusterFeatureExtractor.java | 5 ++- 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/Comma.java b/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/Comma.java index 7da3947d8..1c2a3f76c 100644 --- a/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/Comma.java +++ b/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/Comma.java @@ -14,7 +14,8 @@ import edu.illinois.cs.cogcomp.core.datastructures.QueryableList; import edu.illinois.cs.cogcomp.core.datastructures.ViewNames; import edu.illinois.cs.cogcomp.core.datastructures.textannotation.*; -import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +// import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +import org.apache.commons.lang3.StringUtils; import edu.illinois.cs.cogcomp.nlp.utilities.POSUtils; import edu.illinois.cs.cogcomp.nlp.utilities.ParseTreeProperties; import edu.illinois.cs.cogcomp.nlp.utilities.ParseUtils; @@ -581,15 +582,15 @@ public String[] getParentSiblingPhraseNgrams() { public String getAnnotatedText() { List tokens = Arrays.asList(s.ta.getTokens()); - return StringUtils.join(" ", tokens.subList(0, commaPosition + 1)) + "[" - + StringUtils.join(",", labels) + "] " - + StringUtils.join(" ", tokens.subList(commaPosition + 1, tokens.size())); + return StringUtils.join(tokens.subList(0, commaPosition + 1), " ") + "[" + + StringUtils.join(labels, ",") + "] " + + StringUtils.join(tokens.subList(commaPosition + 1, tokens.size()), " "); } public String getBayraktarAnnotatedText() { List tokens = Arrays.asList(s.ta.getTokens()); - return StringUtils.join(" ", tokens.subList(0, commaPosition + 1)) + "[" + return StringUtils.join(tokens.subList(0, commaPosition + 1), " ") + "[" + getBayraktarLabel() + "] " - + StringUtils.join(" ", tokens.subList(commaPosition + 1, tokens.size())); + + StringUtils.join(tokens.subList(commaPosition + 1, tokens.size()), " "); } } diff --git a/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/CommaSRLSentence.java b/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/CommaSRLSentence.java index c0fb8050e..e796123f4 100644 --- a/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/CommaSRLSentence.java +++ b/commasrl/src/main/java/edu/illinois/cs/cogcomp/comma/datastructures/CommaSRLSentence.java @@ -18,7 +18,8 @@ import edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView; import edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation; import edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotationUtilities; -import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +// import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +import org.apache.commons.lang3.StringUtils; /** * Used to group all the commas in a sentence. The commas can then be accessed based on positional @@ -238,7 +239,7 @@ public String getAnnotatedText() { annotatedText += " " + tokens[tokenIdx]; String commaAnnotation = ""; while (commaNum < commas.size() && commas.get(commaNum).commaPosition == tokenIdx) { - commaAnnotation += StringUtils.join(",", commas.get(commaNum).getLabels()); + commaAnnotation += StringUtils.join(commas.get(commaNum).getLabels(), ","); commaNum++; } if (commaAnnotation.length() > 0) diff --git a/core-utilities/src/main/java/edu/illinois/cs/cogcomp/core/utilities/StringUtils.java b/core-utilities/src/main/java/edu/illinois/cs/cogcomp/core/utilities/StringUtils.java index fe67616c7..e76b8e7c3 100644 --- a/core-utilities/src/main/java/edu/illinois/cs/cogcomp/core/utilities/StringUtils.java +++ b/core-utilities/src/main/java/edu/illinois/cs/cogcomp/core/utilities/StringUtils.java @@ -51,31 +51,31 @@ public static String now() { } - public static String join(String separator, Object... objects) { - StringBuilder sb = new StringBuilder(); + // public static String join(String separator, Object... objects) { + // StringBuilder sb = new StringBuilder(); - for (Object o : objects) { - sb.append(o.toString()).append(separator); - } - return sb.toString().trim(); - } + // for (Object o : objects) { + // sb.append(o.toString()).append(separator); + // } + // return sb.toString().trim(); + // } - public static String join(String separator, List tokens) { - if (tokens.size() == 1) - return tokens.get(0); + // public static String join(String separator, List tokens) { + // if (tokens.size() == 1) + // return tokens.get(0); - StringBuilder sb = new StringBuilder(); + // StringBuilder sb = new StringBuilder(); - for (String token : tokens) { - sb.append(token).append(separator); - } + // for (String token : tokens) { + // sb.append(token).append(separator); + // } - return sb.toString().trim(); - } + // return sb.toString().trim(); + // } - public static String join(String separator, String[] tokens) { - return join(separator, Arrays.asList(tokens)); - } + // public static String join(String separator, String[] tokens) { + // return join(separator, Arrays.asList(tokens)); + // } public static String generateUniqueString() { return UUID.randomUUID().toString(); diff --git a/corpusreaders/src/main/java/edu/illinois/cs/cogcomp/nlp/corpusreaders/corpusutils/CorpusSplitConfigurator.java b/corpusreaders/src/main/java/edu/illinois/cs/cogcomp/nlp/corpusreaders/corpusutils/CorpusSplitConfigurator.java index 71046a752..f0f529ed2 100644 --- a/corpusreaders/src/main/java/edu/illinois/cs/cogcomp/nlp/corpusreaders/corpusutils/CorpusSplitConfigurator.java +++ b/corpusreaders/src/main/java/edu/illinois/cs/cogcomp/nlp/corpusreaders/corpusutils/CorpusSplitConfigurator.java @@ -8,7 +8,8 @@ package edu.illinois.cs.cogcomp.nlp.corpusreaders.corpusutils; import edu.illinois.cs.cogcomp.core.datastructures.ViewNames; -import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +// import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +import org.apache.commons.lang3.StringUtils; import edu.illinois.cs.cogcomp.core.utilities.configuration.Configurator; import edu.illinois.cs.cogcomp.core.utilities.configuration.Property; import edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager; @@ -24,7 +25,7 @@ public class CorpusSplitConfigurator extends Configurator { public static final Property DEV_FRACTION = new Property("devFraction", "0.1"); public static final Property TEST_FRACTION = new Property("testFraction", "0.2"); public static final Property VIEWS_TO_CONSIDER = new Property("viewsToConsider", - StringUtils.join(",", new String[]{ViewNames.EVENT_ERE,ViewNames.MENTION_ERE})); + StringUtils.join(new String[]{ViewNames.EVENT_ERE,ViewNames.MENTION_ERE}, ",")); /** diff --git a/edison/src/main/java/edu/illinois/cs/cogcomp/edison/features/helpers/FeatureNGramUtility.java b/edison/src/main/java/edu/illinois/cs/cogcomp/edison/features/helpers/FeatureNGramUtility.java index d83ca42fc..aeacfb0d6 100644 --- a/edison/src/main/java/edu/illinois/cs/cogcomp/edison/features/helpers/FeatureNGramUtility.java +++ b/edison/src/main/java/edu/illinois/cs/cogcomp/edison/features/helpers/FeatureNGramUtility.java @@ -9,7 +9,8 @@ import edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent; import edu.illinois.cs.cogcomp.core.transformers.ITransformer; -import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +// import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +import org.apache.commons.lang3.StringUtils; import edu.illinois.cs.cogcomp.edison.features.DiscreteFeature; import edu.illinois.cs.cogcomp.edison.features.Feature; @@ -52,7 +53,7 @@ public static Set getNgramsOrdered(List list, int ngramLength, } } - features.add(DiscreteFeature.create(i + ":" + StringUtils.join("-", strings))); + features.add(DiscreteFeature.create(i + ":" + StringUtils.join(strings, "-"))); } return features; } @@ -77,7 +78,7 @@ public static Set getNgramsUnordered(List list, int ngramLength, } } - features.add(DiscreteFeature.create(StringUtils.join("-", strings))); + features.add(DiscreteFeature.create(StringUtils.join(strings, "-"))); } return features; } diff --git a/edison/src/test/java/edu/illinois/cs/cogcomp/edison/features/lrec/ner/TestBrownClusterFeatureExtractor.java b/edison/src/test/java/edu/illinois/cs/cogcomp/edison/features/lrec/ner/TestBrownClusterFeatureExtractor.java index 01a32e8d6..79867c79f 100644 --- a/edison/src/test/java/edu/illinois/cs/cogcomp/edison/features/lrec/ner/TestBrownClusterFeatureExtractor.java +++ b/edison/src/test/java/edu/illinois/cs/cogcomp/edison/features/lrec/ner/TestBrownClusterFeatureExtractor.java @@ -10,7 +10,8 @@ import edu.illinois.cs.cogcomp.core.datastructures.ViewNames; import edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation; -import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +// import edu.illinois.cs.cogcomp.core.utilities.StringUtils; +import org.apache.commons.lang3.StringUtils; import edu.illinois.cs.cogcomp.edison.features.Feature; import edu.illinois.cs.cogcomp.edison.features.factory.BrownClusterFeatureExtractor; import edu.illinois.cs.cogcomp.edison.utilities.EdisonException; @@ -109,7 +110,7 @@ public final void test() { featArray[i++] = f.toString(); Arrays.sort(featArray); - String actualOutput = StringUtils.join(",", featArray); + String actualOutput = StringUtils.join(featArray, ","); assertEquals(expectedOutput, actualOutput); } }