Introducción al procesamiento básico de texto usando TextBlob

  • 90 min | Última modificación: Diciembre 2, 2020

A continuación se definen y ejemplifican las tareas básicas de procesamiento de texto en Python. Por simplicidad se usará el paquete TextBlob.

[1]:
## Se crea el directorio de entrada
!rm -rf input output
!mkdir input
[2]:
%%writefile input/text0.txt
Analytics is the discovery, interpretation, and communication of meaningful patterns
in data. Especially valuable in areas rich with recorded information, analytics relies
on the simultaneous application of statistics, computer programming and operations research
to quantify performance.

Organizations may apply analytics to business data to describe, predict, and improve business
performance. Specifically, areas within analytics include predictive analytics, prescriptive
analytics, enterprise decision management, descriptive analytics, cognitive analytics, Big
Data Analytics, retail analytics, store assortment and stock-keeping unit optimization,
marketing optimization and marketing mix modeling, web analytics, call analytics, speech
analytics, sales force sizing and optimization, price and promotion modeling, predictive
science, credit risk analysis, and fraud analytics. Since analytics can require extensive
computation (see big data), the algorithms and software used for analytics harness the most
current methods in computer science, statistics, and mathematics.
Writing input/text0.txt
[3]:
%%writefile input/text1.txt
The field of data analysis. Analytics often involves studying past historical data to
research potential trends, to analyze the effects of certain decisions or events, or to
evaluate the performance of a given tool or scenario. The goal of analytics is to improve
the business by gaining knowledge which can be used to make improvements or changes.
Writing input/text1.txt
[4]:
%%writefile input/text2.txt
Data analytics (DA) is the process of examining data sets in order to draw conclusions
about the information they contain, increasingly with the aid of specialized systems
and software. Data analytics technologies and techniques are widely used in commercial
industries to enable organizations to make more-informed business decisions and by
scientists and researchers to verify or disprove scientific models, theories and
hypotheses.
Writing input/text2.txt

Lectura de datos

[5]:
##
## Itera sobre todos los archivos de la carpeta `input/`
## para realizar la lectura. Note que readlines retorna
## una lista de strings, donde cada string es una linea
## del archivo
##
import glob

raw_text = []
for filename in glob.glob("input/*.txt"):
    with open(filename, "r") as f:
        raw_text += f.readlines()

raw_text
[5]:
['Analytics is the discovery, interpretation, and communication of meaningful patterns\n',
 'in data. Especially valuable in areas rich with recorded information, analytics relies\n',
 'on the simultaneous application of statistics, computer programming and operations research\n',
 'to quantify performance.\n',
 '\n',
 'Organizations may apply analytics to business data to describe, predict, and improve business\n',
 'performance. Specifically, areas within analytics include predictive analytics, prescriptive\n',
 'analytics, enterprise decision management, descriptive analytics, cognitive analytics, Big\n',
 'Data Analytics, retail analytics, store assortment and stock-keeping unit optimization,\n',
 'marketing optimization and marketing mix modeling, web analytics, call analytics, speech\n',
 'analytics, sales force sizing and optimization, price and promotion modeling, predictive\n',
 'science, credit risk analysis, and fraud analytics. Since analytics can require extensive\n',
 'computation (see big data), the algorithms and software used for analytics harness the most\n',
 'current methods in computer science, statistics, and mathematics.\n',
 'The field of data analysis. Analytics often involves studying past historical data to\n',
 'research potential trends, to analyze the effects of certain decisions or events, or to\n',
 'evaluate the performance of a given tool or scenario. The goal of analytics is to improve\n',
 'the business by gaining knowledge which can be used to make improvements or changes.\n',
 'Data analytics (DA) is the process of examining data sets in order to draw conclusions\n',
 'about the information they contain, increasingly with the aid of specialized systems\n',
 'and software. Data analytics technologies and techniques are widely used in commercial\n',
 'industries to enable organizations to make more-informed business decisions and by\n',
 'scientists and researchers to verify or disprove scientific models, theories and\n',
 'hypotheses.\n']
