Mejorar el uso de spacy para comandos
This commit is contained in:
2
Pipfile
2
Pipfile
@ -14,4 +14,4 @@ nltk = "*"
|
||||
spacy = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
||||
python_version = "3.8"
|
||||
|
@ -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]
|
||||
|
@ -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)')
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user