当前位置: 首页>>代码示例>>Python>>正文


Python Span.set_extension方法代码示例

本文整理汇总了Python中spacy.tokens.Span.set_extension方法的典型用法代码示例。如果您正苦于以下问题:Python Span.set_extension方法的具体用法?Python Span.set_extension怎么用?Python Span.set_extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spacy.tokens.Span的用法示例。


在下文中一共展示了Span.set_extension方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from spacy.tokens import Span [as 别名]
# 或者: from spacy.tokens.Span import set_extension [as 别名]
def __init__(self, keywords_list=[], keywords_dict={}, keywords_file=None,
                 label='', case_sensitive=False,
                 attrs=('has_entities', 'is_entity', 'entity_desc', 'entities', 'canonical')):
        """Initialise the pipeline component.
        """
        self._has_entities, self._is_entity, self._entity_desc, self._entities, self.canonical = attrs

        # Set up the KeywordProcessor
        self.keyword_processor = KeywordProcessor(case_sensitive=case_sensitive)
        self.keyword_processor.add_keywords_from_list(keywords_list)
        self.keyword_processor.add_keywords_from_dict(keywords_dict)
        if keywords_file:
            self.keyword_processor.add_keyword_from_file(keywords_file)
        self.label = label

        # Register attribute on the Doc and Span
        Doc.set_extension(self._has_entities, getter=self.has_entities, force=True)
        Doc.set_extension(self._entities, getter=self.iter_entities, force=True)
        Span.set_extension(self._has_entities, getter=self.has_entities, force=True)
        Span.set_extension(self._entities, getter=self.iter_entities, force=True)

        # Register attribute on the Token.
        Token.set_extension(self._is_entity, default=False, force=True)
        Token.set_extension(self._entity_desc, getter=self.get_entity_desc, force=True)
        Token.set_extension(self.canonical, default=None, force=True) 
开发者ID:mpuig,项目名称:spacy-lookup,代码行数:27,代码来源:__init__.py

示例2: __init__

# 需要导入模块: from spacy.tokens import Span [as 别名]
# 或者: from spacy.tokens.Span import set_extension [as 别名]
def __init__(self, attrs=('languages', 'language_scores')):
        self._languages, self._scores = attrs
        Doc.set_extension(self._languages, getter=get_languages)
        Doc.set_extension(self._scores, getter=get_scores)
        Span.set_extension(self._languages, getter=get_languages)
        Span.set_extension(self._scores, getter=get_scores) 
开发者ID:nickdavidhaynes,项目名称:spacy-cld,代码行数:8,代码来源:spacy_cld.py

示例3: register_extensions

# 需要导入模块: from spacy.tokens import Span [as 别名]
# 或者: from spacy.tokens.Span import set_extension [as 别名]
def register_extensions(exist_ok: bool = False) -> None:
        def do() -> None:
            Token.set_extension('censored', default=None)
            Token.set_extension('is_profane', getter=SpacyProfanityFilterComponent.token_is_profane)
            Token.set_extension('original_profane_word', default=None)

            Span.set_extension('is_profane', getter=SpacyProfanityFilterComponent.tokens_are_profane)
            Doc.set_extension('is_profane', getter=SpacyProfanityFilterComponent.tokens_are_profane)

        if exist_ok:
            with suppress(ValueError):
                do()
        else:
            do() 
开发者ID:rominf,项目名称:profanity-filter,代码行数:16,代码来源:spacy_component.py

示例4: __init__

# 需要导入模块: from spacy.tokens import Span [as 别名]
# 或者: from spacy.tokens.Span import set_extension [as 别名]
def __init__(self, nlp) -> None:
        Doc.set_extension("abbreviations", default=[], force=True)
        Span.set_extension("long_form", default=None, force=True)

        self.matcher = Matcher(nlp.vocab)
        self.matcher.add(
            "parenthesis", None, [{"ORTH": "("}, {"OP": "+"}, {"ORTH": ")"}]
        )
        self.global_matcher = Matcher(nlp.vocab) 
开发者ID:ICLRandD,项目名称:Blackstone,代码行数:11,代码来源:abbreviations.py

示例5: __init__

# 需要导入模块: from spacy.tokens import Span [as 别名]
# 或者: from spacy.tokens.Span import set_extension [as 别名]
def __init__(
        self,
        candidate_generator: CandidateGenerator = None,
        resolve_abbreviations: bool = True,
        k: int = 30,
        threshold: float = 0.7,
        no_definition_threshold: float = 0.95,
        filter_for_definitions: bool = True,
        max_entities_per_mention: int = 5,
        name: str = None,
    ):
        # TODO(Mark): Remove in scispacy v1.0.
        Span.set_extension("umls_ents", default=[], force=True)
        Span.set_extension("kb_ents", default=[], force=True)

        self.candidate_generator = candidate_generator or CandidateGenerator(name=name)
        self.resolve_abbreviations = resolve_abbreviations
        self.k = k
        self.threshold = threshold
        self.no_definition_threshold = no_definition_threshold
        self.kb = self.candidate_generator.kb
        self.filter_for_definitions = filter_for_definitions
        self.max_entities_per_mention = max_entities_per_mention

        # TODO(Mark): Remove in scispacy v1.0. This is for backward compatability only.
        self.umls = self.kb 
开发者ID:allenai,项目名称:scispacy,代码行数:28,代码来源:linking.py

示例6: __init__

# 需要导入模块: 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)) 
开发者ID:jenojp,项目名称:negspacy,代码行数:58,代码来源:negation.py


注:本文中的spacy.tokens.Span.set_extension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。