blueprints-for-text-analytics-python / blueprints-text

Jupyter notebooks for our O'Reilly book "Blueprints for Text Analysis Using Python"
Apache License 2.0
248 stars 139 forks source link

Ch 01 textacy 0.11.0 tweak #3

Closed ajcross1234 closed 3 years ago

ajcross1234 commented 3 years ago

In Chapter 1, in Blueprint: Finding a Keyword in Context (KWIC) textacy 0.11.0 worked with:

from textacy.extract.kwic import keyword_in_context

def kwic(doc_series, keyword, window=35, print_samples=5):

def add_kwic(text):
    kwic_list.extend(**keyword_in_context**(text, keyword, ignore_case=True, 
                          window_width=window **#, print_only=False**
                                       ))
jsalbr commented 3 years ago

Thanks for the tweak.

I added this to the notebook to keep our code stable:

import textacy

if textacy.__version__ < '0.11': # as in printed book
    from textacy.text_utils import KWIC

else: # for textacy 0.11.x
    from textacy.extract.kwic import keyword_in_context

    def KWIC(*args, **kwargs):
        # call keyword_in_context with all params except 'print_only'
        return keyword_in_context(*args, 
                           **{kw: arg for kw, arg in kwargs.items() 
                            if kw != 'print_only'})