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


Java ISynset.getRelatedSynsets方法代码示例

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


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

示例1: extractLastHypernym

import edu.mit.jwi.item.ISynset; //导入方法依赖的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: findDepth

import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
private int findDepth(ISynset synset) {
	if (synset.getRelatedSynsets(Pointer.HYPERNYM).isEmpty()) { return 0; }
	List<Set<ISynset>> list = new ArrayList<>();
	Set<ISynset> set = new HashSet<>();
	set.add(synset);
	list.add(set);
	boolean topReached = false;
	int depth = -1;
	while (!topReached) {
		Set<ISynset> nextSet = new HashSet<>();
		for (ISynset syn : list.get(list.size()-1)) {
			List<ISynsetID> hyperIDs = syn.getRelatedSynsets(Pointer.HYPERNYM);
			if (!hyperIDs.isEmpty()) {
				for (ISynsetID hyperID : hyperIDs) { nextSet.add(dict.getSynset(hyperID)); }
			} else {
				topReached = true;
				depth = list.size()-1;
				break;
			}
		}
		list.add(nextSet);
	}
	return depth;
}
 
开发者ID:DukeNLIDB,项目名称:NLIDB,代码行数:25,代码来源:WordNet.java

示例3: isHypernym

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

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

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

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

示例4: runWord

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

示例5: findRelatedSynsetsAtLooseDistance

import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
/**
 * get all the synsets that are at the end of a 'relation' type path of length 'degree' from any one of the given synsetIDs. We don't care that these paths
 * be minimal
 * @param remoteHypernymIDs
 * @param relation must be a transitive relation like hypernym or hyponym
 * @param degree
 * @return
 */