[6]:
## Concatena las cadenas de texto en un solo string
raw_text = ' '.join(raw_text)
raw_text
[6]:
'Analytics is the discovery, interpretation, and communication of meaningful patterns\n in data. Especially valuable in areas rich with recorded information, analytics relies\n on the simultaneous application of statistics, computer programming and operations research\n to quantify performance.\n \n Organizations may apply analytics to business data to describe, predict, and improve business\n performance. Specifically, areas within analytics include predictive analytics, prescriptive\n analytics, enterprise decision management, descriptive analytics, cognitive analytics, Big\n Data Analytics, retail analytics, store assortment and stock-keeping unit optimization,\n marketing optimization and marketing mix modeling, web analytics, call analytics, speech\n analytics, sales force sizing and optimization, price and promotion modeling, predictive\n science, credit risk analysis, and fraud analytics. Since analytics can require extensive\n computation (see big data), the algorithms and software used for analytics harness the most\n current methods in computer science, statistics, and mathematics.\n The field of data analysis. Analytics often involves studying past historical data to\n research potential trends, to analyze the effects of certain decisions or events, or to\n evaluate the performance of a given tool or scenario. The goal of analytics is to improve\n the business by gaining knowledge which can be used to make improvements or changes.\n Data analytics (DA) is the process of examining data sets in order to draw conclusions\n about the information they contain, increasingly with the aid of specialized systems\n and software. Data analytics technologies and techniques are widely used in commercial\n industries to enable organizations to make more-informed business decisions and by\n scientists and researchers to verify or disprove scientific models, theories and\n hypotheses.\n'
[7]:
## Remueve los retornos de carro.
raw_text = raw_text.replace('\n', '')
raw_text
[7]:
'Analytics is the discovery, interpretation, and communication of meaningful patterns in data. Especially valuable in areas rich with recorded information, analytics relies on the simultaneous application of statistics, computer programming and operations research to quantify performance.  Organizations may apply analytics to business data to describe, predict, and improve business performance. Specifically, areas within analytics include predictive analytics, prescriptive analytics, enterprise decision management, descriptive analytics, cognitive analytics, Big Data Analytics, retail analytics, store assortment and stock-keeping unit optimization, marketing optimization and marketing mix modeling, web analytics, call analytics, speech analytics, sales force sizing and optimization, price and promotion modeling, predictive science, credit risk analysis, and fraud analytics. Since analytics can require extensive computation (see big data), the algorithms and software used for analytics harness the most current methods in computer science, statistics, and mathematics. The field of data analysis. Analytics often involves studying past historical data to research potential trends, to analyze the effects of certain decisions or events, or to evaluate the performance of a given tool or scenario. The goal of analytics is to improve the business by gaining knowledge which can be used to make improvements or changes. Data analytics (DA) is the process of examining data sets in order to draw conclusions about the information they contain, increasingly with the aid of specialized systems and software. Data analytics technologies and techniques are widely used in commercial industries to enable organizations to make more-informed business decisions and by scientists and researchers to verify or disprove scientific models, theories and hypotheses.'

Procesamiento básico de texto

[8]:
##
## Crea un objeto TextBlob a partir del cual se realiza
## el proceasmiento
##
from textblob import TextBlob

