Example #1
0
    def parse(self, query: str) -> List[ModelResult]:
        query = QueryProcessor.preprocess(query, True)

        extraction_results = []
        for item in self.extractor_parser:
            extract_results = item.extractor.extract(query)
            parse_results = [
                r for r in [item.parser.parse(r) for r in extract_results]
                if not r.value is None
            ]

            for parse_result in parse_results:
                model_result = ModelResult()
                model_result.start = parse_result.start
                model_result.end = parse_result.start + parse_result.length - 1
                model_result.text = parse_result.text
                model_result.type_name = self.model_type_name
                model_result.resolution = self.get_resolution(
                    parse_result.value)

                b_add = not [
                    x for x in extraction_results if
                    x.start == model_result.start and x.end == model_result.end
                ]

                if b_add:
                    extraction_results.append(model_result)

        return extraction_results
Example #2
0
    def parse(self, query: str) -> List[ModelResult]:
        query = QueryProcessor.preprocess(query, True)
        extraction_results = []
        parse_results = []

        try:
            for item in self.extractor_parser:
                extract_results = item.extractor.extract(query)
                for result in extract_results:
                    r = item.parser.parse(result)
                    if r.value is not None:
                        if isinstance(r.value, list):
                            for j in r.value:
                                parse_results.append(j)
                        else:
                            parse_results.append(r)

                for parse_result in parse_results:
                    model_result = ModelResult()
                    model_result.start = parse_result.start
                    model_result.end = parse_result.start + parse_result.length - 1
                    model_result.text = parse_result.text
                    model_result.type_name = self.model_type_name
                    model_result.resolution = self.get_resolution(
                        parse_result.value)

                    b_add = not [x for x in extraction_results if x.start ==
                                 model_result.start and x.end == model_result.end]

                    if b_add:
                        extraction_results.append(model_result)
        except Exception:
            pass

        return extraction_results
Example #3
0
    def parse(self, query: str) -> List[ModelResult]:
        query = QueryProcessor.preprocess(query, True)
        results = []

        try:
            extract_results = self.extractor.extract(query)
            results = list(map(self.__single_parse, extract_results))
        except Exception:
            pass

        return results
Example #4
0
    def parse(self, query: str, reference: datetime = None) -> List[ModelResult]:  # pylint: disable=W0221
        query = QueryProcessor.preprocess(query)

        extract_results = self.extractor.extract(query, reference)
        parser_dates = []

        for result in extract_results:
            parse_result = self.parser.parse(result, reference)
            if isinstance(parse_result.value, list):
                parser_dates += parse_result.value
            else:
                parser_dates.append(parse_result)

        return [self.__to_model_result(x) for x in parser_dates]