日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python的span方法_Python Span.set_extension方法代码示例

發布時間:2025/4/16 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python的span方法_Python Span.set_extension方法代码示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# 需要導入模塊: from spacy.tokens import Span [as 別名]

# 或者: from spacy.tokens.Span import set_extension [as 別名]

def __init__(

self,

nlp,

language="en_clinical",

ent_types=list(),

pseudo_negations=list(),

preceding_negations=list(),

following_negations=list(),

termination=list(),

chunk_prefix=list(),

):

if not language in LANGUAGES:

raise KeyError(

f"{language} not found in languages termset. "

"Ensure this is a supported language or specify "

"your own termsets when initializing Negex."

)

termsets = LANGUAGES[language]

if not Span.has_extension("negex"):

Span.set_extension("negex", default=False, force=True)

if not pseudo_negations:

if not "pseudo_negations" in termsets:

raise KeyError("pseudo_negations not specified for this language.")

pseudo_negations = termsets["pseudo_negations"]

if not preceding_negations:

if not "preceding_negations" in termsets:

raise KeyError("preceding_negations not specified for this language.")

preceding_negations = termsets["preceding_negations"]

if not following_negations:

if not "following_negations" in termsets:

raise KeyError("following_negations not specified for this language.")

following_negations = termsets["following_negations"]

if not termination:

if not "termination" in termsets:

raise KeyError("termination not specified for this language.")

termination = termsets["termination"]

# efficiently build spaCy matcher patterns

self.pseudo_patterns = list(nlp.tokenizer.pipe(pseudo_negations))

self.preceding_patterns = list(nlp.tokenizer.pipe(preceding_negations))

self.following_patterns = list(nlp.tokenizer.pipe(following_negations))

self.termination_patterns = list(nlp.tokenizer.pipe(termination))

self.matcher = PhraseMatcher(nlp.vocab, attr="LOWER")

self.matcher.add("pseudo", None, *self.pseudo_patterns)

self.matcher.add("Preceding", None, *self.preceding_patterns)

self.matcher.add("Following", None, *self.following_patterns)

self.matcher.add("Termination", None, *self.termination_patterns)

self.nlp = nlp

self.ent_types = ent_types

self.chunk_prefix = list(nlp.tokenizer.pipe(chunk_prefix))

總結

以上是生活随笔為你收集整理的python的span方法_Python Span.set_extension方法代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。