text = TextBlob(raw_text)
text
[8]:
TextBlob("Analytics is the discovery, interpretation, and communication of meaningful patterns in data. Especially valuable in areas rich with recorded information, analytics relies on the simultaneous application of statistics, computer programming and operations research to quantify performance.  Organizations may apply analytics to business data to describe, predict, and improve business performance. Specifically, areas within analytics include predictive analytics, prescriptive analytics, enterprise decision management, descriptive analytics, cognitive analytics, Big Data Analytics, retail analytics, store assortment and stock-keeping unit optimization, marketing optimization and marketing mix modeling, web analytics, call analytics, speech analytics, sales force sizing and optimization, price and promotion modeling, predictive science, credit risk analysis, and fraud analytics. Since analytics can require extensive computation (see big data), the algorithms and software used for analytics harness the most current methods in computer science, statistics, and mathematics. The field of data analysis. Analytics often involves studying past historical data to research potential trends, to analyze the effects of certain decisions or events, or to evaluate the performance of a given tool or scenario. The goal of analytics is to improve the business by gaining knowledge which can be used to make improvements or changes. Data analytics (DA) is the process of examining data sets in order to draw conclusions about the information they contain, increasingly with the aid of specialized systems and software. Data analytics technologies and techniques are widely used in commercial industries to enable organizations to make more-informed business decisions and by scientists and researchers to verify or disprove scientific models, theories and hypotheses.")
[9]:
##
## Transformaciones básicas usando las funciones propias de
## los strings de Python
##
text.upper()
[9]:
TextBlob("ANALYTICS IS THE DISCOVERY, INTERPRETATION, AND COMMUNICATION OF MEANINGFUL PATTERNS IN DATA. ESPECIALLY VALUABLE IN AREAS RICH WITH RECORDED INFORMATION, ANALYTICS RELIES ON THE SIMULTANEOUS APPLICATION OF STATISTICS, COMPUTER PROGRAMMING AND OPERATIONS RESEARCH TO QUANTIFY PERFORMANCE.  ORGANIZATIONS MAY APPLY ANALYTICS TO BUSINESS DATA TO DESCRIBE, PREDICT, AND IMPROVE BUSINESS PERFORMANCE. SPECIFICALLY, AREAS WITHIN ANALYTICS INCLUDE PREDICTIVE ANALYTICS, PRESCRIPTIVE ANALYTICS, ENTERPRISE DECISION MANAGEMENT, DESCRIPTIVE ANALYTICS, COGNITIVE ANALYTICS, BIG DATA ANALYTICS, RETAIL ANALYTICS, STORE ASSORTMENT AND STOCK-KEEPING UNIT OPTIMIZATION, MARKETING OPTIMIZATION AND MARKETING MIX MODELING, WEB ANALYTICS, CALL ANALYTICS, SPEECH ANALYTICS, SALES FORCE SIZING AND OPTIMIZATION, PRICE AND PROMOTION MODELING, PREDICTIVE SCIENCE, CREDIT RISK ANALYSIS, AND FRAUD ANALYTICS. SINCE ANALYTICS CAN REQUIRE EXTENSIVE COMPUTATION (SEE BIG DATA), THE ALGORITHMS AND SOFTWARE USED FOR ANALYTICS HARNESS THE MOST CURRENT METHODS IN COMPUTER SCIENCE, STATISTICS, AND MATHEMATICS. THE FIELD OF DATA ANALYSIS. ANALYTICS OFTEN INVOLVES STUDYING PAST HISTORICAL DATA TO RESEARCH POTENTIAL TRENDS, TO ANALYZE THE EFFECTS OF CERTAIN DECISIONS OR EVENTS, OR TO EVALUATE THE PERFORMANCE OF A GIVEN TOOL OR SCENARIO. THE GOAL OF ANALYTICS IS TO IMPROVE THE BUSINESS BY GAINING KNOWLEDGE WHICH CAN BE USED TO MAKE IMPROVEMENTS OR CHANGES. DATA ANALYTICS (DA) IS THE PROCESS OF EXAMINING DATA SETS IN ORDER TO DRAW CONCLUSIONS ABOUT THE INFORMATION THEY CONTAIN, INCREASINGLY WITH THE AID OF SPECIALIZED SYSTEMS AND SOFTWARE. DATA ANALYTICS TECHNOLOGIES AND TECHNIQUES ARE WIDELY USED IN COMMERCIAL INDUSTRIES TO ENABLE ORGANIZATIONS TO MAKE MORE-INFORMED BUSINESS DECISIONS AND BY SCIENTISTS AND RESEARCHERS TO VERIFY OR DISPROVE SCIENTIFIC MODELS, THEORIES AND HYPOTHESES.")
[10]:
text[10:25]
[10]:
TextBlob("is the discover")
[11]:
##
## Part-of-speech Tagging (POS-tag)
##
##    TAG    Descripción                            Ejemplo
##    -------------------------------------------------------------------------
##    CC     Coordination conjuntion                and, or
##    CD     Cardinal number                        one, two, 3
##    DT     Determiner                             a, the
##    EX     Existential there                      there were two cars
##    FW     Foreign word                           hola mundo cruel
##    IN     Preposition/subordinating conjunction  of, in, on, that
##    JJ     Adjective                              quick, lazy
##    JJR    Adjective, comparative                 quicker, lazier
##    JJS    Adjective, superlative                 quickest, laziest
##    NN     Noun, singular or mass                 fox, dog
##    NNS    Noun, plural                           foxes, dogs
##    NN PS  Noun, proper singular                  John, Alice
##    NNP    Noun, proper plural                    Vikings, Indians, Germans
##    ...
##
text.tags[:20]
[11]:
[('Analytics', 'NNS'),
 ('is', 'VBZ'),
 ('the', 'DT'),
 ('discovery', 'NN'),
 ('interpretation', 'NN'),
 ('and', 'CC'),
 ('communication', 'NN'),
 ('of', 'IN'),
 ('meaningful', 'JJ'),
 ('patterns', 'NNS'),
 ('in', 'IN'),
 ('data', 'NNS'),
 ('Especially', 'RB'),
 ('valuable', 'JJ'),
 ('in', 'IN'),
 ('areas', 'NNS'),
 ('rich', 'VBP'),
 ('with', 'IN'),
 ('recorded', 'JJ'),
 ('information', 'NN')]
