// this one needs be run locally (at least for now)
import ctext.*;
CText message;
CText[] ctexts;
CTextInput input;
CWordnet wordnet;
void setup()
{
size(300, 300);
wordnet = new CWordnet(this);
input = new CTextInput(this, width/3f, 60);
message = new CText(this, "click in the box & type a noun:", width/2, 55);
}
void draw()
{
background(200);
CText.drawAll();
}
// called when return is typed in the input box
void onTextInput(String input)
{
String[] result = wordnet.getHyponyms(input, "n");
message.setText("hyponyms for: "+input);
if (result == null)
message.setText("'"+input+"' not found!");
displayResults(result);
}
// displays the results from wordnet
void displayResults(String[] result)
{
CText.dispose(ctexts);
// split the results into ctexts, 1 word per
ctexts = CText.toCTextWords(this, result, width/2, 100);
if (ctexts != null) { // and display them
for (int i = 0; ctexts != null && i < ctexts.length; i++) {
CText ct = ctexts[i];
ct.moveTo(random(0, width-ct.textWidth()), height+20, random(4,6));
}
}
else {
ctexts = new CText[1]; // uh-oh, no result
ctexts[0] = new CText(this, "[empty result set]");
}
}