def display_search(): print("\n----- SEARCH -----") print(" s - search by story source") print(" n - search by subject name") print(" p - search for phrase(s) in stories\n") search = input("Search: ").lower() if search == "s": search_term = input("Story Source: ") display_result(es_search(source=search_term)) elif search == "n": search_term = input("Subject Name: ") display_result(es_search(subject=search_term)) elif search == "p": search_term = input("Phrase(s) in Stories: ") resno = 1 for val in es_search(story=search_term): for result in re.finditer(r'(\w+\W+){0,10}' + search_term +'\s+(\w+\W+){0,10}' \ , val.get("story"), flags=re.I): print("Result", resno, "\n", " ".join(result.group().split("\n"))) resno += 1 else: print("\nInvalid search option. Please try again.") display_search()
from elastic import es_search result = es_search(subject="gacy", source="criminalminds") for ndx, val in enumerate(result): print("\n----------\n") print("Story", ndx + 1, "of", val.get("total")) print("Subject:", val.get("subject")) print(val.get("story"))
import os import re import sys import spacy sys.path.append(os.path.abspath(os.path.join('..', 'modules'))) from elastic import es_search, es_update nlp = spacy.load("en_core_web_sm") for val in es_search(): victims = list() for result in re.finditer(r'(\w+\W+){0}victims?\s?(,|is|are|was|were)\s(\w+\W+){1,6}', \ val.get("story"), flags=re.I): doc = nlp(result.group()) for entity in doc.ents: if entity.label_ == "PERSON": result_split = result.group().split() if "\n" in result.group(): pass elif "." in result.group(): period = result_split.index( [i for i in result_split if "." in i][0]) if entity.text in result_split[period:]: pass else: victims.append(entity.text) else: victims.append(entity.text) if len(victims) > 0:
from elastic import es_search result = es_search(story="arrested") for ndx, val in enumerate(result): print("\n----------\n") print("Story", ndx + 1, "of", val.get("total")) print("Subject:", val.get("subject"))
if search == "s": search_term = input("Story Source: ") display_result(es_search(source=search_term)) elif search == "n": search_term = input("Subject Name: ") display_result(es_search(subject=search_term)) elif search == "p": search_term = input("Phrase(s) in Stories: ") resno = 1 for val in es_search(story=search_term): for result in re.finditer(r'(\w+\W+){0,10}' + search_term +'\s+(\w+\W+){0,10}' \ , val.get("story"), flags=re.I): print("Result", resno, "\n", " ".join(result.group().split("\n"))) resno += 1 else: print("\nInvalid search option. Please try again.") display_search() while True: option = display_prompt() if option == "v": display_result(es_search()) elif option == "s": display_search() else: print("\nInvalid option. Please try again.\n") continue break