how to write spacy matcher of POS regex

后端 未结 2 1132
情歌与酒
情歌与酒 2021-01-13 01:32

Spacy has two features I\'d like to combine - part-of-speech (POS) and rule-based matching.

How can I combine them in a neat way?

For example - let\'s say i

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 01:55

    Sure, simply use the POS attribute.

    import spacy
    nlp = spacy.load('en')
    from spacy.matcher import Matcher
    from spacy.attrs import POS
    matcher = Matcher(nlp.vocab)
    matcher.add_pattern("Adjective and noun", [{POS: 'ADJ'}, {POS: 'NOUN'}])
    
    doc = nlp(u'what are the main issues')
    matches = matcher(doc)
    

提交回复
热议问题