有一个比较两个字符串的简单代码,如果它包含一个关键字,它将执行一些操作。问题是,我希望在我检测到文本中的关键字之后,它会以某种方式提取出它所包含的句子。以下是代码:
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的所有句子,然后返回这个句子。也许我们应该在到达一个.时存储一个令牌,然后每当我们找到关键字时,我们就使用这个标记来获取句子的开头,然后继续到到达另一个.,或者这听起来不合理?
发布于 2015-04-07 07:20:34
我认为您应该在.的基础上创建令牌,然后检查关键字如下:
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);
}
}
}https://stackoverflow.com/questions/29484806
复制相似问题