public class SentenceMelder
extends java.lang.Object
Constructs a formatted sentence by melding a list of sentence tokens containing words and punctuation.
Example: Printing reconstituted sentence text.
Assume "sentences" is a java.util.List of sentences. Each entry in "sentences" is a sentence -- a list of words expressed as a java.util.list of word objects. The word objects may be simple strings or any object implementing a "toString()" method that yields the text associated with that word. In the following example, we use String as the type for the word objects.
SentenceMelder melder = new SentenceMelder();
for ( int i = 0 ; i < sentences.size() ; i++ )
{
List
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
LDQUOTESTR
Left double curly quote.
|
protected static java.lang.String |
LSQUOTESTR
Left single curly quote.
|
protected static java.lang.String |
RDQUOTESTR
Right double curly quote.
|
protected static java.lang.String |
RSQUOTESTR
Right single curly quote.
|
protected SentenceMelderState |
state
Sentence melder state.
|
Constructor and Description |
---|
SentenceMelder()
Create sentence melder.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
endSentence()
Finish sentence.
|
SentenceMelderState |
getState()
Get state.
|
void |
outputBlank()
Add blank to sentence.
|
protected void |
outputWord(java.lang.String word)
Add word to sentence.
|
void |
processWord(java.lang.String word)
Process word.
|
java.lang.String |
reconstituteSentence(java.util.List<?> sentence)
Reconstitute a list of words to a sentence.
|
void |
reset()
Reset the melder.
|
void |
setState(SentenceMelderState state)
Set state.
|
boolean |
shouldOutputBlank(java.lang.String word,
boolean isFirstWord)
Should blank be output.
|
void |
startSentence()
Start sentence.
|
protected static final java.lang.String LSQUOTESTR
protected static final java.lang.String RSQUOTESTR
protected static final java.lang.String LDQUOTESTR
protected static final java.lang.String RDQUOTESTR
protected SentenceMelderState state
public java.lang.String reconstituteSentence(java.util.List<?> sentence)
sentence
- List of words and punctuation in a sentence.
Normally each word is a plain string,
but the "toString()" operation is performed
on each, so it may be any object type
whose toString() yields a proper word
(e.g., an AdornedWord).public void startSentence()
public void outputBlank()
protected void outputWord(java.lang.String word)
word
- The word to add.
In general this should not be called directly.
public void processWord(java.lang.String word)
word
- The word to add.public java.lang.String endSentence()
public boolean shouldOutputBlank(java.lang.String word, boolean isFirstWord)
word
- The word.isFirstWord
- First word in sentence.public SentenceMelderState getState()
public void setState(SentenceMelderState state)
state
- The sentence melder state.public void reset()
Clears the internal state which tracks quote mark pairing, word count, and the previous word encountered. Usually called between text divisions such as paragraphs.