private Set<ISynsetID> findRelatedSynsetsAtLooseDistance(	Set<ISynsetID> remoteHypernymIDs, Pointer relation, int degree) {
	Set<ISynsetID> neighborIDs = remoteHypernymIDs; 
	for(int depth = 0; depth < degree; depth++)
	{
		Set<ISynsetID> secondaryNeighborIDs = new HashSet<ISynsetID>();
		for (ISynsetID neighborID : neighborIDs)
		{
			ISynset neighbor = jwiDictionary.jwiRealDictionary.getSynset(neighborID);
			for (ISynsetID secondaryNeighborID : neighbor.getRelatedSynsets(relation))
				secondaryNeighborIDs.add(secondaryNeighborID);
		}
		neighborIDs = secondaryNeighborIDs;
	}
	return neighborIDs;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:24,代码来源:JwiCousinFinder.java

示例6: findRelatedSynsetsAtExactDistance

import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
/**
 * @param relation must be a transitive relation like hypernym or hyponym
 * @param degree
 * @param initialSynsetIDs 
 * @return
 */
private Set<ISynsetID> findRelatedSynsetsAtExactDistance(	Set<ISynsetID> initialSynsetIDs, Pointer relation, int degree) {
	Set<ISynsetID> neighborIDs = new HashSet<ISynsetID>(initialSynsetIDs); 
	Set<ISynsetID> visitedIDs = new HashSet<ISynsetID>(initialSynsetIDs);;
	for(int depth = 0; depth < degree; depth++)
	{
		Set<ISynsetID> secondaryNeighborIDs = new HashSet<ISynsetID>();
		for (ISynsetID neighborID : neighborIDs)
		{
			ISynset neighbor = jwiDictionary.jwiRealDictionary.getSynset(neighborID);
			for (ISynsetID secondaryNeighborID : neighbor.getRelatedSynsets(relation))
				// if we haven't visited this hypernym yet, add it 
				if (!visitedIDs.contains(secondaryNeighborID))
				{
					secondaryNeighborIDs.add(secondaryNeighborID);
					visitedIDs.add(secondaryNeighborID);
				}
		}
		neighborIDs = secondaryNeighborIDs;
	}
	return neighborIDs;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:28,代码来源:JwiCousinFinder.java

示例7: ExtractHypernymWord

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

示例8: getHyperSet

import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
private Set<ISynset> getHyperSet(Set<ISynset> set) {
	Set<ISynset> hyperSet = new HashSet<>();
	for (ISynset syn : set) {
		List<ISynsetID> hyperIDs = syn.getRelatedSynsets(Pointer.HYPERNYM);
		if (!hyperIDs.isEmpty()) {
			for (ISynsetID hyperID : hyperIDs) { hyperSet.add(dict.getSynset(hyperID)); }
		}
	}
	return hyperSet;
}
 
开发者ID:DukeNLIDB,项目名称:NLIDB,代码行数:11,代码来源:WordNet.java

示例9: getHypernyms

import edu.mit.jwi.item.ISynset; //导入方法依赖的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.item.ISynset; //导入方法依赖的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: getTransitivelyRelatedSynsets

import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
/**
 * @param ret 
 * @param realSynset
 * @param jwiPointer
 * @param isTransitive 
 * @param chainingLength
 * @return
 */
protected List<ISynsetID> getTransitivelyRelatedSynsets(List<ISynsetID> ret, ISynset realSynset, Pointer jwiPointer, boolean isTransitive, int chainingLength) {
	List<ISynsetID> neighborSynsetIDs = realSynset.getRelatedSynsets(jwiPointer);
	ret.addAll(neighborSynsetIDs);
	IDictionary realDictionary = jwiDictionary.jwiRealDictionary;
	if (chainingLength == 1 || !isTransitive)
		;	//return neighborSynsetIDs;
	else
		for (ISynsetID synsetID : neighborSynsetIDs)
			getTransitivelyRelatedSynsets(ret, realDictionary.getSynset(synsetID), jwiPointer, isTransitive, chainingLength - 1);	// the return value is an arg
	return ret;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:20,代码来源:JwiSynset.java

示例12: getRelatedWords

import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
public Map<MappedString, Float> getRelatedWords(ISynset s, int depth, int maxDepth, IPointer relationType, boolean assignDepthPenalty, List<TraceElement> trace) {
		if (depth == maxDepth) {
			return Collections.emptyMap();
		}
		float scoreInThisDepth = 1.0f;
		if (assignDepthPenalty) {
			scoreInThisDepth -= (float)depth / maxDepth;
		}
		Map<MappedString, Float> res = new HashMap<MappedString, Float>();
//		Map foo = word.getRelatedMap();
		List<ISynsetID> sIDs = s.getRelatedSynsets(relationType);
		for (ISynsetID sID : sIDs) {
			ISynset hS;
			synchronized (dict) {
				hS = dict.getSynset(sID);
			}
			List<TraceElement> _trace = new LinkedList<TraceElement>(trace);
			_trace.add(new TraceElement(hS.getGloss() + " (" + relationType.getName() + ")", ""));
			for (IWord h : hS.getWords()) {
				List<TraceElement> __trace = new LinkedList<TraceElement>(trace);
				__trace.add(new TraceElement(h.getLemma() + " (" + relationType.getName() + ")", getWordNetUrl(h)));
				addSynonym(res, h.getLemma(), __trace, scoreInThisDepth);
			}
			addSynonyms(res, getRelatedWords(hS, depth + 1, maxDepth, relationType, assignDepthPenalty, _trace));
		}
		return res;
	}
 
开发者ID:johannessimon,项目名称:pal,代码行数:28,代码来源:WordNetConnector.java

示例13: getRoots

import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
public static List<ISynset> getRoots(IDictionary dict, String posTag) {

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

		List<ISynset> roots = new LinkedList<ISynset>();

		if (pos == POS.NOUN) {
			roots.add(WordNetUtils.getSynsets(dict, "person", "n", true).get(0));
			roots.add(WordNetUtils.getSynsets(dict, "thing", "n", true).get(0));
			ISynset entity = WordNetUtils.getSynsets(dict, "entity", "n", true).get(0);
			for (ISynsetID id : entity.getRelatedSynsets(Pointer.HYPONYM)) {
				roots.add(dict.getSynset(id));
			}
			return roots;
		}

		// get all synsets of the given POS, choose the ones that don't have a
		// hypernym
		Iterator<ISynset> it = dict.getSynsetIterator(pos);
		while (it.hasNext()) {
			ISynset s = it.next();
			if (s.getRelatedSynsets(Pointer.HYPERNYM).size() == 0
					&& s.getRelatedSynsets(Pointer.HYPERNYM_INSTANCE).isEmpty()) {
				// if (pos == POS.NOUN) {
				// // use some hyponyms as well (only entity fulfills this
				// condition)
				// for (ISynsetID hypo1 : s.getRelatedSynsets(Pointer.HYPONYM))
				// {
				// ISynset hypoSynset = dict.getSynset(hypo1);
				// for (ISynsetID hypo2 :
				// hypoSynset.getRelatedSynsets(Pointer.HYPONYM)) {
				// ISynset hypoSynset2 = dict.getSynset(hypo2);
				// for (ISynsetID hypo3 :
				// hypoSynset2.getRelatedSynsets(Pointer.HYPONYM)) {
				// ISynset hypoSynset3 = dict.getSynset(hypo3);
				// roots.add(hypoSynset3);
				// System.out.println(hypoSynset3.getID().toString() + " " +
				// hypoSynset3.getWords() + " "
				// + hypoSynset3.getGloss());
				// }
				// }
				// }
				//
				// }
				// else {
				roots.add(s);
				// }

			}
		}

		return roots;

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


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