how can i modify language model before applying patterns

亡梦爱人 提交于 2021-01-07 02:49:59

问题


I have this code :

from spacy.matcher import Matcher,PhraseMatcher
import spacy
from spacy.matcher import Matcher

nlp = spacy.load("en_core_web_sm")
matcher = Matcher(nlp.vocab,validate=True)
patterns = [
    [{'POS': 'QUALIF'}, {'POS': 'CCONJ'}, {'POS': 'ADJ'}, {'POS': 'NOUN'}],
]
matcher.add("process_1", None, *patterns)

texts= ["it is a beautiful and big apple"]
for text in texts:
  doc = nlp(text)
  matches = matcher(doc)
  for _, start, end in matches:
      print(doc[start:end].text)

So, I want to modify for example the POS of "beautiful" from "ADJ" to "QUALIF" just before applying patterns matchers (as you know beautiful in spacy language model is "ADJ" but me I want to modify it to "QUALIF" just before applying the matcher. Help please.

来源:https://stackoverflow.com/questions/65406160/how-can-i-modify-language-model-before-applying-patterns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!