Usando spaCy para NLP que permite diferenciar entidades en el texto
This commit is contained in:
@ -2,10 +2,43 @@ import os
|
||||
import json
|
||||
|
||||
|
||||
class Command:
|
||||
def __init__(self):
|
||||
self.command = ''
|
||||
|
||||
|
||||
class Commands:
|
||||
def __init__(self, data_folder):
|
||||
self.filename = os.path.join(data_folder, 'commands.json')
|
||||
data = []
|
||||
try:
|
||||
with open(self.filename, 'r') as f:
|
||||
data = json.load(f)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
self.commands = []
|
||||
for c in data:
|
||||
cmd = Command()
|
||||
cmd.command = c
|
||||
self.commands.append(cmd)
|
||||
|
||||
def get(self, command):
|
||||
for i, c in enumerate(self.commands):
|
||||
if command == c.command:
|
||||
return i
|
||||
return None
|
||||
|
||||
def find(self, command):
|
||||
return self.commands[self.get(command=command)]
|
||||
|
||||
|
||||
class Instruccion:
|
||||
def __init__(self):
|
||||
self.instruccion = ''
|
||||
self.aliases = []
|
||||
self.command = None
|
||||
self.params = {}
|
||||
|
||||
|
||||
class Instrucciones:
|
||||
@ -18,12 +51,20 @@ class Instrucciones:
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
self.commands = Commands(data_folder)
|
||||
|
||||
self.instrucciones = []
|
||||
for d in data:
|
||||
i = Instruccion()
|
||||
i.instruccion = d['instruccion']
|
||||
for a in d['aliases']:
|
||||
i.aliases.append(a)
|
||||
i.instruccion = d['name']
|
||||
if 'aliases' in d:
|
||||
for a in d['aliases']:
|
||||
i.aliases.append(a)
|
||||
if 'params' in d:
|
||||
for param, val in d['params'].items():
|
||||
i.params[param] = val
|
||||
if 'command' in d:
|
||||
i.command = self.commands.find(d['command'])
|
||||
self.instrucciones.append(i)
|
||||
|
||||
def get(self, instruccion):
|
||||
@ -35,6 +76,11 @@ class Instrucciones:
|
||||
if instruccion in ins.aliases:
|
||||
return i
|
||||
|
||||
def find(self, instruccion):
|
||||
if not self.is_valid(instruccion):
|
||||
return None
|
||||
return self.instrucciones[self.get(instruccion)]
|
||||
|
||||
def is_valid(self, instruccion):
|
||||
for i in self.instrucciones:
|
||||
if instruccion == i.instruccion:
|
||||
|
Reference in New Issue
Block a user