概要

校異源氏物語テキストDBで公開するTEI/XMLファイルに対するDTS(Distributed Text Services) APIを作成したので、備忘録です。

背景

校異源氏物語テキストDBは以下です。

https://kouigenjimonogatari.github.io/

TEI/XMLファイルを公開しています。

開発したDTS

開発したDTSは以下です。

https://dts-typescript.vercel.app/api/dts

Express.jsをVercelに設置しています。

DTSは以下を参考にしてください。

MyCapytainライブラリ

以下の記事で、DTSをPythonから利用するライブラリを紹介しました。

本ライブラリを使用して、開発したDTSを利用してみます。

Create the resolver

With the following line we create the resolver :

frreosmolMvyeCrap=ytHatitnp.DrtessRoelsvoelrvse.rd(t"sh.tatppis_:v/1/ditmsp-otrytpeHstctrpiDptts.Rveesroclevle.rapp/api/dts")

Require metadata : let’s visit the catalog

The following code is gonna find each text that is readable by Alpheios

#r##rpoerWoTiaiethtdneatg=ndb(eol"trweeWees_etschornofeleolovttlurerenorihcdo.eattgvvi%eeeosctnoMdsscleyeoltne=leaanlcdmretaiaocitcnotoaaytin(l.o)lmrnyiessaasdtliahlnbaglttehtDceeeaxsnrtceseba:neddabapbenaltrecssDaeerdse"cfeu%nldlawenintt(shre:tahdiiatsblboern_oecwosolenleahcuuttgioeomnarste)ip)coasliltyortiheesAPIuntil
Wefound54collectionsthatcanbeparsed

Printing the full tree

##dpserhNIfioofnwtsft_eyho(toorrrtuwoeh_spsoeaaturht(trrbio.reecnwioweot_doen(l(t)toclcr)ctoeheolcaeufltr(laei_sdmconuitnubali_mclioibosandelor,,rl*eswcs"ceihu-tetab-ihrc"oa_onnrnl+,deulcme"cmubcharet"aksrirei=o+_v1nnai)sut:iumtynbbr,ceecoretol+hll1oele)fecncttetihxioetonn.cl.iaicdtnh)aeilslodgmr.iegnh.titbeemsa()b:itcomplicated
defauurlnuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuut:rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrknnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnno::::::::::::::::::::::::::::::::::::::::::::::::::::::ukkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkiooooooooooooooooooooooooooooooooooooooooooooooooooooooguuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuueiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiinggggggggggggggggggggggggggggggggggggggggggggggggggggggjeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeinnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnmjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjoiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiinmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmooooooooooooooooooooooooooooooooooooooooooooooooooooooognnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnaooooooooooooooooooooooooooooooooooooooooooooooooooooootggggggggggggggggggggggggggggggggggggggggggggggggggggggaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarttttttttttttttttttttttttttttttttttttttttttttttttttttttiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrriiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii......................................................123456789111111111122222222223333333333444444444455555012345678901234567890123456789012345678901234

Printing details about a specific one

#f#rc#ltpraoaerLoTnlNbxiemhdloetnte_ewl_t'rici(saintl=d"nndieTgddeotc=reoexn'oetmxslca==loiainpelnmerrrclgrpeaeiteaodnanic`nrsddtot"dtiani+otnbi.olmrotlngnaa(efe.bonb0_otiende,cr_dleioml+nbllaa"!teeltb`tneiew(colwertn(ieei)tnao?hdn0asib[dalrnea"d_ncd+to_hlitelneedxncetutx_mi]iboden)rs)o)fcollections
Treaing``withidurn:kouigenjimonogatari.47

What about more detailed informations ? Like the citation scheme ?

dpprerrefiicnnurfttreo((scr""iuMCvrspraiesurext_ibiciapvcnumtreitruii_t(smonpacintrthvciiiaeiSnnor_tygtn_pas_inrttcniuiieignmnomt_btn"accei)tiirnditt*geoaa"_pntt-ct_ii-ihsoo"tcnna:h_.+tesci"mch"o,ehin(el"_ccmdsooer+cll(ehllcnseeei:umcctbettac(iitisooitunnoab..ntccc,iiiiotttcnaaah.tttaniiiraooo_mnnnne,.)u)dmcebhpeatrrh=_)1n)u:mber+1)
MCaixtialmtiuinmoenciStyasttieomndepth:1

Let’s get some references !

rp#erfiNfnistc(e=re!rfefsso)lver.getReffs(collection.id)
#r##rpoerWoTiaiethtdneatg=ndb(eol"trweeWees_etschornofeleolovttlurerenorihcdo.eattgvvi%eeeosctnoMdsscleyeoltne=leaanlcdmretaiaocitcnotoaaytin(l.o)lmrnyiessaasdtliahlnbaglttehtDceeeaxsnrtceseba:neddabapbenaltrecssDaeerdse"cfeu%nldlawenintt(shre:tahdiiatsblboern_oecwosolenleahcuuttgioeomnarste)ip)coasliltyortiheesAPIuntil

0

Let’s get some random passage !

#r##rpoerWoTiaiethtdneatg=ndb(eol"trweeWees_etschornofeleolovttlurerenorihcdo.eattgvvi%eeeosctnoMdsscleyeoltne=leaanlcdmretaiaocitcnotoaaytin(l.o)lmrnyiessaasdtliahlnbaglttehtDceeeaxsnrtceseba:neddabapbenaltrecssDaeerdse"cfeu%nldlawenintt(shre:tahdiiatsblboern_oecwosolenleahcuuttgioeomnarste)ip)coasliltyortiheesAPIuntil

1

#r##rpoerWoTiaiethtdneatg=ndb(eol"trweeWees_etschornofeleolovttlurerenorihcdo.eattgvvi%eeeosctnoMdsscleyeoltne=leaanlcdmretaiaocitcnotoaaytin(l.o)lmrnyiessaasdtliahlnbaglttehtDceeeaxsnrtceseba:neddabapbenaltrecssDaeerdse"cfeu%nldlawenintt(shre:tahdiiatsblboern_oecwosolenleahcuuttgioeomnarste)ip)coasliltyortiheesAPIuntil

2

考察

上記の通り、MyCapytainライブラリの基本操作に対応したDTSを構築することができました。

上記ではPythonから利用しましたが、例えば以下のように、ブラウザからも利用できます。以下は桐壺の1行目を取得する例です。

https://dts-typescript.vercel.app/api/dts/document?id=urn:kouigenjimonogatari.1&ref=https://w3id.org/kouigenjimonogatari/api/items/0005-01.json

注意

今回は以下のAPIを参考に開発しました。

https://texts.alpheios.net/api/dts

ただし、上記APIは以下の最新のガイドラインに対応しているのかは未確認です。

https://distributed-text-services.github.io/specifications/

そのため、今回開発したDTS APIも上記のガイドラインに非対応の箇所がある可能性がある点にご注意ください。

まとめ

DTSの理解にあたり、参考になりましたら幸いです。