Package: udkanbun
UD-KanbunTokenizer, POS-Tagger, and Dependency-Parser for Classical Chinese Texts (漢文/文言文), working onUniversal Dependencies.Basic usage>>>importudkanbun>>>lzh=udkanbun.load()>>>s=lzh("不入虎穴不得虎子")>>>print(s)# text = 不入虎穴不得虎子1不不ADVv,副詞,否定,無界Polarity=Neg2advmod_Gloss=not|SpaceAfter=No2入入VERBv,動詞,行為,移動_0root_Gloss=enter|SpaceAfter=No3虎虎NOUNn,名詞,主体,動物_4nmod_Gloss=tiger|SpaceAfter=No4穴穴NOUNn,名詞,固定物,地形Case=Loc2obj_Gloss=cave|SpaceAfter=No5不不ADVv,副詞,否定,無界Polarity=Neg6advmod_Gloss=not|SpaceAfter=No6得得VERBv,動詞,行為,得失_2parataxis_Gloss=get|SpaceAfter=No7虎虎NOUNn,名詞,主体,動物_8nmod_Gloss=tiger|SpaceAfter=No8子子NOUNn,名詞,人,関係_6obj_Gloss=child|SpaceAfter=No>>>t=s[1]>>>print(t.id,t.form,t.lemma,t.upos,t.xpos,t.feats,t.head.id,t.deprel,t.deps,t.misc)1不不ADVv,副詞,否定,無界Polarity=Neg2advmod_Gloss=not|SpaceAfter=No>>>print(s.kaeriten())不㆑入㆓虎穴㆒不㆑得㆓虎子㆒>>>print(s.to_tree())不<════╗advmod入═══╗═╝═╗root虎<╗║║nmod穴═╝<╝║obj不<════╗║advmod得═══╗═╝<╝parataxis虎<╗║nmod子═╝<╝obj>>>f=open("trial.svg","w")>>>f.write(s.to_svg())>>>f.close()udkanbun.load()has three optionsudkanbun.load(MeCab=True,Danku=False).  By default, the UD-Kanbun pipeline usesMeCabfor tokenizer and POS-tagger, then usesUDPipefor dependency-parser. With the optionMeCab=Falsethe pipeline uses UDPipe for all through the processing. With the optionDanku=Truethe pipeline tries to segment sentences automatically.udkanbun.UDKanbunEntry.to_tree()has an optionto_tree(BoxDrawingWidth=2)for old terminals, whose Box Drawing characters are "fullwidth".to_tree(kaeriten=True,Japanese=True)is convenient for Japanese users.You can simply useudkanbunon the command line:echo不入虎穴不得虎子|udkanbunUsage via spaCyIf you have already installedspaCy2.1.0 or later, you can use UD-Kanbun via spaCy Language pipeline.>>>importudkanbun.spacy>>>lzh=udkanbun.spacy.load()>>>d=lzh("不入虎穴不得虎子")>>>print(type(d))<class'spacy.tokens.doc.Doc'>>>>print(udkanbun.spacy.to_conllu(d))# text = 不入虎穴不得虎子1不不ADVv,副詞,否定,無界_2advmod_Gloss=not|SpaceAfter=No2入入VERBv,動詞,行為,移動_0root_Gloss=enter|SpaceAfter=No3虎虎NOUNn,名詞,主体,動物_4nmod_Gloss=tiger|SpaceAfter=No4穴穴NOUNn,名詞,固定物,地形_2obj_Gloss=cave|SpaceAfter=No5不不ADVv,副詞,否定,無界_6advmod_Gloss=not|SpaceAfter=No6得得VERBv,動詞,行為,得失_2parataxis_Gloss=get|SpaceAfter=No7虎虎NOUNn,名詞,主体,動物_8nmod_Gloss=tiger|SpaceAfter=No8子子NOUNn,名詞,人,関係_6obj_Gloss=child|SpaceAfter=No>>>t=d[0]>>>print(t.i+1,t.orth_,t.lemma_,t.pos_,t.tag_,t.head.i+1,t.dep_,t.whitespace_,t.norm_)1不不ADVv,副詞,否定,無界2advmodnotInstallation for LinuxTar-ball is available for Linux, and is installed by default when you usepip:pipinstalludkanbunInstallation for CygwinMake sure to getgcc-g++python37-pippython37-develpackages, and then:pip3.7installudkanbunUsepython3.7command inCygwininstead ofpython.Installation for Jupyter Notebook (Google Colaboratory)!pipinstalludkanbunTrynotebookfor Google Colaboratory.AuthorKoichi Yasuoka (安岡孝一)ReferencesKoichi Yasuoka:Universal Dependencies Treebank of the Four Books in Classical Chinese, DADH2019: 10th International Conference of Digital Archives and Digital Humanities (December 2019), pp.20-28.安岡孝一:四書を学んだMeCab＋UDPipeはセンター試験の漢文を読めるのか, 東洋学へのコンピュータ利用, 第30回研究セミナー (2019年3月8日), pp.3-110.安岡孝一:漢文の依存文法解析と返り点の関係について, 日本漢字学会第1回研究大会予稿集 (2018年12月1日), pp.33-48.