MCPcopy Index your code
hub / github.com/clips/pattern / identify

Method identify

pattern/web/__init__.py:1093–1111  ·  view source on GitHub ↗

Returns a (language, confidence)-tuple for the given string. Google Translate is a paid service, license without billing raises HTTP401Authentication.

(self, string, **kwargs)

Source from the content-addressed store, hash-verified

1091 return u(data)
1092
1093 def identify(self, string, **kwargs):
1094 """ Returns a (language, confidence)-tuple for the given string.
1095 Google Translate is a paid service, license without billing raises HTTP401Authentication.
1096 """
1097 url = URL("https://www.googleapis.com/language/translate/v2/detect?", method=GET, query={
1098 "key": self.license or GOOGLE_LICENSE,
1099 "q": string[:1000]
1100 })
1101 kwargs.setdefault("cached", False)
1102 kwargs.setdefault("unicode", True)
1103 kwargs.setdefault("throttle", self.throttle)
1104 try:
1105 data = url.download(**kwargs)
1106 except HTTP403Forbidden:
1107 raise HTTP401Authentication, "Google translate API is a paid service"
1108 data = json.loads(data)
1109 data = data.get("data", {}).get("detections", [[{}]])[0][0]
1110 data = u(data.get("language")), float(data.get("confidence"))
1111 return data
1112
1113#--- YAHOO -----------------------------------------------------------------------------------------
1114# Yahoo! Search is a web search engine owned by Yahoo! Inc.

Callers 2

test_google_identifyMethod · 0.80

Calls 4

downloadMethod · 0.95
URLClass · 0.85
setdefaultMethod · 0.45
getMethod · 0.45

Tested by 1

test_google_identifyMethod · 0.64