日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2025/4/16 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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方法代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。

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