Retrieve the frequency of ngrams (1-4) derived from a corpus
This endpoint returns frequencies of ngrams of size 1-4. That is the number of times a word (ngram size = 1) or words (ngram size > 1) appear in the corpus. Ngrams are case sensitive ("I AM" and "I am" will have different frequency) and frequencies are calculated per word (true case) so "the book" and "the books" are two different ngrams. The results can be filtered based on query parameters. <br> <br> Parameters can be provided in PATH, GET or POST (form or json). The parameters in PATH are overridden by parameters in GET, POST and json (in that order). In PATH, individual options are separated by semicolon and values are separated by commas (where multiple values can be used). <br> <br> Example for bigrams (ngram of size 2):
-
PATH: /tokens=a word,another word
-
GET: /?tokens=a word&tokens=another word
-
POST (json):
{ "tokens": ["a word", "another word"] }
Either "tokens" or "contains" has to be provided. <br> <br> Some queries with "contains" or "sort" can exceed the 30s timeout, in which case the API will return an error message with status code 503. You mitigate this by providing additional restrictions such as "minFrequency" and "maxFrequency". <br> <br> You can use the parameters "offset" and "limit" to paginate through large result sets. For convenience, the HTTP header "Link" is set on the response to provide links to "first", "self", "next", "prev" and "last" pages of results (depending on the context). For example, if the result set contains 50 results and the parameter "limit" is set to 25, the Links header will contain an URL for the first 25 results and the next 25 results. <br> <br> Some libraries such as python's requests can parse the header automatically and offer a convenient way of iterating through the results. For example:
while url:
r = requests.get(url)
r.raise_for_status()
for item in r.json()['results']:
yield item
url = r.links.get('next', {}).get('url')
Path parameters
IANA language code
For corpora other than 'nmc' (New Monitor Corpus) please contact api@oxforddictionaries.com
the size of ngrams requested (1-4)
Query parameters
List of tokens to filter. The tokens are separated by spaces, the list items are separated by comma (e.g., for bigrams (n=2) tokens=this is,this was, this will)
Find ngrams containing the given token(s). Use comma or space as token separators; the order of tokens is irrelevant.
Flag specifying whether to lookup ngrams that include punctuation or not (possible values are "true" and "false"; default is "false")
Option specifying whether tokens should be returned as a single string (option "google") or as a list of strings (option "oup")
Restrict the query to entries with frequency of at least minFrequency
Restrict the query to entries with frequency of at most maxFrequency
Restrict the query to entries that appear in at least minDocumentFrequency documents
Restrict the query to entries that appera in at most maxDocumentFrequency documents
collate the results by wordform, trueCase, lemma, lexicalCategory. Multiple values can be separated by commas (e.g., collate=trueCase,lemma,lexicalCategory).
sort the resulting list by wordform, trueCase, lemma, lexicalCategory, frequency, normalizedFrequency. Descending order is achieved by prepending the value with the minus sign ('-'). Multiple values can be separated by commas (e.g., sort=lexicalCategory,-frequency)
pagination - results offset
pagination - results limit
Headers
App ID Authentication Parameter
App Key Authentication Parameter
Response
Successful response.