本文整理汇总了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);
}
}
}
}
}
示例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;
}
示例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();
}
}
示例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()));
}
}
}
示例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);
}
}
}
}
}
示例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();
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
}
示例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);
}
示例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);
}
}
}
示例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));
}
示例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;
}
}
// }
}
示例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;
}