ckipnlp.util.parser module

class ckipnlp.util.parser.ParserNodeData[source]

Bases: ckipnlp.util.parser._ParserNodeData

A parser node.

Fields:
  • role (str): the role.
  • pos (str): the post-tag.
  • term (str): the text term.
classmethod from_text(text)[source]

Create ParserNodeData object from ckipnlp.parser.CkipParser output.

to_dict()[source]
to_json(**kwargs)[source]
class ckipnlp.util.parser.ParserNode(tag=None, identifier=None, expanded=True, data=None)[source]

Bases: treelib.node.Node

A parser node for tree.

to_dict()[source]
to_json(**kwargs)[source]
class ckipnlp.util.parser.ParserRelation[source]

Bases: ckipnlp.util.parser._ParserRelation

A parser relation.

Fields:
to_dict()[source]
to_json(**kwargs)[source]
class ckipnlp.util.parser.ParserTree(tree=None, deep=False, node_class=None)[source]

Bases: treelib.tree.Tree

A parsed tree.

classmethod from_text(tree_text)[source]

Create ParserTree object from ckipnlp.parser.CkipParser output.

to_dict(node_id=0)[source]

Transform the whole tree into a dict.

to_json(**kwargs)[source]

To format the tree in JSON format.

show(*, key=<function ParserTree.<lambda>>, idhidden=False, **kwargs)[source]

Show pretty tree.

has_dummies(node_id)[source]

Determine if a node has dummies.

Parameters:node_id (int) – ID of target node.
Returns:bool – whether or not target node has dummies.
get_dummies(node_id, deep=True, _check=True)[source]

Get dummies of a node.

Parameters:
  • node_id (int) – ID of target node.
  • deep (bool) – find dummies recursively.
Returns:

tuple – the dummies (ParserNode).

Raises:

LookupError – when target node has no dummy (only when _check is set).

get_heads(root_id=0, deep=True)[source]

Get all head nodes of a subtree.

Parameters:
  • node_id (int) – ID of the root node of target subtree.
  • deep (bool) – find heads recursively.
Returns:

Todo

Get information of nodes with pos type PP or GP.

get_relations(root_id=0)[source]

Get all relations of a subtree.

Parameters:node_id (int) – ID of the subtree root node.
Yields:ParserRelation – the relation.