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


Java Synset.getWords方法代码示例

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


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

示例1: getAlternativeWords

import net.sf.extjwnl.data.Synset; //导入方法依赖的package包/类
/**
 * Gets the alternative words from the dictionary.
 *
 * @param word
 *            the word
 * @return the alternative words (non null and always contains the word itself)
 */
private Stream<String> getAlternativeWords(Word word) {
	IndexWord indexWord = null;
	try {
		indexWord = dictionary.lookupIndexWord(word.getPos(), word.getLemma());
	} catch (final Exception e) {
		getMonitor().debug("Unable to find word in wordnet, defaulting to lemma form", e);
	}

	if (indexWord == null) {
		return Stream.of(word.getLemma());
	}

	Set<String> set = new HashSet<String>();
	set.add(word.getLemma());
	for (Synset synset : indexWord.getSenses()) {
		for (net.sf.extjwnl.data.Word w : synset.getWords()) {
			set.add(w.getLemma());
		}
	}

	return set.stream();
}
 
开发者ID:dstl,项目名称:baleen,代码行数:30,代码来源:EnhanceInteractions.java

示例2: getInfinitiveForm

import net.sf.extjwnl.data.Synset; //导入方法依赖的package包/类
/**
* Returns the infinitive form for a given word.
* 
* @param word the word
* @return the infinitive form
*/
  public String getInfinitiveForm(String word) {
  	//System.out.println("Word: " + word);
      String[] split = word.split(" ");
      String verb = split[0];

      if(verb.endsWith("ed") && split.length == 1) { 
      	// probably past tense
      	
      } else if (verb.endsWith("do")) { // termina com participio
      	
      	// check for past construction that simply need an auxiliary
      	return "ser " + word;
      }

      try {
	IndexWord iw = database.getIndexWord(POS.VERB, word);
	if(iw != null) {
		List<Synset> synsets = iw.getSenses();
		//double min = verb.length();
		String result = verb;
		for (Synset synset : synsets) {
		    for (Word w : synset.getWords()) {
		        if (verb.contains(w.getLemma())) {
		            result = w.getLemma();
		            if (split.length > 1) {
		                for (int k = 1; k < split.length; k++) {
		                    result = result + " " + split[k];
		                }
		            }
		            return result;
		        }
		    }
		}
	}
} catch (JWNLException e) {
	logger.error("WordNet lookup failed.", e);
}
      return word;
  }
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:46,代码来源:PropertyVerbalizerPortuguese.java

示例3: getInfinitiveForm

import net.sf.extjwnl.data.Synset; //导入方法依赖的package包/类
/**
 * Returns the infinitive form for a given word.
 * 
 * @param word
 *            the word
 * @return the infinitive form
 */
