javatools.datatypes
Class StringModifier

java.lang.Object
  extended by javatools.datatypes.StringModifier

public abstract class StringModifier
extends java.lang.Object

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class is a collection of additional string modification methods. For instance, it provides methods to generate a string from an array, separating array elements by a given delimiter; String array[]={"cat", "mouse", "cheese"}; String imploded=StringModifier.implode(array," eats "); System.out.println(imploded); -> cat eats mouse eats cheese; imploded=StringModifier.implode(array,","); System.out.println(imploded); -> cat,mouse,cheese; This is helpfull for instance to generate a list of values for database insertion; note that there is also a version of that functionality that makes sure the array strings are all formated for database insertion/queries (e.g. put in quotations).


Constructor Summary
StringModifier()
           
 
Method Summary
static boolean areEqual(java.lang.String s1, java.lang.String s2)
          checks for equality between two potential strings
static java.lang.String implode(java.util.Collection<?> col, java.lang.String delim)
           
static java.lang.String implode(java.lang.String[] array, java.lang.String delim)
           
static java.lang.String implodeForDB(java.util.Collection<?> col, java.lang.String delim, Database database)
           
static java.lang.String implodeForDB(java.util.Iterator<?> it, java.lang.String delim, Database database)
           
static
<T,K> java.lang.String
implodeForDB(java.util.Iterator<java.util.Map.Entry<T,K>> it, java.lang.String keyValueDelim, java.lang.String pairDelim, Database database, boolean formatKey, boolean formatValue)
          Concatenates key value pairs of a Map.Entry iterator into a combined String, separating each key from its value by a key-value delimeter and each key-value pair by pair delimeter while optionally applying the database.format function to each key/value
static java.lang.String implodeForDB(java.util.Map<?,?> map, java.lang.String keyValueDelim, java.lang.String pairDelim, Database database, boolean formatKey, boolean formatValue)
          Concatenates key value pairs of a Map into a combined String, separating each key from its value by a key-value delimeter and each key-value pair by pair delimeter while optionally applying the database.format function to each key/value
static
<T> java.lang.String
implodeForDB(T[] col, java.lang.String delim, Database database)
           
static java.lang.String implodeForDBAsConditions(java.util.Map<?,?> map, Database database)
          Concatenates key value pairs of a Map into a combined String representing the pairs as independent column conditions for a database query, applying the database.format function to each value
static java.lang.String limitLength(java.lang.String s, int length)
          limits the length of a String to the given size ie applies s.substring(0,length) for given length iff length
static java.util.Set<java.lang.String> lowercase(java.lang.String... ar)
          applies lowercase to all Strings in an array, returns them as a set
static void main(java.lang.String[] argv)
          Test method
static java.util.Set<java.lang.String> toNGram(java.lang.String original, int n)
          produces an n-gram set from the string
static java.util.Map<java.lang.String,java.lang.Double> toWeighedNGram(java.lang.String original, int n)
          produces a weighed n-gram set from the string
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringModifier

public StringModifier()
Method Detail

implode

public static java.lang.String implode(java.lang.String[] array,
                                       java.lang.String delim)

implode

public static java.lang.String implode(java.util.Collection<?> col,
                                       java.lang.String delim)

implodeForDB

public static java.lang.String implodeForDB(java.util.Collection<?> col,
                                            java.lang.String delim,
                                            Database database)

implodeForDB

public static java.lang.String implodeForDB(java.util.Iterator<?> it,
                                            java.lang.String delim,
                                            Database database)

implodeForDB

public static <T> java.lang.String implodeForDB(T[] col,
                                                java.lang.String delim,
                                                Database database)

implodeForDBAsConditions

public static java.lang.String implodeForDBAsConditions(java.util.Map<?,?> map,
                                                        Database database)
Concatenates key value pairs of a Map into a combined String representing the pairs as independent column conditions for a database query, applying the database.format function to each value

Parameters:
map - the Map to be imploded
database - the Database instance for which the pairs shall be formatted

implodeForDB

public static java.lang.String implodeForDB(java.util.Map<?,?> map,
                                            java.lang.String keyValueDelim,
                                            java.lang.String pairDelim,
                                            Database database,
                                            boolean formatKey,
                                            boolean formatValue)
Concatenates key value pairs of a Map into a combined String, separating each key from its value by a key-value delimeter and each key-value pair by pair delimeter while optionally applying the database.format function to each key/value

Parameters:
map - the Map to be imploded
keyValueDelimeter - delimeter inserted between each key and its value
pairDelimeter - delimeter inserted between key-value pairs
database - the Database instance for which the pairs shall be formatted
formatKey - flag indicating whether to format the keys with database.format
formatValue - flag indicating whether to format the values with database.format

implodeForDB

public static <T,K> java.lang.String implodeForDB(java.util.Iterator<java.util.Map.Entry<T,K>> it,
                                                  java.lang.String keyValueDelim,
                                                  java.lang.String pairDelim,
                                                  Database database,
                                                  boolean formatKey,
                                                  boolean formatValue)
Concatenates key value pairs of a Map.Entry iterator into a combined String, separating each key from its value by a key-value delimeter and each key-value pair by pair delimeter while optionally applying the database.format function to each key/value

Parameters:
it - the Map.Entry iterator
keyValueDelimeter - delimeter inserted between each key and its value
pairDelimeter - delimeter inserted between key-value pairs
database - the Database instance for which the pairs shall be formatted
formatKey - flag indicating whether to format the keys with database.format
formatValue - flag indicating whether to format the values with database.format

limitLength

public static java.lang.String limitLength(java.lang.String s,
                                           int length)
limits the length of a String to the given size ie applies s.substring(0,length) for given length iff length

toNGram

public static java.util.Set<java.lang.String> toNGram(java.lang.String original,
                                                      int n)
produces an n-gram set from the string

Parameters:
original - the String to be split into n-grams of size n
n - size of the n-grams
Returns:
set of n-grams

toWeighedNGram

public static java.util.Map<java.lang.String,java.lang.Double> toWeighedNGram(java.lang.String original,
                                                                              int n)
produces a weighed n-gram set from the string

Parameters:
original - the String to be split into n-grams of size n
n - size of the n-grams
Returns:
map of n-grams with their weight (frequency/overall number of ngrams)

lowercase

public static final java.util.Set<java.lang.String> lowercase(java.lang.String... ar)
applies lowercase to all Strings in an array, returns them as a set


areEqual

public static final boolean areEqual(java.lang.String s1,
                                     java.lang.String s2)
checks for equality between two potential strings


main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Test method

Throws:
java.lang.Exception