LoginSignup
0
1

国会図書館の収蔵漏れを API を使って調べる

Last updated at Posted at 2023-11-16

日本国内で書籍を出版した場合、国会図書館に納本する義務があります。残念ながら全ての出版社がこの義務を果たしているわけではないため、このような嘆きのポストになっているのが現状です。

では実際のところどれくらい収蔵漏れがあるのか、国会図書館サーチ API を使って調べてみました。手前味噌ですが、私の書いた API の解説記事はこちら(実際これ書いておいたおかげで今の自分がめっちゃ助かった)。

国会図書館サーチ API だけでは実際にどの書籍が収蔵漏れになっているのかわかりませんので、比較用として Google Books API を使用しました。

スクリプト

require 'net/http'
require 'rexml/document'
require 'json'
require 'erb'
include ERB::Util

creator = '紫堂恭子'

idx=1
ndl_books = []
loop do
  ndl_uri = "https://iss.ndl.go.jp/api/opensearch?dpid=iss-ndl-opac&creator=#{url_encode(creator)}&cnt=200&idx=#{idx}"
  response = Net::HTTP.get_response(URI.parse(ndl_uri))
  items = REXML::Document.new(response.body).get_elements('//item')
  break if items.empty?
  ndl_books = items.map do |item|
    {
      title: item.elements['title'].text,
      volume: item.elements['dcndl:volume']&.text,
      isbn: item.elements['dc:identifier[@xsi:type="dcndl:ISBN"]']&.text
    }
  end
  idx += 200
  sleep 1
end

startIndex = 0
google_books = []
loop do
  google_uri = "https://www.googleapis.com/books/v1/volumes?printType=books&q=inauthor:#{url_encode(creator)}&maxResults=40&startIndex=#{startIndex}"
  response = Net::HTTP.get_response(URI.parse(google_uri))
  items = JSON::parse(response.body)['items']
  break if items.nil?
  _google_books = items.map do |item|
    {
      title: item['volumeInfo']['title'],
      isbn10: item['volumeInfo']['industryIdentifiers']&.select {|e| e['type'] == 'ISBN_10'}&.first&.fetch('identifier'),
      isbn13: item['volumeInfo']['industryIdentifiers']&.select {|e| e['type'] == 'ISBN_13'}&.first&.fetch('identifier')
    }
  end
  google_books += _google_books
  startIndex += 40
  sleep 1
end
google_books = google_books.select {|e| e[:isbn10] || e[:isbn13]}

result = google_books.reject do |item|
  ndl_books.any? {|e| e[:isbn] == item[:isbn10] || e[:isbn] == item[:isbn13]}
end
pp result

国会図書館サーチ API はそのままでは提携している全てのデータプロバイダのデータをマージして出力しますので、プロバイダIDとして「国立国会図書館オンライン(データプロバイダID:iss-ndl-opac)」を指定しています。

また、全ての蔵書を対象にしてしまうと件数が多すぎてわけがわからなくなるので、例として著者に「紫堂恭子」と指定しています。

比較には ISBN を使用しました。タイトルでも比較したいのですが、タイトルの表記揺れや巻数の扱いの差があるため、今回の簡易比較では断念しました。

その ISBN ですが、国会図書館サーチ API ではほぼ登録されているのですが、ISBN-10 か ISBN-13 かは特に決まりはないようでバラバラです。Google Books API では ISBN-10 と ISBN-13 の両方が登録されているのですが、登録が漏れている書籍データが結構あります。ISBN が無いものは比較しようがないので、今回は全て省いています。

