public Examples() throws JWNLException { ACCOMPLISH = Dictionary.getInstance().getIndexWord(POS.VERB, "accomplish"); DOG = Dictionary.getInstance().getIndexWord(POS.NOUN, "dog"); CAT = Dictionary.getInstance().lookupIndexWord(POS.NOUN, "cat"); FUNNY = Dictionary.getInstance().lookupIndexWord(POS.ADJECTIVE, "funny"); DROLL = Dictionary.getInstance().lookupIndexWord(POS.ADJECTIVE, "droll"); }
/** * Main word lookup procedure. First try a normal lookup. If that doesn't work, * try looking up the stemmed form of the lemma. * @param pos the part-of-speech of the word to look up * @param lemma the lemma to look up * @return IndexWord the IndexWord found by the lookup procedure, or null * if an IndexWord is not found */ public IndexWord lookupIndexWord(POS pos, String lemma) throws JWNLException { lemma = prepareQueryString(lemma); IndexWord word = getIndexWord(pos, lemma); if (word == null && getMorphologicalProcessor() != null) { word = getMorphologicalProcessor().lookupBaseForm(pos, lemma); } return word; }
private void loadSynset(int i) throws JWNLException { if (_synsets[i] == null) { _synsets[i] = Dictionary.getInstance().getSynsetAt(_pos, _synsetOffsets[i]); } }
private void demonstrateMorphologicalAnalysis(String phrase) throws JWNLException { // "running-away" is kind of a hard case because it involves // two words that are joined by a hyphen, and one of the words // is not stemmed. So we have to both remove the hyphen and stem // "running" before we get to an entry that is in WordNet System.out.println("Base form for \"" + phrase + "\": " + Dictionary.getInstance().lookupIndexWord(POS.VERB, phrase)); }
protected WordNetManager() throws JWNLException { if (wordnet == null) { synchronized (WordNetManager.class) { if (wordnet == null) { JWNL.initialize(); // Create dictionary object wordnet = Dictionary.getInstance(); } } } }
public boolean execute(POS pos, String lemma, BaseFormSet baseForms) throws JWNLException { if (Dictionary.getInstance().getIndexWord(pos, lemma) != null) { baseForms.add(lemma); return true; } return false; } }
public int getNumSenses(String lemma, String pos) { try { IndexWord iw = dict.getIndexWord(POS.NOUN,lemma); if (iw == null){ return 0; } return iw.getSenseCount(); } catch (JWNLException e) { return 0; } }
/** * Get the IndexWord object for a String and POS */ public synchronized IndexWord getIndexWord(POS pos, String s) throws JWNLException { // This function tries the stemmed form of the lemma return wordnet.lookupIndexWord(pos, s); }
private WordNetAPI(InputStream propsFile) throws Exception { info("Initialize WordNet...: "); if (propsFile == null) throw new RuntimeException("Missing required property 'WN_PROP'"); try { JWNL.initialize(propsFile); wDict = Dictionary.getInstance(); pUtils = PointerUtils.getInstance(); morphProcessor = wDict.getMorphologicalProcessor(); } catch (Exception e) { throw new RuntimeException("Initialization failed", e); } info("Done initializing WordNet..."); }
public boolean execute(POS pos, String derivation, BaseFormSet form) throws JWNLException { Exc exc = Dictionary.getInstance().getException(pos, derivation); if (exc != null) { String[] exceptions = exc.getExceptionArray(); for (int i = 0; i < exceptions.length; i++) { form.add(exceptions[i]); } return true; } return false; } }
/** * Return a set of <code>IndexWord</code>s, with each element in the set * corresponding to a part-of-speech of <var>word</var>. * @param lemma the word for which to lookup senses * @return An array of IndexWords, each of which is a sense of <var>word</var> */ public IndexWordSet lookupAllIndexWords(String lemma) throws JWNLException { lemma = prepareQueryString(lemma); IndexWordSet set = new IndexWordSet(lemma); for (Iterator itr = POS.getAllPOS().iterator(); itr.hasNext();) { IndexWord current = lookupIndexWord((POS)itr.next(), lemma); if (current != null) set.add(current); } return set; } }
public synchronized ArrayList<String> getMorphs(POS pos, String lexicalForm) throws JWNLException { HashSet<String> forms = new LinkedHashSet<>(); List<?> baseForms = wordnet.getMorphologicalProcessor().lookupAllBaseForms(pos, lexicalForm); for (Object baseForm : baseForms) { forms.add(baseForm.toString()); } return new ArrayList<>(forms); }
public void getAllIndexWords(String word){ allIndexWords.clear(); IndexWord[] iWordArr = null; IndexWord iWord = null; try { IndexWordSet iWordSet = wDict.lookupAllIndexWords(word); if(iWordSet != null){ iWordArr = iWordSet.getIndexWordArray(); for(int i=0;i<iWordArr.length;i++){ iWord = iWordArr[i]; //System.out.println("indexWord:"+iWord.getLemma()); allIndexWords.add(iWord); } } } catch (Exception e) { //System.out.println("getSynonym ERROR: " + word); } }
public synchronized Synset getSynset(POS pos, long offset) throws JWNLException { return wordnet.getSynsetAt(pos, offset); }
private void demonstrateMorphologicalAnalysis(String phrase) throws JWNLException { // "running-away" is kind of a hard case because it involves // two words that are joined by a hyphen, and one of the words // is not stemmed. So we have to both remove the hyphen and stem // "running" before we get to an entry that is in WordNet System.out.println("Base form for \"" + phrase + "\": " + Dictionary.getInstance().lookupIndexWord(POS.VERB, phrase)); }
protected WordNetManager() throws JWNLException { if (wordnet == null) { synchronized (WordNetManager.class) { if (wordnet == null) { JWNL.initialize(); // Create dictionary object wordnet = Dictionary.getInstance(); } } } }
/** * Lookup the base form of a word. Given a lemma, finds the WordNet * entry most like that lemma. This function returns the first base form * found. Subsequent calls to this function with the same part-of-speech * and word will return the same base form. To find another base form for * the pos/word, call lookupNextBaseForm. * @param pos the part-of-speech of the word to look up * @param derivation the word to look up * @return IndexWord the IndexWord found during lookup */ public IndexWord lookupBaseForm(POS pos, String derivation) throws JWNLException { // See if we've already looked this word up LookupInfo info = getCachedLookupInfo(new POSKey(pos, derivation)); if (info != null && info.getBaseForms().isCurrentFormAvailable()) { // get the last base form we retrieved. if you want // the next possible base form, use lookupNextBaseForm return Dictionary.getInstance().getIndexWord(pos, info.getBaseForms().getCurrentForm()); } else { return lookupNextBaseForm(pos, derivation, info); } }
public int getNumSenses(String lemma, String pos) { try { IndexWord iw = dict.getIndexWord(POS.NOUN,lemma); if (iw == null) { return 0; } return iw.getSenseCount(); } catch (JWNLException e) { return 0; } }
/** * Get the IndexWord object for a String and POS */ public synchronized IndexWord getIndexWord(POS pos, String s) throws JWNLException { // This function tries the stemmed form of the lemma return wordnet.lookupIndexWord(pos, s); }
public JWNLDictionary(String searchDirectory) throws IOException, JWNLException { PointerType.initialize(); Adjective.initialize(); VerbFrame.initialize(); Map<POS, String[][]> suffixMap = new HashMap<POS, String[][]>(); suffixMap.put(POS.NOUN,new String[][] {{"s",""},{"ses","s"},{"xes","x"},{"zes","z"},{"ches","ch"},{"shes","sh"},{"men","man"},{"ies","y"}}); suffixMap.put(POS.VERB,new String[][] {{"s",""},{"ies","y"},{"es","e"},{"es",""},{"ed","e"},{"ed",""},{"ing","e"},{"ing",""}}); suffixMap.put(POS.ADJECTIVE,new String[][] {{"er",""},{"est",""},{"er","e"},{"est","e"}}); DetachSuffixesOperation tokDso = new DetachSuffixesOperation(suffixMap); tokDso.addDelegate(DetachSuffixesOperation.OPERATIONS,new Operation[] {new LookupIndexWordOperation(),new LookupExceptionsOperation()}); TokenizerOperation tokOp = new TokenizerOperation(new String[] {" ","-"}); tokOp.addDelegate(TokenizerOperation.TOKEN_OPERATIONS,new Operation[] {new LookupIndexWordOperation(),new LookupExceptionsOperation(),tokDso}); DetachSuffixesOperation morphDso = new DetachSuffixesOperation(suffixMap); morphDso.addDelegate(DetachSuffixesOperation.OPERATIONS,new Operation[] {new LookupIndexWordOperation(),new LookupExceptionsOperation()}); Operation[] operations = {new LookupExceptionsOperation(), morphDso , tokOp}; morphy = new DefaultMorphologicalProcessor(operations); FileManager manager = new FileManagerImpl(searchDirectory,PrincetonRandomAccessDictionaryFile.class); FileDictionaryElementFactory factory = new PrincetonWN17FileDictionaryElementFactory(); FileBackedDictionary.install(manager, morphy,factory,true); dict = net.didion.jwnl.dictionary.Dictionary.getInstance(); morphy = dict.getMorphologicalProcessor(); }