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


Java IndexWord类代码示例

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


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

示例1: doProcess

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
@Override
protected void doProcess(JCas jCas) throws AnalysisEngineProcessException {
	for (WordToken t : JCasUtil.select(jCas, WordToken.class)) {
		if (t.getLemmas() == null || t.getLemmas().size() > 0) {
			String text = t.getCoveredText();
			POS pos = WordNetUtils.toPos(t.getPartOfSpeech());
			if (pos != null) {
				Optional<IndexWord> lookupWord = wordnet.lookupWord(pos, text);
				if (lookupWord.isPresent()) {
					t.setLemmas(new FSArray(jCas, 1));
					WordLemma wordLemma = new WordLemma(jCas);
					wordLemma.setLemmaForm(lookupWord.get().getLemma());
					t.setLemmas(0, wordLemma);
				}
			}
		}
	}
}
 
开发者ID:tenode,项目名称:baleen-extras,代码行数:19,代码来源:WordNetLemmatizer.java

示例2: getDerivedAdjective

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
/**
 * Returns the derived adjective with the same word form for the most common
 * sense of the given noun if exists.
 *
 * @param noun
 *            the noun
 */
public String getDerivedAdjective(String noun) {
	try {
		IndexWord nounIW = dict.lookupIndexWord(POS.NOUN, noun);

		List<Synset> senses = nounIW.getSenses();

		Synset mainSense = senses.get(0);

		List<Pointer> pointers = mainSense.getPointers(PointerType.DERIVATION);

		for (Pointer pointer : pointers) {
			Synset derivedSynset = pointer.getTargetSynset();
			if (derivedSynset.getPOS() == POS.ADJECTIVE) {
				// return derivedSynset.getWords().get(0).getLemma();
			}
			if (derivedSynset.getPOS() == POS.VERB) {
				System.out.println(derivedSynset);
			}
		}
	} catch (JWNLException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:32,代码来源:WordNetUtils.java

示例3: getSuperSenses

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
/**
 * Gets the super senses of a word.
 *
 * The supersense is the original 'sense file' in which word was defined.
 *
 * @param pos
 *            the pos
 * @param word
 *            the word
 * @return the super senses
 */
public Stream<String> getSuperSenses(POS pos, String word) {
	final Optional<IndexWord> indexWord = lookupWord(pos, word);

	if (!indexWord.isPresent()) {
		return Stream.empty();
	} else {
		// NOTE: This was stream but it WordNet getSenses() somehow seems incompatible with
		// streams
		final List<Synset> senses = indexWord.get().getSenses();
		final Set<String> set = new HashSet<>();
		for (final Synset s : senses) {
			set.add(stripPOSFromSupersense(s.getLexFileName()));
		}
		return set.stream();
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:28,代码来源:SharedWordNetResource.java

示例4: getBestSuperSense

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
/**
 * Gets the best super sense for a word.
 *
 * @param pos
 *            the pos
 * @param word
 *            the word
 * @return the best super sense
 */
public Optional<String> getBestSuperSense(POS pos, String word) {
	final Optional<IndexWord> indexWord = lookupWord(pos, word);

	if (!indexWord.isPresent()) {
		return Optional.empty();
	} else {
		final List<Synset> senses = indexWord.get().getSenses();
		if (senses.isEmpty()) {
			return Optional.empty();
		} else {
			// At this stage we could do something clever, look at the gloss to see is there are
			// word overlaps
			// but we opt for a more predicatable concept of selecting the most commonly used
			// meaning sense.

			return Optional.of(stripPOSFromSupersense(senses.get(0).getLexFileName()));
		}
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:29,代码来源:SharedWordNetResource.java

示例5: doProcess

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
@Override
protected void doProcess(JCas jCas) throws AnalysisEngineProcessException {
	for (final WordToken t : JCasUtil.select(jCas, WordToken.class)) {
		if (t.getLemmas() == null || t.getLemmas().size() == 0) {
			final String text = t.getCoveredText();
			final POS pos = WordNetUtils.toPos(t.getPartOfSpeech());
			if (pos != null) {
				final Optional<IndexWord> lookupWord = wordnet.lookupWord(pos, text);
				if (lookupWord.isPresent()) {
					t.setLemmas(new FSArray(jCas, 1));
					final WordLemma wordLemma = new WordLemma(jCas);
					wordLemma.setLemmaForm(lookupWord.get().getLemma());
					t.setLemmas(0, wordLemma);
				}
			}
		}
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:19,代码来源:WordNetLemmatizer.java

示例6: getAlternativeWords

import net.sf.extjwnl.data.IndexWord; //导入依赖的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

示例7: getSynsetsOf

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
public Set<Synset> getSynsetsOf(String lemma, WordNetPartOfSpeech partOfSpeech)  throws WordNetException
{
	if (doNotProcessThisWord(lemma))
		return new LinkedHashSet<Synset>();
	else
	{
		try
		{
			IndexWord indexWord = extJwnlRealDictionary.lookupIndexWord(ExtJwnlUtils.getJwnlPartOfSpeec(partOfSpeech), lemma);
			return indexWordToSet(indexWord);
		}
		catch(JWNLException e)
		{
			throw new WordNetException("looking for word <"+lemma+"> with part of speech: "+partOfSpeech.toString()+" failed. See nested exception",e);
		}
	}
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:18,代码来源:ExtJwnlDictionary.java

示例8: getAllWords

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
/**
 * Return all {@link Synset}s of a particular POS
 * @param pos
 * @return
 * @throws WordNetException
 */
public List<Synset> getAllWords(WordNetPartOfSpeech pos) throws WordNetException
{
	List<Synset> synsets = new ArrayList<Synset>();
	try {
		@SuppressWarnings("rawtypes")
		Iterator iter = extJwnlRealDictionary.getIndexWordIterator(ExtJwnlUtils.getJwnlPartOfSpeec(pos));
		while (iter.hasNext())
		{
			IndexWord indexWord = (IndexWord) iter.next();
			synsets.addAll(indexWordToList(indexWord));
		}
		
	} catch (JWNLException e) {
		throw new WordNetException("looking for all <"+pos+">s failed. See nested exception",e);
	}
	
	return synsets;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:25,代码来源:ExtJwnlDictionary.java

示例9: indexWordToList

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
protected List<Synset> indexWordToList(IndexWord indexWord) throws JWNLException
{
	List<Synset> ret = null;
	if (indexWord!=null)
	{
		if (indexWord.getSenses()!=null)
		{
			ret = new ArrayList<Synset>(indexWord.getSenses().size());
			for (net.sf.extjwnl.data.Synset jwnlRealSynset : indexWord.getSenses())
			{
				ret.add(new ExtJwnlSynset(this, jwnlRealSynset));
			}
		}
	}
	if (null==ret)
		ret = new ArrayList<Synset>();
	
	return ret;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:20,代码来源:ExtJwnlDictionary.java

示例10: compareIndexWordSets

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
/**
 * Iterate through other forms of the word and see if they return a
 * relationship
 * 
 * @param sourceSet
 * @param targetSet
 * @throws CloneNotSupportedException
 * @throws JWNLException
 */
private void compareIndexWordSets(IndexWordSet sourceSet,
		IndexWordSet targetSet) throws CloneNotSupportedException,
		JWNLException {
	for (IndexWord source : sourceSet.getIndexWordCollection()) {
		for (IndexWord target : targetSet.getIndexWordCollection()) {
			// Only compare like parts of speech
			if (source.getPOS().equals(target.getPOS())) {
				List<PointerType> relevantTypes = PointerType
						.getAllPointerTypesForPOS(source.getPOS());
				if (!relevantTypes.isEmpty()) {
					compareIndexWordsForPointerTypes(source, target,
							relevantTypes);
				}
			}
		}
	}

}
 
开发者ID:pschuette22,项目名称:Zeppa-AppEngine,代码行数:28,代码来源:CompareWordsTask.java

示例11: getSynonyms

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
public List<String> getSynonyms(String lemma) {
	HashSet<String> words = new HashSet<String>();
	try {
		IndexWord lemmaIndex = dictionary.lookupIndexWord(POS.VERB, lemma);

		if (lemmaIndex != null) {

			List<Synset> synsets = lemmaIndex.getSenses();

			for (Synset synset : synsets) {
				words.add(synset.getWords().get(0).getLemma());
			}

		}

	} catch (JWNLException e) {
		e.printStackTrace();
	}
	return Lists.newArrayList(words);
}
 
开发者ID:impro3-nerdle,项目名称:nerdle,代码行数:21,代码来源:WordNetHelper.java

示例12: lookupBaseForm

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
/**
 * Lookup the first base form of a word. Given a lemma, finds the WordNet
 * entry most like that lemma. This function returns the first base form
 * found. Subsequent calls to this function with the same part-of-speech
 * and word will return the same base form.
 *
 * @param pos        the part-of-speech of the word to look up
 * @param derivation the word to look up
 * @return IndexWord the IndexWord found during lookup or null
 */
public IndexWord lookupBaseForm(POS pos, String derivation) throws JWNLException {
    if (null == pos || null == derivation || "".equals(derivation)) {
        return null;
    }
    // See if we've already looked this word up
    LookupInfo info = getCachedLookupInfo(pos, derivation);
    synchronized (info) {
        if (info.getBaseForms().isCurrentFormAvailable()) {
            // get the last base form we retrieved. if you want
            // the next possible base form, use lookupNextBaseForm
            return null == dictionary ? null : dictionary.getIndexWord(pos, info.getBaseForms().getCurrentForm());
        } else {
            return lookupNextBaseForm(pos, info);
        }
    }
}
 
开发者ID:extjwnl,项目名称:extjwnl,代码行数:27,代码来源:DefaultMorphologicalProcessor.java

示例13: lookupNextBaseForm

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
/**
 * Lookup the next base form of a pos/word pair. If a base form has not
 * yet been found for the pos/word, it will find the first base form,
 * otherwise it will find the next base form.
 *
 *
 * @param pos        the part-of-speech of the word to look up
 * @param info       lookup info
 * @return IndexWord the IndexWord found during lookup, or null if an IndexWord is not found
 * @throws JWNLException JWNLException
 */
private IndexWord lookupNextBaseForm(POS pos, LookupInfo info) throws JWNLException {
    String str = null;
    synchronized (info) {
        // if we've already found another possible base form, return that one
        if (info.getBaseForms().isMoreFormsAvailable()) {
            str = info.getBaseForms().getNextForm();
        } else {
            while (info.isNextOperationAvailable() && !info.executeNextOperation()) {
            }
            if (info.getBaseForms().isMoreFormsAvailable()) {
                str = info.getBaseForms().getNextForm();
            }
        }
    }

    return (str == null) ? null : (null == dictionary ? null : dictionary.getIndexWord(pos, str));
}
 
开发者ID:extjwnl,项目名称:extjwnl,代码行数:29,代码来源:DefaultMorphologicalProcessor.java

示例14: runTestCase

import net.sf.extjwnl.data.IndexWord; //导入依赖的package包/类
@Override
        public void runTestCase() throws JWNLException {
            //uncomment this to solve the problem,
            //but I think there's a better way to solve it.
//            synchronized (dictionary) {
            for (String word : words) {
                if (!isInterrupted()) {
                    //throws an Exception or just stop at here
                    log.debug("lookup: " + word);
                    IndexWord iws = dictionary.lookupIndexWord(POS.NOUN, word);
                    log.debug("finished: " + word);
                    Assert.assertEquals("Can't find: " + word, null != iws, test);
                } else {
                    break;
                }
            }
//            }
        }
 
开发者ID:extjwnl,项目名称:extjwnl,代码行数:19,代码来源:TestThreads.java

示例15: getInfinitiveForm

import net.sf.extjwnl.data.IndexWord; //导入依赖的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


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