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