本文整理汇总了Java中net.sf.extjwnl.data.Word类的典型用法代码示例。如果您正苦于以下问题:Java Word类的具体用法?Java Word怎么用?Java Word使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Word类属于net.sf.extjwnl.data包,在下文中一共展示了Word类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIsLexical
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
@Test
public void testIsLexical() throws JWNLException {
Synset s1 = new Synset(null, POS.NOUN);
PointerTargetNode p1 = new PointerTargetNode(s1, PointerType.ANTONYM);
Synset s2 = new Synset(null, POS.NOUN);
Word w2 = new Word(null, s2, "test");
PointerTargetNode p2 = new PointerTargetNode(w2, PointerType.ANTONYM);
Assert.assertFalse(p1.isLexical());
Assert.assertTrue(p2.isLexical());
Assert.assertEquals(s1, p1.getSynset());
Assert.assertEquals(s2, p2.getSynset());
Assert.assertEquals(s1, p1.getPointerTarget());
Assert.assertEquals(w2, p2.getPointerTarget());
Assert.assertNull(p1.getWord());
Assert.assertEquals(w2, p2.getWord());
Assert.assertFalse(p1.equals(p2));
Assert.assertFalse(p1.hashCode() == p2.hashCode());
Assert.assertNotNull(p1.toString());
}
示例2: getInfinitiveForm
import net.sf.extjwnl.data.Word; //导入依赖的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;
}
示例3: lookup
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
@Override
public Optional<Word> lookup(String id) {
try {
return Optional.ofNullable(dictionary.getWordBySenseKey(id));
} catch (JWNLException e) {
log.warn("Error looking up word for sense key: {}", id);
}
return Optional.empty();
}
示例4: mfs
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
@Override
public Optional<String> mfs(String lemma, String pos) {
List<Synset> senses = getSynsets(lemma, pos);
if (senses.size() == 0) {
return Optional.empty();
}
Synset synset = senses.get(0);
int index = synset.indexOfWord(getLemmaString(lemma));
Word word = synset.getWords().get(index);
return getSenseKey(word);
}
示例5: getSenseKey
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
private static Optional<String> getSenseKey(Word word) {
String result = null;
try {
result = word.getSenseKey();
} catch (JWNLException e) {
log.warn("Error retrieving sense key for word", word, e);
}
return Optional.ofNullable(result);
}
示例6: getInfinitiveForm
import net.sf.extjwnl.data.Word; //导入依赖的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;
}
示例7: getStrictExpansion
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
public static List<String> getStrictExpansion(String inputWord) {
List<String> expansion = null;
try {
IndexWordSet wordSet = dictionary.lookupAllIndexWords(inputWord);
if (wordSet.size() == 1) {
IndexWord indexWord = wordSet.getIndexWordCollection().iterator().next();
String lemma = indexWord.getLemma();
List<Synset> senses = indexWord.getSenses();
if (senses.size() == 1) {
List<Word> words = senses.get(0).getWords();
if (words.size() > 1) {
expansion = new ArrayList<>();
for (Word word : words) {
if (!word.getLemma().equals(lemma)) {
expansion.add(word.getLemma());
}
}
}
}
}
} catch (JWNLException e) {
e.printStackTrace();
}
return expansion;
}
示例8: ExtJwnlSensedWord
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
/**
* Ctor that takes a synset and a word. It verifies that the word indeed belongs to the synset.
* <p>
* <b>NOTE</b> ExtJwnl <i>lowercases</i> the words it is queried about. But the words it retrieves in methods like <code>realSynset.getWords()</code>
* are case sensitive!
*
* @param synset
* @param strWord
* @throws WordNetException
*/
public ExtJwnlSensedWord(ExtJwnlSynset synset, String strWord) throws WordNetException {
this.synset = synset;
this.word = strWord;
String wordToLookup = strWord.replace(' ', '_'); // mimic jwnl, which replaces underscores with spaces when looking up
List<Word> words = synset.realSynset.getWords();
Word wordObj = lookupWordInWords(words, wordToLookup);
if (wordObj == null)
throw new WordNetException("\""+ strWord + "\" is not a memeber of the given synset " + synset);
this.wordObj = wordObj;
dictionary = synset.extJwnlDictionary;
this.pos = ExtJwnlUtils.getWordNetPartOfSpeech( wordObj.getPOS());
}
示例9: getNeighborSensedWords
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
public Set<SensedWord> getNeighborSensedWords(WordNetRelation relation) throws WordNetException {
Set<SensedWord> sensedWords = new LinkedHashSet<SensedWord>();
if (relation.isLexical())
{
List<Pointer> pointers = wordObj.getPointers(ExtJwnlUtils.wordNetRelationToPointerType(relation));
for (Pointer pointer : pointers)
// add a new SensedWord made of the Word-cast of this pointer
sensedWords.add( new ExtJwnlSensedWord(((Word) pointer.getTarget()), dictionary));
}
return sensedWords;
}
示例10: lookupWordInWords
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
/**
* @param words
* @param wordToLookup
* @return
*/
private Word lookupWordInWords(List<Word> words, String wordToLookup) {
boolean found = false;
Word someWord = null;
for (int i = 0; i < words.size() && !found; i++)
{
someWord = words.get(i);
found = someWord.getLemma().equalsIgnoreCase(wordToLookup);
}
return someWord;
}
示例11: getWords
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
public Set<String> getWords() throws WordNetException
{
if (words == null)
{
words = new LinkedHashSet<String>();
for (Word word : this.realSynset.getWords())
{
String lemma = word.getLemma();
lemma = lemma.replaceAll("_", " "); // clean
words.add(lemma);
}
}
return new LinkedHashSet<String>(words); // return a copy
}
示例12: getWordsAndUsages
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
public List<WordAndUsage> getWordsAndUsages() throws WordNetException
{
List<WordAndUsage> ret = null;
List<Word> words = this.realSynset.getWords();
ret = new ArrayList<WordAndUsage>(words.size());
for (Word word : words)
{
// TODO handle this better
try
{
ret.add(new WordAndUsage(word.getLemma(), word.getUseCount()));
}
catch(NoSuchElementException e){} // a JWNL bug
}
Collections.sort(ret,
Collections.reverseOrder( // I'm preferring correctness to performance (in this case)
new Comparator<WordAndUsage>()
{
public int compare(WordAndUsage o1, WordAndUsage o2)
{
if (o1.getUsage()<o2.getUsage())return -1;
else if (o1.getUsage()==o2.getUsage()) return 0;
else return 1;
}
} // end of anonymous class Comparator
) // end of reverseOrder function (which returns the reverse of the defined comparator)
);
return ret;
}
示例13: getAllSensedWords
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
@Override
public List<SensedWord> getAllSensedWords() throws WordNetException {
List<Word> objWords = realSynset.getWords();
List<SensedWord> sensedWords = new ArrayList<SensedWord>(objWords.size());
for ( Word word : objWords)
sensedWords.add( new ExtJwnlSensedWord(word, this.extJwnlDictionary));
return sensedWords;
}
示例14: getWord
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
/**
* If the target is a word, return it, otherwise return null.
*
* @return if the target is a word, return it, otherwise return null
*/
public Word getWord() {
if (isLexical()) {
return (Word) target;
} else {
return null;
}
}
示例15: getResourcesWithScores
import net.sf.extjwnl.data.Word; //导入依赖的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);}
}