Package textprocessing
Class Bigram
java.lang.Object
textprocessing.Word
textprocessing.Bigram
- All Implemented Interfaces:
Comparable<Word>
A class that represents a bigram
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLocation
(long location) Adds a new locations to an existing Bigram and increments the number of occurrences.int
Compares this object with the specified object for order.boolean
Compares another Object to check if that Object is equal to this Bigram.toString()
Generates a String representation of the Bigram that contains both words of the Bigram and the number of occurrences of the Bigram.
-
Field Details
-
word2
-
occurrences
private int occurrences -
locations
-
-
Constructor Details
-
Bigram
Constructor for a Bigram- Parameters:
word1
- the first Word in the Bigramword2
- the second Word in the Bigram
-
-
Method Details
-
addLocation
Adds a new locations to an existing Bigram and increments the number of occurrences. If the location already has been added, or the location is not a valid location (i.e. negative), an exception is thrown.- Specified by:
addLocation
in classWord
- Parameters:
location
- a location of the bigram- Throws:
IllegalArgumentException
- thrown if the location already exists or is invalid
-
toString
Generates a String representation of the Bigram that contains both words of the Bigram and the number of occurrences of the Bigram. Example:
the penguin 18
-
equals
Compares another Object to check if that Object is equal to this Bigram. Equality is measured by whether the other Object is also a Bigram and both words contained in this Bigram matches exactly the words contained in the other Bigram object in the same order. -
compareTo
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
For this class, we are comparing the number of occurrences of the two Bigrams.- Parameters:
that
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-