Exemplo n.º 1
0
class EntityRunner(RunnerBase):

    def __init__(self):
        self.azure_table = Database()
        self.consec_error_count = 0

    def __str__(self):
        return "EntityRunner"

    def call(self):
        if self.consec_error_count > self.MAX_ALLOWABLE_ERRORS:
            raise TooManyErrorsException

        transcript, partition_key = self.azure_table.retrieve_next_record_for_extraction()
        location_dict = extract_location(transcript)
        print("Location for {0}: {1}".format(partition_key, str(location_dict)))
        date_dict = extract_date_time(transcript)
        print("Date, time for {0}: {1}".format(partition_key, str(date_dict)))
        self._process_location_date(partition_key, location_dict, date_dict)
        if location_dict == None or date_dict == None:
            self.consec_error_count += 1
            raise EntityExtractionError(
                "failed to extract location or date for {0}"
                .format(partition_key))
        else:
            self.consec_error_count = 0

    def _process_location_date(self, case_number, location_dict, date_dict):
        # location
        city = None
        location_confidence = None
        state = None
        zipcode = None
        if location_dict is not None:
            city = location_dict["City"]
            location_confidence = location_dict["Confidence_location"]
            state = location_dict["State"]
            zipcode = location_dict["Zipcode"]

        # date
        date = None
        if date_dict is not None:
            year = date_dict["year"]
            month = date_dict["month"]
            day = date_dict["day"]
            hour = date_dict["hour"] or 0
            minute = date_dict["minute"] or 0
            # only report a date if we found year, month and day
            if year is not None and month is not None and day is not None:
                date = datetime(year=year, month=month, day=day, hour=hour, minute=minute)

        self.azure_table.update_location_date(case_number, city, location_confidence, state, zipcode, date)
Exemplo n.º 2
0
class ExtractRunner(object):
    def __init__(self):
        self.azureTable = Database()

    def call(self):
        transcript, partition_key = self.azureTable.retrieve_next_record_for_extraction(
        )
        extractor = Extractor(transcript)
        location = extractor.get_location()
        date = extractor.get_date()
        print("Location: " + location)
        print("Date: " + date)
        self.azureTable.update_location_date(partition_key, location, date)
Exemplo n.º 3
0
class EntityRunner(RunnerBase):

    def __init__(self):
        self.azure_table = Database()

    def __str__(self):
        return "EntityRunner"

    def call(self):
        transcript, partition_key = self.azure_table.retrieve_next_record_for_extraction()
        location_dict = extract_location(transcript)
        print("Location: " + str(location_dict))
        date_dict = extract_date_time(transcript)
        print("Date, time: " + str(date_dict))
        self.azure_table.update_location_date(partition_key, location_dict, date_dict)