public class StringUtils
extends java.lang.Object
Many of these methods will be familiar to perl users: join(Iterable)
, split(String, String)
, trim(String, int)
, find(String, String)
, lookingAt(String, String)
, and matches(String,
String)
.
There are also useful methods for padding Strings/Objects with spaces on the right or left for printing even-width
table columns: padLeft(int, int)
, pad(String, int)
.
Example: print a comma-separated list of numbers:
System.out.println(StringUtils.pad(nums, ", "));
Example: print a 2D array of numbers with 8-char cells:
for(int i = 0; i < nums.length; i++) {
for(int j = 0; j < nums[i].length; j++) {
System.out.print(StringUtils.leftPad(nums[i][j], 8));
System.out.println();
Modifier and Type | Field and Description |
---|---|
static java.util.function.Function<java.lang.Object,java.lang.String> |
DEFAULT_TOSTRING |
static java.lang.String[] |
EMPTY_STRING_ARRAY |
Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.String,java.lang.String[]> |
argsToMap(java.lang.String[] args)
Parses command line arguments into a Map.
|
static java.util.Map<java.lang.String,java.lang.String[]> |
argsToMap(java.lang.String[] args,
java.util.Map<java.lang.String,java.lang.Integer> flagsToNumArgs)
Parses command line arguments into a Map.
|
static java.util.Properties |
argsToProperties(java.lang.String... args)
In this version each flag has zero or one argument.
|
static java.util.Properties |
argsToProperties(java.lang.String[] args,
java.util.Map<java.lang.String,java.lang.Integer> flagsToNumArgs)
Analogous to
argsToMap(java.lang.String[]) . |
static java.util.Properties |
argsToPropertiesWithResolve(java.lang.String[] args)
convert args to properties with variable names resolved.
|
static java.lang.String |
capitalize(java.lang.String s)
Uppercases the first character of a string.
|
static java.lang.String |
checkRequiredProperties(java.util.Properties props,
java.lang.String... requiredProps)
If any of the given list of properties are not found, returns the
name of that property.
|
static java.lang.String |
chomp(java.lang.Object o)
Returns the result of calling toString() on the supplied Object, but with
any trailing '\n' removed.
|
static java.lang.String |
chomp(java.lang.String s)
Returns the supplied string with any trailing '\n' removed.
|
static <T> T |
columnStringToObject(java.lang.Class<?> objClass,
java.lang.String str,
java.util.regex.Pattern delimiterPattern,
java.lang.String[] fieldNames)
Converts a tab delimited string into an object with given fields
Requires the object has public access for the specified fields
|
static <T> T |
columnStringToObject(java.lang.Class objClass,
java.lang.String str,
java.lang.String delimiterRegex,
java.lang.String[] fieldNames)
Converts a tab delimited string into an object with given fields
Requires the object has setXxx functions for the specified fields
|
static boolean |
containsIgnoreCase(java.util.Collection<java.lang.String> c,
java.lang.String s)
Convenience method: a case-insensitive variant of Collection.contains
|
static int |
editDistance(java.lang.String s,
java.lang.String t)
Computes the Levenshtein (edit) distance of the two given Strings.
|
static java.lang.String |
escapeString(java.lang.String s,
char[] charsToEscape,
char escapeChar) |
static java.lang.String |
fileNameClean(java.lang.String s)
Returns a "clean" version of the given filename in which spaces have
been converted to dashes and all non-alphanumeric chars are underscores.
|
static boolean |
find(java.lang.String str,
java.lang.String regex)
Say whether this regular expression can be found inside
this String.
|
static java.lang.String |
getBaseName(java.lang.String fileName)
Strip directory from filename.
|
static java.lang.String |
getBaseName(java.lang.String fileName,
java.lang.String suffix)
Strip directory and suffix from filename.
|
static java.util.Collection<java.lang.String> |
getCharacterNgrams(java.lang.String s,
int minSize,
int maxSize)
Build a list of character-based ngrams from the given string.
|
static java.util.Collection<java.lang.String> |
getNgrams(java.util.List<java.lang.String> words,
int minSize,
int maxSize)
n grams for already splitted string.
|
static java.util.Collection<java.lang.String> |
getNgramsFromTokens(java.util.List<CoreLabel> words,
int minSize,
int maxSize)
n grams for already splitted string.
|
static java.util.Collection<java.lang.String> |
getNgramsString(java.lang.String s,
int minSize,
int maxSize)
The string is split on whitespace and the ngrams are joined with a single space
|
static java.lang.String |
getNotNullString(java.lang.String s) |
static java.lang.String |
getShortClassName(java.lang.Object o)
Returns a short class name for an object.
|
static boolean |
isAcronym(java.lang.String s)
Given a String the method uses Regex to check if the String looks like an acronym
|
static boolean |
isAlpha(java.lang.String s)
Given a String the method uses Regex to check if the String only contains alphabet characters
|
static boolean |
isAlphanumeric(java.lang.String s)
Given a String the method uses Regex to check if the String only contains alphanumeric characters
|
static boolean |
isCapitalized(java.lang.String s)
Check if a string begins with an uppercase.
|
static boolean |
isNumeric(java.lang.String s)
Given a String the method uses Regex to check if the String only contains numeric characters
|
static boolean |
isPunct(java.lang.String s)
Given a String the method uses Regex to check if the String only contains punctuation characters
|
static java.lang.String |
join(java.lang.Iterable<?> l)
Joins elems with a space.
|
static <X> java.lang.String |
join(java.lang.Iterable<X> l,
java.lang.String glue)
Joins each elem in the
Iterable with the given glue. |
static <E> java.lang.String |
join(java.util.List<? extends E> l,
java.lang.String glue,
java.util.function.Function<E,java.lang.String> toStringFunc,
int start,
int end) |
static java.lang.String |
join(java.lang.Object[] elements)
Joins elements with a space.
|
static java.lang.String |
join(java.lang.Object[] elements,
int start,
int end,
java.lang.String glue)
Joins an array of elements in a given span.
|
static java.lang.String |
join(java.lang.Object[] elements,
java.lang.String glue)
Joins each elem in the array with the given glue.
|
static <X> java.lang.String |
join(java.util.stream.Stream<X> l,
java.lang.String glue)
Joins each elem in the
Stream with the given glue. |
static java.lang.String |
joinFields(java.util.List<? extends CoreMap> l,
java.lang.Class field) |
static java.lang.String |
joinFields(java.util.List<? extends CoreMap> l,
java.lang.Class field,
java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc) |
static java.lang.String |
joinFields(java.util.List<? extends CoreMap> l,
java.lang.Class field,
java.lang.String defaultFieldValue,
java.lang.String glue,
int start,
int end) |
static java.lang.String |
joinFields(java.util.List<? extends CoreMap> l,
java.lang.Class field,
java.lang.String defaultFieldValue,
java.lang.String glue,
int start,
int end,
java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc) |
static java.lang.String |
joinMultipleFields(java.util.List<? extends CoreMap> l,
java.lang.Class[] fields) |
static java.lang.String |
joinMultipleFields(java.util.List<? extends CoreMap> l,
java.lang.Class[] fields,
java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc) |
static java.lang.String |
joinMultipleFields(java.util.List<? extends CoreMap> l,
java.lang.Class[] fields,
java.lang.String defaultFieldValue,
java.lang.String fieldGlue,
java.lang.String glue,
int start,
int end) |
static java.lang.String |
joinMultipleFields(java.util.List<? extends CoreMap> l,
java.lang.Class[] fields,
java.lang.String defaultFieldValue,
java.lang.String fieldGlue,
java.lang.String glue,
int start,
int end,
java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc) |
static java.lang.String |
joinWithOriginalWhiteSpace(java.util.List<CoreLabel> tokens)
Joins all the tokens together (more or less) according to their original whitespace.
|
static java.lang.String |
joinWords(java.lang.Iterable<? extends HasWord> l,
java.lang.String glue) |
static java.lang.String |
joinWords(java.util.List<? extends HasWord> l,
java.lang.String glue,
int start,
int end) |
static int |
longestCommonContiguousSubstring(java.lang.String s,
java.lang.String t)
Computes the longest common contiguous substring of s and t.
|
static int |
longestCommonSubstring(java.lang.String s,
java.lang.String t)
Computes the longest common substring of s and t.
|
static boolean |
lookingAt(java.lang.String str,
java.lang.String regex)
Say whether this regular expression can be found at the beginning of
this String.
|
static void |
main(java.lang.String[] args)
Tests the string edit distance function.
|
static java.lang.String |
makeHTMLTable(java.lang.String[][] table,
java.lang.String[] rowLabels,
java.lang.String[] colLabels)
Returns an HTML table containing the matrix of Strings passed in.
|
static java.lang.String |
makeTextTable(java.lang.Object[][] table,
java.lang.Object[] rowLabels,
java.lang.Object[] colLabels,
int padLeft,
int padRight,
boolean tsv)
Returns a text table containing the matrix of objects passed in.
|
static java.lang.String[] |
mapStringToArray(java.lang.String map)
Takes a string of the form "x1=y1,x2=y2,..." such
that each y is an integer and each x is a key.
|
static java.util.Map<java.lang.String,java.lang.String> |
mapStringToMap(java.lang.String map)
Takes a string of the form "x1=y1,x2=y2,..." and returns Map.
|
static boolean |
matches(java.lang.String str,
java.lang.String regex)
Say whether this regular expression matches
this String.
|
static java.lang.String |
normalize(java.lang.String s) |
static int |
nthIndex(java.lang.String s,
char ch,
int n)
Returns the index of the nth occurrence of ch in s, or -1
if there are less than n occurrences of ch.
|
static java.lang.String |
objectToColumnString(java.lang.Object object,
java.lang.String delimiter,
java.lang.String[] fieldNames)
Converts an object into a tab delimited string with given fields
Requires the object has public access for the specified fields
|
static java.lang.String |
pad(java.lang.Object obj,
int totalChars)
Pads the toString value of the given Object.
|
static java.lang.String |
pad(java.lang.String str,
int totalChars)
Return a String of length a minimum of totalChars characters by
padding the input String str at the right end with spaces.
|
static java.lang.String |
padLeft(double d,
int totalChars) |
static java.lang.String |
padLeft(int i,
int totalChars) |
static java.lang.String |
padLeft(java.lang.Object obj,
int totalChars) |
static java.lang.String |
padLeft(java.lang.String str,
int totalChars)
Pads the given String to the left with spaces to ensure that it's
at least totalChars long.
|
static java.lang.String |
padLeft(java.lang.String str,
int totalChars,
char ch)
Pads the given String to the left with the given character to ensure that
it's at least totalChars long.
|
static java.lang.String |
padLeftOrTrim(java.lang.String str,
int num)
Pad or trim so as to produce a string of exactly a certain length.
|
static java.lang.String |
padOrTrim(java.lang.Object obj,
int totalChars)
Pad or trim the toString value of the given Object.
|
static java.lang.String |
padOrTrim(java.lang.String str,
int num)
Pad or trim so as to produce a string of exactly a certain length.
|
static java.util.Map<java.lang.String,java.lang.String> |
parseCommandLineArguments(java.lang.String[] args)
A simpler form of command line argument parsing.
|
static java.util.Map<java.lang.String,java.lang.Object> |
parseCommandLineArguments(java.lang.String[] args,
boolean parseNumbers)
A simpler form of command line argument parsing.
|
static java.lang.String |
pennPOSToWordnetPOS(java.lang.String s)
Computes the WordNet 2.0 POS tag corresponding to the PTB POS tag s.
|
static void |
printErrInvocationString(java.lang.String cls,
java.lang.String[] args) |
static void |
printStringOneCharPerLine(java.lang.String s) |
static void |
printToFile(java.io.File file,
java.lang.String message)
Prints to a file.
|
static void |
printToFile(java.io.File file,
java.lang.String message,
boolean append)
Prints to a file.
|
static void |
printToFile(java.io.File file,
java.lang.String message,
boolean append,
boolean printLn,
java.lang.String encoding)
Prints to a file.
|
static void |
printToFile(java.lang.String filename,
java.lang.String message)
Prints to a file.
|
static void |
printToFile(java.lang.String filename,
java.lang.String message,
boolean append)
Prints to a file.
|
static void |
printToFileLn(java.io.File file,
java.lang.String message,
boolean append)
Prints to a file.
|
static void |
printToFileLn(java.lang.String filename,
java.lang.String message,
boolean append)
Prints to a file.
|
static java.util.LinkedHashMap<java.lang.String,java.lang.String> |
propFileToLinkedHashMap(java.lang.String filename,
java.util.Map<java.lang.String,java.lang.String> existingArgs)
This method reads in properties listed in a file in the format prop=value,
one property per line.
|
static java.util.Properties |
propFileToProperties(java.lang.String filename)
This method reads in properties listed in a file in the format prop=value, one property per line.
|
static java.util.List<java.util.regex.Pattern> |
regexesToPatterns(java.lang.Iterable<java.lang.String> regexes) |
static java.util.List<java.lang.String> |
regexGroups(java.util.regex.Pattern regex,
java.lang.String str)
Given a pattern and a string, returns a list with the values of the
captured groups in the pattern.
|
static java.lang.String |
repeat(char ch,
int times) |
static java.lang.String |
repeat(java.lang.String s,
int times) |
static java.lang.String |
resolveVars(java.lang.String str,
java.util.Map props)
Resolve variable.
|
static java.lang.String |
searchAndReplace(java.lang.String text,
java.lang.String from,
java.lang.String to) |
static java.util.List<java.lang.String> |
split(java.lang.String s)
Splits on whitespace (\\s+).
|
static java.util.List<java.lang.String> |
split(java.lang.String str,
java.lang.String regex)
Splits the given string using the given regex as delimiters.
|
static java.util.List<java.util.List<java.lang.String>> |
splitFieldsFast(java.lang.String str,
java.lang.String delimiter)
Splits a string into whitespace tokenized fields based on a delimiter.
|
static java.lang.String[] |
splitOnChar(java.lang.String input,
char delimiter) |
static java.lang.String[] |
splitOnCharWithQuoting(java.lang.String s,
char splitChar,
char quoteChar,
char escapeChar)
This function splits the String s into multiple Strings using the
splitChar.
|
static java.util.Properties |
stringToProperties(java.lang.String str)
This method converts a comma-separated String (with whitespace
optionally allowed after the comma) representing properties
to a Properties object.
|
static java.util.Properties |
stringToProperties(java.lang.String str,
java.util.Properties props)
This method updates a Properties object based on
a comma-separated String (with whitespace
optionally allowed after the comma) representing properties
to a Properties object.
|
static java.util.Set<java.lang.String> |
stringToSet(java.lang.String str,
java.lang.String delimiter) |
static java.lang.String |
stripNonAlphaNumerics(java.lang.String orig) |
static java.lang.String |
stripSGML(java.lang.String orig) |
static java.lang.String |
toAscii(java.lang.String s) |
static java.lang.String |
toCSVString(java.lang.String[] fields) |
static java.lang.String |
toInvocationString(java.lang.String cls,
java.lang.String[] args) |
static java.lang.String |
toString(CoreMap sentence)
Convert a CoreMap representing a sentence into a string, by simply joining them with spaces.
|
static java.lang.String |
toString(java.util.List<CoreLabel> words)
Convert a list of labels into a string, by simply joining them with spaces.
|
static java.lang.String |
tr(java.lang.String input,
java.lang.String from,
java.lang.String to)
Swap any occurrences of any characters in the from String in the input String with
the corresponding character from the to String.
|
static java.lang.String |
trim(java.lang.Object obj,
int maxWidth) |
static java.lang.String |
trim(java.lang.String s,
int maxWidth)
Returns s if it's at most maxWidth chars, otherwise chops right side to fit.
|
static java.lang.String |
truncate(int n,
int smallestDigit,
int biggestDigit)
This returns a string from decimal digit smallestDigit to decimal digit
biggest digit.
|
static java.util.List<java.lang.String> |
valueSplit(java.lang.String str,
java.lang.String valueRegex,
java.lang.String separatorRegex)
Split a string into tokens.
|
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final java.util.function.Function<java.lang.Object,java.lang.String> DEFAULT_TOSTRING
public static boolean find(java.lang.String str, java.lang.String regex)
str
- String to search for match inregex
- String to compile as the regular expressionpublic static boolean containsIgnoreCase(java.util.Collection<java.lang.String> c, java.lang.String s)
c
- Collection<String>s
- Stringpublic static boolean lookingAt(java.lang.String str, java.lang.String regex)
str
- String to search for match at start ofregex
- String to compile as the regular expressionpublic static java.lang.String[] mapStringToArray(java.lang.String map)
map
- A string of the form "x1=y1,x2=y2,..." such
that each y is an integer and each x is a key.public static java.util.Map<java.lang.String,java.lang.String> mapStringToMap(java.lang.String map)
map
- A string of the form "x1=y1,x2=y2,..."public static java.util.List<java.util.regex.Pattern> regexesToPatterns(java.lang.Iterable<java.lang.String> regexes)
public static java.util.List<java.lang.String> regexGroups(java.util.regex.Pattern regex, java.lang.String str)
public static boolean matches(java.lang.String str, java.lang.String regex)
str
- String to search for match at start ofregex
- String to compile as the regular expressionpublic static java.util.Set<java.lang.String> stringToSet(java.lang.String str, java.lang.String delimiter)
public static java.lang.String joinWords(java.lang.Iterable<? extends HasWord> l, java.lang.String glue)
public static <E> java.lang.String join(java.util.List<? extends E> l, java.lang.String glue, java.util.function.Function<E,java.lang.String> toStringFunc, int start, int end)
public static java.lang.String joinWords(java.util.List<? extends HasWord> l, java.lang.String glue, int start, int end)
public static java.lang.String joinFields(java.util.List<? extends CoreMap> l, java.lang.Class field, java.lang.String defaultFieldValue, java.lang.String glue, int start, int end, java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc)
public static java.lang.String joinFields(java.util.List<? extends CoreMap> l, java.lang.Class field, java.lang.String defaultFieldValue, java.lang.String glue, int start, int end)
public static java.lang.String joinFields(java.util.List<? extends CoreMap> l, java.lang.Class field, java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc)
public static java.lang.String joinFields(java.util.List<? extends CoreMap> l, java.lang.Class field)
public static java.lang.String joinMultipleFields(java.util.List<? extends CoreMap> l, java.lang.Class[] fields, java.lang.String defaultFieldValue, java.lang.String fieldGlue, java.lang.String glue, int start, int end, java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc)
public static java.lang.String joinMultipleFields(java.util.List<? extends CoreMap> l, java.lang.Class[] fields, java.util.function.Function<java.lang.Object,java.lang.String> toStringFunc)
public static java.lang.String joinMultipleFields(java.util.List<? extends CoreMap> l, java.lang.Class[] fields, java.lang.String defaultFieldValue, java.lang.String fieldGlue, java.lang.String glue, int start, int end)
public static java.lang.String joinMultipleFields(java.util.List<? extends CoreMap> l, java.lang.Class[] fields)
public static java.lang.String joinWithOriginalWhiteSpace(java.util.List<CoreLabel> tokens)
public static <X> java.lang.String join(java.lang.Iterable<X> l, java.lang.String glue)
Iterable
with the given glue.
For example, given a list of Integers
, you can create
a comma-separated list by calling join(numbers, ", ")
.join(Stream, String)
public static <X> java.lang.String join(java.util.stream.Stream<X> l, java.lang.String glue)
Stream
with the given glue.
For example, given a list of Integers
, you can create
a comma-separated list by calling join(numbers, ", ")
.join(Iterable, String)
public static java.lang.String join(java.lang.Object[] elements, java.lang.String glue)
join(numbers, ", ")
.public static java.lang.String join(java.lang.Object[] elements, int start, int end, java.lang.String glue)
elements
- The elements to join.start
- The start index to join from.end
- The end (non-inclusive) to join until.glue
- The glue to hold together the elements.public static java.lang.String join(java.lang.Iterable<?> l)
public static java.lang.String join(java.lang.Object[] elements)
public static java.util.List<java.lang.String> split(java.lang.String s)
s
- String to splitpublic static java.util.List<java.lang.String> split(java.lang.String str, java.lang.String regex)
str
- String to split upregex
- String to compile as the regular expressionpublic static java.lang.String[] splitOnChar(java.lang.String input, char delimiter)
public static java.util.List<java.util.List<java.lang.String>> splitFieldsFast(java.lang.String str, java.lang.String delimiter)
delimiter
- public static java.util.List<java.lang.String> valueSplit(java.lang.String str, java.lang.String valueRegex, java.lang.String separatorRegex)
str
- The String to splitvalueRegex
- Must match a token. You may wish to let it match the empty StringseparatorRegex
- Must match a separatorjava.lang.IllegalArgumentException
- if str cannot be tokenized by the two regexpublic static java.lang.String pad(java.lang.String str, int totalChars)
public static java.lang.String pad(java.lang.Object obj, int totalChars)
public static java.lang.String padOrTrim(java.lang.String str, int num)
str
- The String to be padded or truncatednum
- The desired lengthpublic static java.lang.String padLeftOrTrim(java.lang.String str, int num)
str
- The String to be padded or truncatednum
- The desired lengthpublic static java.lang.String padOrTrim(java.lang.Object obj, int totalChars)
public static java.lang.String padLeft(java.lang.String str, int totalChars, char ch)
public static java.lang.String padLeft(java.lang.String str, int totalChars)
public static java.lang.String padLeft(java.lang.Object obj, int totalChars)
public static java.lang.String padLeft(int i, int totalChars)
public static java.lang.String padLeft(double d, int totalChars)
public static java.lang.String trim(java.lang.String s, int maxWidth)
public static java.lang.String trim(java.lang.Object obj, int maxWidth)
public static java.lang.String repeat(java.lang.String s, int times)
public static java.lang.String repeat(char ch, int times)
public static java.lang.String fileNameClean(java.lang.String s)
public static int nthIndex(java.lang.String s, char ch, int n)
public static java.lang.String truncate(int n, int smallestDigit, int biggestDigit)
public static java.util.Map<java.lang.String,java.lang.String[]> argsToMap(java.lang.String[] args)
String
[] containing
the optional arguments (if present). The non-flag values not
captured as flag arguments are collected into a String[] array
and returned as the value of null
in the Map. In
this invocation, flags cannot take arguments, so all the String
array values other than the value for null
will be zero-length.args
- A command-line arguments arrayMap
of flag names to flag argument String
arrays.public static java.util.Map<java.lang.String,java.lang.String[]> argsToMap(java.lang.String[] args, java.util.Map<java.lang.String,java.lang.Integer> flagsToNumArgs)
String
[] containing
the optional arguments (if present). The non-flag values not
captured as flag arguments are collected into a String[] array
and returned as the value of null
in the Map. In
this invocation, the maximum number of arguments for each flag
can be specified as an Integer
value of the appropriate
flag key in the flagsToNumArgs
Map
argument. (By default, flags cannot take arguments.)
Example of usage:
Map flagsToNumArgs = new HashMap();
flagsToNumArgs.put("-x",new Integer(2));
flagsToNumArgs.put("-d",new Integer(1));
Map result = argsToMap(args,flagsToNumArgs);
If a given flag appears more than once, the extra args are appended to
the String[] value for that flag.args
- the argument array to be parsedflagsToNumArgs
- a Map
of flag names to Integer
values specifying the number of arguments
for that flag (default min 0, max 1).Map
of flag names to flag argument String
public static java.util.Properties argsToProperties(java.lang.String... args)
argsToProperties(String[], Map)
for full documentation.args
- Command line argumentspublic static java.util.Properties argsToProperties(java.lang.String[] args, java.util.Map<java.lang.String,java.lang.Integer> flagsToNumArgs)
argsToMap(java.lang.String[])
. However, there are several key differences between this method and argsToMap(java.lang.String[])
:
args
- Command line argumentsflagsToNumArgs
- Map of how many arguments flags should have. The keys are without the minus signs.public static java.util.Properties propFileToProperties(java.lang.String filename)
Properties.load(InputStream)
exists, I implemented this method to trim the lines,
something not implemented in the load()
method.filename
- A properties file to readpublic static java.util.Properties stringToProperties(java.lang.String str)
public static java.util.Properties stringToProperties(java.lang.String str, java.util.Properties props)
public static java.lang.String checkRequiredProperties(java.util.Properties props, java.lang.String... requiredProps)
public static void printToFile(java.io.File file, java.lang.String message, boolean append, boolean printLn, java.lang.String encoding)
append=true
, and overwrites if append=false
.public static void printToFileLn(java.io.File file, java.lang.String message, boolean append)
append=true
, and overwrites if append=false
.public static void printToFile(java.io.File file, java.lang.String message, boolean append)
append=true
, and overwrites if append=false
.public static void printToFile(java.io.File file, java.lang.String message)
public static void printToFile(java.lang.String filename, java.lang.String message, boolean append)
append=true
, and overwrites if append=false
public static void printToFileLn(java.lang.String filename, java.lang.String message, boolean append)
append=true
, and overwrites if append=false
public static void printToFile(java.lang.String filename, java.lang.String message)
public static java.util.Map<java.lang.String,java.lang.String> parseCommandLineArguments(java.lang.String[] args)
public static java.util.Map<java.lang.String,java.lang.Object> parseCommandLineArguments(java.lang.String[] args, boolean parseNumbers)
public static java.lang.String stripNonAlphaNumerics(java.lang.String orig)
public static java.lang.String stripSGML(java.lang.String orig)
public static void printStringOneCharPerLine(java.lang.String s)
public static java.lang.String escapeString(java.lang.String s, char[] charsToEscape, char escapeChar)
public static java.lang.String[] splitOnCharWithQuoting(java.lang.String s, char splitChar, char quoteChar, char escapeChar)
s
- The String to split into fields. Cannot be null.splitChar
- The character to split onquoteChar
- The character to quote items withescapeChar
- The character to escape the quoteChar withpublic static int longestCommonSubstring(java.lang.String s, java.lang.String t)
public static int longestCommonContiguousSubstring(java.lang.String s, java.lang.String t)
public static int editDistance(java.lang.String s, java.lang.String t)
public static java.lang.String pennPOSToWordnetPOS(java.lang.String s)
s
- a Penn TreeBank POS tag.public static java.lang.String getShortClassName(java.lang.Object o)
ArrayList
public static <T> T columnStringToObject(java.lang.Class objClass, java.lang.String str, java.lang.String delimiterRegex, java.lang.String[] fieldNames) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.NoSuchFieldException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
T
- type to returnobjClass
- Class of object to be createdstr
- string to convertdelimiterRegex
- delimiter regular expressionfieldNames
- fieldnamesjava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.NoSuchFieldException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
public static <T> T columnStringToObject(java.lang.Class<?> objClass, java.lang.String str, java.util.regex.Pattern delimiterPattern, java.lang.String[] fieldNames) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.lang.NoSuchFieldException, java.lang.reflect.InvocationTargetException
T
- type to returnobjClass
- Class of object to be createdstr
- string to convertdelimiterPattern
- delimiterfieldNames
- fieldnamesjava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.NoSuchMethodException
java.lang.NoSuchFieldException
java.lang.reflect.InvocationTargetException
public static java.lang.String objectToColumnString(java.lang.Object object, java.lang.String delimiter, java.lang.String[] fieldNames) throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
object
- Object to convertdelimiter
- delimiterfieldNames
- fieldnamesjava.lang.IllegalAccessException
java.lang.NoSuchFieldException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
public static java.lang.String capitalize(java.lang.String s)
s
- a string to capitalizepublic static boolean isCapitalized(java.lang.String s)
s
- a stringpublic static java.lang.String searchAndReplace(java.lang.String text, java.lang.String from, java.lang.String to)
public static java.lang.String makeHTMLTable(java.lang.String[][] table, java.lang.String[] rowLabels, java.lang.String[] colLabels)
public static java.lang.String makeTextTable(java.lang.Object[][] table, java.lang.Object[] rowLabels, java.lang.Object[] colLabels, int padLeft, int padRight, boolean tsv)
public static void main(java.lang.String[] args)
public static java.lang.String toAscii(java.lang.String s)
public static java.lang.String toCSVString(java.lang.String[] fields)
public static java.lang.String tr(java.lang.String input, java.lang.String from, java.lang.String to)
Note: This is now optimized to not allocate any objects if the input is returned unchanged.
public static java.lang.String chomp(java.lang.String s)
public static java.lang.String chomp(java.lang.Object o)
public static void printErrInvocationString(java.lang.String cls, java.lang.String[] args)
public static java.lang.String toInvocationString(java.lang.String cls, java.lang.String[] args)
public static java.lang.String getBaseName(java.lang.String fileName)
getBaseName("/u/wcmac/foo.txt") ==> "foo.txt"
public static java.lang.String getBaseName(java.lang.String fileName, java.lang.String suffix)
getBaseName("/u/wcmac/foo.txt", "") ==> "foo.txt"
getBaseName("/u/wcmac/foo.txt", ".txt") ==> "foo"
getBaseName("/u/wcmac/foo.txt", ".pdf") ==> "foo.txt"
public static boolean isAlpha(java.lang.String s)
s
- a String to check using regexpublic static boolean isNumeric(java.lang.String s)
s
- a String to check using regexpublic static boolean isAlphanumeric(java.lang.String s)
s
- a String to check using regexpublic static boolean isPunct(java.lang.String s)
s
- a String to check using regexpublic static boolean isAcronym(java.lang.String s)
s
- a String to check using regexpublic static java.lang.String getNotNullString(java.lang.String s)
public static java.lang.String resolveVars(java.lang.String str, java.util.Map props)
public static java.util.Properties argsToPropertiesWithResolve(java.lang.String[] args)
public static java.util.LinkedHashMap<java.lang.String,java.lang.String> propFileToLinkedHashMap(java.lang.String filename, java.util.Map<java.lang.String,java.lang.String> existingArgs)
filename
- A properties file to readpublic static java.util.Collection<java.lang.String> getNgrams(java.util.List<java.lang.String> words, int minSize, int maxSize)
public static java.util.Collection<java.lang.String> getNgramsFromTokens(java.util.List<CoreLabel> words, int minSize, int maxSize)
public static java.util.Collection<java.lang.String> getNgramsString(java.lang.String s, int minSize, int maxSize)
public static java.util.Collection<java.lang.String> getCharacterNgrams(java.lang.String s, int minSize, int maxSize)
public static java.lang.String normalize(java.lang.String s)
public static java.lang.String toString(java.util.List<CoreLabel> words)
words
- The words to join.public static java.lang.String toString(CoreMap sentence)
sentence
- The sentence to stringify.