[12]:
##
## Noun phrase extraction
##
text.noun_phrases
[12]:
WordList(['analytics', 'meaningful patterns', 'especially', 'analytics relies', 'simultaneous application', 'operations research', 'quantify performance', 'organizations', 'business data', 'business performance', 'specifically', 'predictive analytics', 'prescriptive analytics', 'enterprise decision management', 'descriptive analytics', 'cognitive analytics', 'data analytics', 'retail analytics', 'store assortment', 'unit optimization', 'web analytics', 'speech analytics', 'sales force', 'predictive science', 'credit risk analysis', 'fraud analytics', 'extensive computation', 'big data', 'analytics harness', 'current methods', 'computer science', 'data analysis', 'analytics', 'historical data', 'research potential trends', 'certain decisions', 'data', 'da', 'data', 'analytics technologies', 'commercial industries', 'enable organizations', 'business decisions', 'scientific models'])
[13]:
##
## Sentiment Analysis
##
text.sentiment
[13]:
Sentiment(polarity=0.0885204081632653, subjectivity=0.4217687074829932)
[14]:
##
## Tokenization in words
##   Note que elimina los signos de puntuación
##
text.words
[14]:
WordList(['Analytics', 'is', 'the', 'discovery', 'interpretation', 'and', 'communication', 'of', 'meaningful', 'patterns', 'in', 'data', 'Especially', 'valuable', 'in', 'areas', 'rich', 'with', 'recorded', 'information', 'analytics', 'relies', 'on', 'the', 'simultaneous', 'application', 'of', 'statistics', 'computer', 'programming', 'and', 'operations', 'research', 'to', 'quantify', 'performance', 'Organizations', 'may', 'apply', 'analytics', 'to', 'business', 'data', 'to', 'describe', 'predict', 'and', 'improve', 'business', 'performance', 'Specifically', 'areas', 'within', 'analytics', 'include', 'predictive', 'analytics', 'prescriptive', 'analytics', 'enterprise', 'decision', 'management', 'descriptive', 'analytics', 'cognitive', 'analytics', 'Big', 'Data', 'Analytics', 'retail', 'analytics', 'store', 'assortment', 'and', 'stock-keeping', 'unit', 'optimization', 'marketing', 'optimization', 'and', 'marketing', 'mix', 'modeling', 'web', 'analytics', 'call', 'analytics', 'speech', 'analytics', 'sales', 'force', 'sizing', 'and', 'optimization', 'price', 'and', 'promotion', 'modeling', 'predictive', 'science', 'credit', 'risk', 'analysis', 'and', 'fraud', 'analytics', 'Since', 'analytics', 'can', 'require', 'extensive', 'computation', 'see', 'big', 'data', 'the', 'algorithms', 'and', 'software', 'used', 'for', 'analytics', 'harness', 'the', 'most', 'current', 'methods', 'in', 'computer', 'science', 'statistics', 'and', 'mathematics', 'The', 'field', 'of', 'data', 'analysis', 'Analytics', 'often', 'involves', 'studying', 'past', 'historical', 'data', 'to', 'research', 'potential', 'trends', 'to', 'analyze', 'the', 'effects', 'of', 'certain', 'decisions', 'or', 'events', 'or', 'to', 'evaluate', 'the', 'performance', 'of', 'a', 'given', 'tool', 'or', 'scenario', 'The', 'goal', 'of', 'analytics', 'is', 'to', 'improve', 'the', 'business', 'by', 'gaining', 'knowledge', 'which', 'can', 'be', 'used', 'to', 'make', 'improvements', 'or', 'changes', 'Data', 'analytics', 'DA', 'is', 'the', 'process', 'of', 'examining', 'data', 'sets', 'in', 'order', 'to', 'draw', 'conclusions', 'about', 'the', 'information', 'they', 'contain', 'increasingly', 'with', 'the', 'aid', 'of', 'specialized', 'systems', 'and', 'software', 'Data', 'analytics', 'technologies', 'and', 'techniques', 'are', 'widely', 'used', 'in', 'commercial', 'industries', 'to', 'enable', 'organizations', 'to', 'make', 'more-informed', 'business', 'decisions', 'and', 'by', 'scientists', 'and', 'researchers', 'to', 'verify', 'or', 'disprove', 'scientific', 'models', 'theories', 'and', 'hypotheses'])
[15]:
##
## Tokenization in sentences
##
text.sentences
[15]:
[Sentence("Analytics is the discovery, interpretation, and communication of meaningful patterns in data."),
 Sentence("Especially valuable in areas rich with recorded information, analytics relies on the simultaneous application of statistics, computer programming and operations research to quantify performance."),
 Sentence("Organizations may apply analytics to business data to describe, predict, and improve business performance."),
 Sentence("Specifically, areas within analytics include predictive analytics, prescriptive analytics, enterprise decision management, descriptive analytics, cognitive analytics, Big Data Analytics, retail analytics, store assortment and stock-keeping unit optimization, marketing optimization and marketing mix modeling, web analytics, call analytics, speech analytics, sales force sizing and optimization, price and promotion modeling, predictive science, credit risk analysis, and fraud analytics."),
 Sentence("Since analytics can require extensive computation (see big data), the algorithms and software used for analytics harness the most current methods in computer science, statistics, and mathematics."),
 Sentence("The field of data analysis."),
 Sentence("Analytics often involves studying past historical data to research potential trends, to analyze the effects of certain decisions or events, or to evaluate the performance of a given tool or scenario."),
 Sentence("The goal of analytics is to improve the business by gaining knowledge which can be used to make improvements or changes."),
 Sentence("Data analytics (DA) is the process of examining data sets in order to draw conclusions about the information they contain, increasingly with the aid of specialized systems and software."),
 Sentence("Data analytics technologies and techniques are widely used in commercial industries to enable organizations to make more-informed business decisions and by scientists and researchers to verify or disprove scientific models, theories and hypotheses.")]
