info.ephyra.util
Class StringUtils

java.lang.Object
  extended by info.ephyra.util.StringUtils

public class StringUtils
extends java.lang.Object

A collection of utilities for string processing.

Version:
2007-05-05
Author:
Nico Schlaefer

Field Summary
private static float INTERSECT_THRESH
          Fraction of words that must occur in both strings for equalsIntersect() to be true.
 
Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String concat(java.lang.String[] ss, java.lang.String delim)
          Concatenates an array of strings, using the given delimiter.
static java.lang.String concatWithSpaces(java.lang.String[] ss)
          Concatenates an array of strings, using whitespaces as delimiters.
static java.lang.String concatWithTabs(java.lang.String[] ss)
          Concatenates an array of strings, using tabs as delimiters.
static boolean equalsCommon(java.lang.String s1, java.lang.String s2)
          Compares two strings.
static boolean equalsCommonNorm(java.lang.String s1, java.lang.String s2)
          Compares the normalizations of the two strings, using the same criterion as the equalsCommon() method.
static boolean equalsCommonProp(java.lang.String s1, java.lang.String s2)
          Compares two strings, using the same criterion as the equalsCommonNorm() method, but considers only words starting with a capital letter (proper nouns)
static boolean equalsIntersect(java.lang.String s1, java.lang.String s2)
          Compares two strings.
static boolean equalsIntersectNorm(java.lang.String s1, java.lang.String s2)
          Compares the normalizations of the two strings, using the equalsIntersect() method.
static boolean equalsNorm(java.lang.String s1, java.lang.String s2)
          Compares the normalizations of the two strings, using the standard String.equals() method.
static boolean equalsSubset(java.lang.String s1, java.lang.String s2)
          Compares two strings.
static boolean equalsSubsetNorm(java.lang.String s1, java.lang.String s2)
          Compares the normalizations of the two strings, using the equalsSubset() method.
private static boolean isSubset(java.lang.String[] tokens1, java.lang.String[] tokens2)
          Checks if the first array of tokens is a subset if the second array.
static boolean isSubset(java.lang.String s1, java.lang.String s2)
          Checks if the tokens in the first string form a subset of the tokens in the second string.
static boolean isSubsetKeywords(java.lang.String s1, java.lang.String s2)
          Checks if the tokens in the first string form a subset of the tokens in the second string.
static java.lang.String normalize(java.lang.String s)
          Normalizes a string.
static java.lang.String repeat(java.lang.String s, int n)
          Repeats string s n times.
static java.lang.String replaceIgnoreCase(java.lang.String s, java.lang.String s1, java.lang.String s2)
          Replaces all substrings of s that match s1 with s2.
static void sortByLength(java.lang.String[] ss)
          Sorts an array of strings by their length in ascending order.
static void sortByLengthDesc(java.lang.String[] ss)
          Sorts an array of strings by their length in descending order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERSECT_THRESH

private static final float INTERSECT_THRESH
Fraction of words that must occur in both strings for equalsIntersect() to be true.

See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

isSubset

private static boolean isSubset(java.lang.String[] tokens1,
                                java.lang.String[] tokens2)
Checks if the first array of tokens is a subset if the second array.

Parameters:
tokens1 - token array 1
tokens2 - token array 2
Returns:
true, iff ss1 is a subset of ss2

isSubset

public static boolean isSubset(java.lang.String s1,
                               java.lang.String s2)
Checks if the tokens in the first string form a subset of the tokens in the second string.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the tokens in s1 are a subset of the tokens in s2

isSubsetKeywords

public static boolean isSubsetKeywords(java.lang.String s1,
                                       java.lang.String s2)
Checks if the tokens in the first string form a subset of the tokens in the second string. Function words and tokens of length less than 2 are ignored.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the keywords in s1 are a subset of the tokens in s2

concat

public static java.lang.String concat(java.lang.String[] ss,
                                      java.lang.String delim)
Concatenates an array of strings, using the given delimiter.

Parameters:
ss - array of strings
delim - delimiter
Returns:
concatenated string

concatWithSpaces

public static java.lang.String concatWithSpaces(java.lang.String[] ss)
Concatenates an array of strings, using whitespaces as delimiters.

Parameters:
ss - array of strings
Returns:
concatenated string

concatWithTabs

public static java.lang.String concatWithTabs(java.lang.String[] ss)
Concatenates an array of strings, using tabs as delimiters.

Parameters:
ss - array of strings
Returns:
concatenated string

repeat

public static java.lang.String repeat(java.lang.String s,
                                      int n)
Repeats string s n times.

Parameters:
s - a string
n - number of repetitions

normalize

public static java.lang.String normalize(java.lang.String s)
Normalizes a string. Similar strings are mapped to equal normalizations.

Parameters:
s - the string
Returns:
normalized string

equalsNorm

public static boolean equalsNorm(java.lang.String s1,
                                 java.lang.String s2)
Compares the normalizations of the two strings, using the standard String.equals() method.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the normalizations are equal

equalsSubset

public static boolean equalsSubset(java.lang.String s1,
                                   java.lang.String s2)
Compares two strings. The strings are considered equal, iff one of the strings is a subset of the other string, i.e. iff all the tokens in the one string also occur in the other string.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the strings are equal in the sense defined above

equalsSubsetNorm

public static boolean equalsSubsetNorm(java.lang.String s1,
                                       java.lang.String s2)
Compares the normalizations of the two strings, using the equalsSubset() method.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the normalizations are equal

equalsIntersect

public static boolean equalsIntersect(java.lang.String s1,
                                      java.lang.String s2)
Compares two strings. The strings are considered equal, iff the number of words that occur in both strings over the total number of words is at least INTERSECT_FRAC.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the strings are equal in the sense defined above

equalsIntersectNorm

public static boolean equalsIntersectNorm(java.lang.String s1,
                                          java.lang.String s2)
Compares the normalizations of the two strings, using the equalsIntersect() method.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the normalizations are equal

equalsCommon

public static boolean equalsCommon(java.lang.String s1,
                                   java.lang.String s2)
Compares two strings. The strings are considered equal, iff they have a common token. Function words and tokens of length less than 2 are ignored.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the strings are equal in the sense defined above

equalsCommonNorm

public static boolean equalsCommonNorm(java.lang.String s1,
                                       java.lang.String s2)
Compares the normalizations of the two strings, using the same criterion as the equalsCommon() method.

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the normalizations are equal

equalsCommonProp

public static boolean equalsCommonProp(java.lang.String s1,
                                       java.lang.String s2)
Compares two strings, using the same criterion as the equalsCommonNorm() method, but considers only words starting with a capital letter (proper nouns)

Parameters:
s1 - string 1
s2 - string 2
Returns:
true, iff the proper nouns are equal

replaceIgnoreCase

public static java.lang.String replaceIgnoreCase(java.lang.String s,
                                                 java.lang.String s1,
                                                 java.lang.String s2)
Replaces all substrings of s that match s1 with s2. This method is similar to String.replace(), but it ignores the case of s1.

Parameters:
s - the string
s1 - the substring to be replaced
s2 - the replacement for the substring
Returns:
modified string

sortByLength

public static void sortByLength(java.lang.String[] ss)

Sorts an array of strings by their length in ascending order.

This sort is guaranteed to be stable: strings of equal length are not reordered.

Parameters:
ss - array of strings

sortByLengthDesc

public static void sortByLengthDesc(java.lang.String[] ss)

Sorts an array of strings by their length in descending order.

This sort is guaranteed to be stable: strings of equal length are not reordered.

Parameters:
ss - array of strings