net.didion.jwnl.dictionary.Dictionary类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中net.didion.jwnl.dictionary.Dictionary类的一些代码示例,展示了Dictionary类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dictionary类的具体详情如下:
包路径:net.didion.jwnl.dictionary.Dictionary
类名称:Dictionary

Dictionary介绍

[英]Abstract representation of a WordNet dictionary. See the architecture documentation for information on subclassing Dictionary.
[中]WordNet字典的抽象表示。有关子类化字典的信息,请参阅体系结构文档。

代码示例

代码示例来源:origin: cc.mallet/mallet

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");
}

代码示例来源:origin: net.sf.jwordnet/jwnl

/**
 * 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;
}

代码示例来源:origin: net.sf.jwordnet/jwnl

private void loadSynset(int i) throws JWNLException {
  if (_synsets[i] == null) {
    _synsets[i] = Dictionary.getInstance().getSynsetAt(_pos, _synsetOffsets[i]);
  }
}

代码示例来源:origin: com.github.steveash.mallet/mallet

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));
}

代码示例来源:origin: CogComp/cogcomp-nlp

protected WordNetManager() throws JWNLException {
  if (wordnet == null) {
    synchronized (WordNetManager.class) {
      if (wordnet == null) {
        JWNL.initialize();
        // Create dictionary object
        wordnet = Dictionary.getInstance();
      }
    }
  }
}

代码示例来源:origin: net.sf.jwordnet/jwnl

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;
  }
}

代码示例来源:origin: Ailab403/ailab-mltk4j

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;
 }
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * 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);
}

代码示例来源:origin: Noahs-ARK/semafor

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...");
}

代码示例来源:origin: net.sf.jwordnet/jwnl

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;
  }
}

代码示例来源:origin: net.sf.jwordnet/jwnl

/**
   * 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;
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

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);
}

代码示例来源:origin: Noahs-ARK/semafor

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);
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

public synchronized Synset getSynset(POS pos, long offset) throws JWNLException {
  return wordnet.getSynsetAt(pos, offset);
}

代码示例来源:origin: de.julielab/jcore-mallet-0.4

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));
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-edison

protected WordNetManager() throws JWNLException {
  if (wordnet == null) {
    synchronized (WordNetManager.class) {
      if (wordnet == null) {
        JWNL.initialize();
        // Create dictionary object
        wordnet = Dictionary.getInstance();
      }
    }
  }
}

代码示例来源:origin: net.sf.jwordnet/jwnl

/**
 * 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);
  }
}

代码示例来源:origin: apache/opennlp-sandbox

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;
 }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-edison

/**
 * 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);
}

代码示例来源:origin: Ailab403/ailab-mltk4j

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();
}

相关文章