我想在句子中搜索二元语法并找到它的索引。例如,采用以下句子:
in the absence of functional studies it is not possible at present to conclude that drug is a disease-related drug.
这里尝试搜索“is a”而不是“is”,因为句子中有“is”和“is a”。
我目前使用ArrayList来存储句子,并使用“equals”和“contains”进行比较,但结果是我选取is的索引并返回7,而不是“is a”的索引。我在代码中使用 Java。
最佳答案
这将以一种非常简单的方式为您提供“is a”的索引(字符数)
int index= "in the absence of functional studies it is not possible at present to conclude that drug is a disease-related drug.".indexOf("is a");
当你开始按空格分割时,你也需要开始关心标点符号...... 自然语言处理要复杂得多,你应该看看http://lucene.apache.org/core/
关于java - 如何查找句子中二元语法的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21518653/