有人知道如何检索两个单词之间的第一个常见的超限吗?我可以从给定的单词中访问第一级(直接父级),但是我一直在研究如何从这个单词检索所有的hypernyms (“向上”),直到它与另一个单词匹配为止。这样做的目的是根据词根通过WordNet识别出在什么地方/什么时候/哪两个单词可以被认为是“相同的”(如果找不到,它应该一直持续到单词在wordnet中的末尾)。我在这里找到了一些主题,除了Python和Perl之外,JAVA中没有针对这个问题的任何特定主题。
我使用JWI (2.4.0)访问SynsetID、WordID和来自WordNet的其他信息。如果有一个更简单的API来完成这项工作也是受欢迎的。下面是提供我提到的hypernym的方法。
public void getHypernyms(IDictionary dict_param, String lemma_param) throws IOException {
dict_param.open();
// get the synset
IIndexWord idxWord = dict_param.getIndexWord(lemma_param, POS.NOUN);
// 1st meaning
IWordID wordIDb = idxWord.getWordIDs().get(0);
IWord word = dict_param.getWord(wordIDb);
ISynset synset = word.getSynset();
System.out.println("Synset = " + synset);
// get the hypernyms by pointing a list of <types> in the words
List<ISynsetID> hypernyms = synset.getRelatedSynsets(Pointer.HYPERNYM);
// print out each h y p e r n y m s id and synonyms
List<IWord> words, wordsb;
for (ISynsetID sid : hypernyms) {
words = dict_param.getSynset(sid).getWords();
System.out.println("Lemma: " + word.getLemma());
System.out.print("Hypernonyms = " + sid + " {");
for (Iterator<IWord> i = words.iterator(); i.hasNext();) {
System.out.print(i.next().getLemma());
if (i.hasNext()) {
System.out.print(", ");
}
}
System.out.println("}");
}
}因此,我们提供了一个字典和“狗”这个词(正如你所看到的,我只是使用了执行这个方法的第一个意思):
Synset = SYNSET{SID-02084071-N : Words[W-02084071-N-1-dog, W-02084071-N-2 domestic_dog, W-02084071-N-3-Canis_familiaris]}
Lemma: dog Hypernonyms = SID-02083346-N {canine, canid}
Lemma: dog Hypernonyms = SID-01317541-N {domestic_animal, domesticated_animal}发布于 2016-05-30 15:38:30
对那些可能感兴趣的人来说。过了一段时间我想明白了。
public List<ISynsetID> getListHypernym(ISynsetID sid_pa) throws IOException {
IDictionary dict = openDictionary();
dict.open(); //Open the dictionary to start looking for LEMMA
List<ISynsetID> hypernym_list = new ArrayList<>();
boolean end = false;
while (!end) {
hypernym_list.add(sid_pa);
List<ISynsetID> hypernym_tmp = dict.getSynset(sid_pa).getRelatedSynsets(Pointer.HYPERNYM);
if (hypernym_tmp.isEmpty()) {
end = true;
} else {
sid_pa = hypernym_tmp.get(0);//we will stick with the first hypernym
}
}
//for(int i =0; i< hypernym_list.size();i++){
// System.out.println(hypernym_list.get(i));
//}
return hyp;
}https://stackoverflow.com/questions/37444779
复制相似问题