当通过MIT Java Wordnet接口(JWI)检索Synset的语义关系时,我根本无法得到与派生相关的形式。我使用的是ISynset类方法getRelatedSynsets(IPointer p)
,但列表只返回空。
作为一个简单的测试,我开发了一个类,它迭代wordnet的所有名词同义词,并试图找到暴露衍生相关形式的任何synset。令人惊讶的是,代码无法找到具有该关系的单个synset。这是代码:
public class DerivationallyTest {
private static IDictionary dict = null;
public static void main(String[] args) throws IOException {
IDictionary dict = dicitionaryFactory();
Iterator<ISynset> it = dict.getSynsetIterator(POS.NOUN);
while(it.hasNext()){
ISynset synset = it.next();
if(synset.getRelatedSynsets(Pointer.DERIVATIONALLY_RELATED).size() > 0){
System.out.println("FOUND ONE!!!");
}
}
}
public static IDictionary dicitionaryFactory() throws IOException{
if(dict == null){
System.out.println("Instanciando Dicionario...");
// construct the URL to the Wordnet dictionary directory
String wnhome = System.getenv("WNHOME");
String path = wnhome + File.separator + "dict";
URL url = new URL("file", null, path);
// construct the dictionary object and open it
dict = new Dictionary(url);
dict.open();
}
return dict;
}
}
我做错了什么或这是一个真正奇怪的行为?我已经开发了许多使用MIT JWI的课程,并且不想在经过大量工作后更换为另一个API。
我在Ubuntu 12 LTS下使用Wordnet 3.1和MIT JWI 2.2.3
更新:我也尝试使用Wordnet 3.0,同样的事情发生了。
答案 0 :(得分:3)
只有语义指针附加到synsets。词汇指针只附加于单词。尝试:IWord.getRelatedWords(IPointer ptr)
答案 1 :(得分:1)
正如@ethereous所指出的,似乎Pointer.DERIVATIONALLY_RELATED是一个词法指针,而其他像Pointer.HYPERNYM和Pointer.HOLONYM则是语义指针。我在这个问题上写的课应该重写为下面的课程。
public class DerivationallyTest {
private static IDictionary dict = null;
public static void main(String[] args) throws IOException {
IDictionary dict = dicitionaryFactory();
Iterator<ISynset> it = dict.getSynsetIterator(POS.NOUN);
while(it.hasNext()){
ISynset synset = it.next();
//HERE COMES THE CHANGE!!!! (the ".getWords().get(0).getRelatedWords()")
if(synset.getWords().get(0).getRelatedWords(Pointer.DERIVATIONALLY_RELATED).size()>0){
System.out.println("FOUND ONE!!!");
}
}
}
public static IDictionary dicitionaryFactory() throws IOException{
if(dict == null){
System.out.println("Instanciando Dicionario...");
// construct the URL to the Wordnet dictionary directory
String wnhome = System.getenv("WNHOME");
String path = wnhome + File.separator + "dict";
URL url = new URL("file", null, path);
// construct the dictionary object and open it
dict = new Dictionary(url);
dict.open();
}
return dict;
}
}