本文整理汇总了Java中net.sf.extjwnl.data.Word类的典型用法代码示例。如果您正苦于以下问题:Java Word类的具体用法?Java Word怎么用?Java Word使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Word类属于net.sf.extjwnl.data包,在下文中一共展示了Word类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:extjwnl,项目名称:extjwnl,代码行数:26,代码来源:TestPointerTargetNode.java
示例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;
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:46,代码来源:PropertyVerbalizerPortuguese.java
示例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();
}
开发者ID:clearwsd,项目名称:clearwsd,代码行数:10,代码来源:ExtJwnlWordNet.java
示例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);
}
开发者ID:clearwsd,项目名称:clearwsd,代码行数:12,代码来源:ExtJwnlWordNet.java
示例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);
}
开发者ID:clearwsd,项目名称:clearwsd,代码行数:10,代码来源:ExtJwnlWordNet.java
示例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;
}
开发者ID:dice-group,项目名称:BENGAL,代码行数:46,代码来源:PropertyVerbalizer.java
示例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;
}
开发者ID:oaqa,项目名称:LiveQA,代码行数:26,代码来源:WordNetExpansion.java
示例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());
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:24,代码来源:ExtJwnlSensedWord.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:13,代码来源:ExtJwnlSensedWord.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:17,代码来源:ExtJwnlSensedWord.java
示例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
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:15,代码来源:ExtJwnlSynset.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:32,代码来源:ExtJwnlSynset.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:9,代码来源:ExtJwnlSynset.java
示例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;
}
}
开发者ID:extjwnl,项目名称:extjwnl,代码行数:13,代码来源:PointerTargetNode.java
示例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);}
}
开发者ID:AKSW,项目名称:rdfindex,代码行数:34,代码来源:WordNetIndex.java
示例16: extJwnlTest
import net.sf.extjwnl.data.Word; //导入依赖的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
示例17: testSemcor
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
@Test
public void testSemcor() {
SensePredictor<Word> predictor = DefaultSensePredictor.loadFromResource(SEMCOR_PATH, null);
assertNotNull(predictor);
}
开发者ID:clearwsd,项目名称:clearwsd,代码行数:6,代码来源:ModelLoadingTest.java
示例18: lemmas
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
private static Set<String> lemmas(Synset synset) {
return synset.getWords().stream()
.map(Word::getLemma)
.collect(Collectors.toSet());
}
开发者ID:clearwsd,项目名称:clearwsd,代码行数:6,代码来源:ExtJwnlWordNet.java
示例19: initializeWordNet
import net.sf.extjwnl.data.Word; //导入依赖的package包/类
@Override
protected WordNetFacade<Word> initializeWordNet() {
return new ExtJwnlWordNet();
}
开发者ID:clearwsd,项目名称:clearwsd,代码行数:5,代码来源:ExtJwnlSenseInventory.java
示例20: getRepresentative
import net.sf.extjwnl.data.Word; //导入依赖的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
注:本文中的net.sf.extjwnl.data.Word类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论