solving issues to work as library

parent fdd20aae
# Only required for analysis in Spanish # Only required for analysis in Spanish
import spacy.cli import spacy.cli
spacy.cli.download("es_core_news_sm")
import es_core_news_sm
# Imports # Imports
import spacy import spacy
...@@ -9,6 +7,7 @@ import numpy as np ...@@ -9,6 +7,7 @@ import numpy as np
from tqdm import tqdm from tqdm import tqdm
import re import re
import pandas as pd import pandas as pd
from TextComplexitySpacy import TextComplexitySpacy
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
#%matplotlib inline ## when in Jupyter #%matplotlib inline ## when in Jupyter
...@@ -25,9 +24,9 @@ class TextAnalysisSpacy(): ...@@ -25,9 +24,9 @@ class TextAnalysisSpacy():
# Create language analyzer # Create language analyzer
if lang == 'es': if lang == 'es':
self.nlp = es_core_news_sm.load() spacy.cli.download("es_core_news_sm")
self.nlp = spacy.load("es_core_news_sm")
self.textComplexitySpacy = TextComplexitySpacy() self.textComplexitySpacy = TextComplexitySpacy()
self.nlp = es_core_news_sm.load()
elif lang == 'en': elif lang == 'en':
self.nlp = spacy.load("en_core_web_sm") self.nlp = spacy.load("en_core_web_sm")
self.textComplexitySpacy = TextComplexitySpacy('en') self.textComplexitySpacy = TextComplexitySpacy('en')
...@@ -49,8 +48,8 @@ class TextAnalysisSpacy(): ...@@ -49,8 +48,8 @@ class TextAnalysisSpacy():
# Create category dictionary # Create category dictionary
self.dic_categorias = {} self.dic_categorias = {}
for i in range(len(df)): for i in range(len(self.df)):
if df.iloc[i,0] in self.dic_categorias: if self.df.iloc[i,0] in self.dic_categorias:
self.dic_categorias[df.iloc[i,0]] += 1 self.dic_categorias[df.iloc[i,0]] += 1
else: else:
self.dic_categorias[df.iloc[i,0]] = 1 self.dic_categorias[df.iloc[i,0]] = 1
......
from functools import reduce from functools import reduce
import spacy
import math import math
import syllables import syllables
...@@ -12,7 +13,7 @@ class TextComplexitySpacy(): ...@@ -12,7 +13,7 @@ class TextComplexitySpacy():
# create language analyzer # create language analyzer
if lang == 'es': if lang == 'es':
self.nlp = es_core_news_sm.load() self.nlp = spacy.load("es_core_news_sm")
if lang == 'en': if lang == 'en':
self.nlp = spacy.load("en_core_web_sm") self.nlp = spacy.load("en_core_web_sm")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment