Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9a47ded

Browse filesBrowse files
committed
Adding system test for language Document.analyze_entities().
1 parent 84e5e96 commit 9a47ded
Copy full SHA for 9a47ded

File tree

Expand file treeCollapse file tree

4 files changed

+75
-5
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+75
-5
lines changed

‎docs/language-usage.rst

Copy file name to clipboardExpand all lines: docs/language-usage.rst
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ metadata and other properties.
179179
name: Michelangelo Caravaggio
180180
type: PERSON
181181
metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/Caravaggio'}
182-
salience: 0.75942981
182+
salience: 0.7615959
183183
====================
184184
name: Italian
185185
type: LOCATION
186186
metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/Italy'}
187-
salience: 0.20193423
187+
salience: 0.19960518
188188
====================
189189
name: The Calling of Saint Matthew
190-
type: WORK_OF_ART
191-
metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/index.html?curid=2838808'}
192-
salience: 0.03863598
190+
type: EVENT
191+
metadata: {'wikipedia_url': 'http://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)'}
192+
salience: 0.038798928
193193
194194
Analyze Sentiment
195195
-----------------

‎system_tests/attempt_system_tests.py

Copy file name to clipboardExpand all lines: system_tests/attempt_system_tests.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'storage',
3636
'bigquery',
3737
'pubsub',
38+
'language',
3839
'logging',
3940
'translate',
4041
'monitoring',

‎system_tests/language.py

Copy file name to clipboard
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from gcloud import language
18+
19+
20+
class Config(object):
21+
"""Run-time configuration to be modified at set-up.
22+
23+
This is a mutable stand-in to allow test set-up to modify
24+
global state.
25+
"""
26+
CLIENT = None
27+
28+
29+
def setUpModule():
30+
Config.CLIENT = language.Client()
31+
32+
33+
class TestLanguage(unittest.TestCase):
34+
35+
def test_analyze_entities(self):
36+
from gcloud.language.entity import EntityType
37+
38+
text_content = ("Michelangelo Caravaggio, Italian painter, is "
39+
"known for 'The Calling of Saint Matthew'.")
40+
document = Config.CLIENT.document_from_text(text_content)
41+
entities = document.analyze_entities()
42+
self.assertEqual(len(entities), 3)
43+
entity1, entity2, entity3 = entities
44+
# Verify entity 1.
45+
self.assertEqual(entity1.name, 'Michelangelo Caravaggio')
46+
self.assertEqual(entity1.entity_type, EntityType.PERSON)
47+
self.assertTrue(0.7 < entity1.salience < 0.8)
48+
self.assertEqual(entity1.mentions, [entity1.name])
49+
self.assertEqual(entity1.metadata, {
50+
'wikipedia_url': 'http://en.wikipedia.org/wiki/Caravaggio',
51+
})
52+
# Verify entity 2.
53+
self.assertEqual(entity2.name, 'Italian')
54+
self.assertEqual(entity2.entity_type, EntityType.LOCATION)
55+
self.assertTrue(0.15 < entity2.salience < 0.25)
56+
self.assertEqual(entity2.mentions, [entity2.name])
57+
self.assertEqual(entity2.metadata, {
58+
'wikipedia_url': 'http://en.wikipedia.org/wiki/Italy',
59+
})
60+
# Verify entity 3.
61+
self.assertEqual(entity3.name, 'The Calling of Saint Matthew')
62+
self.assertEqual(entity3.entity_type, EntityType.EVENT)
63+
self.assertTrue(0 < entity3.salience < 0.1)
64+
self.assertEqual(entity3.mentions, [entity3.name])
65+
wiki_url = ('http://en.wikipedia.org/wiki/'
66+
'The_Calling_of_St_Matthew_(Caravaggio)')
67+
self.assertEqual(entity3.metadata, {'wikipedia_url': wiki_url})

‎system_tests/run_system_test.py

Copy file name to clipboardExpand all lines: system_tests/run_system_test.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import bigquery
2020
import bigtable
2121
import datastore
22+
import language
2223
import logging_
2324
import monitoring
2425
import pubsub
@@ -33,6 +34,7 @@
3334
'pubsub': pubsub,
3435
'bigquery': bigquery,
3536
'bigtable': bigtable,
37+
'language': language,
3638
'logging': logging_,
3739
'monitoring': monitoring,
3840
'translate': translate,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.