예제 #1
0
    def test_constructor_defaults(self):
        from google.cloud.language.entity import Mention
        from google.cloud.language.entity import MentionType
        from google.cloud.language.entity import TextSpan

        name = 'Italian'
        entity_type = 'LOCATION'
        wiki_url = 'http://en.wikipedia.org/wiki/Italy'
        metadata = {
            'foo': 'bar',
            'wikipedia_url': wiki_url,
        }
        salience = 0.19960518
        mentions = [
            Mention(
                mention_type=MentionType.PROPER,
                text=TextSpan(content='Italian', begin_offset=0),
            )
        ]
        entity = self._make_one(name, entity_type, metadata, salience,
                                mentions)
        self.assertEqual(entity.name, name)
        self.assertEqual(entity.entity_type, entity_type)
        self.assertEqual(entity.metadata, metadata)
        self.assertEqual(entity.salience, salience)
        self.assertEqual(entity.mentions, mentions)
예제 #2
0
    def test_from_api_repr(self):
        from google.cloud.language.entity import Mention
        from google.cloud.language.entity import MentionType
        from google.cloud.language.entity import TextSpan

        mention = Mention.from_api_repr(self.PAYLOAD)

        self.assertIsInstance(mention, Mention)
        self.assertIsInstance(mention.text, TextSpan)
        self.assertEqual(mention.text.content, 'Greece')
        self.assertEqual(mention.text.begin_offset, 42)
        self.assertEqual(mention.mention_type, MentionType.PROPER)
예제 #3
0
    def test_constructor(self):
        from google.cloud.language.entity import Mention
        from google.cloud.language.entity import MentionType
        from google.cloud.language.entity import TextSpan

        mention = Mention(
            text=TextSpan(content='snails', begin_offset=90),
            mention_type=MentionType.COMMON,
        )

        self.assertIsInstance(mention.text, TextSpan)
        self.assertEqual(mention.text.content, 'snails')
        self.assertEqual(mention.text.begin_offset, 90)
        self.assertEqual(mention.mention_type, MentionType.COMMON)
예제 #4
0
    def test_dunder_str(self):
        from google.cloud.language.entity import Mention

        mention = Mention.from_api_repr(self.PAYLOAD)
        self.assertEqual(str(mention), 'Greece')