[16]:
##
## Singulares
##
text.words[9], text.words[9].singularize()
[16]:
('patterns', 'pattern')
[17]:
##
## Plurales
##
text.words[3], text.words[3].pluralize()
[17]:
('discovery', 'discoveries')
[18]:
##
## Lemmatization
##
text.words.lemmatize()
[18]:
WordList(['Analytics', 'is', 'the', 'discovery', 'interpretation', 'and', 'communication', 'of', 'meaningful', 'pattern', 'in', 'data', 'Especially', 'valuable', 'in', 'area', 'rich', 'with', 'recorded', 'information', 'analytics', 'relies', 'on', 'the', 'simultaneous', 'application', 'of', 'statistic', 'computer', 'programming', 'and', 'operation', 'research', 'to', 'quantify', 'performance', 'Organizations', 'may', 'apply', 'analytics', 'to', 'business', 'data', 'to', 'describe', 'predict', 'and', 'improve', 'business', 'performance', 'Specifically', 'area', 'within', 'analytics', 'include', 'predictive', 'analytics', 'prescriptive', 'analytics', 'enterprise', 'decision', 'management', 'descriptive', 'analytics', 'cognitive', 'analytics', 'Big', 'Data', 'Analytics', 'retail', 'analytics', 'store', 'assortment', 'and', 'stock-keeping', 'unit', 'optimization', 'marketing', 'optimization', 'and', 'marketing', 'mix', 'modeling', 'web', 'analytics', 'call', 'analytics', 'speech', 'analytics', 'sale', 'force', 'sizing', 'and', 'optimization', 'price', 'and', 'promotion', 'modeling', 'predictive', 'science', 'credit', 'risk', 'analysis', 'and', 'fraud', 'analytics', 'Since', 'analytics', 'can', 'require', 'extensive', 'computation', 'see', 'big', 'data', 'the', 'algorithm', 'and', 'software', 'used', 'for', 'analytics', 'harness', 'the', 'most', 'current', 'method', 'in', 'computer', 'science', 'statistic', 'and', 'mathematics', 'The', 'field', 'of', 'data', 'analysis', 'Analytics', 'often', 'involves', 'studying', 'past', 'historical', 'data', 'to', 'research', 'potential', 'trend', 'to', 'analyze', 'the', 'effect', 'of', 'certain', 'decision', 'or', 'event', 'or', 'to', 'evaluate', 'the', 'performance', 'of', 'a', 'given', 'tool', 'or', 'scenario', 'The', 'goal', 'of', 'analytics', 'is', 'to', 'improve', 'the', 'business', 'by', 'gaining', 'knowledge', 'which', 'can', 'be', 'used', 'to', 'make', 'improvement', 'or', 'change', 'Data', 'analytics', 'DA', 'is', 'the', 'process', 'of', 'examining', 'data', 'set', 'in', 'order', 'to', 'draw', 'conclusion', 'about', 'the', 'information', 'they', 'contain', 'increasingly', 'with', 'the', 'aid', 'of', 'specialized', 'system', 'and', 'software', 'Data', 'analytics', 'technology', 'and', 'technique', 'are', 'widely', 'used', 'in', 'commercial', 'industry', 'to', 'enable', 'organization', 'to', 'make', 'more-informed', 'business', 'decision', 'and', 'by', 'scientist', 'and', 'researcher', 'to', 'verify', 'or', 'disprove', 'scientific', 'model', 'theory', 'and', 'hypothesis'])
[19]:
##
## Wordnet integration.
##   Wordnet es una base de datos léxica, donde los sustantivos, verbos,
##   adverbios y adjetivos están agrupados en conjuntos de sinónimos
##   cognitios (synsets)
##
##
from textblob import Word

