package concordance.processing; import java.io.*; import java.nio.*; import java.nio.channels.*; import java.util.*; import java.io.IOException; import a2z.*; import java.util.regex.*; import concordance.treemap.Word; import processing.core.PApplet; import processing.core.PFont; import rita.*; import rita.wordnet.*; //import flickr.FlickrHelper; public class ConcordanceProcessing4 extends PApplet { String[] goodWordsArray = { "insect", "flesh", "liquid", "fluid", "head", "face", "body", "partner", "animal" }; TreeMap words; PFont fo; Iterator iterator; boolean iteratorSet; int width = 1300; int height = 800; int currentWord = 0; String wordsString = ""; // String[] holArray; Vector tokenVector = new Vector(); Vector wordCountVector = new Vector(); Vector posVector = new Vector(); Vector syllableVector = new Vector(); Vector photoVector = new Vector(); String outputWords = ""; String outputWordCounts = ""; String outputPos = ""; String syllableString = ""; String stressString = ""; boolean loadingDone = false; long time = 0; String[] myHypernyms; RiPosTagger posTagger = new RiPosTagger(this); // FlickrHelper f = new FlickrHelper(); RiWordnet wordnet = new RiWordnet(null); public static void main(String _args[]) { PApplet.main(new String[] { getQualifiedClassName() }); } public static String getQualifiedClassName() { return new Exception().getStackTrace()[1].getClassName(); } public void setup() { frameRate(25); size(200, 200); background(200); fillConcordance("whyiatemywife.txt"); } public void draw() { } public void fillConcordance(String path) { try { A2ZFileReader fr = new A2ZFileReader(path); String content = fr.getContent(); words = new TreeMap(); String tokens[] = content.split(" "); Pattern p = Pattern.compile("\\S+", Pattern.CASE_INSENSITIVE); // For every word for (int i = 0; i < tokens.length; i++) { String s = tokens[i].toLowerCase(); // If it matches our regex, insert it in the tree Matcher m = p.matcher(s); if (m.matches()) { if (words.containsKey(s)) { Word w = (Word) words.get(s); w.count(); } else { Word w = new Word(s); words.put(s, w); w.getWord(); } } } // String wordsString = ""; String wordCountsString = ""; String posString = ""; String photoString = ""; for (int i = 0; i < tokens.length; i++) { // System.out.println(i); if (words.containsKey(tokens[i].toLowerCase())) { String thisWord = tokens[i].toLowerCase(); String myWord = tokens[i]; // System.out.println("myWord " + myWord); // String[] pos1 = wordnet.getAllSynonyms(myWord); // String[] holArray = wordnet.getAllHolonyms(thisWord, "n"); // if(holArray != null) { // System.out.println("!!!" + holArray.length); // } else { // System.out.println("!!!null"); // } /* * if (holArray != null) { System.out.println("holArray " + * holArray); } Vector holVector = new Vector(); * String[] holArray = null; if(wordnet.exists(thisWord)) { * holArray = wordnet.getAllHolonyms(thisWord, "n"); } * System.out.println(holArray); if (holArray != null) { * System.out.println("length " + holArray.length); for (int * c = 0; c < holArray.length; c++) { * holVector.add(holArray[c]); } // * System.out.println("Random noun: " + word); // Sort * alphabetically // Arrays.sort(synonyms); int synSize = * holArray.length; for (int d = 0; d < synSize; d++) { * holVector.add(holArray[d]); // * System.out.println("Synonym " + i + ": " + // * holArray[i]); String[] subHolArray = * wordnet.getAllHolonyms( holArray[d], "n"); if * (subHolArray != null) { // * System.out.println(subHolArray.length); for (int j = 0; j < * subHolArray.length; j++) { // * System.out.println(subHolArray[j]); * holVector.add(subHolArray[j]); } } } boolean matchFound = * false; for (int k = 0; k < holVector.size(); k++) { for * (int l = 0; l < goodWordsArray.length; l++) { if * (holVector.get(k).matches(goodWordsArray[l])) { * System.out.println(goodWordsArray[l] + ": " + tokens[i]); * String[] photos = f.findPhotos(tokens[i], 1); * photoVector.add(photos[0]); System.out.println(tokens[i] + " "+ * photos[0]); System.out.println(tokens[i] + * photoVector.get(photoVector.size()-1)); photoString += * photos[0] + " "; matchFound = true; break; } if * (matchFound == true) { break; } } } } else { photoString += * "x "; // /put an x in the photoString } */ String thisGetPos = posTagger.tag(thisWord); System.out.println(thisGetPos); String thisPos = ""; // System.out.println(tokens[i] + " " + thisGetPos); if (thisGetPos.indexOf("v") > -1) { thisPos = "v"; } else if (thisGetPos.indexOf("nn") > -1) { thisPos = "n"; } else if (thisGetPos.indexOf("jj") > -1) { thisPos = "j"; } else { thisPos = "X"; } // System.out.println("thisPos " + thisPos); posString += thisPos + " "; Word wo = (Word) words.get(tokens[i].toLowerCase()); tokenVector.add(tokens[i]); int wordCount = wo.getCount(); String wordCountString = Integer.toString(wordCount); wordCountVector.add(wordCountString); wordsString += tokens[i] + " "; wordCountsString += wordCount + " "; } } FileOutputStream fos = new FileOutputStream("newTest.txt"); FileChannel outfc = fos.getChannel(); String variablesString = "variable1=" + wordsString + "&variable2=" + wordCountsString + "&variable3=" + posString + "&variable4=" + photoString; ByteBuffer bb = ByteBuffer.wrap(variablesString.getBytes()); outfc.write(bb); outfc.close(); System.out.println("DONE!"); loadingDone = true; } catch (IOException e) { // //System.out.println("File I/O Error"); e.printStackTrace(); System.out.println("ERRRRROOOOOOOOORRRRRRRRRRR"); } loadingDone = true; } public void getTextInfo() { } /* * public void stop() { Ess.stop(); // When program stops, stop Ess too * super.stop(); } */ }