Skip to content

Commit

Permalink
Merge branch 'hotfix/0.9.1' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
emfomy committed Aug 28, 2020
2 parents fc0dceb + cd00efb commit 18fc3a8
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion ckipnlp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
__copyright__ = '2018-2020 CKIP Lab'

__title__ = 'CKIPNLP'
__version__ = '0.9.0'
__version__ = '0.9.1'
__description__ = 'CKIP CoreNLP'
__license__ = 'CC BY-NC-SA 4.0'

Expand Down
2 changes: 1 addition & 1 deletion ckipnlp/container/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding:utf-8 -*-

"""
This module provides containers for parse sentences.
This module provides containers for parsed sentences.
"""

__author__ = 'Mu Yang <http://muyang.pro>'
Expand Down
4 changes: 2 additions & 2 deletions ckipnlp/container/util/parse_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding:utf-8 -*-

"""
This module provides tree containers for sentence parse.
This module provides tree containers for parsed sentences.
"""

__author__ = 'Mu Yang <http://muyang.pro>'
Expand All @@ -23,7 +23,7 @@
Node as _Node,
)

from ckipnlp.data.constituency import (
from ckipnlp.data.conparse import (
SUBJECT_ROLES as _SUBJECT_ROLES,
NEUTRAL_ROLES as _NEUTRAL_ROLES,
)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ckipnlp/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from .classic import (
CkipClassicWordSegmenter,
CkipClassicConstituencyParser,
CkipClassicConParser,
)

from .ss import (
Expand Down
32 changes: 16 additions & 16 deletions ckipnlp/driver/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def _call(self, *, _wspos):

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

class CkipClassicConstituencyParser(_BaseDriver):
"""The CKIP sentence parsing driver with CkipClassic backend.
class CkipClassicConParser(_BaseDriver):
"""The CKIP constituency parsing driver with CkipClassic backend.
Arguments
---------
Expand All @@ -140,17 +140,17 @@ class CkipClassicConstituencyParser(_BaseDriver):
.. method:: __call__(*, ws, pos)
Apply sentence parsing.
Apply constituency parsing.
Parameters
- **ws** (:class:`~ckipnlp.container.text.TextParagraph`) — The word-segmented sentences.
- **pos** (:class:`~ckipnlp.container.text.TextParagraph`) — The part-of-speech sentences.
Returns
**constituency** (:class:`~ckipnlp.container.parse.ParseSentence`) — The constituency-parsing sentences.
**conparse** (:class:`~ckipnlp.container.parse.ParseSentence`) — The constituency-parsing sentences.
"""

driver_type = 'constituncy_parser'
driver_type = 'con_parser'
driver_family = 'classic'
driver_inputs = ('ws', 'pos',)

Expand All @@ -169,9 +169,9 @@ def _call(self, *, ws, pos):
assert isinstance(pos, _SegParagraph)


constituency_text = []
conparse_text = []
for ws_sent, pos_sent in zip(ws, pos):
constituency_sent_text = []
conparse_sent_text = []
ws_clause = []
pos_clause = []
for ws_token, pos_token in _chain(zip(ws_sent, pos_sent), [(None, None),]):
Expand All @@ -181,16 +181,16 @@ def _call(self, *, ws, pos):
continue

# Segment clauses by punctuations
if pos_token is None or pos_token.endswith('CATEGORY'):
if pos_token is None or (pos_token.endswith('CATEGORY') and pos_token != 'PAUSECATEGORY'):
if ws_clause:
wspos_clause_text = _WsPosSentence.to_text(ws_clause, pos_clause)
for constituency_clause_text in self._core.apply_list([wspos_clause_text]):
constituency_sent_text.append([self._normalize(constituency_clause_text), '',])
for conparse_clause_text in self._core.apply_list([wspos_clause_text]):
conparse_sent_text.append([self._normalize(conparse_clause_text), '',])

if ws_token:
if not constituency_sent_text:
constituency_sent_text.append([None, '',])
constituency_sent_text[-1][1] += ws_token
if not conparse_sent_text:
conparse_sent_text.append([None, '',])
conparse_sent_text[-1][1] += ws_token

ws_clause = []
pos_clause = []
Expand All @@ -199,10 +199,10 @@ def _call(self, *, ws, pos):
ws_clause.append(self._half2full(ws_token))
pos_clause.append(pos_token)

constituency_text.append(constituency_sent_text)
constituency = _ParseParagraph.from_list(constituency_text)
conparse_text.append(conparse_sent_text)
conparse = _ParseParagraph.from_list(conparse_text)

return constituency
return conparse

@staticmethod
def _half2full(text):
Expand Down
12 changes: 6 additions & 6 deletions ckipnlp/driver/coref.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
CorefParagraph as _CorefParagraph,
)

from ckipnlp.data.constituency import (
from ckipnlp.data.conparse import (
APPOSITION_ROLES as _APPOSITION_ROLES,
)

Expand All @@ -49,12 +49,12 @@ class CkipCorefChunker(_BaseDriver): # pylint: disable=too-few-public-methods
lazy : bool
Lazy initialize the driver.
.. method:: __call__(*, constituency)
.. method:: __call__(*, conparse)
Apply coreference delectation.
Parameters
**constituency** (:class:`~ckipnlp.container.parse.ParseParagraph`) — The constituency-parsing sentences.
**conparse** (:class:`~ckipnlp.container.parse.ParseParagraph`) — The constituency-parsing sentences.
Returns
**coref** (:class:`~ckipnlp.container.coref.CorefParagraph`) — The coreference results.
Expand All @@ -67,15 +67,15 @@ class CkipCorefChunker(_BaseDriver): # pylint: disable=too-few-public-methods
def _init(self):
pass

def _call(self, *, constituency):
assert isinstance(constituency, _ParseParagraph)
def _call(self, *, conparse):
assert isinstance(conparse, _ParseParagraph)

# Convert to tree structure
tree_list = [
[
(clause.to_tree(), clause.delim,)
for clause in sent
] for sent in constituency
] for sent in conparse
]

# Find coreference
Expand Down
18 changes: 9 additions & 9 deletions ckipnlp/pipeline/coref.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ class CkipCorefDocument(_Mapping):
The word-segmented sentences.
pos : :class:`~ckipnlp.container.seg.SegParagraph`
The part-of-speech sentences.
constituency : :class:`~ckipnlp.container.constituency.ParseParagraph`
conparse : :class:`~ckipnlp.container.parse.ParseParagraph`
The constituency sentences.
coref : :class:`~ckipnlp.container.coref.CorefParagraph`
The coreference resolution results.
"""

__keys = ('ws', 'pos', 'constituency', 'coref',)
__keys = ('ws', 'pos', 'conparse', 'coref',)

def __init__(self, *, ws=None, pos=None, constituency=None, coref=None):
def __init__(self, *, ws=None, pos=None, conparse=None, coref=None):
self.ws = ws
self.pos = pos
self.constituency = constituency
self.conparse = conparse
self.coref = coref

def __len__(self):
Expand Down Expand Up @@ -74,8 +74,8 @@ class CkipCorefPipeline(_CkipPipeline):
ner_chunker : str
The type of named-entity recognition chunker.
sentence_parser : str
The type of sentence parser.
con_parser : str
The type of constituency parser.
coref_chunker : str
The type of coreference resolution chunker.
Expand Down Expand Up @@ -171,10 +171,10 @@ def get_coref(self, doc, corefdoc):
)

# Do parsing
if corefdoc.constituency is None:
corefdoc.constituency = self.get_constituency(corefdoc)
if corefdoc.conparse is None:
corefdoc.conparse = self.get_conparse(corefdoc)

# Do coreference resolution
corefdoc.coref = self._coref_chunker(constituency=corefdoc.constituency)
corefdoc.coref = self._coref_chunker(conparse=corefdoc.conparse)

return corefdoc.coref
28 changes: 14 additions & 14 deletions ckipnlp/pipeline/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ class CkipDocument(_Mapping):
The part-of-speech sentences.
ner : :class:`~ckipnlp.container.ner.NerParagraph`
The named-entity recognition results.
constituency : :class:`~ckipnlp.container.parse.ParseParagraph`
conparse : :class:`~ckipnlp.container.parse.ParseParagraph`
The constituency-parsing sentences.
"""

__keys = ('raw', 'text', 'ws', 'pos', 'ner', 'constituency',)
__keys = ('raw', 'text', 'ws', 'pos', 'ner', 'conparse',)

def __init__(self, *, raw=None, text=None, ws=None, pos=None, ner=None, constituency=None):
def __init__(self, *, raw=None, text=None, ws=None, pos=None, ner=None, conparse=None):
self.raw = raw
self.text = text
self.ws = ws
self.pos = pos
self.ner = ner
self.constituency = constituency
self.conparse = conparse

self._wspos = None

Expand Down Expand Up @@ -78,8 +78,8 @@ class CkipPipeline:
ner_chunker : str
The type of named-entity recognition chunker.
sentence_parser : str
The type of sentence parser.
con_parser : str
The type of constituency parser.
Other Parameters
----------------
Expand All @@ -94,7 +94,7 @@ def __init__(self, *,
sentence_segmenter='default',
word_segmenter='tagger',
pos_tagger='tagger',
sentence_parser='classic',
con_parser='classic',
ner_chunker='tagger',
lazy=True,
opts={},
Expand Down Expand Up @@ -125,8 +125,8 @@ def __init__(self, *,
self._pos_tagger = _DriverRegister.get('pos_tagger', pos_tagger)(
lazy=lazy, **opts.get('pos_tagger', {}),
)
self._constituency_parser = _DriverRegister.get('constituncy_parser', sentence_parser)(
lazy=lazy, **opts.get('sentence_parser', {}),
self._con_parser = _DriverRegister.get('con_parser', con_parser)(
lazy=lazy, **opts.get('con_parser', {}),
)
self._ner_chunker = _DriverRegister.get('ner_tagger', ner_chunker)(
lazy=lazy, **opts.get('ner_chunker', {}),
Expand All @@ -151,8 +151,8 @@ def _get(self, key, doc):
'pos': (
self._pos_tagger, 'part-of-speech tagging',
),
'constituency': (
self._constituency_parser, 'constituency parsing',
'conparse': (
self._con_parser, 'constituency parsing',
),
'ner': (
self._ner_chunker, 'named-entity recognition',
Expand Down Expand Up @@ -261,7 +261,7 @@ def get_ner(self, doc):

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

def get_constituency(self, doc):
def get_conparse(self, doc):
"""Apply constituency parsing.
Arguments
Expand All @@ -271,11 +271,11 @@ def get_constituency(self, doc):
Returns
-------
doc.constituency : :class:`~ckipnlp.container.parse.ParseParagraph`
doc.conparse : :class:`~ckipnlp.container.parse.ParseParagraph`
The constituency parsing sentences.
.. note::
This routine modify **doc** inplace.
"""
return self._get('constituency', doc)
return self._get('conparse', doc)
2 changes: 1 addition & 1 deletion docs/main/_defn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.. Driver
.. |CkipClassicWordSegmenter| replace:: :class:`~ckipnlp.driver.classic.CkipClassicWordSegmenter`
.. |CkipClassicConstituencyParser| replace:: :class:`~ckipnlp.driver.classic.CkipClassicConstituencyParser`
.. |CkipClassicConParser| replace:: :class:`~ckipnlp.driver.classic.CkipClassicConParser`

.. |CkipTaggerWordSegmenter| replace:: :class:`~ckipnlp.driver.tagger.CkipTaggerWordSegmenter`
.. |CkipTaggerPosTagger| replace:: :class:`~ckipnlp.driver.tagger.CkipTaggerPosTagger`
Expand Down
4 changes: 2 additions & 2 deletions docs/main/tag.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Constituency Parsing Tags
-------------------------

.. csv-table::
:file: ./tag/constituency_pos.csv
:file: ./tag/conparse_pos.csv
:widths: 50 50
:header-rows: 1

Constituency Parsing Roles
--------------------------

.. csv-table::
:file: ./tag/constituency_role.csv
:file: ./tag/conparse_role.csv
:widths: 50 50
:header-rows: 1
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/main/usage/driver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Sentence Segmenter |CkipSentenceSegmenter|
Word Segmenter |CkipTaggerWordSegmenter| |CkipClassicWordSegmenter|†
Pos Tagger |CkipTaggerPosTagger| |CkipClassicWordSegmenter|†
Ner Chunker |CkipTaggerNerChunker|
Constituncy Parser |CkipClassicConstituencyParser|
Constituency Parser |CkipClassicConParser|
Coref Chunker |CkipCorefChunker|
================================ ================================ ================================ ================================

Expand Down
4 changes: 2 additions & 2 deletions docs/main/usage/pipeline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ The |CkipPipeline| will compute all necessary dependencies. For example, if one
print(doc.ner)
# Constituency Parsing
pipeline.get_constituency(doc)
print(doc.constituency)
pipeline.get_conparse(doc)
print(doc.conparse)
################################################################
Expand Down
2 changes: 1 addition & 1 deletion test/script/pipeline/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
[ [ '中文字', 'LANGUAGE', (0, 3), ], ],
[ [ '畢卡索', 'PERSON', (6, 9), ], ],
]
constituency = [
conparse = [
[
[ 'S(Head:Nab:中文字|particle:Td:耶)', ',', ],
[ '%(particle:I:啊|manner:Dh:哈|manner:D:哈哈)', '。', ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from _base import *

def test_classic_constituency_parser():
obj = CkipPipeline(sentence_parser='classic')
def test_classic_con_parser():
obj = CkipPipeline(con_parser='classic')
doc = CkipDocument(ws=SegParagraph.from_list(ws), pos=SegParagraph.from_list(pos))
obj.get_constituency(doc)
assert doc.constituency.to_list() == constituency
obj.get_conparse(doc)
assert doc.conparse.to_list() == conparse
2 changes: 1 addition & 1 deletion test/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ commands_pre =
commands =
pytest {toxinidir}/script/pipeline/run_classic_word_segmenter.py {env:NO_COV:--cov=ckipnlp.pipeline --cov=ckipnlp.driver} {posargs}
pytest {toxinidir}/script/pipeline/run_classic_word_segmenter_pos_tagger.py {env:NO_COV:--cov=ckipnlp.pipeline --cov=ckipnlp.driver} {posargs}
pytest {toxinidir}/script/pipeline/run_classic_constituency_parser.py {env:NO_COV:--cov=ckipnlp.pipeline --cov=ckipnlp.driver} {posargs}
pytest {toxinidir}/script/pipeline/run_classic_con_parser.py {env:NO_COV:--cov=ckipnlp.pipeline --cov=ckipnlp.driver} {posargs}

0 comments on commit 18fc3a8

Please sign in to comment.