Word('wind').synsets
[19]:
[Synset('wind.n.01'),
 Synset('wind.n.02'),
 Synset('wind.n.03'),
 Synset('wind.n.04'),
 Synset('tip.n.03'),
 Synset('wind_instrument.n.01'),
 Synset('fart.n.01'),
 Synset('wind.n.08'),
 Synset('weave.v.04'),
 Synset('wind.v.02'),
 Synset('wind.v.03'),
 Synset('scent.v.02'),
 Synset('wind.v.05'),
 Synset('wreathe.v.03'),
 Synset('hoist.v.01')]
[20]:
##
## Synsets
##
from textblob.wordnet import Synset

Synset('wind.n.01').definition()
[20]:
'air moving (sometimes with considerable force) from an area of high pressure to an area of low pressure'
[21]:
##
## Iteración sobre los synsets usando definition()
##
for synset in Word('wind').synsets:
    print(synset.definition())
air moving (sometimes with considerable force) from an area of high pressure to an area of low pressure
a tendency or force that influences events
breath
empty rhetoric or insincere or exaggerated talk
an indication of potential opportunity
a musical instrument in which the sound is produced by an enclosed column of air that is moved by the breath
a reflex that expels intestinal gas through the anus
the act of winding or twisting
to move or cause to move in a sinuous, spiral, or circular course
extend in curves and turns
arrange or or coil around
catch the scent of; get wind of
coil the spring of (some mechanical device) by turning a stem
form into a wreath
raise or haul up with or as if with mechanical help
[22]:
##
## Acceso directo a las definiciones
##
Word('wind').definitions
[22]:
['air moving (sometimes with considerable force) from an area of high pressure to an area of low pressure',
 'a tendency or force that influences events',
 'breath',
 'empty rhetoric or insincere or exaggerated talk',
 'an indication of potential opportunity',
 'a musical instrument in which the sound is produced by an enclosed column of air that is moved by the breath',
 'a reflex that expels intestinal gas through the anus',
 'the act of winding or twisting',
 'to move or cause to move in a sinuous, spiral, or circular course',
 'extend in curves and turns',
 'arrange or or coil around',
 'catch the scent of; get wind of',
 'coil the spring of (some mechanical device) by turning a stem',
 'form into a wreath',
 'raise or haul up with or as if with mechanical help']
