Skip to content

Commit

Permalink
Store word-segmented and pos-tagging sentences in different class.
Browse files Browse the repository at this point in the history
  • Loading branch information
emfomy committed Apr 9, 2020
1 parent ce0ac5c commit 4bc11e5
Show file tree
Hide file tree
Showing 31 changed files with 892 additions and 686 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ disable =
missing-docstring,
too-many-ancestors,
too-many-branches,
too-many-instance-attributes,

[FORMAT]

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Requirements
* `TreeLib <https://treelib.readthedocs.io>`_ 1.5+

* `CkipClassic <https://ckip-classic.readthedocs.io>`_ 1.0+ [Optional]
* `CkipTagger <https://pypi.org/project/ckiptagger>`_ 0.1+ [Optional]
* `CkipTagger <https://pypi.org/project/ckiptagger>`_ 0.1.1+ [Optional]

Usage
=====
Expand Down
2 changes: 1 addition & 1 deletion ckipnlp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__copyright__ = '2018-2020 CKIP Lab'

__title__ = 'CKIPNLP'
__version__ = '0.7.2'
__version__ = '0.8.0dev'
__description__ = 'CKIP CoreNLP'
__license__ = 'CC BY-NC-SA 4.0'

Expand Down
2 changes: 1 addition & 1 deletion ckipnlp/container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from .text import *
from .seg import *
from .ws import *
from .ner import *
from .parsed import *

from .wspos import *
from .parsed_tree import *
28 changes: 14 additions & 14 deletions ckipnlp/container/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def from_text(cls, data):
def to_text(self):
"""Transform to plain text.
Return
------
Returns
-------
str
"""
return NotImplemented
Expand Down Expand Up @@ -90,8 +90,8 @@ def from_json(cls, data, **kwargs):
def to_json(self, **kwargs):
"""Transform to JSON format.
Return
------
Returns
-------
str
"""
return _json.dumps(self.to_dict(), **kwargs)
Expand Down Expand Up @@ -127,8 +127,8 @@ def from_dict(cls, data):
def to_dict(self):
"""Transform to python built-in containers.
Return
------
Returns
-------
dict
"""
return self._asdict() # pylint: disable=no-member
Expand All @@ -148,8 +148,8 @@ def from_list(cls, data):
def to_list(self):
"""Transform to python built-in containers.
Return
------
Returns
-------
list
"""
return list(self)
Expand Down Expand Up @@ -177,8 +177,8 @@ def from_text(cls, data):
def to_text(self):
"""Transform to plain text.
Return
------
Returns
-------
List[str]
"""
return list(map(self._item_to_text, self)) # pylint: disable=no-member
Expand All @@ -199,8 +199,8 @@ def from_dict(cls, data):
def to_dict(self):
"""Transform to python built-in containers.
Return
------
Returns
-------
List[Container]
"""
return list(map(self._item_to_dict, self)) # pylint: disable=no-member
Expand All @@ -221,8 +221,8 @@ def from_list(cls, data):
def to_list(self):
"""Transform to python built-in containers.
Return
------
Returns
-------
List[Container]
"""
return list(map(self._item_to_list, self)) # pylint: disable=no-member
Expand Down
2 changes: 1 addition & 1 deletion ckipnlp/container/ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def to_tagger(self):

################################################################################################################################

class NerSentenceList(_BaseList):
class NerParagraph(_BaseList):
"""A list of NER sentence.
.. admonition:: Data Structure Examples
Expand Down
6 changes: 3 additions & 3 deletions ckipnlp/container/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

################################################################################################################################

class ParsedSentenceList(_BaseList0):
class ParsedParagraph(_BaseList0):
"""A list of parsed sentence.
.. admonition:: Data Structure Examples
Expand All @@ -27,8 +27,8 @@ class ParsedSentenceList(_BaseList0):
.. code-block:: python
[
'#1:1.[0] S(Head:Nab:中文字|particle:Td:耶)#', # Sentence 1
'#2:1.[0] %(particle:I:啊|manner:Dh:哈|manner:Dh:哈|time:Dh:哈)#', # Sentence 2
'S(Head:Nab:中文字|particle:Td:耶)', # Sentence 1
'%(particle:I:啊|manner:Dh:哈|manner:Dh:哈|time:Dh:哈)', # Sentence 2
]
"""

Expand Down
8 changes: 4 additions & 4 deletions ckipnlp/container/parsed_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ def to_text(self, node_id=0): # pylint: disable=arguments-differ
node_id : int
Output the plain text format for the subtree under **node_id**.
Return
------
Returns
--------
str
"""
node = self[node_id]
Expand Down Expand Up @@ -397,8 +397,8 @@ def to_dict(self, node_id=0): # pylint: disable=arguments-differ
node_id : int
Output the plain text format for the subtree under **node_id**.
Return
------
Returns
-------
str
"""
tree_dict = self[node_id].to_dict()
Expand Down
12 changes: 11 additions & 1 deletion ckipnlp/container/seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class SegSentence(_BaseSentence0):
.. code-block:: python
[ '中文字', '喔', ]
.. note::
This class is also used for part-of-speech tagging.
"""

item_class = str
Expand All @@ -45,7 +50,7 @@ def from_text(cls, data):
def to_text(self):
return '\u3000'.join(map(self._item_to_text, self))

class SegSentenceList(_BaseList):
class SegParagraph(_BaseList):
"""A list of word-segmented sentences.
.. admonition:: Data Structure Examples
Expand All @@ -69,6 +74,11 @@ class SegSentenceList(_BaseList):
[ '中文字', '喔', ], # Sentence 1
[ '啊哈', '哈哈', ], # Sentence 2
]
.. note::
This class is also used for part-of-speech tagging.
"""

item_class = SegSentence
2 changes: 1 addition & 1 deletion ckipnlp/container/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

################################################################################################################################

class TextSentenceList(_BaseList0):
class TextParagraph(_BaseList0):
"""A list of text sentence.
.. admonition:: Data Structure Examples
Expand Down

0 comments on commit 4bc11e5

Please sign in to comment.