You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// needs Wordnet...publicclassReplaceableWritingextendsPApplet
{
RiText[] rts;
RiWordnetwordnet;
intcharsPerLine = 60;
Stringtest = "Last Wednesday we decided to visit the zoo. We arrived the next morning after we breakfasted, cashed in our passes and entered. We walked toward the first exhibits. I looked up at a giraffe as it stared back at me. I stepped nervously to the next area. One of the lions gazed at me as he lazed in the shade while the others napped. One of my friends first knocked then banged on the tempered glass in front of the monkey’s cage. They howled and screamed at us as we hurried to another exhibit where we stopped and gawked at plumed birds. After we rested, we headed for the petting zoo where we petted wooly sheep who only glanced at us but the goats butted each other and nipped our clothes when we ventured too near their closed pen. Later, our tired group nudged their way through the crowded paths and exited the turnstiled gate. Our car bumped, jerked and swayed as we dozed during the relaxed ride home.";
publicvoidsetup()
{
size(400, 400);
RiText.defaults.alignment = LEFT;
wordnet = newRiWordnet(this);
rts = RiText.createLines(this, test, 30, 50, charsPerLine);
}
publicvoiddraw()
{
background(180);
// substitute every 50 frames if (frameCount % 50 == 1)
doSubstitution();
}
/* replace a random word in the paragraph with one from wordnet with the same (basic) part-of-speech */voiddoSubstitution()
{
String[] words = test.split(" ");
// loop from a random spotintcount = (int)random(0, words.length);
for (inti = count; i < words.length; i++)
{
// only words of 3 or more charsif (words[i].length()<3) continue;
// get the posStringpos = wordnet.getBestPos(words[i].toLowerCase());
if (pos != null)
{
// get the synsetString[] syns = wordnet.getSynset(words[i], pos);
if (syns == null) continue;
// pick a random synonymStringnewStr = syns[(int)random(0, syns.length)];
if (Character.isUpperCase(words[i].charAt(0)))
newStr = RiTa.upperCaseFirst(newStr); // keep capitals// and make a substitutiontest = RiText.regexReplace("\\b"+words[i]+"\\b", test, newStr);
RiText.deleteAll(); // clean up the last batch// create a RiText[] from 'test' starting at (30,50) & going downrts = RiText.createLines(this, test, 30, 50, charsPerLine);
break;
}
if (count == words.length) count = 0;
}
}
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: