Ejemplo n.º 1
0
    def en_parsers_speed(self):
        file_path = os.path.join(lexnlp_test_path, 'long_parsed_text.txt')
        with codecs.open(file_path, 'r', encoding='utf-8') as fr:
            text = fr.read()

        ge_path = os.path.join(lexnlp_test_path, 'lexnlp/extract/en/tests/test_geoentities/')
        entities_fn = ge_path + 'geoentities.csv'
        aliases_fn = ge_path + 'geoaliases.csv'
        geo_config = list(DictionaryEntry.load_entities_from_files(entities_fn, aliases_fn))

        times = {}  # type: Dict[str, float]
        self.check_time(text, lambda s: list(get_amounts(s)), 'get_amounts', times)
        self.check_time(text, lambda s: list(get_acts(s)), 'get_acts', times)
        self.check_time(text, lambda s: list(get_citations(s)), 'get_citations', times)
        self.check_time(text, lambda s: list(get_conditions(s)), 'get_conditions', times)
        self.check_time(text, lambda s: list(get_constraints(s)), 'get_constraints', times)
        self.check_time(text, lambda s: list(get_copyright(s)), 'get_copyright', times)
        self.check_time(text, lambda s: list(_get_courts(s)), 'get_courts', times)
        self.check_time(text, lambda s: list(get_cusip(s)), 'get_cusip', times)
        self.check_time(text, lambda s: list(get_dates(s)), 'get_dates', times)
        self.check_time(text, lambda s: list(get_definitions(s)), 'get_definitions', times)
        self.check_time(text, lambda s: list(get_distances(s)), 'get_distances', times)
        self.check_time(text, lambda s: list(get_durations(s)), 'get_durations', times)
        self.check_time(text, lambda s: list(get_geoentities(s, geo_config)), 'get_geoentities', times)
        self.check_time(text, lambda s: list(get_money(s)), 'get_money', times)
        self.check_time(text, lambda s: list(get_percents(s)), 'get_percents', times)
        self.check_time(text, lambda s: list(get_pii(s)), 'get_pii', times)
        self.check_time(text, lambda s: list(get_ratios(s)), 'get_ratios', times)
        self.check_time(text, lambda s: list(get_regulations(s)), 'get_regulations', times)
        self.check_time(text, lambda s: list(get_trademarks(s)), 'get_trademarks', times)
        self.check_time(text, lambda s: list(get_urls(s)), 'get_urls', times)

        self.assertTrue('get_amounts' in times)
Ejemplo n.º 2
0
    def test_percent(self):
        text = "I'm 146.5 percent sure (or just 100%)"
        ds = list(get_percents(text))
        self.assertEqual(2, len(ds))

        ants = list(get_percent_annotations(text))
        self.assertEqual(2, len(ants))
        self.assertEqual('en', ants[0].locale)
        self.assertEqual('percent', ants[0].sign)
        self.assertEqual(146.5, ants[0].amount)

        self.assertEqual('%', ants[1].sign)
        self.assertEqual(100.0, ants[1].amount)
Ejemplo n.º 3
0
 def parse(self, text, text_unit_id, _text_unit_lang,
           **kwargs) -> ParseResults:
     found = list(percents.get_percents(text, return_sources=True))
     if found:
         unique = set(found)
         return ParseResults({
             PercentUsage: [
                 PercentUsage(text_unit_id=text_unit_id,
                              amount=item[1],
                              amount_str=item[3],
                              unit_type=item[0],
                              total=item[2],
                              count=found.count(item)) for item in unique
             ]
         })
Ejemplo n.º 4
0
 def _extract_variants_from_text(self, text: str, **kwargs):
     percents = list(get_percents(text, float_digits=8))
     if not percents:
         return None
     return [percent[2] * 100 for percent in percents]
Ejemplo n.º 5
0
 def getPercentages(self):
     mem = []
     percentages = list(get_percents(self.bill_text))
     for percent in percentages:
         mem.append(str(percent[1]) + str(percent[0]))
     self.bill.info['percentages'] = mem