當前位置: 首頁>>代碼示例>>Python>>正文


Python Doc.set_extension方法代碼示例

本文整理匯總了Python中spacy.tokens.Doc.set_extension方法的典型用法代碼示例。如果您正苦於以下問題:Python Doc.set_extension方法的具體用法?Python Doc.set_extension怎麽用?Python Doc.set_extension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在spacy.tokens.Doc的用法示例。


在下文中一共展示了Doc.set_extension方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc 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 Doc [as 別名]
# 或者: from spacy.tokens.Doc import set_extension [as 別名]
def __init__(self):
        """Initialise the pipeline component.
        """
        if not Doc.has_extension("flesch_kincaid_grade_level"):
            Doc.set_extension("flesch_kincaid_grade_level", getter=self.fk_grade)

        if not Doc.has_extension("flesch_kincaid_reading_ease"):
            Doc.set_extension("flesch_kincaid_reading_ease", getter=self.fk_ease)

        if not Doc.has_extension("dale_chall"):
            Doc.set_extension("dale_chall", getter=self.dale_chall)

        if not Doc.has_extension("smog"):
            Doc.set_extension("smog", getter=self.smog)

        if not Doc.has_extension("coleman_liau_index"):
            Doc.set_extension("coleman_liau_index", getter=self.coleman_liau)

        if not Doc.has_extension("automated_readability_index"):
            Doc.set_extension("automated_readability_index", getter=self.ari)

        if not Doc.has_extension("forcast"):
            Doc.set_extension("forcast", getter=self.forcast) 
開發者ID:mholtzscher,項目名稱:spacy_readability,代碼行數:25,代碼來源:__init__.py

示例3: init_spacy

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc import set_extension [as 別名]
def init_spacy():
    # TODO: Create nlp instance in core:startup state, save in context instead of global var
    global empty_token
    try:
        import en_core_web_sm as spacy_en
    except ImportError:
        from spacy.cli import download as spacy_download
        spacy_download("en_core_web_sm")
        import en_core_web_sm as spacy_en
    spacy_nlp_en = spacy_en.load()
    empty_token = spacy_nlp_en(u" ")[0]

    # TODO: Make agent id configurable, rename nlp:contains-roboy to nlp:agent-mentioned
    about_roboy = ('you', 'roboy', 'robot', 'roboboy', 'your')

    def roboy_getter(doc) -> bool:
        return any(roboy in doc.text.lower() for roboy in about_roboy)

    from spacy.tokens import Doc
    Doc.set_extension('about_roboy', getter=roboy_getter)
    Doc.set_extension('empty_token', getter=lambda doc: empty_token)
    Doc.set_extension('triples', getter=extract_triples)
    Doc.set_extension('yesno', getter=yes_no)
    return spacy_nlp_en 
開發者ID:Roboy,項目名稱:ravestate,代碼行數:26,代碼來源:__init__.py

示例4: __init__

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc 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

示例5: spacy_model

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc import set_extension [as 別名]
def spacy_model():
    nlp = spacy_nlp_en
    from spacy.tokens import Doc
    if not Doc.has_extension('triples'):
        Doc.set_extension('triples', getter=extract_triples)
    return nlp 
開發者ID:Roboy,項目名稱:ravestate,代碼行數:8,代碼來源:test_extract_triples.py

示例6: register_extensions

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc 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

示例7: __init__

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc import set_extension [as 別名]
def __init__(self, nlp) -> None:
        Doc.set_extension("concepts", default={}, force=True)
        self.ruler = EntityRuler(nlp)
        self.ruler.add_patterns(CONCEPT_PATTERNS)
        pipes = nlp.pipe_names
        if "EntityRuler" not in pipes:
            nlp.add_pipe(self.ruler, last=True) 
開發者ID:ICLRandD,項目名稱:Blackstone,代碼行數:9,代碼來源:concepts.py

示例8: __init__

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc import set_extension [as 別名]
def __init__(self, nlp) -> None:
        Doc.set_extension("compound_cases", default=[], force=True)
        self.matcher = Matcher(nlp.vocab)
        common_pattern = [{"ent_type": "CASENAME"}, {"ent_type": "CITATION", "OP": "+"}]
        possessive_pattern = [
            {"ent_type": "CASENAME"},
            {"lower": "case"},
            {"ent_type": "CITATION"},
        ]
        self.matcher.add("compound_case", None, common_pattern, possessive_pattern)
        self.global_matcher = Matcher(nlp.vocab)
        merge_ents = nlp.create_pipe("merge_entities")
        nlp.add_pipe(merge_ents) 
開發者ID:ICLRandD,項目名稱:Blackstone,代碼行數:15,代碼來源:compound_cases.py

示例9: __init__

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc 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

示例10: __init__

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc import set_extension [as 別名]
def __init__(self, model, word_vocab, char_vocab, chunk_vocab, batch_size: int = 32):
        self.model = model
        self.bs = batch_size
        self.word_vocab = word_vocab
        self.char_vocab = char_vocab
        self.chunk_vocab = chunk_vocab
        Doc.set_extension("noun_phrases", default=[], force=True) 
開發者ID:NervanaSystems,項目名稱:nlp-architect,代碼行數:9,代碼來源:spacy_np_annotator.py


注:本文中的spacy.tokens.Doc.set_extension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。