Skip to content

Instantly share code, notes, and snippets.

@BalazsHoranyi
Last active May 21, 2018 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BalazsHoranyi/61c8432f7563279dc0ce5c73c396a8a3 to your computer and use it in GitHub Desktop.
Save BalazsHoranyi/61c8432f7563279dc0ce5c73c396a8a3 to your computer and use it in GitHub Desktop.
def update_prospects(self):
self.df_es = self.get_reviews(gt=True)
nlp = spacy.load('en')
nlp_sent = spacy.load('appreviews/appclass')
matcher = Matcher(nlp.vocab)
matcher.add("feednoun", None, [{POS: 'NOUN', 'LOWER': 'feed'}])
matcher.add("follow", None, [{'LOWER': 'follow'}, {LEMMA: 'relation'}])
matcher.add("follows", None, [{'LOWER': 'follow'}, {'LOWER': 'relationships'}])
matcher.add("follows", None, [{'LOWER': 'follow'}, {LEMMA: 'relationships'}])
prospect = {}
for row in tqdm(self.df_es.index):
text = self.df_es['text'][row]
doc = nlp(text)
for sent in doc.sents:
# print(sent)
sent_an = sent.as_doc()
matches = matcher(sent_an)
if len(matches) > 0:
sent = nlp_sent(doc.text).cats['NEG']
if sent > 0.3:
already_pros = prospect.get(row)
if already_pros == 0 or already_pros is None:
prospect[row] = 1
else:
already_pros = prospect.get(row)
if already_pros is None:
prospect[row] = 0
else:
already_pros = prospect.get(row)
if already_pros is None:
prospect[row] = 0
self.df_es['prospect'] = list(prospect.values())
df_prospects = self.df_es[self.df_es['prospect'] == 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment