number 词的可能词性
number possible part of speech of the word
我知道如何获取文本中单词的位置,但我需要知道句子中单词的可能位置是什么 "like" 可以有 4 个词性:动词名词介词....
有可能从斯坦福图书馆得到吗?
Stanford CoreNLP 似乎没有与 WordNet 的接口,但使用其他小型 Java WordNet 库之一很容易做到这一点。对于这个例子,我使用了 JWI 2.3.3.
除了 JWI,您还需要下载 WordNet 数据库的副本。例如,您可以下载WordNet-3.0.tar.gz from Princeton。解压字典。
以下代码包含一个函数,该函数 returns 一个单词的可能词性列表:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import edu.mit.jwi.Dictionary;
import edu.mit.jwi.item.POS;
import edu.mit.jwi.item.IIndexWord;
import edu.mit.jwi.morph.WordnetStemmer;
public class WNDemo {
/**
* Given a dictionary and a word, find all the parts of speech the
* word can be.
*/
public static Collection getPartsOfSpeech(Dictionary dict, String word) {
ArrayList<POS> parts = new ArrayList<POS>();
WordnetStemmer stemmer = new WordnetStemmer(dict);
// Check every part of speech.
for (POS pos : POS.values()) {
// Check every stem, because WordNet doesn't have every surface
// form in its database.
for (String stem : stemmer.findStems(word, pos)) {
IIndexWord iw = dict.getIndexWord(stem, pos);
if (iw != null) {
parts.add(pos);
}
}
}
return parts;
}
public static void main(String[] args) {
try {
Dictionary dict = new Dictionary(new File("WordNet-3.0/dict"));
dict.open();
System.out.println("'like' is a " + getPartsOfSpeech(dict, "like"));
} catch (IOException e) {
System.err.println("Error: " + e);
}
}
}
并且输出:
'like' is a [noun, verb, adjective]
我知道如何获取文本中单词的位置,但我需要知道句子中单词的可能位置是什么 "like" 可以有 4 个词性:动词名词介词.... 有可能从斯坦福图书馆得到吗?
Stanford CoreNLP 似乎没有与 WordNet 的接口,但使用其他小型 Java WordNet 库之一很容易做到这一点。对于这个例子,我使用了 JWI 2.3.3.
除了 JWI,您还需要下载 WordNet 数据库的副本。例如,您可以下载WordNet-3.0.tar.gz from Princeton。解压字典。
以下代码包含一个函数,该函数 returns 一个单词的可能词性列表:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import edu.mit.jwi.Dictionary;
import edu.mit.jwi.item.POS;
import edu.mit.jwi.item.IIndexWord;
import edu.mit.jwi.morph.WordnetStemmer;
public class WNDemo {
/**
* Given a dictionary and a word, find all the parts of speech the
* word can be.
*/
public static Collection getPartsOfSpeech(Dictionary dict, String word) {
ArrayList<POS> parts = new ArrayList<POS>();
WordnetStemmer stemmer = new WordnetStemmer(dict);
// Check every part of speech.
for (POS pos : POS.values()) {
// Check every stem, because WordNet doesn't have every surface
// form in its database.
for (String stem : stemmer.findStems(word, pos)) {
IIndexWord iw = dict.getIndexWord(stem, pos);
if (iw != null) {
parts.add(pos);
}
}
}
return parts;
}
public static void main(String[] args) {
try {
Dictionary dict = new Dictionary(new File("WordNet-3.0/dict"));
dict.open();
System.out.println("'like' is a " + getPartsOfSpeech(dict, "like"));
} catch (IOException e) {
System.err.println("Error: " + e);
}
}
}
并且输出:
'like' is a [noun, verb, adjective]