gpt4 book ai didi

java - 词网关系

转载 作者:行者123 更新时间:2023-11-30 05:09:25 25 4
gpt4 key购买 nike

如何从wordnet生成更一般、不太一般和等价关系?

RitaWordnet 中的 wordnet 相似度给出类似 -1.0、0.222 或 1.0 的数字,但如何得出单词之间更一般、不太一般的关系?哪个工具最适合这个?请帮助我

打印后我得到 java.lang.NullPointerException“全音是”

package wordnet;

import rita.wordnet.RiWordnet;

public class Main {
public static void main(String[] args) {
try {
// Would pass in a PApplet normally, but we don't need to here
RiWordnet wordnet = new RiWordnet();
wordnet.setWordnetHome("/usr/share/wordnet/dict");
// Demo finding parts of speech
String word = "first name";
System.out.println("\nFinding parts of speech for " + word + ".");
String[] partsofspeech = wordnet.getPos(word);
for (int i = 0; i < partsofspeech.length; i++) {
System.out.println(partsofspeech[i]);
}

//word = "eat";
String pos = wordnet.getBestPos(word);
System.out.println("\n\nDefinitions for " + word + ":");
// Get an array of glosses for a word
String[] glosses = wordnet.getAllGlosses(word, pos);
// Display all definitions
for (int i = 0; i < glosses.length; i++) {
System.out.println(glosses[i]);
}

// Demo finding a list of related words (synonyms)
//word = "first name";
String[] poss = wordnet.getPos(word);
for (int j = 0; j < poss.length; j++) {
System.out.println("\n\nSynonyms for " + word + " (pos: " + poss[j] + ")");
String[] synonyms = wordnet.getAllSynonyms(word, poss[j], 10);
for (int i = 0; i < synonyms.length; i++) {
System.out.println(synonyms[i]);
}
}

// Demo finding a list of related words
// X is Hypernym of Y if every Y is of type X
// Hyponym is the inverse
//word = "nurse";
pos = wordnet.getBestPos(word);
System.out.println("\n\nHyponyms for " + word + ":");
String[] hyponyms = wordnet.getAllHyponyms(word, pos);
//System.out.println(hyponyms.length);
//if(hyponyms!=null)
for (int i = 0; i < hyponyms.length; i++) {


System.out.println(hyponyms[i]);
}

System.out.println("\n\nHypernyms for " + word + ":");
String[] hypernyms = wordnet.getAllHypernyms(word, pos);
//if(hypernyms!=null)
for (int i = 0; i < hypernyms.length; i++) {
System.out.println(hypernyms[i]);
}

System.out.println("\n\nHolonyms for " + word + ":");

String[] holonyms = wordnet.getAllHolonyms(word, pos);
//if(holonyms!=null)
for (int i = 0; i < holonyms.length; i++) {
System.out.println(holonyms[i]);
}

System.out.println("\n\nmeronyms for " + word + ":");
String[] meronyms = wordnet.getAllMeronyms(word, pos);
if(meronyms!=null)
for (int i = 0; i < meronyms.length; i++) {
System.out.println(meronyms[i]);
}
System.out.println("\n\nAntonym for " + word + ":");
String[] antonyms = wordnet.getAllAntonyms(word, pos);
if(antonyms!=null)
for (int i = 0; i < antonyms.length; i++) {
System.out.println(antonyms[i]);
}


String start = "cameras";
String end = "digital cameras";
pos = wordnet.getBestPos(start);

// Wordnet can find relationships between words
System.out.println("\n\nRelationship between: " + start + " and " + end);
float dist = wordnet.getDistance(start, end, pos);
String[] parents = wordnet.getCommonParents(start, end, pos);
System.out.println(start + " and " + end + " are related by a distance of: " + dist);

// These words have common parents (hyponyms in this case)
System.out.println("Common parents: ");
if (parents != null) {
for (int i = 0; i < parents.length; i++) {
System.out.println(parents[i]);
}
}

//wordnet.
// System.out.println("\n\nHypernym Tree for " + start);
// int[] ids = wordnet.getSenseIds(start,wordnet.NOUN);
// wordnet.printHypernymTree(ids[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
}

最佳答案

Rita wordnet 确实提供了用于查找上位词(更通用)、下位词(不太通用)和同义词的 API。查看以下页面了解详细信息:-

http://www.rednoise.org/rita/wordnet/documentation/index.htm

要了解所有这些术语(上位词等),请查看 wordnet 的维基百科页面。

关于java - 词网关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3977100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com