11package detectlanguage
22
3+ import "context"
4+
35// DetectRequest contains language detection request params
46type DetectRequest struct {
57 Query string `json:"q"`
68}
79
8- // DetectResponse is a resource containing language detection response
9- type DetectResponse struct {
10- Data * DetectResponseData `json:"data"`
11- }
12-
13- // DetectResponseData contains language detection response data
14- type DetectResponseData struct {
15- Detections []* DetectionResult `json:"detections"`
16- }
17-
1810// DetectionResult is single language detection result
1911type DetectionResult struct {
20- Language string `json:"language"`
21- Reliable bool `json:"isReliable"`
22- Confidence float32 `json:"confidence"`
12+ Language string `json:"language"`
13+ Score float64 `json:"score"`
2314}
2415
2516// DetectBatchRequest contains batch language detection request params
2617type DetectBatchRequest struct {
2718 Query []string `json:"q"`
2819}
2920
30- // DetectBatchResponse is a resource batch containing language detection response
31- type DetectBatchResponse struct {
32- Data * DetectBatchResponseData `json:"data"`
33- }
34-
35- // DetectBatchResponseData contains batch language detection response data
36- type DetectBatchResponseData struct {
37- Detections [][]* DetectionResult `json:"detections"`
38- }
39-
4021// Detect executes language detection for a single text
4122func (c * Client ) Detect (in string ) (out []* DetectionResult , err error ) {
42- var response DetectResponse
43- err = c .post (nil , "detect" , & DetectRequest {Query : in }, & response )
23+ var response [] * DetectionResult
24+ err = c .post (context . TODO () , "detect" , & DetectRequest {Query : in }, & response )
4425
4526 if err != nil {
4627 return nil , err
4728 }
4829
49- return response . Data . Detections , err
30+ return response , err
5031}
5132
5233// DetectCode executes language detection for a single text and returns detected language code
@@ -67,12 +48,12 @@ func (c *Client) DetectCode(in string) (out string, err error) {
6748// DetectBatch executes language detection with multiple texts.
6849// It is significantly faster than doing a separate request for each text indivdually.
6950func (c * Client ) DetectBatch (in []string ) (out [][]* DetectionResult , err error ) {
70- var response DetectBatchResponse
71- err = c .post (nil , "detect" , & DetectBatchRequest {Query : in }, & response )
51+ var response [][] * DetectionResult
52+ err = c .post (nil , "detect-batch " , & DetectBatchRequest {Query : in }, & response )
7253
7354 if err != nil {
7455 return nil , err
7556 }
7657
77- return response . Data . Detections , err
58+ return response , err
7859}
0 commit comments