Python包,用于根据关键字从文本文件中提取句子



我需要一个python包,它可以根据提供的关键字从文本中获取相关的句子。

例如,下面是J.J Oppenheimer-的维基百科页面

Early life
Childhood and education
J. Robert Oppenheimer was born in New York City on April 22, 1904,[note 1][7] to Julius Oppenheimer, a wealthy Jewish textile importer who had immigrated to the United States from Germany in 1888, and Ella Friedman, a painter. 
Julius came to the United States with no money, no baccalaureate studies, and no knowledge of the English language. He got a job in a textile company and within a decade was an executive with the company. Ella was from Baltimore.[8] The Oppenheimer were non-observant Ashkenazi Jews.[9] 
The first atomic bomb was successfully detonated on July 16, 1945, in the Trinity test in New Mexico. 
Oppenheimer later remarked that it brought to mind words from the Bhagavad Gita: "Now I am become Death, the destroyer of worlds.

如果我传递的字符串是-">JJ Oppenheimer出生日期";,它应该返回">J。罗伯特·奥本海默于1904年4月22日出生于纽约市";

如果我传递的字符串是-";JJ Openheimer Trinity测试";,它应该返回">第一颗原子弹于1945年7月16日在新墨西哥州的三一试验中成功引爆;

我尝试了很多搜索,但没有什么能更接近我想要的,而且我对NLP矢量化技术了解不多。如果有人知道(或存在(,请提出一些包裹,那就太好了。

您可以使用fuzzywuzzy。

fuzz.ratio(search_text, sentence). 

这会给你两个字符串的相似程度打分。

https://github.com/seatgeek/fuzzywuzzy

我很确定有一个模块可以为您做到这一点,您可以尝试通过解析文本并创建诸如"[quot;出生日期"、"出生日期"等单词来自己制作它,您可以为多个字段这样做。这样,您就可以找到可用的信息。

想法是:

你获取了你的文本或你拥有的任何东西,

你抓住了你要找的东西(例如出生日期(

然后,你将出生日期分配给一个类似单词的列表,

你浏览一下你的文件,看看你是否找到了一个句子。

我很确定没有模块,也许我错了,但这样的smth应该可以工作。

您描述的任务看起来像信息检索。给定一个查询(关键字(,模型应该返回一个与查询最匹配的文档(句子(列表。

这基本上就是使用fuzzywuzzy的响应所暗示的。但也许仅仅计算每个句子中查询词的出现次数就足够了(而且更有效(。

下一步是使用Tf-Idf。它是一种加权方案,相对于一组文档(语料库(,对文档特定的单词给予高分。

这导致每个文档都有一个相关的向量,然后您就可以根据它们与查询向量的相似性对文档进行排序。所以回答做

最新更新