de.aitools.ie.keyphraseextraction
Class Phrase

java.lang.Object
  extended by de.aitools.ie.keyphraseextraction.Phrase
All Implemented Interfaces:
java.lang.Comparable<Phrase>, java.lang.Iterable<java.lang.String>

public class Phrase
extends java.lang.Object
implements java.lang.Comparable<Phrase>, java.lang.Iterable<java.lang.String>

A class to represent a phrase. A phrase is a sequence of one or more words that forms a piece of written or spoken language. This class is a common object to implement several concepts used by different key phrase extraction algorithms such as n-grams or head head noun phrases.

Version:
$Id: Phrase.java,v 1.2 2011/02/15 10:32:47 hoppe Exp $
Author:
martin.trenkmann@uni-weimar.de

Constructor Summary
Phrase()
          The default constructor.
Phrase(java.util.Collection<java.lang.String> words, double score)
          Explicit constructor.
Phrase(java.lang.String word, double score)
          Explicit constructor.
 
Method Summary
 Phrase appendWord(java.lang.String word)
          Adds a new word to the end of this phrase.
 void clear()
          Deletes all words of this phrase and zeros its score.
 int compareTo(Phrase phrase)
          Compares this object with the specified object for order.
 void decrementScore(double decrement)
          Decrements the score of this phrase.
 boolean equals(java.lang.Object obj)
           
 java.lang.String getFirstWord()
          Returns the first word of this phrase.
 java.lang.String getLastWord()
          Returns the last word of this phrase.
 double getScore()
          Returns an algorithm-dependent score value.
 java.lang.String getString()
          Returns the entire phrase as one string.
 java.lang.String getWord(int index)
          Returns the word at the specified position.
 int hashCode()
           
 void incrementScore(double increment)
          Increments the score of this phrase.
 boolean isEmpty()
          Checks if the phrase has zero words.
 java.util.Iterator<java.lang.String> iterator()
           
 Phrase prependWord(java.lang.String word)
          Adds a new word to the beginning of this phrase.
 java.lang.String removeFirstWord()
          Removes and returns the first word of this phrase.
 java.lang.String removeLastWord()
          Removes and returns the last word of this phrase.
 void setScore(double score)
          Sets the algorithm-dependent score value of this phrase.
 void setWord(int index, java.lang.String word)
          Replaces the index-th word of the phrase.
 int size()
          Returns the number of word in this phrase.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Phrase

public Phrase()
The default constructor. Creates an empty phrase.


Phrase

public Phrase(java.lang.String word,
              double score)
Explicit constructor. Creates a phrase from a word/score pair.


Phrase

public Phrase(java.util.Collection<java.lang.String> words,
              double score)
Explicit constructor. Creates a phrase from a collection of words.

Method Detail

appendWord

public Phrase appendWord(java.lang.String word)
Adds a new word to the end of this phrase.

Parameters:
word - the word to append.
Returns:
this object.

clear

public void clear()
Deletes all words of this phrase and zeros its score.


compareTo

public int compareTo(Phrase phrase)
Compares this object with the specified object for order. Note that phrases will be sorted in descending order with respect to their scores. That means, a phrase will be greater than another phrase if its score is less than the other score.

Specified by:
compareTo in interface java.lang.Comparable<Phrase>
See Also:
Comparable.compareTo(Object)

decrementScore

public void decrementScore(double decrement)
Decrements the score of this phrase.

Parameters:
decrement - the value to subtract from the current score.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getFirstWord

public java.lang.String getFirstWord()
Returns the first word of this phrase.

Returns:
the first word of this phrase.
Throws:
java.util.NoSuchElementException - if the phrase is empty.

getLastWord

public java.lang.String getLastWord()
Returns the last word of this phrase.

Returns:
the last word of this phrase.
Throws:
java.util.NoSuchElementException - if the phrase is empty.

getScore

public double getScore()
Returns an algorithm-dependent score value. This value is primarily used by the compareTo(Phrase) method.

Returns:
an algorithm-dependent score value.

getString

public java.lang.String getString()
Returns the entire phrase as one string.

Returns:
the entire phrase.

getWord

public java.lang.String getWord(int index)
Returns the word at the specified position.

Parameters:
index - the position of the element to return.
Returns:
the element at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index is invalid.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

incrementScore

public void incrementScore(double increment)
Increments the score of this phrase.

Parameters:
increment - the value to add to the current score.

isEmpty

public boolean isEmpty()
Checks if the phrase has zero words.

Returns:
true if empty, false otherwise.

iterator

public java.util.Iterator<java.lang.String> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.String>

prependWord

public Phrase prependWord(java.lang.String word)
Adds a new word to the beginning of this phrase.

Parameters:
word - the word to prepend.
Returns:
this object.

removeFirstWord

public java.lang.String removeFirstWord()
Removes and returns the first word of this phrase.

Returns:
the removed first word.
Throws:
java.util.NoSuchElementException - if the phrase is empty.

removeLastWord

public java.lang.String removeLastWord()
Removes and returns the last word of this phrase.

Returns:
the removed last word.
Throws:
java.util.NoSuchElementException - if the phrase is empty.

setScore

public void setScore(double score)
Sets the algorithm-dependent score value of this phrase.

Parameters:
score - the score value.

setWord

public void setWord(int index,
                    java.lang.String word)
Replaces the index-th word of the phrase.

Parameters:
index - the position of the word to replace.
word - the new word to set.
Throws:
java.lang.IndexOutOfBoundsException - if index is invalid.

size

public int size()
Returns the number of word in this phrase.

Returns:
the length of this phrase in words.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object