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


Java IIndexWord类代码示例

本文整理汇总了Java中edu.mit.jwi.item.IIndexWord的典型用法代码示例。如果您正苦于以下问题:Java IIndexWord类的具体用法?Java IIndexWord怎么用?Java IIndexWord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getSense

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
@Override
public String getSense(String lemma, TAG pos) {

	String sense = null, word;
	IIndexWord indexWord = null;
	POS POS;
	boolean multi;
	int i = 0;

	word = lemma;
	multi = lemma.contains(MULTIWORD_SEPARATOR);
	POS = getPOS(pos);

	do {

		word = lemma.replace(MULTIWORD_SEPARATOR, SEPARATORS[i++]);
		indexWord = mDictionary.getIndexWord(word, POS);

		if (indexWord != null)
			sense = mDictionary.getWord(indexWord.getWordIDs().get(0)).getSenseKey().toString();

	} while (sense == null && multi && i < SEPARATORS.length);

	return sense;
}
 
开发者ID:SI3P,项目名称:supWSD,代码行数:26,代码来源:WordNetInventory.java

示例2: extractLastHypernym

import edu.mit.jwi.item.IIndexWord; //导入依赖的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

示例3: runWord

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
public static void runWord(WordnetRulesSource wns, IIndexWord iw1,
		StringBuilder bs) {

	for (int i = 0; i < iw1.getWordIDs().size(); i++) {
		ISynsetID synsetID = iw1.getWordIDs().get(i).getSynsetID();
		ISynset synset = wns.dictionary().getSynset(synsetID);
		List<ISynsetID> hypernymsSynset = synset
				.getRelatedSynsets(Pointer.HYPONYM);

		for (ISynsetID sid : hypernymsSynset) {
			List<IWord> iws = wns.dictionary().getSynset(sid).getWords();
			for (IWord iw : iws) {
				List<IWordID> x = iw.getRelatedWords();
				for (IWordID xx : x)
					bs.append(xx.getLemma().replace("_", " ") + "\n");
				bs.append(iw.getLemma().replace("_", " ") + "\n");
			}
		}
	}
}
 
开发者ID:kouylekov,项目名称:edits,代码行数:21,代码来源:WordnetRulesSource.java

示例4: main

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
public static void main(String[] args) {
	WordnetRulesSource wns = new WordnetRulesSource();
	StringBuilder bs = new StringBuilder();

	IIndexWord iw1 = wns.dictionary().getIndexWord("person", POS.NOUN);
	runWord(wns, iw1, bs);

	iw1 = wns.dictionary().getIndexWord("adult", POS.NOUN);
	runWord(wns, iw1, bs);

	iw1 = wns.dictionary().getIndexWord("human", POS.NOUN);
	runWord(wns, iw1, bs);

	iw1 = wns.dictionary().getIndexWord("profession", POS.NOUN);
	runWord(wns, iw1, bs);

	FileTools.saveString("/home/milen/jobs.txt", bs.toString(), true);
	wns.close();
}
 
开发者ID:kouylekov,项目名称:edits,代码行数:20,代码来源:WordnetRulesSource.java

示例5: getAllGlosses

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
public String getAllGlosses(String search_word) {

		int i = 1;
		for (POS p : POS_ARR) {
			IIndexWord idxWord = dict.getIndexWord(search_word, p);
			if (idxWord == null)
				continue;
			List<IWordID> wordIDs = idxWord.getWordIDs();
			for (IWordID wordID : wordIDs) {
				IWord iword = dict.getWord(wordID);
				m.append(String.format(Locale.getDefault(), "%d. (%s) %s\n",
						i, shorten(iword.getPOS().toString()), iword.getSynset()
						.getGloss()));
				++i;
			}
		}
		return m.toString();
	}
 
开发者ID:vin-ivar,项目名称:XDictionary,代码行数:19,代码来源:DictSearch.java

示例6: getTopGlosses

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
public String getTopGlosses(String search_word) {

		int i = 1;
		for (POS p : POS_ARR) {
			IIndexWord idxWord = dict.getIndexWord(search_word, p);
			if (idxWord == null)
				continue;
			List<IWordID> wordIDs = idxWord.getWordIDs();
			IWordID wordID = wordIDs.get(0);
			IWord iword = dict.getWord(wordID);
			m.append(String.format(Locale.getDefault(), "%d. (%s) %s\n",
					i, shorten(iword.getPOS().toString()), iword.getSynset()
					.getGloss()));
			++i;
		}
		return m.toString();
	}
 
开发者ID:vin-ivar,项目名称:XDictionary,代码行数:18,代码来源:DictSearch.java

示例7: getAll

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
public static List<WordParse> getAll(String wordString, POS pos) {
    if (dict == null) {
        return null;            
    }
    
    IIndexWord idxWord = dict.getIndexWord(wordString, pos);
    if (idxWord == null)
        return null;
    
    List<IWordID> words = idxWord.getWordIDs();
    if (words == null)
        return null;
    
    List<WordParse> parsed = new ArrayList(words.size());        
    for (IWordID iw : words) {
    
        IWordID wordID = idxWord.getWordIDs().get(0);
        IWord word = dict.getWord(wordID);
        parsed.add(new WordParse(wordString, word));
    }
    return parsed;
    
}
 
开发者ID:automenta,项目名称:netentionj-desktop,代码行数:24,代码来源:WordParse.java

