Haiku Finder

Haiku Finder (in Java)

So far this might not 
seem very interesting, and 
in fact it is not. 

WARNING: this page is in violation of the Call for Complete Elimination of Joke Haiku Production on the Internet.

Haiku.java is a program that searches a file for instances of unintentional haiku; that is, complete sentences that form a stanza with 5 syllables in the first line, seven in the second, and 5 in the last.

I got the idea from Danny O'Brien who wrote a version in Python. According to his README, he got the idea from Don Marti, who wrote a version in Perl. His README also contains a brief discussion of the validity of calling a seventeen-syllable sentence a haiku.

Don elisted the aid of the linux elitists, who helped with the hard part of the problem, which is mappings words to syllable counts.

All of us got our syllable counters from CMU, in a file called c06d

Here are some of the haiku I found in my book, How to Think Like a Computer Scientist:

The first line creates 
a new Point object and makes 
blank refer to it. 

There are two kinds of 
types in Java, primitive 
types and object types. 

In any program, 
one class is designated 
as the startup class. 

We have already 
seen two built-in types like this, 
Point and Rectangle. 

All by itself, this 
code fragment is a legal 
class definition. 

So far this might not 
seem very interesting, and 
in fact it is not. 

Diamonds? One has a 
higher rank, but the other 
has a higher suit. 

To search the array, 
choose an index between low 
and high (call it mid) 
and compare it to 
the card you are looking for. 
If you found it, stop. 

The easiest way 
to tell that your card is not 
in the deck is if 
there are no cards in 
the deck, which is the case if 
high is less than low. 

Drawing a picture 
is usually the best 
way to avoid them. 

Place both decks face up 
in front of you. Compare the 
top card from each deck 
and choose the lower 
one. Flip it over and add 
it to the merged deck. 

So far, every 
method we have written has 
been a class method. 

Java assumes that 
you are invoking it on 
the current object. 

If you look at the 
documentation of Frame, 
for example, you 
will see the part of 
the hierarchy that makes 
up Frame's pedigree. 

We have to use the 
next value from each node to 
get to the next node. 

So, even though head 
and tail have the same type, they 
play different roles. 

Priority Queues: 
In real life a queue is a 
line of customers 
waiting for service 
of some kind. In most cases, 
the first customer 
in line is the next 
customer to be served. There 
are exceptions, though. 

Golfer implements 
Comparable. If we try 
to compile Golfer.java 
at this point, we get 
something like "class Golfer must 
be declared abstract."

Return the left child 
of this node, or an empty 
tree if there is none. 

Return the right child 
of this node, or an empty 
tree if there is none. 

A way to traverse 
a tree, visiting each node 
before its children. 

Heap remove: It might 
seem odd that we are going 
to remove things from 
the heap before we 
insert any, but it turns 
out that removal 
is easier to 
explain.  At first glance, we might 
think that removing 
an item from the 
heap would be a constant time 
operation, since 
the item with the 
highest priority is 
always at the root. 

For example, see 
the documentation of 
equals for Doubles. 

A function that maps 
values of a certain type 
onto integers.