国会図書館サーチ API の結果例
<item>
<title>イセングリムの夜警</title>
<link>https://iss.ndl.go.jp/books/R100000002-I023757475-00</link>
<description>
<![CDATA[ <p>1,朝日新聞出版,9784022140975</p> <ul><li>タイトル: イセングリムの夜警</li> <li>タイトル(読み): イセングリム ノ ヤケイ</li> <li>責任表示: 紫堂恭子 著,</li> <li>シリーズ名: ASAHIコミックス</li> <li>シリーズ名(読み): アサヒ コミックス</li> <li>NDC(9): 726.1</li> </ul> ]]>
</description>
<author>紫堂恭子 著,紫堂, 恭子,</author>
<category></category>
<guid isPermaLink="true">https://iss.ndl.go.jp/books/R100000002-I023757475-00</guid>
<pubDate>Mon, 22 Nov 2021 09:00:00 +0900</pubDate>
<dc:title>イセングリムの夜警</dc:title>
<dcndl:titleTranscription>イセングリム ノ ヤケイ</dcndl:titleTranscription>
<dc:creator>紫堂, 恭子</dc:creator>
<dcndl:creatorTranscription>シトウ, キョウコ</dcndl:creatorTranscription>
<dcndl:volume>1</dcndl:volume>
<dcndl:seriesTitle>ASAHIコミックス</dcndl:seriesTitle>
<dcndl:seriesTitleTranscription>アサヒ コミックス</dcndl:seriesTitleTranscription>
<dc:publisher>朝日新聞出版</dc:publisher>
<dc:date>2012.7</dc:date>
<dcterms:issued xsi:type="dcterms:W3CDTF">2012</dcterms:issued>
<dcndl:price>620円</dcndl:price>
<dc:extent>1冊 ; 19cm</dc:extent>
<dc:identifier xsi:type="dcndl:ISBN">9784022140975</dc:identifier>
<dc:identifier xsi:type="dcndl:NDLBibID">023757475</dc:identifier>
<dc:identifier xsi:type="dcndl:JPNO">22094748</dc:identifier>
<dc:identifier xsi:type="dcndl:TOHANMARCNO">32778767</dc:identifier>
<dcndl:genre>漫画</dcndl:genre>
<dc:subject xsi:type="dcndl:NDLC">Y84</dc:subject>
<dc:subject xsi:type="dcndl:NDC9">726.1</dc:subject>
<rdfs:seeAlso rdf:resource="http://id.ndl.go.jp/bib/023757475"/>
</item>
  • 巻数が <dcndl:volume>1</dcndl:volume> としてタイトルとは別項目になっている。
  • ISBN はこの書籍では <dc:identifier xsi:type="dcndl:ISBN">9784022140975</dc:identifier> と ISBN-13
Google Books API の結果例
    {
      "kind": "books#volume",
      "id": "to3KEAAAQBAJ",
      "etag": "CFSs4uf6se8",
      "selfLink": "https://www.googleapis.com/books/v1/volumes/to3KEAAAQBAJ",
      "volumeInfo": {
        "title": "魔女の箱庭 1",
        "authors": [
          "紫堂恭子"
        ],
        "publisher": "秋田書店",
        "publishedDate": "2023-08-16",
        "description": "レイラが暮らす村には「村人が村の外に出ると村に大きな不幸が訪れる」という言い伝えがある。村人たちは村の中で幸せに暮らし、けして村の外にでることはなかった。しかし、村を囲む塀の外からの助けを求める声に反応し、塀を乗り越えてしまったレイラだったが…!?",
        "industryIdentifiers": [
          {
            "type": "OTHER",
            "identifier": "PKEY:BT000138545100100101900209"
          }
        ],
        "readingModes": {
          "text": true,
          "image": true
        },
        "pageCount": 164,
        "printType": "BOOK",
        "categories": [
          "Comics & Graphic Novels"
        ],
        "maturityRating": "NOT_MATURE",
        "allowAnonLogging": false,
        "contentVersion": "1.2.1.0.preview.3",
        "panelizationSummary": {
          "containsEpubBubbles": true,
          "containsImageBubbles": true,
          "epubBubbleVersion": "cb88ade5d7d61c5f_A",
          "imageBubbleVersion": "cb88ade5d7d61c5f_A"
        },
        "imageLinks": {
          "smallThumbnail": "http://books.google.com/books/content?id=to3KEAAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
          "thumbnail": "http://books.google.com/books/content?id=to3KEAAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
        },
        "language": "ja",
        "previewLink": "http://books.google.co.jp/books?id=to3KEAAAQBAJ&printsec=frontcover&dq=inauthor:%E7%B4%AB%E5%A0%82%E6%81%AD%E5%AD%90&hl=&as_pt=BOOKS&cd=1&source=gbs_api",
        "infoLink": "https://play.google.com/store/books/details?id=to3KEAAAQBAJ&source=gbs_api",
        "canonicalVolumeLink": "https://play.google.com/store/books/details?id=to3KEAAAQBAJ"
      },
      "saleInfo": {
        "country": "JP",
        "saleability": "FOR_SALE",
        "isEbook": true,
        "listPrice": {
          "amount": 660,
          "currencyCode": "JPY"
        },
        "retailPrice": {
          "amount": 594,
          "currencyCode": "JPY"
        },
        "buyLink": "https://play.google.com/store/books/details?id=to3KEAAAQBAJ&rdid=book-to3KEAAAQBAJ&rdot=1&source=gbs_api",
        "offers": [
          {
            "finskyOfferType": 1,
            "listPrice": {
              "amountInMicros": 660000000,
              "currencyCode": "JPY"
            },
            "retailPrice": {
              "amountInMicros": 594000000,
              "currencyCode": "JPY"
            }
          }
        ]
      },
      "accessInfo": {
        "country": "JP",
        "viewability": "PARTIAL",
        "embeddable": true,
        "publicDomain": false,
        "textToSpeechPermission": "ALLOWED",
        "epub": {
          "isAvailable": true,
          "acsTokenLink": "http://books.google.co.jp/books/download/%E9%AD%94%E5%A5%B3%E3%81%AE%E7%AE%B1%E5%BA%AD_%EF%BC%91-sample-epub.acsm?id=to3KEAAAQBAJ&format=epub&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api"
        },
        "pdf": {
          "isAvailable": true,
          "acsTokenLink": "http://books.google.co.jp/books/download/%E9%AD%94%E5%A5%B3%E3%81%AE%E7%AE%B1%E5%BA%AD_%EF%BC%91-sample-pdf.acsm?id=to3KEAAAQBAJ&format=pdf&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api"
        },
        "webReaderLink": "http://play.google.com/books/reader?id=to3KEAAAQBAJ&hl=&as_pt=BOOKS&source=gbs_api",
        "accessViewStatus": "SAMPLE",
        "quoteSharingAllowed": false
      },
      "searchInfo": {
        "textSnippet": "レイラが暮らす村には「村人が村の外に出ると村に大きな不幸が訪れる」という言い伝えがある。村人たちは村の中で幸せに暮らし、けして村の外にでることはなかった。しかし ..."
      }
    },
  • 巻数は"title": "魔女の箱庭 1"とタイトルに含まれている。
  • この書籍では ISBN の登録は無し。ISBN がある場合は以下のような項目が含まれる。
        "industryIdentifiers": [
          {
            "type": "ISBN_10",
            "identifier": "4091720714"
          },
          {
            "type": "ISBN_13",
            "identifier": "9784091720719"
          }
        ],