示例8: getSortedSynsetsOf

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
public List<Synset> getSortedSynsetsOf(String lemma, WordNetPartOfSpeech partOfSpeech) throws WordNetException
{
	List<Synset> synsets = new ArrayList<Synset>();
	IIndexWord idxWord = jwiRealDictionary.getIndexWord (lemma, JwiUtils.getJwiPartOfSpeec(partOfSpeech));
	if (idxWord != null)
	{
		List<IWordID> wordIDs = idxWord.getWordIDs();
		for (IWordID wordID :  wordIDs)
		{
			IWord word = jwiRealDictionary.getWord(wordID);
			if (word == null)
				throw new WordNetException("Internal error: got this wordID " + wordID + " from the JWI dictionary, but the dictionary didn't find a word for it");
			ISynset jwiRealSynset = word.getSynset ();
			synsets.add(getSynset(jwiRealSynset));
		}
	}
	
	return synsets;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:20,代码来源:JwiDictionary.java

示例9: getRealSynsets

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
/**
 * @param lemma
 * @param pos
 * @return
 * @throws WordNetException 
 */
protected ISynset[] getRealSynsets(String lemma, WordNetPartOfSpeech pos) throws WordNetException  {
	IIndexWord idxWord = jwiRealDictionary.getIndexWord (lemma, JwiUtils.getJwiPartOfSpeec(pos));
	ISynset[] realSynsets ;
	if (idxWord != null)
	{
		List<IWordID> wordIDs = idxWord.getWordIDs();
		realSynsets = new ISynset[wordIDs.size()];
		int i = 0;
		for (IWordID wordID :  wordIDs)
		{
			IWord iWord = jwiRealDictionary.getWord(wordID);
			if (iWord == null)
				throw new WordNetException("Internal error: got this wordID " + wordID + " from the JWI dictionary, but the dictionary didn't find a word for it");
			ISynset jwiRealSynset = iWord.getSynset ();
			realSynsets[i++] = jwiRealSynset;
		}
	}
	else	// there is no synset matching <lemma, pos>
		realSynsets = new ISynset[0];
	return realSynsets;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:28,代码来源:JwiDictionary.java

示例10: similarity

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
/**
 * Computes a score denoting how similar two word senses are, based on the
 * shortest path that connects the senses in the is-a (hypernym/hypnoym)
 * taxonomy.
 *
 * @param indexWord1
 * @param indexWord2
 * @return Returns a similarity score is in the range 0 to 1. A score of 1
 *         represents identity i.e. comparing a sense with itself will return
 *         1.
 */
public double similarity(String word1String, POS word1POS,
    String word2String, POS word2POS) {
  IIndexWord indexWord1 = getIndexWord(word1String, word1POS);
  Set<ISynset> synsets1 = getSynsets(indexWord1);

  IIndexWord indexWord2 = getIndexWord(word2String, word2POS);
  Set<ISynset> synsets2 = getSynsets(indexWord2);

  double maxSim = 0;
  for (ISynset synset1 : synsets1) {
    for (ISynset synset2 : synsets2) {
      double sim = pathSimilarity(synset1, synset2);
      if ((sim > 0) && (sim > maxSim)) {
        maxSim = sim;
      }
    }
  }
  return maxSim;
}
 
开发者ID:millecker,项目名称:storm-apps,代码行数:31,代码来源:WordNet.java

示例11: trek

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
/**
 * Treking across Wordnet for performance measurements
 * 
 */
private void trek() {
  int tickNext = 0;
  int tickSize = 20000;
  int seen = 0;
  System.out.print("Treking across Wordnet");
  long t = System.currentTimeMillis();
  for (POS pos : POS.values()) {
    for (Iterator<IIndexWord> i = m_dict.getIndexWordIterator(pos); i
        .hasNext();) {
      for (IWordID wid : i.next().getWordIDs()) {
        seen += m_dict.getWord(wid).getSynset().getWords().size();
        if (seen > tickNext) {
          System.out.print(".");
          tickNext = seen + tickSize;
        }
      }
    }
  }
  System.out.printf("done (%1d msec)\n", System.currentTimeMillis() - t);
  System.out.println("In my trek I saw " + seen + " words");
}
 
开发者ID:millecker,项目名称:storm-apps,代码行数:26,代码来源:WordNet.java

示例12: getMeanings

import edu.mit.jwi.item.IIndexWord; //导入依赖的package包/类
private String getMeanings(String word, POS pos){
	String result = "";
	IIndexWord idxWord = dict.getIndexWord (word , pos) ;
	if(idxWord == null) return "";
	
	int i= 1;
	
	for (IWordID iwordid: idxWord.getWordIDs()){
		result += i + " - ";
		result += "(" + iwordid.getSynsetID().getOffset() + ") ";
		IWord iword = dict.getWord(iwordid);
		result += ": ";
		for(IWord iword2 : iword.getSynset().getWords())
			result += iword2.getLemma() + ", ";
		result += "\n==> " + iword.getSynset().getGloss() + "\n\n";
		i++;
	}
	return result;
}
 
开发者ID:kariminf,项目名称:langpi,代码行数:20,代码来源:WNsearchWords.java

示例13: testWordSearch

import edu.mit.jwi.item.IIndexWord; //导入依赖的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

示例14: ExtractSynsetsSentence

import edu.mit.jwi.item.IIndexWord; //导入依赖的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

示例15: ExtractSynonymWord

import edu.mit.jwi.item.IIndexWord; //导入依赖的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


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