java - 在java中使用wordnet查找给定形容词的同义词和反义词集
问题描述
我正在使用 java 中的 nlp 项目,我想使用 wordnet 获取给定形容词的同义词和反义词集。到目前为止,我已经这样做了,但我没有得到想要的输出,它只是同义词和反义词集的列表。
net.didion.jwnl.dictionary.Dictionary dict;
File file = new File("properties.xml");
JWNL.initialize(new FileInputStream(file));
dict = net.didion.jwnl.dictionary.Dictionary.getInstance();
IndexWord indexWord = dict.getIndexWord(POS.ADJECTIVE, "bad");
Synset[] senses = indexWord.getSenses();
for(int i=0;i<senses.length;i++){
Synset set= senses[i];
Word[] words=set.getWords();
for(int k=0;k<words.length;k++){
System.out.println(i+","+k+":"+words[k].getLemma());
}
}
输出
信息:安装字典 net.didion.jwnl.dictionary.FileBackedDictionary@70177ecd
好,充分,好,好,可贵,好,可敬,可敬,有益,好,好,好,公正,正直,熟练,专家,好,熟练,熟练,熟练,熟练,好,亲爱的,好,近,可靠,好,安全,安全,好,正确,成熟,好,好(p),有效,好,in_effect(p),in_force(p),好,好,严重,好,健全,好,有益,好, 诚实, 好, 未受破坏, 未受破坏, 好,
解决方案
你需要过滤你的答案,
Synset syn;
String word = null;
ArrayList syns = new ArrayList<>();
for(int i=0;i<sensesVerbe.length;i++){
// syn=sensesVerbe[i];
//System.out.println(sensesVerbe[i]);
String v= sensesVerbe[i].toString();
//String v= sensesVerbe[i].toString();
if(v.contains("Words:")){
//System.out.println("yeeh");
//System.out.println("Index of NN = "+ line.indexOf("N "));
int chaine = v.indexOf("Words:");
//System.out.println("index Words: ="+ chaine+"");
int chaine1 = v.indexOf("--");
//System.out.println("index -- ="+ chaine1+"");
word = v.substring(chaine+6, chaine1);
//System.out.println("the sub of line where index is ("+ chaine +","+ chaine1 +") is :" + word);
//System.out.println(word);
String mots[] =word.split(",");
//System.out.println("mots séparés :");
for (int j = 0; j < mots.length; j++) {
mots[j]=mots[j].replaceAll(" ", "");
//System.out.println(mots[j]);
if(!syns.contains(mots[j].toLowerCase())){
syns.add(mots[j].toLowerCase());
}
}
}
}
推荐阅读
- php - 从循环内的用户列表中更新单个值
- cmake - How to tell cmake to look for Boost headers in a specified location?
- asp.net-core - Microsoft.EntityFrameworkCore.DbUpdateException
- performance - 如何利用 R3 2X 大型 8 节点集群中的所有 vcore
- arrays - 循环,从尾注中提取文本并将注释附加到尾注源段落
- ionic3 - 我想要一个 ionic3 简单的选轮器
- javascript - 重构 React.js 代码以提高风格和效率
- c# - Log4net 自定义过滤器不过滤
- python - 由于 hdf5 错误,无法安装库
- python - 比较数据框中的结果和分组结果