public class GraphPoet extends Object
GraphPoet is initialized with a corpus of text, which it uses to derive a word affinity graph. Vertices in the graph are words. Words are defined as non-empty case-insensitive strings of non-space non-newline characters. They are delimited in the corpus by spaces, newlines, or the ends of the file. Edges in the graph count adjacencies: the number of times "w1" is followed by "w2" in the corpus is the weight of the edge from w1 to w2.
For example, given this corpus:
Hello, HELLO, hello, goodbye!
the graph would contain two edges:
where the vertices represent case-insensitive "hello,"
and
"goodbye!"
.
Given an input string, GraphPoet generates a poem by attempting to insert a bridge word between every adjacent pair of words in the input. The bridge word between input words "w1" and "w2" will be some "b" such that w1 -> b -> w2 is a two-edge-long path with maximum-weight weight among all the two-edge-long paths from w1 to w2 in the affinity graph. If there are no such paths, no bridge word is inserted. In the output poem, input words retain their original case, while bridge words are lower case. The whitespace between every word in the poem is a single space.
For example, given this corpus:
This is a test of the Mugar Omni Theater sound system.
on this input:
Test the system.
the output poem would be:
Test of the system.
PS2 instructions: this is a required ADT class, and you MUST NOT weaken the required specifications. However, you MAY strengthen the specifications and you MAY add additional methods. You MUST use Graph in your rep, but otherwise the implementation of this class is up to you.
public GraphPoet(File corpus) throws IOException
corpus
- text file from which to derive the poet's affinity graphIOException
- if the corpus file cannot be found or read