当前位置: 首页>>代码示例>>Java>>正文


Java IDictionary.getIndexWord方法代码示例

本文整理汇总了Java中edu.mit.jwi.IDictionary.getIndexWord方法的典型用法代码示例。如果您正苦于以下问题:Java IDictionary.getIndexWord方法的具体用法?Java IDictionary.getIndexWord怎么用?Java IDictionary.getIndexWord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.mit.jwi.IDictionary的用法示例。


在下文中一共展示了IDictionary.getIndexWord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractLastHypernym

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
private String extractLastHypernym(Token token) throws IOException {
  String result = token.getCoveredText();
  String path = "wordnet" + File.separator + "dict";
  URL url = new URL("file", null, path);
  IDictionary dict = new Dictionary(url);
  dict.open();
  IIndexWord idxWord = dict.getIndexWord(token.getCoveredText().toLowerCase(), getCorrectPOS(token.getPos()));
  if (idxWord != null && idxWord.getWordIDs().size() > 0) {
    IWordID wordID = idxWord.getWordIDs().get(0);
    IWord word = dict.getWord(wordID);
    ISynset synset = word.getSynset();
    List<ISynsetID> hypernyms = synset.getRelatedSynsets(Pointer.HYPERNYM);
    List<IWord> words;
    for (ISynsetID sid : hypernyms) {
      words = dict.getSynset(sid).getWords();
      for (Iterator<IWord> i = words.iterator(); i.hasNext();) {
        result = i.next().getLemma();
      }
    }
  }
  dict.close();
  return result;
}
 
开发者ID:utk4rsh,项目名称:question-classifier,代码行数:24,代码来源:HeadWordExtractor.java

示例2: testWordSearch

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public static void testWordSearch() throws IOException{

		// construct the URL to the Wordnet dictionary directory
		File file =new File("wordnetDB/dict/");
		// construct the dictionary object and open it
		IDictionary dict = new Dictionary(file) ;
		dict.open();
		
		IIndexWord idxWord = dict.getIndexWord ("midnight" , POS.NOUN) ;
		if(idxWord == null) System.out.println("no word\n--------\n");
		
		for (IWordID iword: idxWord.getWordIDs()){
			System.out.println("offset: " + iword.getSynsetID().getOffset());
			IWord word = dict.getWord(iword);
			System.out.println("gloss: " + word.getSynset().getGloss());
		}
		
		//System.out.println("offset: " + idxWord.getWordIDs().get(0).getSynsetID().getOffset());

		dict.close();
	}
 
开发者ID:kariminf,项目名称:langpi,代码行数:22,代码来源:WordNetTest.java

