Fixing Analyzer.py and ComplexityAnalyzer.py

parent 90b019e9
......@@ -7,6 +7,8 @@ authors = ["Jaime Collado <jcollado@ujaen.es>", "Estrella Vallecillo <mevr0003@r
[tool.poetry.dependencies]
python = "^3.8"
nltk = "^3.7"
spacy = "^3.3.0"
transformers = "^4.18.0"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
......
This diff could not be displayed because it is too large.
......@@ -270,5 +270,46 @@ class Sequence:
children = [c.children for c in child[r]]
else:
raise ValueError(f"Sequence level '{r}' not found in {child}")
yield criteria(results)
cont=0
gen = criteria(results)
for r in gen:
yield gen[cont]
cont+=1
def filterMetadata(self, level, criteria): #TODO
'''
Filter the children of a Sequence according to a criteria
Args:
level: the route of the level as string, separating each level with "/"
criteria: the filter function
Returns:
A generator with the result of the filter
'''
ruta = level.split("/")
children = [self.children]
metadata = [self.metadata]
results=[]
if len(ruta) == 1 and ruta[0] in metadata[0]:
results.append(metadata[0][ruta[0]])
else:
for r in ruta:
if r == ruta[-1]:
for m in metadata:
if r in m:
results.append(m[r])
else:
for child in children:
if r in child:
children = [c.children for c in child[r]]
metadata = [c.metadata for c in child[r]]
else:
raise ValueError(f"Sequence level '{r}' not found in {child}")
#yield criteria(results)
cont=0
gen = criteria(results)
for r in gen:
yield gen[cont]
cont+=1
\ No newline at end of file
from typing import Optional
import spacy
import spacy.cli
class StylometryyAnalyzer: #TODO
def __init__(self, lang = "es"):
if lang == "es":
spacy.cli.download("es_core_news_sm")
self.nlp = spacy.load("es_core_news_sm")
self.function = self.stylometry
pass
#Este analizador, solo puede analizar cadenas de texto, por lo que solo tiene sentido que use el atributo text de metadata
def analyze(self, sequence, tag, levelOfAnalyzer, levelOfResult:Optional[str] = ""): #TODO
"""Analyze a sequence
Args:
sequence: the Sequence we want to analyze
tag: the label to store the analysis resut
levelOfAnalyzer: the path of the sequence level to analyze inside of the result(la subsequencia a analizar dentro de la sequencia en la que queremos almacenar el resultado)
levelOfResult: the path of the sequence level to store the result. (Podemos querer analizar los tokens pero almacenarlo a nivel de oracion)
analyzeMetadata: boolean, if the result of the analyzer is applied in metadata (True) or in children(False)
Raises:
ValueError if the levelOfResult is incorrect
"""
if levelOfResult == "":
analyzeResult = sequence.filterMetadata(levelOfAnalyzer,self.function)#TODO
resultOfAnalisys= []
for i in analyzeResult:
resultOfAnalisys.append(i)
sequence.metadata[tag] = resultOfAnalisys
else:
children = [sequence.children]
ruta = levelOfResult.split("/")
for r in ruta: #Para cada nivel de la ruta
for child in children: #Miramos en todas las secuencias disponibles
if r in child: #Si dentro de la secuencia actual está r
if r == ruta[-1]:
for seq in child[r]:
analyzeResult = seq.filterMetadata(levelOfAnalyzer,self.function)
resultOfAnalisys= []
for i in analyzeResult:
resultOfAnalisys.append(i)
seq.metadata[tag] = resultOfAnalisys
else:
children = [c.children for c in child[r]]
else:
raise ValueError(f"Sequence level '{r}' not found in {child}")
def stylometry(self):
pass
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