Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.54k stars 2.77k forks source link

EntitySearchClient.entities.search returns NoneType as entities results #9732

Closed siminchengithub closed 4 years ago

siminchengithub commented 4 years ago

Describe the bug The EntitySearch python sdk returns NoneType as entity search results for query "RED BAY HOSPITAL". However on https://azure.microsoft.com/en-us/services/cognitive-services/bing-entity-search-api/ it returns the correct entity.

To Reproduce Steps to reproduce the behavior:

  1. Install azure.cognitiveservices.search.entitysearch 2.0.0
  2. Run following code from azure.cognitiveservices.search.entitysearch import EntitySearchClient from msrest.authentication import CognitiveServicesCredentials key = <your-key> client = EntitySearchClient('https://api.cognitive.microsoft.com', CognitiveServicesCredentials(key)) entity_data = client.entities.search(query="RED BAY HOSPITAL", market = 'en-US') if entity_data.entities.value: main_entities = [entity for entity in entity_data.entities.value if entity.entity_presentation_info.entity_scenario == "DominantEntity"] if main_entities: print(main_entities[0].description)

Expected behavior I expect no error

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @dfulcer

v-xuto commented 4 years ago

Hi @siminchengithub, Please update "if entity_data.entities.value:" to "if entity_data.places.value:" in code.

Because the Entity Search API lets you send a search query to Bing and get back search results that include entities and places:

The detailed code is shown below for how to use rename_file (here is the official sample ):

from azure.cognitiveservices.search.entitysearch import EntitySearchClient  
from msrest.authentication import CognitiveServicesCredentials  

key = <your-key> 
client = EntitySearchClient('https://api.cognitive.microsoft.com', CognitiveServicesCredentials(key)) 

entity_data = client.entities.search(query="RED BAY HOSPITAL",market = 'en-US')  
# Your question appears this step. 
if entity_data.places.value: 
    hospital = entity_data.places.value[0] 
    try: 
        telephone = hospital.telephone 
        print( 
            'Searched for "RED BAY HOSPITAL" and found a hospital with this phone number:') 
        print(telephone) 
    except AttributeError: 
        print("Couldn't find a place!") 
else: 
    print("Didn't see any data..") 

@jongio

v-xuto commented 4 years ago

Hi @siminchengithub , How is this issue going? Feel free to let us know if further help is needed.

tzhanl commented 4 years ago

We are going to close this issue because we haven’t heard from you in a few days, but please re-open it if the issue still persists.