@Test public void testSearch() throws NoSuchAlgorithmException { search.setMatcher(new MatcherForMd5(matchingMd5)); wordlist.addWord("poultry"); wordlist.addWord("outwits"); wordlist.addWord("ants"); String phrase = search.findit(); Assert.assertEquals(testPhrase, phrase); }
/** * Returns the index of the word which has the <var>lemma</var> or -1 if not found. * * @param lemma lemma to check * @return true if <var>lemma</var> is one of the words contained in this synset */ public int indexOfWord(String lemma) { if (null == lemma) { throw new IllegalArgumentException(JWNL.resolveMessage("DICTIONARY_EXCEPTION_046")); } for (int i = 0; i < words.size(); i++) { if (words.get(i).getLemma().equalsIgnoreCase(lemma)) { return i; } } return -1; }
@Test public void testMakeTestPhrase() { int[] indexArray = search.makeIndexArray(); wordlist.addWord("this"); wordlist.addWord("isa"); wordlist.addWord("test"); indexArray[0] = 0; indexArray[1] = 1; indexArray[2] = 2; String phrase = search.makePhrase(indexArray); Assert.assertEquals("this isa test", phrase); }
@Test public void testMatching() throws NoSuchAlgorithmException { search.setMatcher(new MatcherForMd5(matchingMd5)); int[] indexArray = search.makeIndexArray(); wordlist.addWord("poultry"); wordlist.addWord("outwits"); wordlist.addWord("ants"); indexArray[0] = 0; indexArray[1] = 1; indexArray[2] = 2; String probe = testPhrase.replace(" ", ""); Assert.assertEquals(testPhrase, search.makePhrase(indexArray)); Assert.assertTrue(search.matching(probe, indexArray)); }
/** Print the stored script. */ public void print() { if (printKeys) keys.print(0); if (printSyns) syns.print(0); if (printPrePost) { pre.print(0); post.print(0); } if (printInitialFinal) { System.out.println("initial: " + initial); System.out.println("final: " + finl); quit.print(0); } }
/** * Process a sentence. (1) Make pre transformations. (2) Check for quit word. (3) Scan sentence * for keys, build key stack. (4) Try decompositions for each key. */ String sentence(String s) { s = pre.translate(s); s = EString.pad(s); if (quit.find(s)) { finished = true; return finl; } keys.buildKeyStack(keyStack, s); for (int i = 0; i < keyStack.keyTop(); i++) { Key gotoKey = new Key(); String reply = decompose(keyStack.key(i), s, gotoKey); if (reply != null) return reply; // If decomposition returned gotoKey, try it while (gotoKey.key() != null) { reply = decompose(gotoKey, s, gotoKey); if (reply != null) return reply; } } return null; }
@Before public void prolog() throws NoSuchAlgorithmException { wordlist = new WordList(); search = new Search(wordlist.getList()); }
/** Process a line of script input. */ public void collect(String s) { String lines[] = new String[4]; if (EString.match(s, "*reasmb: *", lines)) { if (lastReasemb == null) { System.out.println("Error: no last reasemb"); return; } lastReasemb.add(lines[1]); } else if (EString.match(s, "*decomp: *", lines)) { if (lastDecomp == null) { System.out.println("Error: no last decomp"); return; } lastReasemb = new ReasembList(); String temp = new String(lines[1]); if (EString.match(temp, "$ *", lines)) { lastDecomp.add(lines[0], true, lastReasemb); } else { lastDecomp.add(temp, false, lastReasemb); } } else if (EString.match(s, "*key: * #*", lines)) { lastDecomp = new DecompList(); lastReasemb = null; int n = 0; if (lines[2].length() != 0) { try { n = Integer.parseInt(lines[2]); } catch (NumberFormatException e) { System.out.println("Number is wrong in key: " + lines[2]); } } keys.add(lines[1], n, lastDecomp); } else if (EString.match(s, "*key: *", lines)) { lastDecomp = new DecompList(); lastReasemb = null; keys.add(lines[1], 0, lastDecomp); } else if (EString.match(s, "*synon: * *", lines)) { WordList words = new WordList(); words.add(lines[1]); s = lines[2]; while (EString.match(s, "* *", lines)) { words.add(lines[0]); s = lines[1]; } words.add(s); syns.add(words); } else if (EString.match(s, "*pre: * *", lines)) { pre.add(lines[1], lines[2]); } else if (EString.match(s, "*post: * *", lines)) { post.add(lines[1], lines[2]); } else if (EString.match(s, "*initial: *", lines)) { initial = lines[1]; } else if (EString.match(s, "*final: *", lines)) { finl = lines[1]; } else if (EString.match(s, "*quit: *", lines)) { quit.add(" " + lines[1] + " "); } else { System.out.println("Unrecognized input: " + s); } }