Kinkos Disgruntled Customer Dialog Generator
Originally developed for Ian Bogost's game, Disaffected!, the DCDG simply uses the sentence() method of Switchboard with some elaborate queries to find dialog for the customers that enter the Kinkos. I think it is a good illustration of how the sentences() method can be used to get pretty specific results. Here is some of the source code.
// This will be used in the search engines // to find documents that contain the sentences docQuery = "intitle:Kinkos ~sucks customer complaints OR \"kinkos experiences\""; // Make a big long Lucene query to match against the sentences. luceneQuery = "Kinkos^8 copies^4 waited waiting help computers slow "+ ListUtil.implode(WordUtil.getSynonyms("irritated", 10, thes), "^2 ")+" "+ ListUtil.implode(WordUtil.getSynonyms("rude", 5, thes), "^3 ")+" "+ ListUtil.implode(WordUtil.getSynonyms("inept", 10, thes), "^3 "); board = new Switchboard(this); board.setGoogleKey("XXXXXXXXXXXXXXXXXXXXXXX"); board.setYahooKey("XXXXXX"); board.sentences(docQuery, luceneQuery);
The sentence() function first searches Yahoo and Google for pages that have Kinkos in the title, as well as a word that is similar to "sucks", and which can contain the words "customer", "complaints", or "kinos experiences". As the pages come in, Webpages are constructed with the URLs, and the Text is extracted using the getText() method. A Text object is simply a collection of sentences found on the page, and some methods for analyzing and manipulating them. Each sentence on the page is analyzed to see if it matches the Lucene query (see dependencies page for more information about Lucene). If the sentences match, they are returned as results.
This particular program also starts a server socket, and clients can connect to it to receive the results. It starts over when it is done, and goes on indefinitely. You can run it yourself by downloading Switchboard and typing
java -classpath switchboard.jar org.switchboard.test.kinkos.Main
This little program is also a good example of how, using Switchboard, services can be built on top of other services. For example, the sentences() method simply constructs a Switchboard internally, and then uses both google() and yahoo() to find its results. To become a service, it simply extends GenericService, and after it is done breaking down and analyzing the page, it sends results to registered listeners using sendResultsToListeners(), like any other Switchboard service.