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


Java POS.getPartOfSpeech方法代码示例

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


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

示例1: getStems

import edu.mit.jwi.item.POS; //导入方法依赖的package包/类
/**
 * Get a list of possible stems. Assume we are looking up a noun.
 */
public static List<String> getStems(String word, String posTag, IDictionary iDictionary) {

	POS pos = POS.getPartOfSpeech(posTag.charAt(0));
	if (pos == null) {
		return new ArrayList<String>();
	}

	WordnetStemmer wordnetStemmer = new WordnetStemmer(iDictionary);
	List<String> stems = wordnetStemmer.findStems(word, pos);

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

示例2: getSynsets

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

示例3: getSynonyms

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

示例4: getHypernyms

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

示例5: getHyperHypernyms

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

示例6: isHypernym

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

示例7: getRoots

import edu.mit.jwi.item.POS; //导入方法依赖的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.POS.getPartOfSpeech方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。