タイトルの表記揺れとしては グラン・ローヴァ物語 : 決定版(国会図書館サーチ API)と グラン・ローヴァ物語 2(決定版)(Google Books API)などがありました。

比較結果

[{:title=>"魔女の箱庭 2", :isbn10=>"4253265774", :isbn13=>"9784253265775"},
 {:title=>"姬神町物語: 孩子的約定", :isbn10=>"9861141103", :isbn13=>"9789861141107"},
 {:title=>"グラン・ロ一ヴァ物語", :isbn10=>"4267902607", :isbn13=>"9784267902604"},
 {:title=>"姬神町物語: 神隱傳說", :isbn10=>"9861141219", :isbn13=>"9789861141213"},
 {:title=>"魔法使物語-銀枝傳奇", :isbn10=>"9576436710", :isbn13=>"9789576436710"},
 {:title=>"东凯尔·羊角村", :isbn10=>"9867664248", :isbn13=>"9789867664242"},
 {:title=>"王國之鑰", :isbn10=>"9867189442", :isbn13=>"9789867189448"},
 {:title=>"王國之鑰", :isbn10=>"9867664752", :isbn13=>"9789867664754"}]

「魔女の箱庭 2巻」は2024年1月発売予定ですから収蔵されていなくても当たり前です。Google Books API では既に登録されているのですね。

「グラン・ロ一ヴァ物語」は巻数が登録されていませんが、ISBN から調べたところ潮出版社版の4巻ですね。

その他は海外で出版されたもののようです。

所感

API によって巻数をタイトルに含めるか、別項目で持つかというデータスキーマの違いがあるのはやっかいですね。書籍データの流通を考えると、データの規格があると便利なのかもしれません(既にあったりする?)

タイトルの表記揺れもやっかいですが、これはどうしようもないのかなぁという気がします。

比較用に Google Books API を使用しましたが、こちらも登録漏れが結構ありました。Amazon など他の API も試してみるといいかもしれませんね。登録されている書籍でも ISBN が抜けているものは今回は比較に使えなかったのも残念なところです。

0
1
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
0
1