SD Python Monthly Meetup
Hobson Lane, Travis Harper
Dec 19, 2019
San Diego Python Monthly Meetup by Hobson Lane, Travis Harper Oct 24, 2019
UCSD Extension Data Science for Digital Health Enroll at: bit.ly/ucsd-ds Discount Code ($100 off): UCSDDSDHWI20
key)value)DuckDuckGo: “discovered radiation”
O(log(N))nlpia-bot importsqary.glossary_bots.Botclass Bot:
def __init__(self, domains=('dsdh',)):
global nlp
self.nlp = nlp
self.glossary = glossaries.load(domains=domains)
self.glossary.fillna('', inplace=True)
self.vector = dict()
self.vector['term'] = pd.DataFrame({s: nlp(s or '').vector for s in self.glossary['term']})
self.vector['definition'] = pd.DataFrame({s: nlp(s or '').vector for s in self.glossary['definition']})qary.glossary_bots.Bot.reply def reply(self, statement):
""" Suggest responses to a user statement string with [(score, reply_string)..]"""
responses = []
match = re.match(r'\b(what\s(is|are))\b([^\?]*)(\?*)', statement.lower())
if match:
responses.append((1, str(match.groups())))
else:
responses = [(1.0, "I don't understand")]
return responsesglossary_bots testglossary_bots test>>> bot.reply('Nucleotide')
[(1.0, "I don't understand")]
>>> bot.reply('What is a Nucleotide')
[(1, "('what is', 'is', ' a nucleotide', '')")]Now strip whitespace and stop words and look up the definition in bot.glossary.
Or use the semantic vectors…
glossary_bots works!