Exemplo n.º 1
0
    def test_normalizer_normalizes(self):
        res = [
            ParseResult('Test', 'Test', 100),
            ParseResult('Test', 'Test', 0)
        ]

        conf = TestConfig()
        conf.enabled_confidence_normalizers.append(NormalizerStub)
        hnc = HierarchicalNormalizerChain(conf, [], [])
        results = hnc.normalize(res)

        self.assertEqual(1, len(results))
        self.assertIsInstance(results[0], ParseResult)
Exemplo n.º 2
0
    def test_normalizer_with_pc_conf_under_70(self):
        date_result = ParseResult('Date', None, 10)
        pc_result = ParseResult('Postal Code', None, 40)

        results = DateWithPostalCode.normalize([date_result, pc_result])

        count = 0
        for res in results:
            if res.type == 'Date':
                count += 1
                self.assertEqual(res.confidence, 44)
            elif res.type == "Postal Code":
                count += 1

        self.assertEqual(count, len(results))
Exemplo n.º 3
0
    def test_normalizer(self):
        char_result = ParseResult('Character', None, 25)
        pc_result = ParseResult('Postal Code', None, 80)

        results = CharacterWithoutBoolean.normalize([char_result, pc_result])

        count = 0
        for res in results:
            if res.type == 'Character':
                count += 1
                self.assertEqual(res.confidence, 100)
            elif res.type == "Postal Code":
                count += 1
                self.assertEqual(res.confidence, 80)

        self.assertEqual(count, len(results))
Exemplo n.º 4
0
    def test_normalizer(self):
        eq_result = ParseResult('Phone', None, 90)
        uri_result = ParseResult('URI', None, 80)

        results = PhoneWithUri.normalize([eq_result, uri_result])

        count = 0
        for res in results:
            if res.type == 'Phone':
                count += 1
                self.assertEqual(res.confidence, 65)
            elif res.type == "URI":
                count += 1
                self.assertEqual(res.confidence, 80)

        self.assertEqual(count, len(results))
Exemplo n.º 5
0
    def test_normalizer(self):
        eq_result = ParseResult('Equation', None, 90)
        pc_result = ParseResult('Postal Code', None, 80)

        results = EquationWithPhonePostalCode.normalize([eq_result, pc_result])

        count = 0
        for res in results:
            if res.type == 'Equation':
                count += 1
                self.assertEqual(res.confidence, 75)
            elif res.type == "Postal Code":
                count += 1
                self.assertEqual(res.confidence, 80)

        self.assertEqual(count, len(results))
Exemplo n.º 6
0
    def result(self, subtype="Unknown", confidence=0, value=None, data=None):
        """
        Returns a ParseResult object detailing the results of parsing

        :param subtype: parse result subtype
        :type subtype: str
        :param confidence: how confident we are in this result (1-100)
        :type confidence: int
        :param value: representation of the parsed data
        :type value: mixed
        :param additional_data: any additional data a parser wants to provide
        :type additional_data: mixed
        :return: parse result
        :rtype: ParseResult
        """
        if confidence == 0:
            confidence = self.confidence

        if data is None:
            data = {}

        return ParseResult(p_type=self.type,
                           subtype=subtype,
                           confidence=confidence,
                           value=value,
                           additional_data=data)
Exemplo n.º 7
0
    def test_normalize(self):
        results = [
            ParseResult('Number', 'Integer', 100),
            ParseResult('Number', 'Octal', 25),
            ParseResult('Date', 'Date', 50)
        ]

        results = IntOctWithPhoneDatePostalCode.normalize(results)

        count = 0
        for res in results:
            count += 1
            if res.subtype == 'Integer':
                self.assertEqual(10, res.confidence)
            elif res.subtype == 'Octal':
                self.assertEqual(5, res.confidence)
            else:
                self.assertEqual(50, res.confidence)

        self.assertEqual(count, 3)
Exemplo n.º 8
0
    def test_normalize(self):
        result = ParseResult('Number', None, 70)

        results = NumberWithNonNumbers.normalize([result])

        count = 0
        for res in results:
            count += 1
            self.assertEqual(res.confidence, 35)

        self.assertEqual(count, len(results))