Mejorar el uso de spacy para comandos

This commit is contained in:
2020-11-18 01:41:51 -03:00
parent e2fd9b7daa
commit d67ffbced2
4 changed files with 10 additions and 8 deletions

View File

@ -14,4 +14,4 @@ nltk = "*"
spacy = "*"
[requires]
python_version = "3.9"
python_version = "3.8"

View File

@ -1,5 +1,6 @@
import os
import spacy
from pprint import pprint
class Brain:
@ -9,4 +10,6 @@ class Brain:
def get_command(self, phrase):
doc = self.nlp(phrase)
return doc
verbs = [t for t in doc if t.pos_ == 'VERB']
pprint(verbs)
return doc.ents[0]

View File

@ -1,4 +1,5 @@
import email
from email.parser import BytesParser
from email.policy import default as DefaultPolicy
class Email:
@ -10,8 +11,7 @@ class Email:
status, raw_data = imap.uid('fetch', self.uid, '(RFC822)')
if status != 'OK':
raise Exception('Could not recover message {0}'.format(self.uid))
self.message = email.message_from_bytes(raw_data[0][1])
self.message = BytesParser(policy=DefaultPolicy).parsebytes(text=raw_data[0][1])
def delete(self, imap):
status, result = imap.uid('STORE', self.uid, '+FLAGS', '(\\Deleted)')

View File

@ -70,7 +70,7 @@ class Obtenedor(Worker):
for part in email_part.get_payload():
output += self.build_message(part)
else:
html = email_part.get_payload(decode=True)
html = email_part.get_payload(decode=True).decode('utf-8')
bs = BeautifulSoup(html, 'html.parser')
if bs.body:
html = bs.body.get_text()
@ -288,7 +288,6 @@ class Procesador(Worker):
em = self.queue.get(timeout=self.frec)
except queue.Empty:
continue
print(em.text)
command = self.brain.get_command(em.text)
[print(ent) for ent in command.ents]
self.end_turn()