Example #1
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 #2
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 #3
0
    def parse(self, query: str) -> List[ModelResult]:
        query = FormatUtility.preprocess(query, False)
        #query = FormatUtility.preProcess(query, false) TODO: for chinese characters
        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.end - 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 #4
0
 def __to_model_result(self, parse_result_value) -> ModelResult:
     result = ModelResult()
     result.start = parse_result_value.start
     result.end = parse_result_value.start + parse_result_value.length - 1
     result.resolution = parse_result_value.value
     result.text = parse_result_value.text
     result.type_name = parse_result_value.type
     return result
Example #5
0
    def parse(self, source: str):
        extract_results = self.extractor.extract(source)
        parse_results = [self.parser.parse(e) for e in extract_results]
        result = []
        for o in parse_results:
            model_result = ModelResult()
            model_result.start = o.start
            model_result.end = o.start + len(o.text) - 1
            model_result.resolution = self.get_resolution(o)
            model_result.text = o.text
            model_result.type_name = self.model_type_name

            result.append(model_result)

        return result
Example #6
0
    def parse(self, query: str) -> List[ModelResult]:
        extract_results = self.extractor.extract(query)
        parse_results = [self.parser.parse(e) for e in extract_results]
        model_results: List[ModelResult] = list()

        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)

            model_results.append(model_result)

        return model_results
Example #7
0
    def parse(self, query: str) -> List[ModelResult]:
        model_results: List[ModelResult] = list()
        parse_results = []

        try:
            extract_results = self.extractor.extract(query)
            parse_results = [self.parser.parse(e) for e in extract_results]
        except Exception:
            pass

        filtered_parse_results = list(filter(lambda o: o.data is not None, parse_results))
        for parse_result in filtered_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)

            model_results.append(model_result)

        return model_results