API

注釈

API機能はベータ版であり、予告なく機能が変更・停止される場合があります。 API is under development (beta), and its functionality may change or be suspended without notice.

一覧 Contents catalog

対応形式 Formats

下記の手段によるコンテンツ一覧情報の取得に対応しています。 Listing of MDR contents can be obtained by using the methods below:

  • HTML

  • JSON

  • RDF (Turtle)

  • RSS

以下のURLによって、HTMLでworkとcollectionを一覧することができます。 The list of all works and collections can be accessed as a web page using the following URL:

このURLの catalog のあとに .rss.ttl, .json の拡張子を付加することにより、それぞれの形式で全件一覧を取得できます。 By appending the file extension .rss, .ttl, or .json after catalog in that URL, you can obtain the list in respective formats.

全件一覧に限らず、各種の絞り込み検索条件に対しこれが実行できます。まずブラウザで 検索機能と "Limit your search" 絞り込み により、希望する絞り込み条件を指定してください。このときのURLに拡張子を足すことにより、同じ条件の一覧をそれぞれの形式で取得できます。 You can do the same for more limited searches, not just for a list of everything. First, drill down the search conditions that you want by keyword search an/or "Limit your search" filters using your browser. Then, by adding the extensions as above, you can obtain the list in respective formats.

Example

例えば、"XAFS" をキーワードに含み、"Tantalum nitride" を試料とするデータ一覧を取得するURLは以下の通りです。 For example, these URLs will allow you to obtain list of works containing "XAFS" as one of their keywords and have "Tantalum nitride" as the specimen.

  • HTML: https://mdr.nims.go.jp/catalog?f%5Bkeyword_sim%5D%5B%5D=XAFS&f%5Bspecimen_set_sim%5D%5B%5D=Tantalum+nitride

  • JSON: https://mdr.nims.go.jp/catalog.json?f%5Bkeyword_sim%5D%5B%5D=XAFS&f%5Bspecimen_set_sim%5D%5B%5D=Tantalum+nitride

RDF, RSS も同様。 Same for RDF and RSS.

catalog.json

最も多くの機能を持つのはJSON形式であるため、ここでは特にそのフォーマットについて記します。最上位に response という要素、その下位に docs, facet, pages という3つの要素があります。 JSON is the format with the richest response. You will find response at the highest level, and elements docs, facet, and pages will be nested in there.

docs:

検索条件に合致する結果の配列(デフォルトでは10件ずつ)。 An array containing the works and collections that match the current search conditions, with 10 results being shown per page by default.

id:
MDR上でのwork/collectionのID。このIDを用いて、各workに関する情報を個別に取得 できます。
The MDR identifier for the work/collection. You can use this ID to obtain metadata about individual works.
date_uploaded_dtsi:

アップロード日。 Uploaded date.

date_modified_dtsi:

更新日。 Modified date.

その他/Others:
各種メタデータ。 Various metadata.
facet:

現在の結果からさらに絞り込み可能なメタデータ一覧の配列と、それで絞り込んだ場合に返る件数。 The list of metadata filters that you can add to refine your search, based on your current results. Also includes the number of results to be expected when adding that filter.

name:

絞り込みに使えるメタデータ項目名。 Metadata key available for filtering.

label:

その項目のラベル。 Label for said metadata key.

items/value:

絞り込みに使えるメタデータの値。 Metadata value available for filtering.

items/hits:

その項目で絞り込んだ場合期待される結果件数。 Number of results expected when filtering by said value.

pages:

結果件数、ページ情報など。 Number of results and pagination.

current_page:

現在のページ番号。 Current page number.

next_page:

次のページ番号。Next page number.

prev_page:

前のページ番号。Previous page number.

total_pages:

この結果に対する合計ページ数。 Total number of pages available for this search condition.

limit_value:
1ページあたりの表示件数。 Number of results in a page.
offset_value:

現在の結果一覧は何件目から表示しているか。 The value indicating the offset of current array within the whole result.

total_count:

現在の検索条件に一致する総数。 The total number of results matching the current search conditions.

first_page?:

最初のページか否かを示す真偽値。 Boolean indicating if this is the first page.

last_page?:

最後のページか否かを示す真偽値。 Boolean indicating if this is the last page.

ページ操作 Pagination

以下のURLパラメーターを足すことにより、結果一覧のページ操作が可能です。 By adding the following URL parameters, you can obtain different pages of the results and control how many works to be returned in a page.

per_page:

1ページあたりの表示件数。整数。最大値100。 How many results to be returned in a page. Integer. Maximum 100.

page:

結果一覧のページ番号。整数。 Page number. Integer.

JSONの場合は応答の response.pages を見ると、次のページがあるかどうかが判別できます。

