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 fromckipnlp.parser.CkipParser
output.
-
class
ckipnlp.util.parser.
ParserNode
(tag=None, identifier=None, expanded=True, data=None)[source]¶ Bases:
treelib.node.Node
A parser node for tree.
-
class
ckipnlp.util.parser.
ParserRelation
[source]¶ Bases:
ckipnlp.util.parser._ParserRelation
A parser relation.
- Fields:
- head (
ParserNode
): the head node. - tail (
ParserNode
): the tail node. - relation (str): the relation.
- head (
-
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 fromckipnlp.parser.CkipParser
output.
-
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: - list – the head nodes (
ParserNode
). ParserNode
– the head node (when deep is set).
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.
-
classmethod