python 匹配段落_如何使用python(nltk)匹配段落中的关键字

不需要为此使用NLTK。首先,您必须清除段落中的文本,或更改“辅助键”列表中的值。”下一代“商店”和“下一代商店”是两个不同的东西。在

在此之后,您可以迭代“secondary”的值,并检查文本中是否存在这些字符串。在match = [i for i in Keywords['secondary'] if i in paragraph]

编辑:正如我上面所说的,“下一代”商店和“下一代商店”是两个不同的东西,这就是为什么你只能得到1个匹配。如果你有'下一代商店'和'下一代商店',你会得到两个匹配-因为实际上有两个匹配。在

输入:

^{pr2}$

输出:['groceries']

输入:paragraph="""HOUSTON Target has unveiled its first next generation store in the Houston area, part of a multibillion-dollar effort to reimagine more than 1,000 stores nationwide to compete with e-commerce giants.

The 124,000-square-foot store, which opened earlier this week at Aliana market center in Richmond, Texas, has two distinct entrances and aims to appeal to consumers on both ends of the shopping spectrum.

Busy families seeking convenience can enter the "ease" side of the store, which offers a supermarket-style experience. Customers can pick up online orders, both in store and curbside, and buy grab-and-go items like groceries, wine, last-minute gifts, cleaning supplies and prepared meals."""

输出:['next generation store','groceries']

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值