[23]:
##
## Corrección de textos.
##   corrección de la frase
##
TextBlob("I havv goood speling!").correct()
[23]:
TextBlob("I have good spelling!")
[24]:
##
## Corrección de textos.
##   corrección de una palabra
##
Word("falibility").spellcheck()
[24]:
[('fallibility', 1.0)]
[25]:
##
## Frecuencia de la palabras con word_counts
##
text.word_counts['analytics']
[25]:
20
[26]:
##
## Frecuencia usando count
##
text.words.count('analytics')
[26]:
20
[27]:
##
## Conteo sensitivo al caso
##
text.words.count('analytics', case_sensitive=True)
[27]:
17
[28]:
##
## Noun phrases
##
text.noun_phrases
[28]:
WordList(['analytics', 'meaningful patterns', 'especially', 'analytics relies', 'simultaneous application', 'operations research', 'quantify performance', 'organizations', 'business data', 'business performance', 'specifically', 'predictive analytics', 'prescriptive analytics', 'enterprise decision management', 'descriptive analytics', 'cognitive analytics', 'data analytics', 'retail analytics', 'store assortment', 'unit optimization', 'web analytics', 'speech analytics', 'sales force', 'predictive science', 'credit risk analysis', 'fraud analytics', 'extensive computation', 'big data', 'analytics harness', 'current methods', 'computer science', 'data analysis', 'analytics', 'historical data', 'research potential trends', 'certain decisions', 'data', 'da', 'data', 'analytics technologies', 'commercial industries', 'enable organizations', 'business decisions', 'scientific models'])
[29]:
text.noun_phrases.count('analytics')
[29]:
2
[30]:
##
## Parsing
##
for t in text.parse().split(' ')[0:15]:
    print(t)
Analytics/NNP/B-NP/O
is/VBZ/B-VP/O
the/DT/B-NP/O
discovery/NN/I-NP/O
,/,/O/O
interpretation/NN/B-NP/O
,/,/O/O
and/CC/O/O
communication/NN/B-NP/O
of/IN/B-PP/B-PNP
meaningful/JJ/B-NP/I-PNP
patterns/NNS/I-NP/I-PNP
in/IN/B-PP/B-PNP
data/NNS/B-NP/I-PNP
././O/O
Especially/RB/B-ADJP/O
[31]:
##
## N-gramas
##
TextBlob("Now is better than never.").ngrams(n=3)
[31]:
[WordList(['Now', 'is', 'better']),
 WordList(['is', 'better', 'than']),
 WordList(['better', 'than', 'never'])]

Ejercicio

De las definiciones de analytics dadas al principio de este documento, construya una lista que contenga únicamente los sustantivos, adjetivos, verbos y adverbios presentes en el texto.

AYUDA: puede obtener la lista de todos los tags disponibles con el siguiente código:

import nltk

nltk.help.upenn_tagset()