if语句对标记文本进行迭代,并删除不需要的项



我有点困惑。

我正在根据我在网上复制的工作描述运行以下内容(在帖子底部(

我想说"如果句子中没有"捐赠"这个词,那么就采取行动

这运行时没有错误,但也会在单词"捐赠"确实存在的情况下执行语句

有什么想法吗?

from rake_nltk import Rake
from nltk import tokenize
stop = ['benefits', 'Data Engineer', 'benefits', 'donate', 'role', 'engineer']
word = 'donate'
r = Rake(min_length=1, max_length=5) # Uses stopwords for english from NLTK, and all puntuation characters.
sentences = []
for x in job:
sentencesx = tokenize.sent_tokenize(x)
for sentence in sentencesx:
if word not in sentencesx:
sentences.append(sentence)

作业定义

job = ['''
Lead Data Engineer
c.£65-75k + bonus + flexible benefits
London or Telford. If the successful candidate is based in London, there will be some requirement for travel to Telford.
We are seeking an experienced Lead Data Engineer to join a leading innovative data team in a prestigious organisation. Our client offers excellence in career growth, professional development and a coveted personalised benefits package.
This opportunity covers the full project lifecycle from bid and proposal stage, requirements gathering and analysis, solution design and solution development. In addition this role will include leadership responsibility for a team of four; but this will also be a very hands-on position. You will have in depth data engineering skills and significant experience in the delivery of large/complex data solutions. You will advise project leadership on technical issues, progress, plans to resolve. You will be comfortable attending client work-shops and providing consultancy/advice on technical decisions and designs.
Our client are fairly open minded when it comes to technical experience, we are ideally looking for candidates with good proficiency in at least 2 of the following key technologies Oracle, SQL, PLSQL, Unix, Java; and an understanding of how "some" of the following technologies apply to data solutions:
-Hadoop Cloudera Ecosystem
-Pentaho DI, BA, Ctools
-SAS - Terraform, Ansible, Artifactory
-Jenkins, Git, Bitbucket, Maven
-AWS, Azure
-Amazon Redshift
We see this as a really exciting opportunity, where the selected candidate will have an excellent opportunity to expand their technical experience and also work on various different simultaneous projects / solutions utilising different technologies.
Deerfoot IT Resources Ltd is a leading specialist recruitment business for the IT industry. We will always email you a full role specification, name our client and wait for your email authorisation before we send your CV to this organisation. Deerfoot IT: Est. 1997. REC member. ISO certified. *Each time we send a CV to a recruiting client we donate £1 to The Born Free Foundation (charity no. 1070906
''',
'''
Lead Data Engineer
c.£65-75k + bonus + flexible benefits
London or Telford. If the successful candidate is based in London, there will be some requirement for travel to Telford.
We are seeking an experienced Lead Data Engineer to join a leading innovative data team in a prestigious organisation. Our client offers excellence in career growth, professional development and a coveted personalised benefits package.
This opportunity covers the full project lifecycle from bid and proposal stage, requirements gathering and analysis, solution design and solution development. In addition this role will include leadership responsibility for a team of four; but this will also be a very hands-on position. You will have in depth data engineering skills and significant experience in the delivery of large/complex data solutions. You will advise project leadership on technical issues, progress, plans to resolve. You will be comfortable attending client work-shops and providing consultancy/advice on technical decisions and designs.
Our client are fairly open minded when it comes to technical experience, we are ideally looking for candidates with good proficiency in at least 2 of the following key technologies Oracle, SQL, PLSQL, Unix, Java; and an understanding of how "some" of the following technologies apply to data solutions:
-Hadoop Cloudera Ecosystem
-Pentaho DI, BA, Ctools
-SAS - Terraform, Ansible, Artifactory
-Jenkins, Git, Bitbucket, Maven
-AWS, Azure
-Amazon Redshift
We see this as a really exciting opportunity, where the selected candidate will have an excellent opportunity to expand their technical experience and also work on various different simultaneous projects / solutions utilising different technologies.
Deerfoot IT Resources Ltd is a leading specialist recruitment business for the IT industry. We will always email you a full role specification, name our client and wait for your email authorisation before we send your CV to this organisation. Deerfoot IT: Est. 1997. REC member. ISO certified. *Each time we send a CV to a recruiting client we donate £1 to The Born Free Foundation (charity no. 1070906
''']

这看起来像是一个拼写错误。你正在检查单词是否存在于句子列表中,而不是检查实际的句子。如果您在循环中更改If条件,则如下所示:

for x in job:
sentencesx = tokenize.sent_tokenize(x)
for sentence in sentencesx:
# You had: "if word not in sentencesx" which is the list of sentences
# So change that to check against the actual sentence    
if word not in sentence:
sentences.append(sentence)

打印报表运行示例:

-------
We will always email you a full role specification, name our client and wait for your email authorisation before we send your CV to this organisation.
Donate not in the sentence
-------
Deerfoot IT: Est.
Donate not in the sentence
-------
1997.
Donate not in the sentence
-------
REC member.
Donate not in the sentence
-------
ISO certified.
Donate not in the sentence
-------
*Each time we send a CV to a recruiting client we donate £1 to The Born Free Foundation (charity no.
*Found the word*
-------
1070906
Donate not in the sentence

最新更新