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

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

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

Dictionary.getIndexWord介绍

[英]Look up a word in the database. The search is case-independent, and phrases are separated by spaces ("look up", not "look_up"). Note: this method does not subject lemma to any morphological processing. If you want this, use #lookupIndexWord(POS,String).
[中]在数据库中查找一个单词。搜索与大小写无关,短语之间用空格分隔(“查找”,而不是“查找”)。注:此方法不需要对引理进行任何形态学处理。如果需要,请使用#lookupIndexWord(POS,String)。

代码示例

代码示例来源: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: 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: Ailab403/ailab-mltk4j

public String getSenseKey(String lemma, String pos,int sense) {
 try {
  IndexWord iw = dict.getIndexWord(POS.NOUN,lemma);
  if (iw == null) {
   return null;
  }
  return String.valueOf(iw.getSynsetOffsets()[sense]);
 }
 catch (JWNLException e) {
  e.printStackTrace();
  return null;
 }
}

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

public String getSenseKey(String lemma, String pos,int sense) {
 try {
  IndexWord iw = dict.getIndexWord(POS.NOUN,lemma);
  if (iw == null) {
   return null;
  }
  return String.valueOf(iw.getSynsetOffsets()[sense]);
 }
 catch (JWNLException e) {
  e.printStackTrace();
  return null;
 }
}

代码示例来源: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: SmartDataAnalytics/DL-Learner

public List<String> getHyponyms(POS pos, String s) {
  ArrayList<String> result = new ArrayList<>();
  try {
    IndexWord word = dict.getIndexWord(pos, s);
    if (word == null) {
      System.err.println("Unable to find index word for " + s);
      return result;
    }
    Synset sense = word.getSense(1);
    getHyponymsRecursive(result, sense, 3);
  }
  catch (JWNLException e) {
    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
  }
  return result;
}

代码示例来源:origin: SmartDataAnalytics/DL-Learner

public List<LemmaScorePair> getHyponymsScored(POS pos, String s) {
  ArrayList<LemmaScorePair> result = new ArrayList<>();
  try {
    IndexWord word = dict.getIndexWord(pos, s);
    if (word == null) {
      System.err.println("Unable to find index word for " + s);
      return result;
    }
    Synset sense = word.getSense(1);
    getHyponymsScoredRecursive(result, sense, 3, SYNONYM_FACTOR);
  }
  catch (JWNLException e) {
    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
  }
  return result;
}

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

public String[] getParentSenseKeys(String lemma, String pos, int sense) {
 //System.err.println("JWNLDictionary.getParentSenseKeys: lemma="+lemma);
 try {
  IndexWord iw = dict.getIndexWord(POS.NOUN,lemma);
  if (iw != null) {
   Synset synset = iw.getSense(sense+1);
   List<String> parents = new ArrayList<String>();
   getParents(synset,parents);
   return parents.toArray(new String[parents.size()]);
  }
  else {
   return empty;
  }
 }
 catch (JWNLException e) {
  e.printStackTrace();
  return null;
 }
}

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

public String[] getParentSenseKeys(String lemma, String pos, int sense) {
 //System.err.println("JWNLDictionary.getParentSenseKeys: lemma="+lemma);
 try {
  IndexWord iw = dict.getIndexWord(POS.NOUN,lemma);
  if (iw != null) {
   Synset synset = iw.getSense(sense + 1);
   List<String> parents = new ArrayList<>();
   getParents(synset,parents);
   return parents.toArray(new String[parents.size()]);
  }
  else {
   return empty;
  }
 }
 catch (JWNLException e) {
  e.printStackTrace();
  return null;
 }
}

代码示例来源:origin: SmartDataAnalytics/DL-Learner

public List<String> getAttributes(String s) {
  List<String> result = new ArrayList<>();
  try {
    IndexWord iw = dict.getIndexWord(POS.ADJECTIVE, s);
    if (iw != null) {
      Synset[] synsets = iw.getSenses();
      Word[] words = synsets[0].getWords();
      for (Word w : words) {
        String c = w.getLemma();
        if (!c.equals(s) && !c.contains(" ") && result.size() < 4) {
          result.add(c);
        }
      }
    }
  }
  catch (JWNLException e) {
    e.printStackTrace();
  }
  return result;
}

代码示例来源:origin: SmartDataAnalytics/DL-Learner

public List<String> getBestSynonyms(POS pos, String s) {

    List<String> synonyms = new ArrayList<>();

    try {
      IndexWord iw = dict.getIndexWord(pos, s);//dict.getMorphologicalProcessor().lookupBaseForm(pos, s)
//            IndexWord iw = dict.getMorphologicalProcessor().lookupBaseForm(pos, s);
      if (iw != null) {
        Synset[] synsets = iw.getSenses();
        Word[] words = synsets[0].getWords();
        for (Word w : words) {
          String c = w.getLemma();
          if (!c.equals(s) && !c.contains(" ") && synonyms.size() < 4) {
            synonyms.add(c);
          }
        }
      }

    }
    catch (JWNLException e) {
      e.printStackTrace();
    }
    return synonyms;
  }

代码示例来源:origin: SmartDataAnalytics/DL-Learner

public List<String> getAllSynonyms(POS pos, String s) {
  List<String> synonyms = new ArrayList<>();
  try {
    IndexWord iw = dict.getIndexWord(pos, s);
    if (iw != null) {
      Synset[] synsets = iw.getSenses();
      for (Synset synset : synsets) {
        for (Word w : synset.getWords()) {
          String lemma = w.getLemma();
          if (!lemma.equals(s) && !lemma.contains(" ")) {
            synonyms.add(lemma);
          }
        }
      }
    }
  }
  catch (JWNLException e) {
    e.printStackTrace();
  }
  return synonyms;
}

代码示例来源:origin: SmartDataAnalytics/DL-Learner

public List<String> getSisterTerms(POS pos, String s) {
    List<String> sisterTerms = new ArrayList<>();

    try {
      IndexWord iw = dict.getIndexWord(pos, s);//dict.getMorphologicalProcessor().lookupBaseForm(pos, s)
//            IndexWord iw = dict.getMorphologicalProcessor().lookupBaseForm(pos, s);
      if (iw != null) {
        Synset[] synsets = iw.getSenses();
        //System.out.println(synsets[0]);
        PointerTarget[] pointerArr = synsets[0].getTargets();
      }

    }
    catch (JWNLException e) {
      e.printStackTrace();
    }
    return sisterTerms;
  }

代码示例来源:origin: SmartDataAnalytics/DL-Learner

/**
 * Returns a list of lemmas for the most frequent synset of the given word.
 * @param word word to get synonyms for
 * @param pos POS of the word to look up
 * @return list of lemmas of the most frequent synset
 */
public List<String> getWordsForFirstSynset(POS pos, String word) {
  List<String> result = new ArrayList<>();
  IndexWord indexWord = null;
  Synset sense = null;
  try {
    indexWord = dict.getIndexWord(pos, word);
    sense = indexWord.getSense(1);
    for (Word w : sense.getWords()) {
      result.add(w.getLemma());
    }
  }
  catch (JWNLException e) {
    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
  }
  return result;
}

代码示例来源: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: 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: 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: 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

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

相关文章