gpt4 book ai didi

java - 使用分词器提取句子

转载 作者:太空宇宙 更新时间:2023-11-04 13:59:12 27 4
gpt4 key购买 nike

有一个简单的代码可以比较两个字符串,如果它包含关键字,它将执行一些操作。问题是,我希望在检测到文本中的关键字后,它能以某种方式提取其中的句子。这是代码:

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的所有句子然后返回句子。也许我们应该在 token 到达 . 时存储它。然后每当我们找到关键字时,我们就使用该标记来获取句子的开头并继续,直到到达另一个 .或者这听起来不合理?

最佳答案

我认为你应该在.的基础上创建 token ,然后检查关键字如下:

    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);
}
}
}

关于java - 使用分词器提取句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29484806/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com