def test_definitions_in_one_sentence(self): sentence = 'The "Pope": the head of the Catholic Church.' definitions = list(get_definitions_in_sentence(sentence, return_sources=False)) self.assertEqual(1, len(definitions)) self.assertEqual('Pope', definitions[0].strip(' :"')) definitions = list(get_definitions_in_sentence(sentence, return_sources=True)) self.assertEqual(1, len(definitions)) self.assertEqual('Pope', definitions[0][0].strip(' :"'))
def _matches_definition_words(self, sentence: str) -> bool: if self._definition_words: terms = get_definitions_in_sentence(sentence) if not terms: return False terms = set([self._clean_def_words(t) for t in terms]) for w in self._definition_words: if w in terms: return True return False
def parse(self, text, text_unit_id, _text_unit_lang, **kwargs) -> ParseResults: found = list(definitions.get_definitions_in_sentence(text)) if found: unique = set(found) return ParseResults({ DefinitionUsage: [ DefinitionUsage(text_unit_id=text_unit_id, definition=item, count=found.count(item)) for item in unique ] })
def _matches_definition_words(self, text: str, text_is_sentence: bool) -> bool: if not self.detector.detector_definition_words: return False try: terms = get_definitions_in_sentence(text) \ if text_is_sentence else get_definitions(text) except Exception as e: msg = f'{self.get_detector_code()}: error in ' + \ f'_matches_definition_words("{text}"), ' + \ 'in get_definitions_in_sentence' if text_is_sentence \ else 'if get_definitions' e.detailed_error = msg raise if not terms: return False terms = set([self._clean_def_words(t) for t in terms]) for w in self.detector.detector_definition_words: if w in terms: return True return False
def test_the(self): text = '''The mean-\ning of our English term has shifted\nfrom character to actions-to external\nacts, manner of life, conduct, or\nhabits.''' definitions = list(get_definitions_in_sentence(text)) self.assertEqual(len(definitions), 0)
def test_trigger_word_fullmatches(self): text = '''(i)\nThe meanings given to terms defined herein shall be equally applicable to both\n the singular and plural forms of such terms.''' definitions = list(get_definitions_in_sentence(text)) self.assertEqual(len(definitions), 0)
def test_dot_in_definition(self): text = '''“U.S. Person” means any Person that is a “United States Person” as defined in Section 7701(a)(30) of the Code.''' definitions = list(get_definitions_in_sentence(text)) self.assertEqual(definitions[0], 'U.S. Person')