Skip to content

Commit 04da42e

Browse files
committed
Merge branch 'release/0.6.3'
2 parents 0c48549 + f5f8a7c commit 04da42e

File tree

13 files changed

+372
-200
lines changed

13 files changed

+372
-200
lines changed

.pylintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
max-line-length = 128
44

55
disable =
6-
missing-docstring,
6+
bad-continuation,
77
duplicate-code,
8+
missing-docstring,

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ doc:
2222
( cd docs ; make clean ; make html )
2323

2424
upload: dist check
25+
ls dist/*.tar.gz
2526
$(TWINE) upload --repository-url https://test.pypi.org/legacy/ dist/*.tar.gz --verbose
2627

2728
clean:

README.rst

+28-12
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,18 @@ Requirements
7373

7474
* `Python <http://www.python.org>`_ 3.5+
7575
* `Cython <http://cython.org>`_ 0.29+
76+
* `TreeLib <https://treelib.readthedocs.io>`_ 1.5+
7677

7778
.. note::
7879
For Python 2 users, please use `PyCkip 0.4.2 <https://pypi.org/project/pyckip/0.4.2/>`_ instead.
7980

80-
CkipWs (Optional)
81+
CKIPWS (Optional)
8182
^^^^^^^^^^^^^^^^^
8283

8384
* `CKIP Word Segmentation <http://ckip.iis.sinica.edu.tw/project/wordsegment/>`_ Linux version 20190524+
8485

85-
CkipParser (Optional)
86-
^^^^^^^^^^^^^^^^^^^^^
86+
CKIP-Parser (Optional)
87+
^^^^^^^^^^^^^^^^^^^^^^
8788

8889
* `CKIP Parser <http://ckip.iis.sinica.edu.tw/project/parser/>`_ Linux version 20190506+ (20190725+ recommended)
8990

@@ -191,8 +192,15 @@ Utilities
191192
192193
# Format CkipWs output
193194
ws_text = ['中文字(Na) 喔(T)', '啊哈(I) 哈哈(D)']
194-
for text in ws_text: print(ckipnlp.util.ws.WsSentence.from_text(text))
195-
for text in ws_text: print(repr(ckipnlp.util.ws.WsSentence.from_text(text)))
195+
196+
# Show Sentence List
197+
ws_sents = WsSentenceList.from_text(ws_text)
198+
print(repr(ws_sents))
199+
print(ws_sents.to_text())
200+
201+
# Show Each Sentence
202+
for ws_sent in ws_sents: print(repr(ws_sent))
203+
for ws_sent in ws_sents: print(ws_sent.to_text())
196204
197205
# Show CkipParser output as tree
198206
tree_text = 'S(theme:NP(property:N‧的(head:Nhaa:我|Head:DE:的)|Head:Nad(DUMMY1:Nab:早餐|Head:Caa:和|DUMMY2:Naa:午餐))|quantity:Dab:都|Head:VC31:吃完|aspect:Di:了)'
@@ -206,31 +214,39 @@ Utilities
206214
for node in tree.get_heads(1): print(node)
207215
208216
# Get relations
209-
for r in tree.get_relations(0): print(r)
217+
for rel in tree.get_relations(0): print(rel)
210218
211219
212220
FAQ
213221
===
214222

223+
.. warning::
224+
225+
Due to C code implementation, one should not instance more than one ``CkipWs`` driver object and one ``CkipParser`` driver object.
226+
227+
------------
228+
215229
.. warning::
216230

217231
The CKIPWS throws "``what(): locale::facet::_S_create_c_locale name not valid``". What should I do?
218232

219-
Install locale data.
233+
Install locale data.
220234

221-
.. code-block:: bash
235+
.. code-block:: bash
222236
223-
apt-get install locales-all
237+
apt-get install locales-all
238+
239+
------------
224240

225241
.. warning::
226242

227243
The CKIPParser throws "``ImportError: libCKIPParser.so: cannot open shared object file: No such file or directory``". What should I do?
228244

229-
Add below command to ``~/.bashrc``:
245+
Add below command to ``~/.bashrc``:
230246

231-
.. code-block:: bash
247+
.. code-block:: bash
232248
233-
export LD_LIBRARY_PATH=<ckipparser-linux-root>/lib:$LD_LIBRARY_PATH
249+
export LD_LIBRARY_PATH=<ckipparser-linux-root>/lib:$LD_LIBRARY_PATH
234250
235251
License
236252
=======

ckipnlp/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__copyright__ = '2018-2019 CKIP Lab'
77

88
__title__ = 'CKIPNLP'
9-
__version__ = '0.6.2'
9+
__version__ = '0.6.3'
1010
__description__ = 'CKIP CoreNLP Wrappers'
1111
__license__ = 'CC BY-NC-SA 4.0'
1212

ckipnlp/parser/__init__.py

+39-27
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,30 @@ class CkipParser:
2727
2828
Parameters
2929
----------
30-
logger : bool
31-
enable logger.
32-
inifile : str
33-
the path to the INI file.
34-
wsinifile : str
35-
the path to the INI file for CKIPWS.
36-
options:
37-
the options, see :func:`ckipnlp.util.ini.create_ws_ini` and :func:`ckipnlp.util.ini.create_parser_ini`
30+
logger : bool
31+
enable logger.
32+
inifile : str
33+
the path to the INI file.
34+
wsinifile : str
35+
the path to the INI file for CKIPWS.
36+
Other Parameters
37+
----------------
38+
**
39+
the configs for CKIPParser, ignored if **inifile** is set. Please refer :func:`ckipnlp.util.ini.create_parser_ini`.
40+
**
41+
the configs for CKIPWS, ignored if **wsinifile** is set. Please refer :func:`ckipnlp.util.ini.create_ws_ini`.
42+
43+
Warning
44+
-------
45+
Never instance more than one object of this class!
3846
"""
3947

40-
def __init__(self, *, logger=False, inifile=None, wsinifile=None, **options):
48+
def __init__(self, *,
49+
logger=False,
50+
inifile=None,
51+
wsinifile=None,
52+
**kwargs,
53+
):
4154

4255
self.__core = CkipParserCore()
4356

@@ -48,19 +61,19 @@ def __init__(self, *, logger=False, inifile=None, wsinifile=None, **options):
4861
if not wsinifile:
4962
fwsini = _tempfile.NamedTemporaryFile(mode='w')
5063
wsinifile = fwsini.name
51-
wsinidata, options = create_ws_ini(**options)
64+
wsinidata, kwargs = create_ws_ini(**kwargs)
5265
fwsini.write(wsinidata)
5366
fwsini.flush()
5467

5568
if not inifile:
5669
fini = _tempfile.NamedTemporaryFile(mode='w')
5770
inifile = fini.name
58-
inidata, options = create_parser_ini(wsinifile=wsinifile, **options)
71+
inidata, kwargs = create_parser_ini(wsinifile=wsinifile, **kwargs)
5972
fini.write(inidata)
6073
fini.flush()
6174

6275
def CkipParser(*, _=None): pass # pylint: disable=redefined-outer-name, invalid-name, multiple-statements
63-
CkipParser(**options)
76+
CkipParser(**kwargs)
6477

6578
self.__core.init_data(inifile)
6679

@@ -82,17 +95,16 @@ def apply(self, text):
8295
8396
Parameters
8497
----------
85-
text : str
86-
the input sentence.
98+
text : str
99+
the input sentence.
87100
88101
Return
89102
------
90-
str
91-
the output sentence.
103+
str
104+
the output sentence.
92105
93-
Notes
94-
-----
95-
One may also call this method as :func:`__call__`.
106+
.. note::
107+
One may also call this method as :func:`__call__`.
96108
"""
97109
return self.apply_list([text])[0]
98110

@@ -101,13 +113,13 @@ def apply_list(self, ilist):
101113
102114
Parameters
103115
----------
104-
ilist: list
105-
the list of input sentences (str).
116+
ilist
117+
the list of input sentences.
106118
107119
Return
108120
------
109-
olist: list
110-
the list of output sentences (str).
121+
List[str]
122+
the list of output sentences.
111123
"""
112124
return self.__core.apply_list(ilist)
113125

@@ -116,9 +128,9 @@ def apply_file(self, ifile, ofile):
116128
117129
Parameters
118130
----------
119-
ifile: str
120-
the input file.
121-
ofile: str
122-
the output file (will be overwritten).
131+
ifile : str
132+
the input file.
133+
ofile : str
134+
the output file (will be overwritten).
123135
"""
124136
return self.__core.apply_file(ifile, ofile)

ckipnlp/util/ini.py

+42-44
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,30 @@
1212

1313
import ckipnlp as _about
1414

15-
def create_ws_ini( # pylint: disable=too-many-statements
16-
*,
17-
data2dir=None,
18-
lexfile=None,
19-
new_style_format=False,
20-
show_category=True,
21-
sentence_max_word_num=80,
22-
**options,
15+
def create_ws_ini(*, # pylint: disable=too-many-statements
16+
data2dir=None,
17+
lexfile=None,
18+
new_style_format=False,
19+
show_category=True,
20+
sentence_max_word_num=80,
21+
**options,
2322
):
2423
"""Generate CKIP word segmentation config.
2524
2625
Parameters
2726
----------
28-
data2dir : str
29-
the path to the folder "Data2/".
30-
lexfile : str
31-
the path to the user-defined lexicon file.
32-
33-
new_style_format : bool
34-
split sentences by newline characters ("\\\\n") rather than punctuations.
35-
show_category : bool
36-
show part-of-speech tags.
37-
38-
sentence_max_word_num : int
39-
maximum number of words per sentence.
27+
data2dir : str
28+
the path to the folder "Data2/".
29+
lexfile : str
30+
the path to the user-defined lexicon file.
31+
32+
new_style_format : bool
33+
split sentences by newline characters ("\\\\n") rather than punctuations.
34+
show_category : bool
35+
show part-of-speech tags.
36+
37+
sentence_max_word_num : int
38+
maximum number of words per sentence.
4039
"""
4140

4241
# pylint: disable=invalid-name
@@ -312,35 +311,34 @@ def create_ws_ini( # pylint: disable=too-many-statements
312311

313312
return '\n'.join(cfg), options
314313

315-
def create_parser_ini( # pylint: disable=too-many-statements
316-
*,
317-
wsinifile,
318-
ruledir=None,
319-
rdbdir=None,
320-
do_ws=True,
321-
do_parse=True,
322-
do_role=True,
323-
sentence_delim=',,;。!?',
324-
**options,
314+
def create_parser_ini(*, # pylint: disable=too-many-statements
315+
wsinifile,
316+
ruledir=None,
317+
rdbdir=None,
318+
do_ws=True,
319+
do_parse=True,
320+
do_role=True,
321+
sentence_delim=',,;。!?',
322+
**options,
325323
):
326324
"""Generate CKIP parser config.
327325
328326
Parameters
329327
----------
330-
ruledir : str
331-
the path to "Rule/".
332-
rdbdir : str
333-
the path to "RDB/".
334-
335-
do_ws : bool
336-
do word-segmentation.
337-
do_parse : bool
338-
do parsing.
339-
do_role : bool
340-
do role.
341-
342-
sentence_delim: str
343-
the sentence delimiters.
328+
ruledir : str
329+
the path to "Rule/".
330+
rdbdir : str
331+
the path to "RDB/".
332+
333+
do_ws : bool
334+
do word-segmentation.
335+
do_parse : bool
336+
do parsing.
337+
do_role : bool
338+
do role.
339+
340+
sentence_delim : str
341+
the sentence delimiters.
344342
"""
345343

346344
# pylint: disable=invalid-name

0 commit comments

Comments
 (0)