LoginSignup
7
5

More than 3 years have passed since last update.

Oxford Dictionaries APIの使い方

Posted at

Oxford Dictionaries APIとは

一言でいえば、かの有名なOxford Universityが提供する35か国語対応の辞書APIです。
月1000アクセスまでは無償で(商用も含めた)利用が可能です。
詳細はこちら

FAQより抜粋&意訳

Who built the Oxford Dictionaries API?

The Oxford Dictionaries API was built by a team in Oxford Dictionaries which is a part of Oxford University Press. You can find out more about our API here, and more about Oxford Dictionaries here.

Q:誰がOxford Dictionaries APIを作ったの?
A:Oxford University出版局のOxford Dictionaries部門のチームによって構築されました。
詳しくはこちら

What can I do with the Oxford Dictionaries API?

The Oxford Dictionaries API offers an easy way to access powerful lexical data (words, definitions, translations, audio pronunciations, synonyms, antonyms, parts of speech, and more) to use in your apps and websites. Please read our Terms and Conditions before signing up. If you would like to discuss your use of the API then please complete the Enterprise form to contact us.

Q:何ができる?
A:自然言語処理(見出し語変換や定義、翻訳、類義語など)。

Which dictionary does the API data come from?

The Oxford Dictionaries API provides access to our current English dictionaries which are available on en.oxforddictionaries.com. This is our most comprehensive current English dictionary dataset and includes enhanced, updated versions of the Oxford Dictionary of English and the New Oxford American Dictionary. It includes more than 350,000 entries and is regularly updated with new words, senses, and definitions.
We also have content in Spanish, German, Portuguese, Romanian, isiZulu, Northern Sotho, Malay, Indonesian...and many more, and we're adding more all the time. Take a look at our supported languages page for the most up-to-date list.

Q:データはどこから?
A:こちらのサイトで利用しているものと同じ。

Which languages do you support?

In the API, we currently offer content in English, Spanish, German, Portuguese, Romanian, isiZulu, Northern Sotho, Latvian, Malay, Indonesian...and many more, and we're adding more all the time. Take a look at our supported languages page for the most up-to-date list.
If you’re looking for a dictionary dataset for a language which isn’t currently available via the API, we might still be able to help. We have over 35 language datasets, from Afrikaans to Vietnamese, available to license via Oxford Dictionaries Licensing. We are also building content in 100 of the world's languages, many of which are digitally under-represented, as part of our Oxford Global Languages initiative.

Q:対応言語は?
A:英語、スペイン語、ドイツ語、ポルトガル語、ルーマニア語、ズールー語、北ソト語、ラトビア語、マレー語、インドネシア語など。

アカウントの作り方

  1. こちらからサイトにアクセスし、Get your API keyをクリック
    ox1.jpg

  2. (無料枠で運用したい場合は)左枠のPrototypeのGET STARTEDをクリック
    ox2.jpg

  3. 必要事項を記入。なお"Please tell us more about your application"は短くても大丈夫(自分の場合はTo develop English learning bot.としました)。
    ox3.jpg

  4. 入力したアドレスにメールが来るので、アカウントアクティベート用のURLをクリック。

  5. アクティベート完了後にトップページに戻り、Sign In
    ox1.jpg

使い方

  1. サインイン後はトップページに(API) CREDENTIALSが追加されるので、そこをクリック
    ox4.jpg

  2. 自分で設定したアプリ名をクリック
    ox5.jpg

  3. Application IDとApplication KEYを確認
    ox6.jpg

  4. 以下コピペ

app_id = "Your own ID"
app_key = "Your own Key"
language = "en-gb"
word = "Word you want to search"
url = "https://od-api.oxforddictionaries.com:443/api/v2/entries/" + language + "/" + word.lower()
response = requests.get(url, headers={"app_id":app_id, "app_key":app_key})

response.status_codeが200であれば成功、それ以外であれば失敗

status_code Message
400 Invalid value for filters such as lexicalCategory, registers, domains, etc. Invalid value for fields projections accepted. It is not possible to project a non-existing field.
404 No entry was found matching the selection parameters; OR an invalid filter was specified.
414 URL is too long.
500 Internal error. An error occurred during processing.

試し方

  1. DOCUMENTATIONタブのV2 SWAGGER DOCSをクリック
    ox7.jpg

  2. 下の方にあるExpand Operationsをクリック
    ox8.jpg

  3. 確認したいプログラミング言語を選択]
    ox9.jpg

例:Pythonを選択
ox9-extra.jpg

python
# for more information on how to install requests
# http://docs.python-requests.org/en/master/user/install/#install
import requests
import json

# TODO: replace with your own app_id and app_key
app_id = '<my_app_id>'
app_key = '<my_app_key>'

language = 'en-gb'
word_id = 'Ace'
fields = 'pronunciations'
strictMatch = 'false'

url = 'https://od-api.oxforddictionaries.com:443/api/v2/entries/' + language + '/' + word_id.lower() + '?fields=' + fields + '&strictMatch=' + strictMatch;

r = requests.get(url, headers = {'app_id': app_id, 'app_key': app_key})

print("code {}\n".format(r.status_code))
print("text \n" + r.text)
print("json \n" + json.dumps(r.json()))
  1. word_idに調べたい単語の「原形」を入力
    ox9.jpg

  2. Try it outをクリック
    ox10.jpg

  3. Try it outの下に表示されるAPIの返り値を確認
    ox11.jpg

最後に

月1000回まではちょっと少ない気もしますが、いろいろ使えそうです!

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5