有一个简单的代码比较两个字符串,然后如果它包含一个关键字,它将执行一些操作。我希望在检测到文本中的关键字之后,它会以某种方式提取它所在的句子。这是代码:
String keyword="Keyword(S)";
StringTokenizer tokenizer =new StringTokenizer(text) ;
if(tokenizer.hasMoreTokens())
{
tokenizer.nextToken();
for(final String s :text.split(" ")){
if(keyword.equals(s))
{
//get the whole sentence
}
}
}
修改 这是一个示例: 考虑到我们有以下文字:
Text summarization is the process of extracting salient information from the source text and to present that
information to the user in the form of summary. It is very difficult for human beings to manually
summarize large documents of text. Automatic abstractive summarization provides the required solution
but it is a challenging task because it requires deeper analysis of text. In this paper, a survey on abstractive
text summarization methods has been presented. Abstractive summarization methods are classified into two
categories i.e. structured based approach and semantic based approach.
现在我们正在查找包含单词abstractive
的所有句子,然后返回句子。也许我们应该在到达.
时存储令牌,然后每当我们找到关键字时,我们会使用该令牌来获取句子的开头并继续直到我们到达另一个.
或听起来不合理?
答案 0 :(得分:0)
我认为你应该在.
的基础上创建令牌,然后检查关键字如下:
String keyword="summarization";
StringTokenizer tokenizer =new StringTokenizer(text,"\\.") ;
while(tokenizer.hasMoreTokens())
{
String x= tokenizer.nextToken();
for(final String s :x.split(" ")){
if(keyword.equals(s))
{
System.out.println(x);
}
}
}