示例3: ExtractSynsetsSentence

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public List<SynonymDomain> ExtractSynsetsSentence(String Sentence,File englishStopwordsFilePath) throws IOException, Exception
{
    List<SynonymDomain> lstSynset=new ArrayList<>();
    String sentenceKeyWords=EX.ExtractKeyword(Sentence, englishStopwordsFilePath);
    for(String str:sentenceKeyWords.split(","))
    {
    String strSynset="";
    File dicFile=new File(path);
    IDictionary dict=new Dictionary(dicFile);
    dict.open();
    WordnetStemmer stemmer=new WordnetStemmer(dict);
     try
     {
        List<String> lstStem=stemmer.findStems(str, POS.NOUN);
        IIndexWord idxWord = dict . getIndexWord (lstStem.get(0), POS.NOUN);
        IWordID wordID = idxWord . getWordIDs ().get(0);
        IWord word = dict.getWord(wordID);
        ISynset sen=word.getSynset();
         for(IWord w:sen.getWords())
         {
           strSynset+=w.getLemma()+",";
           
         }
        lstSynset.add(new SynonymDomain(str, strSynset));
     }
     catch(Exception ex)
     {
        
     }
    }
    return lstSynset;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:33,代码来源:Synonyms.java

示例4: ExtractSynonymWord

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
@Override
public List<String> ExtractSynonymWord(String word) throws URISyntaxException, IOException 
{
	List<String> lstSynonym=new ArrayList<>();
	java.net.URL url = getClass().getClassLoader().getResource("dict\\");
    //File dicFile = new File(url.toURI());
    String strSynset="";
       IDictionary dict=new Dictionary(new File(path));
       dict.open();
       WordnetStemmer stemmer=new WordnetStemmer(dict);
        try
        {
           List<String> lstStem=stemmer.findStems(word, POS.NOUN);
           for(int i=0;i<1000;i++)
           {
           IIndexWord idxWord = dict . getIndexWord (lstStem.get(0), POS.NOUN);
           IWordID wordID = idxWord . getWordIDs ().get(i);
           IWord words = dict.getWord(wordID);
           ISynset sen=words.getSynset();
            for(IWord w:sen.getWords())
            {
           	 
           	 lstSynonym.add(w.getLemma());
            }
            
           }
        }
        catch(Exception ex)
        {
        }
       return lstSynonym;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:33,代码来源:WordNetFile.java

示例5: ExtractHypernymWord

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
@Override
public List<String> ExtractHypernymWord(String word) {
	 //String strHypernym="";
	 List<String> lstHypernym=new ArrayList<>();
      try
        {
    	   // java.net.URL url = getClass().getClassLoader().getResource("dict\\");
  	       // File dicFile = new File(url.toURI());
            IDictionary dict=new Dictionary(new File(path));
            dict.open();
            WordnetStemmer stemmer=new WordnetStemmer(dict);
            List<String> lstStem=stemmer.findStems(word, POS.NOUN);
            for(int j=0;j<1000;j++)
            {
            IIndexWord idxWord = dict.getIndexWord(lstStem.get(0),POS.NOUN);
            IWordID wordID = idxWord.getWordIDs().get (j) ;
            IWord mywords = dict . getWord (wordID);
            ISynset sen=mywords.getSynset();
            List <ISynsetID> hypernyms = sen.getRelatedSynsets (Pointer.HYPERNYM);
            List<IWord> words;
            for(ISynsetID sid : hypernyms)
            {
                words = dict . getSynset (sid). getWords ();
                for( Iterator <IWord > i = words . iterator (); i. hasNext () ;)
                {
                	
                	lstHypernym.add((i. next (). getLemma ()));
                //if(i. hasNext ())
                 //  strHypernym+=",";
                }
            }
            }
         }
       catch(Exception ex)
       {
       }
        return lstHypernym;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:39,代码来源:WordNetFile.java

示例6: ExtractSynonymSentence

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public List<ExtractSynonym> ExtractSynonymSentence(String inputSentence) throws MalformedURLException, IOException
{
    List<ExtractSynonym> lstSynset=new ArrayList<>();
        for(String str:inputSentence.split(" "))
        {
            String strSynset="";
            File dicFile=new File(path);
            IDictionary dict=new Dictionary(dicFile);
            dict.open();
            WordnetStemmer stemmer=new WordnetStemmer(dict);
            for(int j=0;j<10;j++)
         {
              try
              {
                List<String> lstStem=stemmer.findStems(str, POS.NOUN);
                IIndexWord idxWord = dict . getIndexWord (lstStem.get(0), POS.NOUN);
                IWordID wordID = idxWord . getWordIDs ().get(j);
                IWord word = dict.getWord(wordID);
                ISynset sen=word.getSynset();
                 for(IWord w:sen.getWords())
                 {
                   strSynset+=w.getLemma()+",";
                 }
                
              }
              
              catch(Exception ex)
              {

              }
              
         }
            lstSynset.add(new ExtractSynonym(str, strSynset));
        }
    return lstSynset;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:37,代码来源:WordNetFile.java

示例7: getSynsets

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
/**
 * Retrieve a set of synonyms for a word. Use only the first sense if
 * useFirstSense flag is true.
 */
public static List<ISynset> getSynsets(IDictionary iDictionary, String word, String posTag,
		boolean firstSenseOnly) {

	// need a set to avoid repeating words
	List<ISynset> synonyms = new LinkedList<ISynset>();

	POS pos = POS.getPartOfSpeech(posTag.charAt(0));
	if (pos == null) {
		return synonyms;
	}

	IIndexWord iIndexWord = iDictionary.getIndexWord(word, pos);
	if (iIndexWord == null) {
		return synonyms; // no senses found
	}

	// iterate over senses
	for (IWordID iWordId : iIndexWord.getWordIDs()) {
		IWord iWord = iDictionary.getWord(iWordId);

		ISynset iSynset = iWord.getSynset();
		synonyms.add(iSynset);

		if (firstSenseOnly) {
			break;
		}
	}

	return synonyms;
}
 
开发者ID:annefried,项目名称:sitent,代码行数:35,代码来源:WordNetUtils.java

示例8: getSynonyms

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
/**
 * Retrieve a set of synonyms for a word. Use only the first sense if
 * useFirstSense flag is true.
 */
public static HashSet<String> getSynonyms(IDictionary iDictionary, String word, String posTag,
		boolean firstSenseOnly) {

	// need a set to avoid repeating words
	HashSet<String> synonyms = new HashSet<String>();

	POS pos = POS.getPartOfSpeech(posTag.charAt(0));
	if (pos == null) {
		return synonyms;
	}

	IIndexWord iIndexWord = iDictionary.getIndexWord(word, pos);
	if (iIndexWord == null) {
		return synonyms; // no senses found
	}

	// iterate over senses
	for (IWordID iWordId : iIndexWord.getWordIDs()) {
		IWord iWord = iDictionary.getWord(iWordId);

		ISynset iSynset = iWord.getSynset();
		for (IWord synsetMember : iSynset.getWords()) {
			synonyms.add(synsetMember.getLemma());
		}

		if (firstSenseOnly) {
			break;
		}
	}

	return synonyms;
}
 
开发者ID:annefried,项目名称:sitent,代码行数:37,代码来源:WordNetUtils.java

示例9: getHypernyms

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
/**
 * Retrieve a set of hypernyms for a word. Use only the first sense if
 * useFirstSense flag is true.
 */
public static HashSet<String> getHypernyms(IDictionary dict, String word, String posTag, boolean firstSenseOnly) {

	HashSet<String> hypernyms = new HashSet<String>();

	POS pos = POS.getPartOfSpeech(posTag.charAt(0));
	if (pos == null) {
		return hypernyms;
	}

	IIndexWord iIndexWord = dict.getIndexWord(word, pos);
	if (iIndexWord == null) {
		return hypernyms; // no senses found
	}

	// iterate over senses
	for (IWordID iWordId : iIndexWord.getWordIDs()) {
		IWord iWord1 = dict.getWord(iWordId);
		ISynset iSynset = iWord1.getSynset();

		// multiple hypernym chains are possible for a synset
		for (ISynsetID iSynsetId : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
			List<IWord> iWords = dict.getSynset(iSynsetId).getWords();
			for (IWord iWord2 : iWords) {
				String lemma = iWord2.getLemma();
				hypernyms.add(lemma.replace(' ', '_')); // also get rid of
														// spaces
			}
		}

		if (firstSenseOnly) {
			break;
		}
	}

	return hypernyms;
}
 
开发者ID:annefried,项目名称:sitent,代码行数:41,代码来源:WordNetUtils.java

示例10: getHyperHypernyms

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public static HashSet<String> getHyperHypernyms(IDictionary dict, String word, String posTag,
		boolean firstSenseOnly) {

	HashSet<String> hypernyms = new HashSet<String>();

	POS pos = POS.getPartOfSpeech(posTag.charAt(0));
	if (pos == null) {
		return hypernyms;
	}

	IIndexWord iIndexWord = dict.getIndexWord(word, pos);
	if (iIndexWord == null) {
		return hypernyms; // no senses found
	}

	// iterate over senses
	for (IWordID iWordId : iIndexWord.getWordIDs()) {
		IWord iWord1 = dict.getWord(iWordId);
		ISynset iSynset = iWord1.getSynset();

		for (ISynsetID iSynsetId1 : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
			for (ISynsetID iSynsetId2 : dict.getSynset(iSynsetId1).getRelatedSynsets(Pointer.HYPERNYM)) {
				List<IWord> iWords = dict.getSynset(iSynsetId2).getWords();
				for (IWord iWord2 : iWords) {
					String lemma = iWord2.getLemma();
					hypernyms.add(lemma.replace(' ', '_')); // also get rid
															// of spaces
				}
			}
		}

		if (firstSenseOnly) {
			break;
		}
	}

	return hypernyms;
}
 
开发者ID:annefried,项目名称:sitent,代码行数:39,代码来源:WordNetUtils.java

示例11: isHypernym

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
/**
 * written by anne
 * 
 * @param dict
 * @param word
 * @param posTag
 * @param firstSenseOnly
 * @return
 */
public static Boolean isHypernym(IDictionary dict, String word, String posTag, ISynset hypernym,
		boolean firstSenseOnly) {

	POS pos = POS.getPartOfSpeech(posTag.charAt(0));
	if (pos == null) {
		return false;
	}

	IIndexWord iIndexWord = dict.getIndexWord(word, pos);
	if (iIndexWord == null) {
		return false; // no senses found
	}

	// iterate over senses
	for (IWordID iWordId : iIndexWord.getWordIDs()) {
		IWord iWord1 = dict.getWord(iWordId);
		ISynset iSynset = iWord1.getSynset();

		if (iSynset.equals(hypernym)) {
			return true;
		}

		for (ISynsetID iSynsetId : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
			ISynset hyperSynset = dict.getSynset(iSynsetId);
			if (isHypernym(dict, hyperSynset, hypernym, firstSenseOnly)) {
				return true;
			}
		}

		if (firstSenseOnly) {
			break;
		}
	}

	return false;
}
 
开发者ID:annefried,项目名称:sitent,代码行数:46,代码来源:WordNetUtils.java

示例12: main

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {


        // construct the dictionary object and open it
        URL u = ClassLoader.getSystemResource("resources/wordnet/dict");
        IDictionary dict = new Dictionary(u);
        dict.open();
        
        // look up first sense of the word "dog"
        IIndexWord idxWord = dict.getIndexWord("computer", POS.NOUN);
        IWordID wordID = idxWord.getWordIDs().get(0);
        IWord word = dict.getWord(wordID);
        System.out.println(word.toString());
        System.out.println("Id = " + wordID);
        System.out.println("Lemma = " + word.getLemma());
        System.out.println("Synset words = " + word.getSynset().getWords());
        System.out.println("Related Synsets = " + word.getSynset().getRelatedSynsets());
        System.out.println("Gloss = " + word.getSynset().getGloss());
        System.out.println("Verbframes = " + word.getVerbFrames());
        System.out.println("POS = " + word.getPOS());
        System.out.println("Related words = " + word.getRelatedMap());
        List<String> relatedWords = word.getRelatedWords().stream().map(
                    (IWordID t) -> (String)dict.getWord(t).getLemma() ).collect(Collectors.toList());
        System.out.println("Related words = " + relatedWords);
        System.out.println("Sensekey = " + word.getSenseKey());
        System.out.println("AdjMarker = " + word.getAdjectiveMarker());

    }
 
开发者ID:automenta,项目名称:netentionj-desktop,代码行数:29,代码来源:WordnetDemo.java

示例13: ExtractSynonymFile

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public List<ExtractSynonym> ExtractSynonymFile(File filePath) throws MalformedURLException, IOException
{
    List<ExtractSynonym> lstSynset=new ArrayList<>();
    BufferedReader reader=new BufferedReader(new FileReader(filePath));
    String Line="";
    List<String> lstText=new ArrayList<>();
    while((Line=reader.readLine())!=null)
    {
        lstText.add(Line);
    }
    for(String Sentence:lstText)
    {
        for(String str:Sentence.split(" "))
        {
            String strSynset="";
            File dicFile=new File(path);
            IDictionary dict=new Dictionary(dicFile);
            dict.open();
            WordnetStemmer stemmer=new WordnetStemmer(dict);
            for(int j=0;j<10;j++)
         {
             try
             {
            	List<String> lstStem=stemmer.findStems(str, POS.NOUN);
                IIndexWord idxWord = dict . getIndexWord (lstStem.get(0), POS.NOUN);
                IWordID wordID = idxWord . getWordIDs ().get(j);
                IWord word = dict.getWord(wordID);
                ISynset sen=word.getSynset();
                 for(IWord w:sen.getWords())
                 {
                   strSynset+=w.getLemma()+",";

                 }
                lstSynset.add(new ExtractSynonym(str, strSynset));
             }
             catch(Exception ex)
             {
             }
         }
        }
    }
    return lstSynset;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:44,代码来源:WordNetFile.java

示例14: setWordNetFeatures

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
/**
 * @author afried, Annemarie Friedrich
 * 
 *         WordNet based features, use Most Frequent Sense heuristic.
 *         Adapted from code by Nils Reiter.
 * 
 * @param token
 * @param classAnnot
 */
public static void setWordNetFeatures(Token token, ClassificationAnnotation classAnnot, JCas jCas,
		String featurePrefix, IDictionary wordnet) {
	if (token.getPos() != null && token.getLemma() != null) {

		POS pos = WordNetUtils.getPOSFromPenn(token.getPos().getPosValue());
		if (pos != null) {
			IIndexWord iw = wordnet.getIndexWord(token.getLemma().getValue(), pos);

			if (iw != null) {
				ISynsetID mfs = iw.getWordIDs().get(0).getSynsetID();
				ISynset synset = wordnet.getSynset(mfs);

				// lexcial filename:
				FeaturesUtil.addFeature(featurePrefix + "wnLexicalFilename", synset.getLexicalFile().getName(),
						jCas, classAnnot);
				int gran = 0;
				ISynset curr = synset;
				Set<ISynset> seen = new HashSet<ISynset>();
				while (!seen.contains(curr) && !curr.getRelatedSynsets(Pointer.HYPERNYM).isEmpty()) {
					seen.add(curr);
					// The substring operation removes the leading 'SID-'
					String senseId = curr.getID().toString().substring(4);
					if (gran == 0) {
						FeaturesUtil.addFeature(featurePrefix + "sense0", senseId, jCas, classAnnot);
					} else if (gran == 1) {
						FeaturesUtil.addFeature(featurePrefix + "sense1", senseId, jCas, classAnnot);
					} else if (gran == 2) {
						FeaturesUtil.addFeature(featurePrefix + "sense2", senseId, jCas, classAnnot);
					} else if (gran == 3) {
						FeaturesUtil.addFeature(featurePrefix + "sense3", senseId, jCas, classAnnot);
					}
					curr = wordnet.getSynset(curr.getRelatedSynsets(Pointer.HYPERNYM).get(0));
					gran++;
				}
				FeaturesUtil.addFeature(featurePrefix + "wnGranularity", new Integer(gran).toString(), jCas,
						classAnnot);
				// curr must now refer to the top sense

				FeaturesUtil.addFeature(featurePrefix + "senseTop", curr.getID().toString().substring(4), jCas,
						classAnnot);
			}
		}
	}
}
 
开发者ID:annefried,项目名称:sitent,代码行数:54,代码来源:WordNetUtils.java

示例15: getSynonyms

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
/**
 * 根据一定规则来获取当前词的最佳同义词
 * 2015-6-9 19:47:30 添加synchronized关键字,jwi不是线程安全的
 * @param dict
 * @param word
 * @param selectedSynonymsWords 文章中已经选择的同义词集合
 * @return
 */
public synchronized static List<Word> getSynonyms(IDictionary dict, Word word){

    List<Word> synonymsWords = new ArrayList<Word>();

    IIndexWord idxWord = null;
    if(POS_NOUN.contains(word.getPos())){
        idxWord = dict.getIndexWord(word.getLemma(), POS.NOUN);
    }else if(POS_VERB.contains(word.getPos())){
        idxWord = dict.getIndexWord(word.getLemma(), POS.VERB);
    }else if(POS_ADVERB.contains(word.getPos())){
        idxWord = dict.getIndexWord(word.getLemma(), POS.ADVERB);
    }else if(POS_ADJ.contains(word.getPos())){
        idxWord = dict.getIndexWord(word.getLemma(), POS.ADJECTIVE);
    }

    if(idxWord == null) {
        return synonymsWords;
    }

    IWordID wordID = idxWord.getWordIDs().get(0); // 1st meaning
    IWord iword = dict.getWord(wordID);
    ISynset synset = iword.getSynset (); //ISynset是一个词的同义词集的接口

    for(IWord w : synset.getWords()){

        Word synonymsWord = null;
        try {
            synonymsWord = (Word) word.clone();
            synonymsWord.setName(w.getLemma());
            synonymsWord.setLemma(w.getLemma());
        } catch (CloneNotSupportedException e) {
            log.error("Clone word[" + word + "] error!", e);
        }
        if(null != synonymsWord) {
            synonymsWords.add(synonymsWord);
        }

    }

    return synonymsWords;
}
 
开发者ID:procyon-lotor,项目名称:event-direct-mts,代码行数:50,代码来源:WordNetUtil.java


注:本文中的edu.mit.jwi.IDictionary.getIndexWord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。