Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def detect_language(*documents):
- '''Returns language detected for each string in documents (*args)'''
- params = urllib.parse.urlencode({})
- headers = {
- 'Content-Type': 'application/json',
- 'Ocp-Apim-Subscription-Key': subscriptions['TextAnalytics']}
- # redefine body for proper text format
- body={"documents": []}
- ID = 0
- for document in documents:
- doc = {
- # assign unique idea
- "id": ID,
- "text": "'{}'".format(document)
- }
- body['documents'].append(doc)
- ID+= 1
- body = json.dumps(body)
- r = send_request('/text/analytics/v2.0/languages', params=params, headers=headers, body=body)
- return [i['detectedLanguages'][0]['name'] for i in r['documents']]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement