简体   繁体   中英

how to import [spacy] .pos_ on python

i try to do a code to get a parser on some words by using spacy and its methods like.pos_ and.dep_ but i have an error that i dont understand what can i do?

import spacy, textphonographer
test = spacy.load('fr_core_news_md')

def fct(tok1, tok2):
    token1 = test(tok1)
    token2 = test(tok2)

    if token1.pos_ == "DET":
        if token2.pos_ == "NOUN" or token2.pos_ == "ADJ":
            print(token1.pos_,"_", token2.pos_)
            return True

print (fct("suis", "une"))
_________________________________
File "doc.py", line 37, in fct
if token1.pos_ == "DET":

AttributeError: 'spacy.tokens.doc.Doc' object has no attribute 'pos_'

replace token.pos_ with token[0].pos_

if token1[0].pos_ == "DET":
    if token2[0].pos_ == "NOUN" or token2[0].pos_ == "ADJ":
        print(token1[0].pos_,"_", token2[0].pos_)
        return True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM