概要

校異源氏物語に対する類似テキスト検索アプリを作成しました。以下のURLからお試しいただけます。

https://huggingface.co/spaces/nakamura196/genji_predict

本アプリの使用方法などについて紹介します。

データ

以下の校異源氏物語DBで公開されているテキストデータを使用します。

https://kouigenjimonogatari.github.io/

アプリの内容

仕組みは単純で、校異源氏物語の巻毎・ページ毎のテキストを用意しておき、入力された文字列との編集距離を算出し、類似度が高いテキスト(+巻とページ)を返却します。

ソースコードは以下です。

https://huggingface.co/spaces/nakamura196/genji_predict/tree/main

応用例

例えば、以下の「[源氏物語] [4](東京大学総合図書館所蔵)」では、1つのIIIFマニフェスト内に複数の巻が含まれており、何コマ目から何コマ目までが何巻に属するのか、素人には判断が難しい場合があります。

https://da.dl.itc.u-tokyo.ac.jp/portal/assets/b90bbddc-509d-7c12-0fb9-af409a90a487

そこで、上記に資料に対してコマ毎のOCRテキストを取得し、今回作成したアプリに問い合わせることで、ページ毎に推定される巻数が提示され、巻の変わり目を知る手助けを行うことができます。

OCR

OCRにあたっては、NDL古典籍OCR-Liteを使用します。

https://github.com/ndl-lab/ndlkotenocr-lite

OCR結果を修正して、以下のようなTEI/XMLを作成しました。

<<<<???TxxxE<<mmmIt/tllle<te<--xif/exbvmmmHi<<<fito<<<eoolelt/p/s/iH>da/a/arddnaei<tu<<po<sleyb<<<<<<<<ab<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ab<<<<<<<<<<<<seesdDttibpduub/oea>lslslslsblslslslslslslslslslslslslslslslslslslsblslslslslslsill=eelitluabri<buDdnbebebebe>nbebebebebebebebebebebebebebebebebebebe>nbebebebebebeo"rsetlibtlcbpiree=/g/g/g/g=/g/g/g/g/g/g/g/g/g/g/g/g/g/g/g/g/g/g/g=/g/g/g/g/g/gnhhh>cSlecleieltbcsr">>>>">>>>>>>>>>>>>>>>>>>">>>>>>=rrt>teSai>cD>rlec>1tttt2ttttttttttttttttttt3tttttt"eetm>tts2ae>D>"yyyy"yyyyyyyyyyyyyyyyyyy"yyyyyy1ffptOmih0tsteppppppppppppppppppppppppppppp.==:>Ctoe2icasteeeeteeeeeeeeeeeeeeeeeeeteeeeee0""/R>nr5o>rcy====y===================y======"hh/S>-ng>p""""p"""""""""""""""""""p""""""ttwtN0Seeeeettw:mD1tt===nppwtL-m=""""""""""""""""""""""""""""""""c::.h>2t"pppo/tt9>hannnnannnnnnnnnnnnnnnnnnnannnnnnd/et<tg====g===================g======iwwipO/te""""e"""""""""""""""""""e""""""nww-sCdp"1345"1234567891111111111"123456gwwc:Ras"""""""""""""0123456789""""""=.../-t:ff""""""""""f"tto/Le/accccacccccccccaccccccUeerii>/coooocooooooooocccccccccccooooooTiigitisrrrrsrrrrrrrrroooooooooosrrrrrrF--/iei=rrrr=rrrrrrrrrrrrrrrrrrr=rrrrrr-ccnf<i"eeee"eeeeeeeeerrrrrrrrrr"eeeeee8..s./fhsssshssssssssseeeeeeeeeehssssss"oo/dp.tpppptpppppppppsssssssssstpppppp?rr1ludt====t=========ppppppppppt======>gg..blp""""p"""""""""==========p""""""/0il.s####s#########""""""""""s######rr"tii:zzzz:zzzzzzzzz##########:zzzzzzee>cst/oooo/ooooooooozzzzzzzzzz/ooooooll.hc/nnnn/nnnnnnnnnoooooooooo/nnnnnneeue.ieeeeieeeeeeeeennnnnnnnnnieeeeeeaa-rui----i---------eeeeeeeeeei------sst>-i1111i222222222----------i333333eeotf----f---------2222222222f------//ko.1345.123456789----------.123456xxykd""""d"""""""""1111111111d""""""mmoyl>>>>l>>>>>>>>>0123456789l>>>>>>ll.o.."""""""""".//a.ii>>>>>>>>>>ittcat<ttee.cc/<c<ciij..s</././/pjue/<susucc/p-gs/e-e-uur/t>esgtgtsseroge>o><ottpek>gk/kooopy>ysymm/oooeo//i/..g.ssiiaa>acciiccc<hhfi..<<<./<<<ee/fjj/<//j<s///<mmb/pp<s</ss<p/esss/aa9b///e/se<e<<<//sgeees//09iisgseg/g/</</s<ie>gggerrb0iie>eg>s>s/s/<s<e/ig>>>geebbiigg>eese<s/e/gsi>>lldbff>>ggeg/esgs>efaadd//>>g>sge>eg/xxcdss>e>gg>snn-coog>>ogg5-tt>t//05ooott90___eed9oooii-dggg__7-aaaaac7iiill1c___ll21222..-2000rr0-222nnf0333ggbf111""9b000-9///tta-AAAyyfa000pp4f555ee04___==90444""a9///aa9a000pp09000ppa0444ll4a///ii84AAAcc78000aa/7555ttm/___iiam444oona___nnin000//fi000xxef444mmse___llts000""<t000/"000sst/123cci>...hhtttteeliiimmefffaa>///ttfffyyuuuppllleelllnn///ssfff==uuu""lllhhllltt///tt000pp///::ddd/eee/fffrpaaaeuuuulrlllaltttx....nojjjgcppp.lgggoc"""r.>>>grngsdsstdrlu/cstcuhreem/a1t.r0o"n?">?>

