4

Can't find module 'textacy' has no attribute 'Doc' I am trying to extract verb phrases from spacy but there is such no library. Please help me how can I extract the verb phrases or adjective phrases using spacy. I want to do full shallow parsing.

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)

module 'textacy' has no attribute 'Doc'

Quinn Mortimer
  • 671
  • 6
  • 14
Gul Jabeen
  • 86
  • 1
  • 4

2 Answers2

7

Try following the examples here: https://chartbeat-labs.github.io/textacy/getting_started/quickstart.html#make-a-doc

It should be as simple as:

doc = textacy.make_spacy_doc("The author is writing a new book.", lang='en_core_web_sm')

You might look into just using spacy (without textacy) with its built-in Matcher instead (https://spacy.io/usage/rule-based-matching).

aab
  • 10,858
  • 22
  • 38
  • Thank you so much. It worked. I just want to extract Verb phrases from a very large dataset. I haven't seen any library for it. Do you know how can i extract verb phrases using spacy. Check this code on https://www.kaggle.com/sudosharma/quick-and-dirty-entity-extractions – Gul Jabeen Jun 23 '19 at 22:33
-1
spacy_lang = textacy.load_spacy_lang("en_core_web_en")
docx_textacy = spacy_lang(sentence)
Newt
  • 787
  • 8
  • 15