从字符串提取商业标题和时间段

2024-10-04 11:29:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python从路透社获取有关某些公司的信息。我已经能够从this page获得高级职员/行政人员的姓名、传记和报酬

现在,我想从传记部分提取以前的职位和公司,如下所示:

Mr. Donald T. Grimes is Senior Vice President, Chief Financial Officer and Treasurer of Wolverine World Wide, Inc., since May 2008. From 2007 to 2008, he was the Executive Vice President and Chief Financial Officer for Keystone Automotive Operations, Inc., a distributor of automotive accessories and equipment. Prior to Keystone, Mr. Grimes held a series of senior corporate and divisional finance roles at Brown-Forman Corporation, a manufacturer and marketer of premium wines and spirits. During his employment at Brown-Forman, Mr. Grimes was Vice President, Director of Beverage Finance from 2006 to 2007; Vice President, Director of Corporate Planning and Analysis from 2003 to 2006; and Senior Vice President, Chief Financial Officer of Brown-Forman Spirits America from 1999 to 2003.

我可以使用简单的regex来获取起始和结束年份,但是我不知道如何编写regex来获得标题和公司名称。我知道字符串格式是不一致的,所以我会选择一个对至少70%的情况有效的答案。下面是我想要的输出:

2007-2008, executive vice president and chief financial officer, Keystone Automotive operations

Tags: andoftofromkeystonevice公司mr
2条回答

我不认为会有一个单一的正则表达式,你可以使用这个,除非它真的很讨厌。我想解决这个问题的办法可能是Natural Language Processing。当然,有一些软件包可以解决这个问题,但是使用它们可能并不简单。在

基本上,你想用一个像“X is/was Y”这样的句子,找出哪个部分是名字,哪个部分是职位列表,哪些部分是无关的。也许要寻找大写的单词序列或者像“and”和“of”这样的小单词?在

(?:\u\w+)( (?:\u\w*)|(?:of)|(?:and))*  #Note the space

\u表示下一个单个字符(\w+组的第一个字符)是大写的。还没有测试过,但看起来应该有用。这可能是个不小的问题。在

您试图解决的问题是众所周知的,并且经过研究,如果您搜索“命名实体提取”和“关系提取”两个术语,您会发现大量描述方法和算法的研究论文。一些好的起点是:

这些只是我发现的一些有趣的链接,有一吨更多,也许更好的,但这应该让你开始。在

相关问题 更多 >