1 | 1 | # API |
---|
2 | 2 | |
---|
3 | | Briefly, ... |
---|
| 3 | This page gives a few examples of how to use the Tatoeba API. |
---|
4 | 4 | |
---|
5 | 5 | ## For one sentence |
---|
6 | 6 | |
---|
7 | | https://tatoeba.org/eng/api_v0/sentence/1 |
---|
|
|
| 7 | To retrieve sentence number 1: |
---|
| 8 | |
---|
| 9 | https://tatoeba.org/eng/api_v0/sentence/1 |
---|
8 | 10 | |
---|
9 | 11 | ## Search results |
---|
10 | 12 | |
---|
11 | | ### Search: Canadian (not an exact match, so gets "Canadians", too.) |
---|
12 | | from: eng |
---|
13 | | to: jpn |
---|
14 | | list: 907 |
---|
15 | | direct translations only |
---|
| 13 | ### Search: "Canadian" (not an exact match, so also matches "Canadians") |
---|
| 14 | from: **eng** |
---|
| 15 | to: **jpn** |
---|
| 16 | list: **907** |
---|
| 17 | translations: **direct only** |
---|
16 | 18 | |
---|
17 | | https://tatoeba.org/eng/api_v0/search?from=eng&list=907&query=Canadian&trans_filter=limit&trans_link=direct&trans_to=jpn&to=jpn |
---|
| 19 | https://tatoeba.org/eng/api_v0/search?from=eng&list=907&query=Canadian&trans_filter=limit&trans_link=direct&trans_to=jpn&to=jpn |
---|
18 | 20 | |
---|
19 | | ### Search: Boston |
---|
20 | | from: eng |
---|
21 | | to: jpn |
---|
22 | | audio: yes |
---|
23 | | sort: created |
---|
24 | | (direct and indirect translations) |
---|
| 21 | ### Search: "Boston" |
---|
| 22 | from: **eng** |
---|
| 23 | to: **jpn** |
---|
| 24 | audio: **yes** |
---|
| 25 | sort: **by creation date** |
---|
| 26 | translations: **direct and indirect** |
---|
25 | 27 | |
---|
26 | | https://tatoeba.org/eng/api_v0/search?from=eng&trans_filter=limit&query=Boston&sort=created&has_audio=yes&trans_to=jpn&to=jpn |
---|
| 28 | https://tatoeba.org/eng/api_v0/search?from=eng&trans_filter=limit&query=Boston&sort=created&has_audio=yes&trans_to=jpn&to=jpn |
---|
27 | 29 | |
---|
28 | | ### Search: =play (exact match) |
---|
29 | | from: eng |
---|
30 | | to: jpn |
---|
31 | | list: 907 |
---|
32 | | sort: words |
---|
33 | | direct translations only |
---|
| 30 | ### Search: "=play" (exact match) |
---|
| 31 | from: **eng** |
---|
| 32 | to: **jpn** |
---|
| 33 | list: **907** |
---|
| 34 | sort: **words** |
---|
| 35 | translations: **direct only** |
---|
34 | 36 | |
---|
35 | | https://tatoeba.org/eng/api_v0/search?from=eng&list=907&query=%3Dplay&sort=created&trans_filter=limit&trans_link=direct&trans_to=jpn&to=jpn |
---|
| 37 | https://tatoeba.org/eng/api_v0/search?from=eng&list=907&query=%3Dplay&sort=created&trans_filter=limit&trans_link=direct&trans_to=jpn&to=jpn |
---|
36 | 38 | |
---|
37 | 39 | |
---|
38 | 40 | ### Other |
---|
39 | 41 | |
---|
40 | | Do an advanced search, copy the resulting URL and change the first part of the URL to match the first part of the API URL. |
---|
| 42 | To figure out how to make a call to the API, perform an advanced search, then change the first part of the URL from this: |
---|
41 | 43 | |
---|
42 | | https://tatoeba.org/en/sentences/advanced_search |
---|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 | https://tatoeba.org/en/sentences |
---|
| 45 | |
---|
| 46 | to this: |
---|
| 47 | |
---|
| 48 | https://tatoeba.org/eng/api_v0 |
---|
| 49 | |
---|
| 50 | For instance, if you use the advanced search interface to select English sentences without audio that contain the word "those", you will see that the URL looks like this: |
---|
| 51 | |
---|
| 52 | https://tatoeba.org/en/sentences/search?from=eng&has_audio=no&native=&orphans=no&query=those&sort=relevance&sort_reverse=&tags=&to=&trans_filter=limit&trans_has_audio=&trans_link=&trans_orphan=&trans_to=&trans_unapproved=&trans_user=&unapproved=no&user= |
---|
| 53 | |
---|
| 54 | Change the first part of the URL in order to produce this URL that can be called against the API: |
---|
| 55 | |
---|
| 56 | https://tatoeba.org/eng/api_v0/search?from=eng&has_audio=no&native=&orphans=no&query=those&sort=relevance&sort_reverse=&tags=&to=&trans_filter=limit&trans_has_audio=&trans_link=&trans_orphan=&trans_to=&trans_unapproved=&trans_user=&unapproved=no&user= |
---|
43 | 57 | |
---|
44 | 58 | ## Paging |
---|
45 | 59 | |
---|
46 | | You can find out how many pages there thanks to the count and the perPage in the paging information. |
---|
| 60 | You can use the count and perPage in the paging information to find out how many pages are contained in the search results. For instance, the following call: |
---|
47 | 61 | |
---|
48 | | https://dev.tatoeba.org/eng/api_v0/search?from=eng&list=907&query=Canadian&trans_filter=limit&trans_link=direct&trans_to=jpn&to=jpn&page=2 |
---|
| 62 | https://dev.tatoeba.org/eng/api_v0/search?from=eng&list=907&query=Canadian&trans_filter=limit&trans_link=direct&trans_to=jpn&to=jpn&page=2 |
---|
49 | 63 | |
---|
50 | | "paging": { |
---|
51 | | "Sentences": { |
---|
52 | | "finder": "all", |
---|
53 | | "page": 2, |
---|
54 | | "current": 8, |
---|
55 | | "count": 18, |
---|
56 | | "perPage": 10, |
---|
57 | | "start": 11, |
---|
58 | | "end": 18, |
---|
59 | | "prevPage": true, |
---|
60 | | "nextPage": false, |
---|
61 | | "pageCount": 2, |
---|
62 | | "sort": null, |
---|
63 | | "direction": null, |
---|
64 | | "limit": null, |
---|
65 | | "sortDefault": false, |
---|
66 | | "directionDefault": false, |
---|
67 | | "scope": null, |
---|
68 | | "completeSort": [] |
---|
|
|
| 64 | will produce the following result: |
---|
| 65 | |
---|
| 66 | "paging": { |
---|
| 67 | "Sentences": { |
---|
| 68 | "finder": "all", |
---|
| 69 | "page": 2, |
---|
| 70 | "current": 8, |
---|
| 71 | "count": 18, |
---|
| 72 | "perPage": 10, |
---|
| 73 | "start": 11, |
---|
| 74 | "end": 18, |
---|
| 75 | "prevPage": true, |
---|
| 76 | "nextPage": false, |
---|
| 77 | "pageCount": 2, |
---|
| 78 | "sort": null, |
---|
| 79 | "direction": null, |
---|
| 80 | "limit": null, |
---|
| 81 | "sortDefault": false, |
---|
| 82 | "directionDefault": false, |
---|
| 83 | "scope": null, |
---|
| 84 | "completeSort": [] |
---|
69 | 85 | } |
---|
70 | 86 | }, |
---|
71 | 87 | |
---|
72 | 88 | |
---|
73 | 89 | |
---|
74 | | The properties you'll be interested in are: |
---|
| 90 | The relevant properties are: |
---|
75 | 91 | |
---|
76 | | page - this is the current page. |
---|
77 | | current - this is the number of items displayed in the current page. |
---|
78 | | count - this is the total number of results. |
---|
79 | | perPage - this is the number of results per page. |
---|
80 | | To know how many pages there are in total, you divide count by perPage and round up to the upper integer. |
---|
|
| 92 | - `page`: current page |
---|
| 93 | - `current`: number of items displayed in the current page |
---|
| 94 | - `count`: total number of results |
---|
| 95 | - `perPage`: number of results per page |
---|
| 96 | |
---|
| 97 | To find the number of pages in total, divide `count` by `perPage` and round up to the nearest integer. |
---|
81 | 98 | |
---|
82 | 99 | |
---|
83 | 100 | |
---|
84 | 101 | |
---|
85 | | ## For information on the API, ... |
---|
| 102 | ## For more information on the API |
---|
86 | 103 | |
---|
87 | | See https://github.com/Tatoeba/tatoeba2/issues/2669 |
---|
| 104 | See Tatoeba/tatoeba2 GitHub issue [#2669][1]. |
---|
88 | 105 | |
---|
| 106 | [1]: https://github.com/Tatoeba/tatoeba2/issues/2669 |
---|
89 | 107 | |
---|
90 | | |
---|
diff view generated by jsdifflib |
---|