【发布时间】:2015-02-10 21:17:10
【问题描述】:
我有一个包含 5 个“谁”、“什么”、“何时”、“在哪里”、“为什么”问题的短篇故事的语料库。我使用Stanford NLP API 将故事分成句子,然后我得到句子中每个单词的引理,给我基本单词。我对问题也这样做。我将故事和句子保存在单独的文件中,我使用 WS4J 来帮助我确定故事中的哪个句子可以回答每个问题。
我正在使用这种方法,它接受 2 个字符串(问题和可能的)并将它们相互比较并返回一个值,该值是否是问题的可能答案。
public int compSen(double prob, String sen1, String sen2) {
int cant = 0;
// String sen2c = remStopWords(sen2);
String[] sent1 = getWords(sen1);
String[] sent2 = getWords(sen2);
for (int s = 0; s < sent2.length - 1; s++) {
for (int m = s + 1; m < sent2.length; m++) {
if (sent2[s] != "" && sent2[s].equals(sent2[m])) {
sent2[m] = "";
}
}
}
for (int i = 0; i < sent1.length; i++) {
for (int j = 0; j < sent2.length; j++) {
if (sent2[j] != "") {
double res = compWord(sent1[i].trim(), sent2[j].trim());
if (res >= prob) {
// System.out.println(sent1[i] + " " + sent2[j]);
// System.out.println(res);
cant++;
}
}
}
}
return cant;
}
我的另一个比较单词的方法是这样的:
public double compWord(String word1, String word2) {
ILexicalDatabase db = new NictWordNet();
WS4JConfiguration.getInstance().setMFS(true);
RelatednessCalculator rc = new Path(db);
// String word1 = "gender";
// String word2 = "sex";
List<POS[]> posPairs = rc.getPOSPairs();
double maxScore = -1D;
for (POS[] posPair : posPairs) {
List<Concept> synsets1 = (List<Concept>) db.getAllConcepts(word1, posPair[0].toString());
List<Concept> synsets2 = (List<Concept>) db.getAllConcepts(word2, posPair[1].toString());
for (Concept synset1 : synsets1) {
for (Concept synset2 : synsets2) {
Relatedness relatedness = rc.calcRelatednessOfSynset(synset1, synset2);
double score = relatedness.getScore();
if (score > maxScore) {
maxScore = score;
}
}
}
}
if (maxScore == -1D) {
maxScore = 0.0;
}
// System.out.println(word1);
// System.out.println(word2);
//
// System.out.println(maxScore);
// System.out.println("sim('" + word1 + "', '" + word2 + "') = " + maxScore);
return maxScore;
}
我想知道是否有另一种方法可以更好地回答给定故事的语料库中的问题,因为我的方法非常基础,我设法回答了 20 个问题中的近 1-3 个问题。对我来说,这真的很好.任何帮助,想法表示赞赏。
【问题讨论】:
标签: java system stanford-nlp analyzer corpus