Example

例えば下記のようにすると一度に20件を取得できます。 For example, the following will request 20 results per page.

https://mdr.nims.go.jp/catalog.json?f[keyword_sim][]=XAFS&f[specimen_set_sim][]=Tantalum+nitride&per_page=20

個別 Individual works

Metadata

各 Work の URL は https://mdr.nims.go.jp/concern/publications/abcdefghi のような形ですが、この最後の9桁からなる ID の後に .ttl.json の拡張子を付加することにより、それぞれの形式で Work のメタデータを取得できます。

The URL for each work is in the form that looks like this: https://mdr.nims.go.jp/concern/publications/abcdefghi By appending the file extension .ttl or .json after the nine-digit identifier in the URL, you can obtain the work's metadata in respective formats.

  • https://mdr.nims.go.jp/concern/publications/abcdefghi.ttl

  • https://mdr.nims.go.jp/concern/publications/abcdefghi.json

URLの最後に ?locale=en などが付く場合がありますが、拡張子はその前につけてください。

The URL may have the parameter ?locale=en at the end, but the file extension should go before that.

Download

IDが例えば abcdefghi の Work に対し https://mdr.nims.go.jp/download_all/abcdefghi.zip の形式のリソースを要求することにより、Work に属する Item(ファイル)全件をまとめた ZIP アーカイブを取得することができます。

By requesting, for example, a URL in the form of https://mdr.nims.go.jp/download_all/abcdefghi.zip for a work ID abcdefghi, you can obtain a ZIP archive containing all the item files for the work.

応用例 Application

一括DL Bulk download

以上の機能を応用した例として、指定した絞り込み条件でのデータを一括取得するPythonスクリプトを作ることができます。 As an example, you could write a Python script like this to obtain all the files for works that match the conditions that you specify.

注意

ここに示したスクリプト例は参考情報として提供するものであり、これまたはこの派生物を使用した結果生じた事象についてNIMSは責任を負いません。

This script is only meant to illustrate an example, and NIMS is not responsible for any outcome caused by using this script or its derivatives.

短時間の集中的なダウンロードは自動的にブロックされる場合があります。ブロックが発動した場合、ブラウザでのアクセスを含めてMDRが利用できなくなる場合があります。適度に間隔を開けていただきますようお願いします。

Too many requests over a short period of time may trigger an automatic block. When that happens, you may not be able to browse MDR including access from your web browser. Please limit your script to a reasonable amount of requests.

想定手順 How to use:

  1. ブラウザから検索・絞り込み機能を用いて、希望する条件のURLを得る。 Using your web browser, decide what search/filter conditions you would like to use.

  2. python3 mdr_zip_dl_example.py https://mdr.nims.go.jp/catalog?... のような形で、引数としてURLを渡す。 Give the URL as an argument for the Python script.

  3. 手元にZIPファイルが保存されます。 ZIP files will be downloaded to your machine.

リスト 1 mdr_zip_dl_example.py
 1import sys
 2import requests
 3import json
 4import urllib.parse
 5
 6def update_query(url, key, org_val, new_val):
 7    pr = urllib.parse.urlparse(url)
 8    d = urllib.parse.parse_qs(pr.query)
 9    l = d.get(key)
10    if l:
11        d[key] = [new_val if v == org_val else v for v in l]
12    else:
13        d[key] = new_val
14    return urllib.parse.urlunparse(pr._replace(query=urllib.parse.urlencode(d, doseq=True)))
15
16if len(sys.argv) != 2 or not sys.argv[1]:
17    print("Usage:  python "+sys.argv[0]+" 'https://mdr.nims.go.jp/catalog?...'")
18    sys.exit()
19url = sys.argv[1]
20
21if "catalog?" in url:
22    url = url.replace("catalog", "catalog.json")
23
24response = json.loads(requests.get(url).text)
25current_page = response['response']['pages']['current_page']
26last_page = response['response']['pages']['last_page?']
27id_list = [ sub['id'] for sub in response['response']['docs'] ]
28
29while not last_page:
30    next_page = int(current_page) + 1
31    url = update_query(url, 'page', current_page, next_page)
32    response = json.loads(requests.get(url).text)
33    id_sublist = [ sub['id'] for sub in response['response']['docs'] ]
34    id_list = id_list + id_sublist
35    current_page = response['response']['pages']['current_page']
36    last_page = response['response']['pages']['last_page?']
37
38for work_id in id_list:
39    download_url = "https://mdr.nims.go.jp/download_all/" + work_id + ".zip"
40    print(download_url)
41    z = requests.get(download_url, allow_redirects=True)
42    open(work_id + '.zip', 'wb').write(z.content)