推定

上記のXMLファイルを入力として、先に紹介したGradioアプリのAPIを利用します。

fiifcdddtprmmrleeeeroppoifffiemoome_drrne"lrf"frp#r#ei#pf#pxigttttx"ieo"ierolfrormcrqt"ntr"rteXoeeriltajxd=reumsudMtmldn_(dsmmasratriLeieiitrptptiolCcnt_nc=nmlc,eer(aeon.ilt=_rttietxsejti_emi_pef(Estm_etudsh_ctpeters'tTerllqaioxlronel.eu{e.=>nee=tupcn=miertxejdlfiptsmeit.leet(tmoioti_ar0suee=r__d"_n."_eiclrxro:lnxynru.ptEtnfnnt-=smso=tttc=aem/alqart(iptletsrltmspotiedko.loar__(.eiaieeusuhmmmamfingerptfl=ncex=l(t)pem_in_eseaeietnt"tpponulner'ustinm{t_t,/srurtrid.eluh_de}qt.p[ettTanatstl,xandeprid.r1eleu[tmltmxre]ixCe9s"lxl0[llls(tedcmle6("(tt]"i_([e_di=tli/e""([vmp":nfic_"eagl.fr0oia.lurctfrnsee/e]ltt/imot"oetnmrs"=h/mem(rsEje*u]-)*ir_muTin[ll}1.[talal_t@it-)g@]tittp)tn)"{:eten_sr:ye:"fty(ep,ep"irp#esrdeiroel(eei=nso=eednc'tt'mlistl_(peecu"ir)anmtr)'negteie]esesno_"su',tna))l])_st"1rc[))ei")sip:u=alFgtae#(l"rs]eee}ns,'uumlietnr)daetnet(=e4l)e)ments,1)1

結果、以下のような結果が得られます。キーはコマ数、値は{巻数}-{校異源氏物語のページ数}です。以下の結果から、2コマ目から第7巻が始まり、29または30コマ目(また40または41コマ目)で巻が変わっているように思われます。

{}"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""1234567891111111111222222222233333333334444444444555555555566666666667777777777888888888899"""""""""0123456789012345678901234567890123456789012345678901234567890123456789012345678901:::::::::""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"""""""""377777777""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""3--------7777777777777777777788888888888999999999999999999999999999999999999999999999999911-22222222--------------------------------------------------------------------------------3-13333444422222222222222222222222222222222222222222222222222233333333333333333333333333333-5078990123444444555555555556666677777777788888888999999999999000000000001111111111222222224"1""""""""4567890123445678901299112345678334567890012345677890123455678901223457890123345679,,,,,,,,""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""8",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,",,

実際に30コマ目を確認すると、巻が変わっていることが確認できます。

また41コマ目は以下です。

まとめ

くずし字に対するOCR精度の向上により、様々な応用が可能になっているように思います。画像の公開および提供機関、OCRプログラムの開発に携わっている方々に感謝いたします。