Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我是否可以在Spacy Matcher中使用if-else语句?_Python 3.x_Spacy_Matcher - Fatal编程技术网

Python 3.x 我是否可以在Spacy Matcher中使用if-else语句?

Python 3.x 我是否可以在Spacy Matcher中使用if-else语句?,python-3.x,spacy,matcher,Python 3.x,Spacy,Matcher,我正试图在工作要求上使用Spacy的Matcher,这样我就能找到雇主想要的多年经验 doc = nlp(""" <ul><li>2-3 years working experience ideal but driven Fresh Grads are welcomed!</li><li>Create elegant and compelling designs for all of Dapat products and Social Me

我正试图在工作要求上使用Spacy的Matcher,这样我就能找到雇主想要的多年经验

    doc = nlp("""
<ul><li>2-3 years working experience ideal but driven Fresh Grads are welcomed!</li><li>Create elegant and compelling designs for all of Dapat products and Social Media channels</li><li>Knowledge in Social Media / Digital Marketing is a PLUS!</li><li>You are a chameleon - Able to adapt to new challenges, working environments etc.</li><li>Ability to work on multiple projects, prioritize as needed and manage time in an efficient manner</li><li>Knowledge in Adobe Creative Suite / Cloud (Photoshop, Illustrator, InDesign)</li><li>Knowledge in UI/UX tools like Sketch, Invision, Balsamiq - is also a PLUS!</li><li>You are an excellent team player and do not shy away from responsibilities and challenges&nbsp;</li><li>Organized, detail oriented and able to work independently on multiple projects</li><li>Proficiency with office productivity tools including email, web browsers, web apps, database search, spreadsheets/word processors (Google Apps)</li><li>Interest in and familiarity with current tech products</li></ul><div><br></div>
""")

# Initialize the Matcher with the shared vocabulary
matcher = Matcher(nlp.vocab)

# Create a pattern matching the tokens
pattern = [{'IS_DIGIT':True}, {"LEMMA": "year", 'POS':'NOUN'}]
pattern1 = [{'IS_DIGIT': True},{'TEXT':'-'},{'IS_DIGIT':True},{"LEMMA": "year", 'POS':'NOUN'}]
pattern2 = [{'IS_DIGIT': True},{'TEXT':'to'},{'IS_DIGIT':True},{"LEMMA": "year", 'POS':'NOUN'}]
pattern3 = [{'IS_DIGIT': True},{'TEXT':'or'},{'IS_DIGIT':True},{"LEMMA": "year", 'POS':'NOUN'}]
pattern4 = [{'IS_DIGIT': True},{'TEXT':'+'},{"LEMMA": "year", 'POS':'NOUN'}]
pattern5 = [{'IS_ALPHA': True},{'TEXT':'('},{'IS_DIGIT': True},{'TEXT':')'},{'TEXT':'to'},{'IS_ALPHA':True},{'TEXT':'('},{'IS_DIGIT': True},{'TEXT':')'},{"LEMMA": "year", 'POS':'NOUN'}]
pattern6 = [{'lower':'fresh grads'}]

# Add the pattern to the matcher
matcher.add("x years", None, pattern)
matcher.add("z - x years", None, pattern1)
matcher.add("z to x years", None, pattern2)
matcher.add("z or y years",None, pattern3)
matcher.add('x+ years', None, pattern4)
matcher.add('alpha(digit) to alpha(digit) years', None, pattern5)


# Use the matcher on the doc
matches = matcher(doc)
matched = [doc[start:end].text for match_id, start, end in matches]
print("Matches:", matched)
doc=nlp(“”)
  • 2-3年工作经验理想,但欢迎应届毕业生!
  • 为所有Dapat产品和社交媒体渠道创造优雅而引人注目的设计
  • 社交媒体/数字营销知识尤佳!
  • 你是一只变色龙-能够适应新挑战、工作环境等。
  • 能力o在Adobe Creative Suite/Cloud(Photoshop、Illustrator、InDesign)中处理多个项目,根据需要排定优先级,并以高效的方式管理时间
  • 熟悉UI/UX工具(如Sketch、Invision、Balsamiq)也是一个加号!
  • 您是一名优秀的团队合作者,不会回避责任和挑战
  • 组织有序,注重细节,能够独立处理多个项目
  • 熟练使用办公效率工具,包括电子邮件、网络浏览器s、 网络应用程序、数据库搜索、电子表格/文字处理器(谷歌应用程序)
  • 对当前科技产品的兴趣和熟悉程度

""") #使用共享词汇表初始化匹配器 matcher=matcher(nlp.vocab) #创建与令牌匹配的模式 模式=[{'IS_DIGIT':True},{“引理”:“年”,“位置”:“名词”}] pattern1=[{'IS_DIGIT':True},{'TEXT':'-'},{'IS_DIGIT':True},{'LEMMA:'year','POS':'NOUN'}] 模式2=[{'IS_DIGIT':True},{'TEXT':'to'},{'IS_DIGIT':True},{'LEMMA:'year','POS':'NOUN'}] 模式3=[{'IS_DIGIT':True},{'TEXT':'or'},{'IS_DIGIT':True},{'LEMMA:'year','POS':'NOUN'}] pattern4=[{'IS_DIGIT':True},{'TEXT':'+'},{'LEMMA:'year','POS':'NOUN'}] 模式5=[{'IS_-ALPHA':True},{'TEXT':'('},{'IS-DIGIT':True},{'TEXT':'to'},{'IS-ALPHA':True},{'TEXT':'('},{'IS-DIGIT':True},{'TEXT':')},{'LEMMA year','POS':'NOUN'}] 模式6=[{'lower':'fresh grads'}] #将图案添加到匹配器 matcher.add(“x年”,无,模式) 添加(“z-x年”,无,模式1) 匹配器。添加(“z到x年”,无,模式2) 匹配器。添加(“z或y年”,无,模式3) 匹配器。添加('x+年',无,模式4) 匹配器。添加('字母(数字)到字母(数字)年份',无,模式5) #使用文档上的匹配器 匹配=匹配器(文档) matched=[doc[start:end]。匹配的文本\u id,开始,结束在匹配中] 打印(“匹配:”,匹配)
对于最后一个模式,模式6,我试图匹配新毕业生,所以当我在要求中获得新毕业生时,它只会打印出0年的经验,但如果没有,它只会打印出句子中匹配的任何内容。我是否可以使用if-else语句,如果触发pattern6,那么它将打印匹配项:0年


提前谢谢你

使用
匹配器本身无法做到这一点。您需要运行matcher,分析结果以查看匹配的模式,然后如果没有找到任何模式,则输出“0年”(例如)

<>也请记住,<代码> Matcher < /代码>模式是针对单个令牌,所以<代码> {“下”:“新鲜梯度”} /代码>与中间的空间不匹配。您需要将其分为两种令牌模式