本文整理汇总了Java中edu.mit.jwi.item.Pointer类的典型用法代码示例。如果您正苦于以下问题:Java Pointer类的具体用法?Java Pointer怎么用?Java Pointer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pointer类属于edu.mit.jwi.item包,在下文中一共展示了Pointer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: extractLastHypernym
import edu.mit.jwi.item.Pointer; //导入依赖的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.Pointer; //导入依赖的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.Pointer; //导入依赖的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: fillList
import edu.mit.jwi.item.Pointer; //导入依赖的package包/类
Set<String> fillList(Pointer ptype,Map<IPointer, List<IWordID>> wordMap,Map<IPointer, List<ISynsetID>> synMap){
Set<String> ts;
List<IWordID> tw;
List<ISynsetID> tsy;
ts = new TreeSet<String>();
tw = wordMap.get(ptype);
if(tw!=null){
for(IWordID wid:tw){
String tempString = wid.getLemma();
if(tempString!=null)ts.add(tempString);
}
}
tsy = synMap.get(ptype);
if(tsy!=null){
for(ISynsetID sid:tsy){
List<IWord> t = dict.getSynset(sid).getWords();
if(t!=null)
for(IWord w:t){
ts.add(w.getLemma());
}
}
}
if(!ts.isEmpty())return ts;
return null;
}
开发者ID:MusicCraftor,项目名称:WordNet-Explorer,代码行数:26,代码来源:WordDic.java
示例5: runWord
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例6: findRelatedSynsetsAtLooseDistance
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例7: findRelatedSynsetsAtExactDistance
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例8: getRelatedSynsets
import edu.mit.jwi.item.Pointer; //导入依赖的package包/类
public Set<Synset> getRelatedSynsets(WordNetRelation relation, int chainingLength) throws WordNetException {
if (relation == null) throw new WordNetException("null wordnet relation");
if (relation.equals(WordNetRelation.SYNONYM)) // some relations (SYNONYM) have no neighbors, cos they have no matching JWNL relation
return getSynonyms();
else if (relation.equals(WordNetRelation.STRICT_2ND_DEGREE_COUSIN))
return this.jwiDictionary.cousinFinder.getStrictCousinSynsets(this.realSynset, 2);
else
{
Pointer jwiPointer = JwiUtils.wordNetRelationToPointer(relation);
if (jwiPointer == null)
return new HashSet<Synset>(); // relationType has no matching JWI Pointer. shouldn't happen, but for a couple of marginal relations
else
return relation.isLexical() ? getLexicalNeighbors(jwiPointer) : getSemanticNeighbors(jwiPointer, chainingLength, relation.isTransitive());
}
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:17,代码来源:JwiSynset.java
示例9: ExtractHypernymWord
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例10: getHyperSet
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例11: getHypernyms
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例12: getHyperHypernyms
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例13: getStrictCousinsForRealSynset
import edu.mit.jwi.item.Pointer; //导入依赖的package包/类
/**
* @param iSynsets
* @param degree
* @return
* @throws WordNetException
*/
Set<String> getStrictCousinsForRealSynset( ISynset[] iSynsets, int degree) throws WordNetException {
Set<String> cousinLemmas = new HashSet<String>();
if (iSynsets != null && iSynsets.length > 0)
{
POS pos = iSynsets[0].getPOS();
if (pos.equals(POS.NOUN) || pos.equals(POS.VERB)) // only nouns and verbs have hypernyms
{
Set<ISynsetID> synsetIDs = new HashSet<ISynsetID>();
for (ISynset synset : iSynsets)
synsetIDs.add(synset.getID());
Set<ISynsetID> remoteHypernymIDs = findRelatedSynsetsAtExactDistance(synsetIDs, Pointer.HYPERNYM, degree);
Set<ISynsetID> remoteCousinIDs = findRelatedSynsetsAtExactDistance(remoteHypernymIDs, Pointer.HYPONYM, degree);
remoteCousinIDs.removeAll(synsetIDs); // the initial synsets are not their own cousins
// screen out the cousins that are reachable by climbing and sliding less than 'degree' steps, and remain with those cousins reachable only by climbing
// and sliding 'degree' steps.
remoteCousinIDs.removeAll(getLooseCousinsForRealSynset(iSynsets, degree-1));
// collect the lemmas
cousinLemmas = getWordsOfSynsetIDs(remoteCousinIDs);
// screen out the original synset's lemmas
Set<String> originalSynsetLemmas = getWordsOfSynsets(iSynsets);
cousinLemmas.removeAll(originalSynsetLemmas);
}
}
return cousinLemmas;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:37,代码来源:JwiCousinFinder.java
示例14: computeRemoteCousinSynsetIDs
import edu.mit.jwi.item.Pointer; //导入依赖的package包/类
/**
* @param iSynsets
* @param degree
* @return
*/
private Set<ISynsetID> computeRemoteCousinSynsetIDs(ISynset[] iSynsets, int degree) {
Set<ISynsetID> synsetIDs = new HashSet<ISynsetID>();
for (ISynset synset : iSynsets)
synsetIDs.add(synset.getID());
Set<ISynsetID> remoteHypernymIDs = findRelatedSynsetsAtLooseDistance(synsetIDs, Pointer.HYPERNYM, degree);
Set<ISynsetID> remoteCousinSynsetIDs = findRelatedSynsetsAtLooseDistance(remoteHypernymIDs, Pointer.HYPONYM, degree);
remoteCousinSynsetIDs.removeAll(synsetIDs); // the initial synsets are not their own cousins
return remoteCousinSynsetIDs;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:18,代码来源:JwiCousinFinder.java
示例15: getLexicalNeighbors
import edu.mit.jwi.item.Pointer; //导入依赖的package包/类
/**
* Get neighbors for a lexical relation type
* @param antonym
* @return
*/
protected Set<Synset> getLexicalNeighbors(Pointer pointer) {
Set<Synset> synsets = new HashSet<Synset>();
for (IWord word : realSynset.getWords())
{
synsets.addAll(jwiDictionary.getSetOfSynsetsOfWords( word.getRelatedWords(pointer) ));
}
return synsets;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:14,代码来源:JwiSynset.java
示例16: getTransitivelyRelatedSynsets
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例17: getRoots
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例18: setWordNetFeatures
import edu.mit.jwi.item.Pointer; //导入依赖的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
示例19: getTMap
import edu.mit.jwi.item.Pointer; //导入依赖的package包/类
private Map<String,Set<String>> getTMap(int nType,int nOrder,int n){
if(nType>=wordIndexArray.length)return null;
Map<String,Set<String>>ret = new HashMap<String, Set<String>>();
IIndexWord iarray = wordIndexArray[nType];
IWordID wordID = iarray.getWordIDs().get(nOrder);
Map<IPointer, List<IWordID>> wordMap = dict.getWord(wordID).getRelatedMap();
Map<IPointer, List<ISynsetID>> synMap = dict.getSynset(wordID.getSynsetID()).getRelatedMap();
Set<String> stemp;
if((stemp = fillList(Pointer.ALSO_SEE,wordMap,synMap))!=null)ret.put(TALSO_SEE,stemp);
if((stemp = fillList(Pointer.ANTONYM,wordMap,synMap))!=null)ret.put(TANTONYM,stemp);
if((stemp = fillList(Pointer.ATTRIBUTE,wordMap,synMap))!=null)ret.put(TATTRIBUTE,stemp);
if((stemp = fillList(Pointer.CAUSE,wordMap,synMap))!=null)ret.put(TCAUSE,stemp);
if((stemp = fillList(Pointer.DERIVATIONALLY_RELATED,wordMap,synMap))!=null)ret.put(TDERIVATIONALLY_RELATED,stemp);
if((stemp = fillList(Pointer.DERIVED_FROM_ADJ,wordMap,synMap))!=null)ret.put(TDERIVED_FROM_ADJ,stemp);
if((stemp = fillList(Pointer.DOMAIN,wordMap,synMap))!=null)ret.put(TDOMAIN,stemp);
if((stemp = fillList(Pointer.ENTAILMENT,wordMap,synMap))!=null)ret.put(TENTAILMENT,stemp);
if((stemp = fillList(Pointer.HOLONYM_MEMBER,wordMap,synMap))!=null)ret.put(THOLONYM_MEMBER,stemp);
if((stemp = fillList(Pointer.HOLONYM_PART,wordMap,synMap))!=null)ret.put(THOLONYM_PART,stemp);
if((stemp = fillList(Pointer.HOLONYM_SUBSTANCE,wordMap,synMap))!=null)ret.put(THOLONYM_SUBSTANCE,stemp);
if((stemp = fillList(Pointer.HYPERNYM,wordMap,synMap))!=null)ret.put(THYPERNYM,stemp);
if((stemp = fillList(Pointer.HYPERNYM_INSTANCE,wordMap,synMap))!=null)ret.put(THYPERNYM_INSTANCE,stemp);
if((stemp = fillList(Pointer.HYPONYM,wordMap,synMap))!=null)ret.put(THYPONYM,stemp);
if((stemp = fillList(Pointer.HYPONYM_INSTANCE,wordMap,synMap))!=null)ret.put(THYPONYM_INSTANCE,stemp);
if((stemp = fillList(Pointer.MEMBER,wordMap,synMap))!=null)ret.put(TMEMBER,stemp);
if((stemp = fillList(Pointer.MERONYM_MEMBER,wordMap,synMap))!=null)ret.put(TMERONYM_MEMBER,stemp);
if((stemp = fillList(Pointer.MERONYM_PART,wordMap,synMap))!=null)ret.put(TMERONYM_PART,stemp);
if((stemp = fillList(Pointer.MERONYM_SUBSTANCE,wordMap,synMap))!=null)ret.put(TMERONYM_SUBSTANCE,stemp);
if((stemp = fillList(Pointer.PARTICIPLE,wordMap,synMap))!=null)ret.put(TPARTICIPLE,stemp);
if((stemp = fillList(Pointer.PERTAINYM,wordMap,synMap))!=null)ret.put(TPERTAINYM,stemp);
if((stemp = fillList(Pointer.REGION,wordMap,synMap))!=null)ret.put(TREGION,stemp);
if((stemp = fillList(Pointer.REGION_MEMBER,wordMap,synMap))!=null)ret.put(TREGION_MEMBER,stemp);
if((stemp = fillList(Pointer.SIMILAR_TO,wordMap,synMap))!=null)ret.put(TSIMILAR_TO,stemp);
if((stemp = fillList(Pointer.TOPIC,wordMap,synMap))!=null)ret.put(TTOPIC,stemp);
if((stemp = fillList(Pointer.TOPIC_MEMBER,wordMap,synMap))!=null)ret.put(TTOPIC_MEMBER,stemp);
if((stemp = fillList(Pointer.USAGE,wordMap,synMap))!=null)ret.put(TUSAGE,stemp);
if((stemp = fillList(Pointer.USAGE_MEMBER,wordMap,synMap))!=null)ret.put(TUSAGE_MEMBER,stemp);
if((stemp = fillList(Pointer.VERB_GROUP,wordMap,synMap))!=null)ret.put(TVERB_GROUP,stemp);
List<IWord> synsetWords = dict.getSynset(wordID.getSynsetID()).getWords();
if(synsetWords.size()>1){
stemp = new TreeSet<String>();
for(IWord tword:synsetWords){
String tstr;
if((tstr=tword.getLemma())!=wordName){
stemp.add(tstr);
}
}
ret.put(TSYNSET, stemp);
}
return ret;
}
开发者ID:MusicCraftor,项目名称:WordNet-Explorer,代码行数:51,代码来源:WordDic.java
示例20: getRelatedWords
import edu.mit.jwi.item.Pointer; //导入依赖的package包/类
public synchronized Map<MappedString, Float> getRelatedWords(String word, String posStr) {
String cacheKey = word + "#" + posStr;
Map<MappedString, Float> synonymScores = relatedWordsCache.get(cacheKey);
if (synonymScores == null) {
synonymScores = new HashMap<MappedString, Float>();
relatedWordsCache.put(cacheKey, synonymScores);
POS pos = posFromString(posStr);
if (pos == null) {
return new HashMap<MappedString, Float>();
}
List<TraceElement> trace = new LinkedList<TraceElement>();
trace.add(new TraceElement(word, ""));
Collection<ComparablePair<String, Float>> partialWords = StringUtil.getPartialMainWords(word);
for (ComparablePair<String, Float> partialWord : partialWords) {
float factor = partialWord.value;
IIndexWord idxWord;
synchronized (dict) {
idxWord = dict.getIndexWord(partialWord.key, pos);
}
if (idxWord == null) {
continue;
}
// Use hypernyms to find related words, but assign a penalty
// as hypernyms are a "bad" way to find synonyms
// (human is not a synonym of author, but the other way around)
float hypernymPenalty = 0.1f;
for (IWordID wordID : idxWord.getWordIDs()) {
IWord w;
synchronized (dict) {
w = dict.getWord(wordID);
}
List<TraceElement> _trace = new LinkedList<TraceElement>(trace);
// only add "partial node" notice if it actually is only a part
if (!w.getLemma().equals(word)) {
_trace.add(new TraceElement(w.getLemma() + " (partial word)", getWordNetUrl(w)));
}
addSynonyms(synonymScores, getHyponyms(w.getSynset(), 3, _trace), factor);
addSynonyms(synonymScores, getHypernyms(w.getSynset(), 3, _trace), factor*hypernymPenalty);
addSynonym(synonymScores, w.getLemma(), _trace, factor);
// Get direct and transitive synonyms
addSynonyms(synonymScores, getSynonyms(w, 1, 2, _trace), factor);
List<IWordID> rWordIDs = w.getRelatedWords(Pointer.DERIVATIONALLY_RELATED);
for (IWordID rWordID : rWordIDs) {
IWord rW;
synchronized (dict) {
rW = dict.getWord(rWordID);
}
List<TraceElement> __trace = new LinkedList<TraceElement>(_trace);
__trace.add(new TraceElement(rW.getLemma() + " (related form)", getWordNetUrl(rW)));
addSynonym(synonymScores, rW.getLemma(), __trace, factor);
addSynonyms(synonymScores, getHyponyms(rW.getSynset(), 3, __trace), factor);
addSynonyms(synonymScores, getHypernyms(rW.getSynset(), 3, __trace), factor*hypernymPenalty);
// Get direct and transitive synonyms
addSynonyms(synonymScores, getSynonyms(rW, 1, 2, __trace));
}
}
}
}
return synonymScores;
}
开发者ID:johannessimon,项目名称:pal,代码行数:64,代码来源:WordNetConnector.java
注:本文中的edu.mit.jwi.item.Pointer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论