SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def detect_language(*documents):
  2.     '''Returns language detected for each string in documents (*args)'''
  3.    
  4.     params = urllib.parse.urlencode({})
  5.     headers = {
  6.         'Content-Type': 'application/json',
  7.         'Ocp-Apim-Subscription-Key': subscriptions['TextAnalytics']}
  8.    
  9.     # redefine body for proper text format
  10.     body={"documents": []}
  11.     ID = 0
  12.     for document in documents:
  13.        doc = {
  14.             # assign unique idea
  15.             "id": ID,
  16.             "text": "'{}'".format(document)
  17.         }
  18.        body['documents'].append(doc)
  19.        ID+= 1
  20.     body = json.dumps(body)
  21.    
  22.     r = send_request('/text/analytics/v2.0/languages', params=params, headers=headers, body=body)
  23.     return  [i['detectedLanguages'][0]['name'] for i in  r['documents']]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top