首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的问题是“模块'textacy‘没有’Doc‘属性”

我的问题是“模块'textacy‘没有’Doc‘属性”
EN

Stack Overflow用户
提问于 2019-06-23 09:00:29
回答 2查看 2.4K关注 0票数 3

找不到没有属性'Doc‘的模块'textacy’我正在尝试从spacy中提取动词短语,但是没有这样的库。请帮助我如何使用spacy提取动词短语或形容词短语。我想做完整的浅层解析。

代码语言:javascript
复制
def extract_named_nouns(row_series):
    """Combine nouns and non-numerical entities. 

    Keyword arguments:
    row_series -- a Pandas Series object

    """
    ents = set()
    idxs = set()
    # remove duplicates and merge two lists together
    for noun_tuple in row_series['nouns']:
        for named_ents_tuple in row_series['named_ents']:
            if noun_tuple[1] == named_ents_tuple[1]: 
                idxs.add(noun_tuple[1])
                ents.add(named_ents_tuple)
        if noun_tuple[1] not in idxs:
            ents.add(noun_tuple)

    return sorted(list(ents), key=lambda x: x[1])

def add_named_nouns(df):
    """Create new column in data frame with nouns and named ents.

    Keyword arguments:
    df -- a dataframe object

    """
    df['named_nouns'] = df.apply(extract_named_nouns, axis=1)


    from __future__ import unicode_literals
    import spacy,en_core_web_sm
    import textacy
    from textacy import io
    #using spacy for nlp
    nlp = en_core_web_sm.load()
    sentence = 'The author is writing a new book.'
    pattern = r'<VERB>?<ADV>*<VERB>+'
    doc = textacy.Doc.load(sentence, metadata=metadata, lang='en_core_web_sm')
    # doc = textacy.corpus.Corpus(sentence, lang='en_core_web_sm')
    lists = textacy.extract.pos_regex_matches(doc, pattern)
    for list in lists: 
        print(list.text)

模块“textacy”没有属性“Doc”

EN

回答 2

Stack Overflow用户

发布于 2019-06-24 03:25:26

尝试按照这里的示例操作:https://chartbeat-labs.github.io/textacy/getting_started/quickstart.html#make-a-doc

它应该像这样简单:

代码语言:javascript
复制
doc = textacy.make_spacy_doc("The author is writing a new book.", lang='en_core_web_sm')

你可以考虑只使用spacy (没有textacy)和内置的Matcher (https://spacy.io/usage/rule-based-matching)。

票数 5
EN

Stack Overflow用户

发布于 2020-10-06 23:46:34

代码语言:javascript
复制
spacy_lang = textacy.load_spacy_lang("en_core_web_en")
docx_textacy = spacy_lang(sentence)
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56720269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档