Class SentenceUtil

java.lang.Object
  extended bySentenceUtil

public class SentenceUtil
extends java.lang.Object

The SentenceUtil class provide utility functions for the various Books. It is not designed to be used outside of the book package, so using it outside of these bounds is at your own risk.

Distribution Licence:
JSword is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
The copyright to this program is held by it's authors.

Version:
$Id: SentenceUtil.java,v 1.1 2005/05/09 01:29:07 dmsmith Exp $
Author:
Joe Walker [joe at eireneh dot com] Morten Tvenning rewrote some of this Class
See Also:
gnu.gpl.Licence

Method Summary
static int firstLetter(java.lang.String word)
          Where is the first letter in this word
static java.lang.String[] getWords(java.lang.String sentence)
          From a sentence get a list of words (in original order) without any punctuation, and all in lower case.
static int lastLetter(java.lang.String word)
          Where is the last letter in this word
static java.lang.String[] stripPunctuation(java.lang.String[] words)
          From a sentence get a list of words (in original order) without any punctuation, and all in lower case.
static java.lang.String stripPunctuationWord(java.lang.String word)
          Remove the punctuation from the ends of the word
static java.lang.String[] stripWords(java.lang.String[] words)
          From a sentence get a list of words (in original order) without any punctuation, and all in lower case.
static java.lang.String stripWords(java.lang.String first, java.lang.String last)
          Remove the punctuation from the ends of the word.
static java.lang.String[] tokenize(java.lang.String sentence)
          Take a string and tokenize it using " " and "--" as delimiters into an Array of Strings.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

tokenize

public static java.lang.String[] tokenize(java.lang.String sentence)
Take a string and tokenize it using " " and "--" as delimiters into an Array of Strings. There is a question mark over what to do with initial spaces. This algorithm disgards them, I'm not sure if this is the right thing to do.

Parameters:
sentence - The string to parse.
Returns:
The string array

stripPunctuation

public static java.lang.String[] stripPunctuation(java.lang.String[] words)
From a sentence get a list of words (in original order) without any punctuation, and all in lower case.

Parameters:
words - Words with punctuation
Returns:
Words without punctuation

stripWords

public static java.lang.String[] stripWords(java.lang.String[] words)
From a sentence get a list of words (in original order) without any punctuation, and all in lower case.

Parameters:
words - Words with punctuation
Returns:
Punctuation without words

getWords

public static java.lang.String[] getWords(java.lang.String sentence)
From a sentence get a list of words (in original order) without any punctuation, and all in lower case.

Parameters:
sentence - The string to parse.
Returns:
The words split up as an array

stripPunctuationWord

public static java.lang.String stripPunctuationWord(java.lang.String word)
Remove the punctuation from the ends of the word

Parameters:
word - Word with punctuation
Returns:
Word without punctuation

stripWords

public static java.lang.String stripWords(java.lang.String first,
                                          java.lang.String last)
Remove the punctuation from the ends of the word. The special case is that if the first word ends "--" and the last word has no punctuation at the beginning, then the answer is "--" and not "-- ". We miss out the space because "--" is a special separator.

Parameters:
first - The word to grab the punctuation from the end of
last - The word to grab the punctuation from the start of
Returns:
The end of the first, a space, and the end of the first

firstLetter

public static int firstLetter(java.lang.String word)
Where is the first letter in this word

Parameters:
word - The word to search for letters
Returns:
The offset of the first letter

lastLetter

public static int lastLetter(java.lang.String word)
Where is the last letter in this word

Parameters:
word - The word to search for letters
Returns:
The offset of the last letter