net.didion.jwnl.dictionary.Dictionary.lookupIndexWord()方法的使用及代码示例

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

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

Dictionary.lookupIndexWord介绍

[英]Main word lookup procedure. First try a normal lookup. If that doesn't work, try looking up the stemmed form of the lemma.
[中]主字查找程序。首先尝试正常查找。如果这不起作用,试着查找引理的词干形式。

代码示例

代码示例来源: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: 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: cc.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: de.julielab/jcore-mallet-2.0.9

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: 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: 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: Noahs-ARK/semafor

/**
 * Gets the lemma of a word.
 * 
 * @param word a word
 * @param pos part of speech
 * @return lemma or the input if it could not be lemmatized
 */
public static String getLemma(String word, POS pos) {
  if (wDict == null) return word;
  IndexWord indexWord = null;
  try {
    indexWord = wDict.lookupIndexWord(pos, word);
  } catch (JWNLException e) {}
  return (indexWord != null) ? indexWord.getLemma() : word;
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

protected IndexWord getIndexWord(String lemma, WordNetPartOfSpeech partOfSpeech) throws JWNLException {
  return doNotProcessThisWord(lemma) ? null : jwnlRealDictionary.lookupIndexWord(JwnlUtils.getJwnlPartOfSpeec(partOfSpeech), lemma);
}

代码示例来源:origin: de.julielab/dragontool

public String lemmatize(String word,int pos)
{
  IndexWord indexWord;
  if(Character.isDigit(word.charAt(word.length()-1)))
    return word;
  if(pos>Lemmatiser.LASTPOS || pos<Lemmatiser.FIRSTPOS) return word;
  try{
    indexWord = dict.lookupIndexWord(getPOS(pos), word);
    if (indexWord != null)
      return indexWord.getLemma();
    else
      return word;
  }
  catch(JWNLException ex)
  {
    ex.printStackTrace();
    return null;
  }
}

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

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: com.github.steveash.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: 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: de.julielab/jcore-mallet-0.4

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: de.julielab/dragontool

public String lemmatize(String word)
{
  IndexWord indexWord;
  int i;
  if(Character.isDigit(word.charAt(word.length()-1)))
    return word;
  for(i=Lemmatiser.FIRSTPOS;i<=Lemmatiser.LASTPOS;i++){
    try {
      indexWord = dict.lookupIndexWord(getPOS(i), word);
      if (indexWord != null)
        return indexWord.getLemma();
    }
    catch (JWNLException ex) {
      ex.printStackTrace();
      return null;
    }
  }
  return word;
}

代码示例来源: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: eu.fbk.pikes/pikes-resources

public static List<String> getSynsetsForLemma(String lemma, String pos) {
  try {
    synchronized (WordNet.class) {
      IndexWord indexWord = getDictionary().lookupIndexWord(POS.getPOSForKey(pos), lemma);
      if (indexWord == null) {
        return new ArrayList<>();
      }
      Synset[] synsets = indexWord.getSenses();
      ArrayList<String> ret = new ArrayList<>();
      for (int i = 0; i < synsets.length; i++) {
        Synset synset = synsets[i];
        ret.add(getSynsetID(synset.getOffset(), synset.getPOS().getKey()));
      }
      return ret;
    }
  } catch (final JWNLException ex) {
    throw new Error(ex);
  }
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

public List<Synset> getSortedSynsetsOf(String lemma, WordNetPartOfSpeech partOfSpeech) throws WordNetException
{
  if (doNotProcessThisWord(lemma)) return new ArrayList<Synset>();
  else
  {
    try
    {
      net.didion.jwnl.data.IndexWord indexWord = jwnlRealDictionary.lookupIndexWord(JwnlUtils.getJwnlPartOfSpeec(partOfSpeech), lemma);
      return indexWordToList(indexWord);
    }
    catch(JWNLException e)
    {
      throw new WordNetException("looking for word <"+lemma+"> with part of speech: "+partOfSpeech.toString()+" failed. See nested exception",e);
    }
  }
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

public Set<Synset> getSynsetsOf(String lemma, WordNetPartOfSpeech partOfSpeech)  throws WordNetException
{
  if (doNotProcessThisWord(lemma))
    return new HashSet<Synset>();
  else
  {
    try
    {
      net.didion.jwnl.data.IndexWord indexWord = jwnlRealDictionary.lookupIndexWord(JwnlUtils.getJwnlPartOfSpeec(partOfSpeech), lemma);
      return indexWordToSet(indexWord);
    }
    catch(JWNLException e)
    {
      throw new WordNetException("looking for word <"+lemma+"> with part of speech: "+partOfSpeech.toString()+" failed. See nested exception",e);
    }
  }
}

代码示例来源:origin: eu.fbk.pikes/pikes-resources

@Nullable
public static String getReadableSynsetID(@Nullable final String synsetID) {
  if (synsetID == null) {
    return null;
  }
  final Synset synset = getSynset(synsetID);
  if (synset == null) {
    throw new IllegalArgumentException("Illegal synset ID " + synsetID);
  }
  final String lemma = synset.getWords()[0].getLemma();
  final POS pos = POS.getPOSForKey(getPOS(synsetID));
  try {
    final IndexWord word;
    synchronized (WordNet.class) {
      word = getDictionary().lookupIndexWord(pos, lemma);
    }
    final Synset[] senses = word.getSenses();
    for (int i = 0; i < senses.length; ++i) {
      if (senses[i].equals(synset)) {
        return lemma + "-" + (i + 1) + pos.getKey();
      }
    }
    throw new Error("Could not determine sense index for lemma " + lemma + " and synset "
        + synsetID);
  } catch (final JWNLException ex) {
    throw new Error(ex);
  }
  // return synset.getSenseKey(lemma); // TODO
}

相关文章