Skip to content

Commit 705f0db

Browse files
authored
Merge pull request #34 from iscai-msft/entity_search
updated entity search samples
2 parents 1f08a93 + 5875cb0 commit 705f0db

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ENV/
100100
# mypy
101101
.mypy_cache/
102102

103-
# idea files
103+
# idea
104104
.idea/
105105

106106
#DS store

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ azure-cognitiveservices-language-luis
33
azure-cognitiveservices-language-spellcheck
44
azure-cognitiveservices-language-textanalytics>=0.2.0 # sample won't work with previous versions
55
azure-cognitiveservices-search-autosuggest
6+
azure-cognitiveservices-search-customsearch
7+
azure-cognitiveservices-search-entitysearch>=1.0
68
azure-cognitiveservices-search-customimagesearch
7-
azure-cognitiveservices-search-customsearch>=0.2.0 # sample won't work with previous versions
8-
azure-cognitiveservices-search-entitysearch
99
azure-cognitiveservices-search-imagesearch
1010
azure-cognitiveservices-search-newssearch
1111
azure-cognitiveservices-search-videosearch

samples/search/entity_search_samples.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from azure.cognitiveservices.search.entitysearch import EntitySearchAPI
1+
from azure.cognitiveservices.search.entitysearch import EntitySearchClient
22
from azure.cognitiveservices.search.entitysearch.models import Place, ErrorResponseException
33
from msrest.authentication import CognitiveServicesCredentials
44

@@ -11,7 +11,10 @@ def dominant_entity_lookup(subscription_key):
1111
1212
This will look up a single entity (Satya Nadella) and print out a short description about them.
1313
"""
14-
client = EntitySearchAPI(CognitiveServicesCredentials(subscription_key))
14+
client = EntitySearchClient(
15+
endpoint="https://api.cognitive.microsoft.com",
16+
credentials=CognitiveServicesCredentials(subscription_key)
17+
)
1518

1619
try:
1720
entity_data = client.entities.search(query="satya nadella")
@@ -41,7 +44,10 @@ def handling_disambiguation(subscription_key):
4144
4245
"This will handle disambiguation results for an ambiguous query (William Gates)".
4346
"""
44-
client = EntitySearchAPI(CognitiveServicesCredentials(subscription_key))
47+
client = EntitySearchClient(
48+
endpoint="https://api.cognitive.microsoft.com",
49+
credentials=CognitiveServicesCredentials(subscription_key)
50+
)
4551

4652
try:
4753
entity_data = client.entities.search(query="william gates")
@@ -89,7 +95,10 @@ def restaurant_lookup(subscription_key):
8995
9096
This will look up a single restaurant (john howie bellevue) and print out its phone number.
9197
"""
92-
client = EntitySearchAPI(CognitiveServicesCredentials(subscription_key))
98+
client = EntitySearchClient(
99+
endpoint="https://api.cognitive.microsoft.com",
100+
credentials=CognitiveServicesCredentials(subscription_key)
101+
)
93102

94103
try:
95104
entity_data = client.entities.search(query="john howie bellevue")
@@ -133,7 +142,10 @@ def multiple_restaurant_lookup(subscription_key):
133142
This will look up a list of restaurants (seattle restaurants) and present their names and phone numbers.
134143
"""
135144

136-
client = EntitySearchAPI(CognitiveServicesCredentials(subscription_key))
145+
client = EntitySearchClient(
146+
endpoint="https://api.cognitive.microsoft.com",
147+
credentials=CognitiveServicesCredentials(subscription_key)
148+
)
137149

138150
try:
139151
restaurants = client.entities.search(query="seattle restaurants")
@@ -176,7 +188,10 @@ def error(subscription_key):
176188
This triggers a bad request and shows how to read the error response.
177189
"""
178190

179-
client = EntitySearchAPI(CognitiveServicesCredentials(subscription_key))
191+
client = EntitySearchClient(
192+
endpoint="https://api.cognitive.microsoft.com",
193+
credentials=CognitiveServicesCredentials(subscription_key)
194+
)
180195

181196
try:
182197
entity_data = client.entities.search(
@@ -199,8 +214,8 @@ def error(subscription_key):
199214

200215

201216
if __name__ == "__main__":
202-
import sys
203-
import os.path
204-
sys.path.append(os.path.abspath(os.path.join(__file__, "..", "..")))
205-
from tools import execute_samples
217+
import sys, os.path
218+
sys.path.append(os.path.abspath(os.path.join(__file__, "..", "..")))
219+
from samples.tools import execute_samples
220+
import execute_samples
206221
execute_samples(globals(), SUBSCRIPTION_KEY_ENV_NAME)

0 commit comments

Comments
 (0)