diff --git a/docs/language-usage.rst b/docs/language-usage.rst index 62ecff14fc01a..e8d8212b10af6 100644 --- a/docs/language-usage.rst +++ b/docs/language-usage.rst @@ -179,17 +179,17 @@ metadata and other properties. name: Michelangelo Caravaggio type: PERSON metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/Caravaggio'} - salience: 0.75942981 + salience: 0.7615959 ==================== name: Italian type: LOCATION metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/Italy'} - salience: 0.20193423 + salience: 0.19960518 ==================== name: The Calling of Saint Matthew - type: WORK_OF_ART - metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/index.html?curid=2838808'} - salience: 0.03863598 + type: EVENT + metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)'} + salience: 0.038798928 Analyze Sentiment ----------------- diff --git a/system_tests/attempt_system_tests.py b/system_tests/attempt_system_tests.py index 5c53db1c61848..ce97a97fd33c5 100644 --- a/system_tests/attempt_system_tests.py +++ b/system_tests/attempt_system_tests.py @@ -35,6 +35,7 @@ 'storage', 'bigquery', 'pubsub', + 'language', 'logging', 'translate', 'monitoring', diff --git a/system_tests/language.py b/system_tests/language.py new file mode 100644 index 0000000000000..a84b28cfd5c39 --- /dev/null +++ b/system_tests/language.py @@ -0,0 +1,69 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from gcloud import language + +from system_test_utils import unique_resource_id + + +class Config(object): + """Run-time configuration to be modified at set-up. + + This is a mutable stand-in to allow test set-up to modify + global state. + """ + CLIENT = None + + +def setUpModule(): + Config.CLIENT = language.Client() + + +class TestLanguage(unittest.TestCase): + + def test_analyze_entities(self): + from gcloud.language.entity import EntityType + + text_content = ("Michelangelo Caravaggio, Italian painter, is " + "known for 'The Calling of Saint Matthew'.") + document = Config.CLIENT.document_from_text(text_content) + entities = document.analyze_entities() + self.assertEqual(len(entities), 3) + entity1, entity2, entity3 = entities + # Verify entity 1. + self.assertEqual(entity1.name, 'Michelangelo Caravaggio') + self.assertEqual(entity1.entity_type, EntityType.PERSON) + self.assertTrue(0.7 < entity1.salience < 0.8) + self.assertEqual(entity1.mentions, [entity1.name]) + self.assertEqual(entity1.metadata, { + 'wikipedia_url': 'http://en.wikipedia.org/wiki/Caravaggio', + }) + # Verify entity 2. + self.assertEqual(entity2.name, 'Italian') + self.assertEqual(entity2.entity_type, EntityType.LOCATION) + self.assertTrue(0.15 < entity2.salience < 0.25) + self.assertEqual(entity2.mentions, [entity2.name]) + self.assertEqual(entity2.metadata, { + 'wikipedia_url': 'http://en.wikipedia.org/wiki/Italy', + }) + # Verify entity 3. + self.assertEqual(entity3.name, 'The Calling of Saint Matthew') + self.assertEqual(entity3.entity_type, EntityType.EVENT) + self.assertTrue(0 < entity3.salience < 0.1) + self.assertEqual(entity3.mentions, [entity3.name]) + wiki_url = ('http://en.wikipedia.org/wiki/' + 'The_Calling_of_St_Matthew_(Caravaggio)') + self.assertEqual(entity3.metadata, {'wikipedia_url': wiki_url}) diff --git a/system_tests/run_system_test.py b/system_tests/run_system_test.py index 2fd6ff93fc2df..d3593db8be22e 100644 --- a/system_tests/run_system_test.py +++ b/system_tests/run_system_test.py @@ -19,6 +19,7 @@ import bigquery import bigtable import datastore +import language import logging_ import monitoring import pubsub @@ -33,6 +34,7 @@ 'pubsub': pubsub, 'bigquery': bigquery, 'bigtable': bigtable, + 'language': language, 'logging': logging_, 'monitoring': monitoring, 'translate': translate,