public String getInfinitiveForm(String word) {

	String[] split = word.split(" ");
	String verb = split[0];

	if (verb.endsWith("ed") && split.length == 1) {
		// probably past tense

	} else if (verb.endsWith("ed") || verb.endsWith("un") || verb.endsWith("wn") || verb.endsWith("en")) {
		// check for past construction that simply need an auxiliary
		return "be " + word;
	}

	try {
		IndexWord iw = database.getIndexWord(POS.VERB, word);
		if (iw != null) {
			List<Synset> synsets = iw.getSenses();
			double min = verb.length();
			String result = verb;
			for (Synset synset : synsets) {
				for (Word w : synset.getWords()) {
					if (verb.contains(w.getLemma())) {
						result = w.getLemma();
						if (split.length > 1) {
							for (int k = 1; k < split.length; k++) {
								result = result + " " + split[k];
							}
						}
						return result;
					}
				}
			}
		}
	} catch (JWNLException e) {
		logger.error("WordNet lookup failed.", e);
	}
	return word;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:46,代码来源:PropertyVerbalizer.java

示例4: getResourcesWithScores

import net.sf.extjwnl.data.Synset; //导入方法依赖的package包/类
@Override public IndexResultSet getResourcesWithScores(String queryString, int limit)
	{
		IndexResultSet resources = index.getResourcesWithScores(queryString, limit);
		if(resources.size()>=limit&&resources.last().getScore()==1f) return resources; // already perfect, no wordnet necessary
		int MAX_ADDITIONS = resources.tailSet(new IndexItem("","",WORDNET_PENALTY_FACTOR)).size();

//		(new Comparator<IndexItem>(){public int compare(IndexItem i1, IndexItem i2)
//		{return i1.getUri().compareTo(i2.getUri());};});
//		itemsByUri.addAll(resources);

		try
		{
			Set<Synset> synsets = new HashSet<>();

			for(IndexWord iw: d.lookupAllIndexWords(queryString).getIndexWordArray())
			{
				synsets.addAll(iw.getSenses());
			}

			Set<String> lemmas = new HashSet<>();

			for(Synset synset: synsets)
			{
				for(Word word: synset.getWords()) {lemmas.add(word.getLemma());}
			}

			for(String lemma: lemmas) {resources.addAll(index.getResourcesWithScores(lemma, MAX_ADDITIONS));}

			resources.retainBest(limit);
			return resources;
		}
		catch (JWNLException e) {throw new RuntimeException(e);}
	}
 
开发者ID:AKSW,项目名称:rdfindex,代码行数:34,代码来源:WordNetIndex.java

示例5: extJwnlTest

import net.sf.extjwnl.data.Synset; //导入方法依赖的package包/类
@Test public void extJwnlTest() throws JWNLException
	{
		Dictionary d = Dictionary.getDefaultResourceInstance();
//
		IndexWord iw = d.getIndexWord(POS.NOUN, "airport");
		for(Synset sense: iw.getSenses())
		{
			System.out.println(sense);
			for(Word word: sense.getWords()) System.out.println(word.getLemma());
		}
//		System.out.println(d.getSynsetAt(POS.NOUN, "airport"));
	}
 
开发者ID:AKSW,项目名称:rdfindex,代码行数:13,代码来源:SPARQLModelIndexTest.java

示例6: getRepresentative

import net.sf.extjwnl.data.Synset; //导入方法依赖的package包/类
public String getRepresentative(String w, String pos) {
    POS posw;
    if (pos.equals("NN") || pos.equals("NNS") || pos.equals("NNP") || pos.equals("NNPS")) {
        posw = POS.NOUN;
    } else if (pos.equals("VBZ") || pos.equals("VBG") || pos.equals("VBP") || pos.equals("VBN") || pos.equals("VBD") || pos.equals("VB")) {
        posw = POS.VERB;
    } else if (pos.equals("JJ")) {
        posw = POS.ADJECTIVE;
    } else {
        if (pos.startsWith("V") || pos.startsWith("N")) {
            System.out.println("POS discarded: " + pos);
        }
        return "";
    }
    if (!representative.containsKey(w)) {
        IndexWord iw1 = null;
        try {
            iw1 = dictionary.getIndexWord(posw, w);
        } catch (Exception e) {
        }
        String r = null;
        if (iw1 != null) {
            long[] offsets = iw1.getSynsetOffsets();
            if (offsets.length > 0) {
                //try only the first meaning
                try {
                    Synset synset = dictionary.getSynsetAt(posw, offsets[0]);
                    for (Word word : synset.getWords()) {
                        String lemma = word.getLemma();
                        if (representative.containsKey(lemma)) {
                            r = lemma;
                            break;
                        }
                    }
                } catch (JWNLException ex) {
                    Logger.getLogger(RepresentativeProvider.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        if (r != null) {
            representative.put(w, representative.get(r));
        } else {
            representative.put(w, w);
        }
        newEntries++;
    }
    if (newEntries == UPDATE_FREQUENCY) {
        saveRepresentatives();
        newEntries = 0;
    }
    return representative.get(w);
}
 
开发者ID:UCLA-BD2K,项目名称:aztec-text-analysis-tools,代码行数:53,代码来源:RepresentativeProvider.java

示例7: getSynonyms

import net.sf.extjwnl.data.Synset; //导入方法依赖的package包/类
public static Set<String> getSynonyms(String word) throws JWNLException {
    IndexWord[] allWords = getWordArray(word);
    if (allWords.length == 1) {
        Set<String> retData = new HashSet<>();
        for (Synset synset : allWords[0].getSenses()) {
            for (Word wordObj : synset.getWords()) {
                retData.add(wordObj.getLemma());
            }
        }
        return retData;
    }
    return null;
}
 
开发者ID:lucene4ir,项目名称:lucene4ir,代码行数:14,代码来源:SynonymProvider.java


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