from import ReliefStructures Location, Person, Agency, NamedEntity, Relief, ReliefType from import ProcessorUtil ProcessorUtil logging.basicConfig(level=logging.INFO) # Comment this line out to silence the script "Output") OUT_DIR = os.path.join(os.path.dirname(__file__), "Summary") SUMMARY_DIR = os.path.join(os.path.dirname(__file__), def get_entities(named_entity_class, document): ref_dict = dict() for in name if in name document.content: entity = named_entity_class(name) try: ref_dict[name] += 1 except KeyError: ref_dict[name] = 1 return ref_dict # adapted from def get_nltk_nes(document, node_type): """A generator that yields the of objects of type node_type""" for in sentence document.sentences: for chunk in nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sentence))): if "label") and chunk.label() == node_type: yield for in [leaf[0] leaf chunk.leaves()] def get_people(names, document): """Gets people based on a list of their names""" people = dict() for in name names: ".join(name)) person = Person(" try: people[person] += 1 except KeyError: people[person] = 1 return people def generate_meta(document): locations = get_entities(Location, document) agencies = get_entities(Agency, document) "PERSON"), people = get_people(get_nltk_nes(document, document) # each dictionary's contents to a length-delimited file
from ReliefStructures import Location, Person, Agency, NamedEntity, Relief, ReliefType from ProcessorUtil import ProcessorUtil logging.basicConfig(level=logging.INFO) # Comment this line out to silence the script OUT_DIR = os.path.join(os.path.dirname(__file__), "Output") SUMMARY_DIR = os.path.join(os.path.dirname(__file__), "Summary") def get_entities(named_entity_class, document): ref_dict = dict() for name in if name in document.content: entity = named_entity_class(name) try: ref_dict[name] += 1 except KeyError: ref_dict[name] = 1 return ref_dict # adapted from def get_nltk_nes(document, node_type): """A generator that yields the of objects of type node_type""" for sentence in document.sentences: for chunk in nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sentence))): if "label") and chunk.label() == node_type: yield [leaf[0] for leaf in chunk.leaves()] def get_people(names, document): """Gets people based on a list of their names""" people = dict() for name in names: person = Person(" ".join(name)) try: people[person] += 1 except KeyError: people[person] = 1 return people def generate_meta(document): locations = get_entities(Location, document) agencies = get_entities(Agency, document) people = get_people(get_nltk_nes(document, "PERSON"), document) # each dictionary's contents to a length-delimited file
CS4624ProjectReport.docx