java - 如何查找句子中二元语法的索引

标签 java search

我想在句子中搜索二元语法并找到它的索引。例如,采用以下句子:

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/

相关文章:

java - 如何在 AsyncTask 中使用 Runnable.wait()?为什么 AsyncTask 不等待...?

java - 取消 SQL 字符串引号的方法

mysql - Web 应用程序中具有多个因素的动态搜索过滤器

mysql - Sphinx 搜索结果中的行号作为 id

list - Python : search through list of tuples

python - 在 python 中定义和遍历树的有效方法是什么?

java - enablePassThrough 不适用于 selenium 服务器 3.9.1

java - 验证 Spring Jpa 查询中参数的最小长度

iOS实时搜索支持

java - 在 Oracle 中构建图像数据库 - 电子商务风格的界面可行吗?