Skip to main content

Tokenizer POS-tagger and Dependency-parser for Classical Chinese

Project description

Current PyPI packages

GuwenCOMBO

Tokenizer, POS-Tagger, and Dependency-Parser for Classical Chinese Texts (漢文/文言文), working with COMBO-pytorch.

Basic usage

>>> import guwencombo
>>> lzh=guwencombo.load()
>>> s=lzh("不入虎穴不得虎子")
>>> print(s)
# text = 不入虎穴不得虎子
1			ADV	v,副詞,否定,無界	Polarity=Neg	2	advmod	_	Gloss=not|SpaceAfter=No
2			VERB	v,動詞,行為,移動	_	0	root	_	Gloss=enter|SpaceAfter=No
3			NOUN	n,名詞,主体,動物	_	4	nmod	_	Gloss=tiger|SpaceAfter=No
4			NOUN	n,名詞,固定物,地形	Case=Loc	2	obj	_	Gloss=cave|SpaceAfter=No
5			ADV	v,副詞,否定,無界	Polarity=Neg	6	advmod	_	Gloss=not|SpaceAfter=No
6			VERB	v,動詞,行為,得失	_	2	parataxis	_	Gloss=get|SpaceAfter=No
7			NOUN	n,名詞,主体,動物	_	8	nmod	_	Gloss=tiger|SpaceAfter=No
8			NOUN	n,名詞,,関係	_	6	obj	_	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   ADV v,副詞,否定,無界 Polarity=Neg 2 advmod _ Gloss=not|SpaceAfter=No

>>> print(s.to_tree())
 <════╗   advmod
 ═══╗═╝═╗ root
 <     nmod
 ═╝<    obj
 <════╗  advmod
 ═══╗═╝< parataxis
 <      nmod
 ═╝<     obj

>>> f=open("trial.svg","w")
>>> f.write(s.to_svg())
>>> f.close()

trial.svg guwencombo.load() has two options guwencombo.load(BERT="guwenbert-base",Danku=False). With the option BERT="guwenbert-large" the pipeline utilizes GuwenBERT-large. With the option Danku=True the pipeline tries to segment sentences automatically. to_tree() and to_svg() are borrowed from those of UD-Kanbun.

Kundoku usage

>>> import guwencombo
>>> lzh=guwencombo.load()
>>> s=lzh("不入虎穴不得虎子")
>>> t=guwencombo.translate(s)
>>> print(t)
# text = 虎の穴に入らずして虎の子を得ず
1			NOUN	n,名詞,主体,動物	_	3	nmod	_	Gloss=tiger|SpaceAfter=No
2		_	ADP	_	_	1	case	_	SpaceAfter=No
3			NOUN	n,名詞,固定物,地形	Case=Loc	5	obj	_	Gloss=cave|SpaceAfter=No
4		_	ADP	_	_	3	case	_	SpaceAfter=No
5	入ら		VERB	v,動詞,行為,移動	_	0	root	_	Gloss=enter|SpaceAfter=No
6	ずして		AUX	v,副詞,否定,無界	Polarity=Neg	5	advmod	_	Gloss=not|SpaceAfter=No
7			NOUN	n,名詞,主体,動物	_	9	nmod	_	Gloss=tiger|SpaceAfter=No
8		_	ADP	_	_	7	case	_	SpaceAfter=No
9			NOUN	n,名詞,,関係	_	11	obj	_	Gloss=child|SpaceAfter=No
10		_	ADP	_	_	9	case	_	SpaceAfter=No
11			VERB	v,動詞,行為,得失	_	5	parataxis	_	Gloss=get|SpaceAfter=No
12			AUX	v,副詞,否定,無界	Polarity=Neg	11	advmod	_	Gloss=not|SpaceAfter=No

>>> print(t.sentence())
虎の穴に入らずして虎の子を得ず

>>> print(s.kaeriten())
虎穴虎子

>>> print(t.to_tree())
 ═╗<     nmod(体言による連体修飾語)
 <      case(格表示)
 ═╗═╝<   obj(目的語)
 <      case(格表示)
 ═╗═══╝═╗ root()
       
 <      advmod(連用修飾語)
        
        
 ═╗<    nmod(体言による連体修飾語)
 <     case(格表示)
 ═╗═╝<  obj(目的語)
 <     case(格表示)
 ═╗═══╝< parataxis(隣接表現)
 <       advmod(連用修飾語)

translate() and reorder() are borrowed from those of UD-Kundoku.

Installation for Linux

pip3 install guwencombo

Installation for Cygwin64

Make sure to get python37-devel python37-pip python37-cython python37-numpy python37-cffi gcc-g++ mingw64-x86_64-gcc-g++ gcc-fortran git curl make cmake libopenblas liblapack-devel libhdf5-devel libfreetype-devel libuv-devel packages, and then:

curl -L https://raw.githubusercontent.com/KoichiYasuoka/UniDic-COMBO/master/cygwin64.sh | sh
pip3.7 install guwencombo

Installation for macOS

g++ --version
pip3 install guwencombo --user
python3 -m spacy download en_core_web_sm --user

If you fail to install Jsonnet, try below before installing GuwenCOMBO:

( echo '#! /bin/sh' ; echo 'exec gcc `echo $* | sed "s/-arch [^ ]*//g"`' ) > /tmp/clang
chmod 755 /tmp/clang
env PATH="/tmp:$PATH" pip3 install jsonnet --user

If you fail to install fugashi, try to install MeCab before installing GuwenCOMBO:

cd /tmp
git clone --depth=1 https://github.com/taku910/mecab
cd mecab/mecab
./configure --with-charset=UTF8
make && sudo make install

Reference

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

guwencombo-1.5.3-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file guwencombo-1.5.3-py3-none-any.whl.

File metadata

  • Download URL: guwencombo-1.5.3-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for guwencombo-1.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6b5a812e5347d2be97e2580efe1fee0402ef31f52382f9dd47f9f6650fce7b6c
MD5 f97d5e5a5ba8053b92838843b93fcf68
BLAKE2b-256 0f47de073a8ee4e452b5a52a57b5bd33bbf812d33f4d443c5ddedc3c2d5e8b22

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page