CKIP E-HowNet¶
CKIP E-HowNet Tools¶
Author¶
Mu Yang <https://muyang.pro>
Requirements¶
Python 3.6+
PLY (Python Lex-Yacc) 3.11+
TreeLib 1.5.5+
wcwidth 0.1.7+
Installation¶
pip install -U ehownet
Usage¶
See https://ehownet.readthedocs.io/en/latest/main/grammar.html for E-HowNet grammar.
See https://ehownet.readthedocs.io/en/latest/main/parse_node.html for E-HowNet parsing nodes usage.
E-HowNet Parser¶
CLI¶
# Usage
ehn-parser <text> [<text> ...]
# Example
ehn-parser \
"{MusicTool|樂器_x:predication={own|有:possession={按鈕|PushingButton:whole={x}}}}" \
"{InstitutePlace|場所:telic={or({experiment|實驗:location={~}},{research|研究:location={~}})}}" \
"TimePoint={},manner={urgent|急}"
Output:
#1
[Entity $x] MusicTool|樂器
└── [Feature] predication
└── [Entity] own|有
└── [Feature] possession
└── [Entity] 按鈕|PushingButton
└── [Feature] whole
└── $x
#2
[Entity] InstitutePlace|場所
└── [Feature] telic
└── [Entity]
└── [Function] or
├── [Entity] experiment|實驗
│ └── [Feature] location
│ └── [TildeEntity]
└── [Entity] research|研究
└── [Feature] location
└── [TildeEntity]
#3
[Root]
├── [Feature] TimePoint
│ └── [AnyEntity]
└── [Feature] manner
└── [Entity] urgent|急
Python API¶
from ehn.parse import EhnParser
text = '{MusicTool|樂器_x:predication={own|有:possession={按鈕|PushingButton:whole={x}}}}'
parser = EhnParser()
ress = parser(text, debug=False)
for res in ress:
print(res)
Output:
[Entity $x] MusicTool|樂器
└── [Feature] predication
└── [Entity] own|有
└── [Feature] possession
└── [Entity] 按鈕|PushingButton
└── [Feature] whole
└── $x
E-HowNet Grammar¶
This section describes the grammar of the E-HowNet expression.
Text¶
TEXT
[A-Za-z0-9\x80-\U0010FFFF|+\-.]+
NUMBER
e.g.
1
,0.1
,1e-4
COINDEX
x[0-9]*
Node¶
Entity¶
-
{TEXT}
{TEXT:FEATURE}
{TEXT:FEATURE,FEATURE}
{TEXT:FEATURE,FEATURE,...}
{TEXT_COINDEX:FEATURE}
{TEXT_COINDEX:FEATURE,FEATURE}
{TEXT_COINDEX:FEATURE,FEATURE,...}
-
{FUNCTION}
{FUNCTION:FEATURE}
{FUNCTION:FEATURE,FEATURE}
{FUNCTION:FEATURE,FEATURE,...}
{FUNCTION_COINDEX:FEATURE}
{FUNCTION_COINDEX:FEATURE,FEATURE}
{FUNCTION_COINDEX:FEATURE,FEATURE,...}
-
{}
-
{"TEXT"}
-
{NUMBER}
-
{~}
-
{COINDEX}
Feature¶
-
TEXT=ENTITY
TEXT=RESTRICTION
-
FUNCTION=ENTITY
FUNCTION=RESTRICTION
Function¶
-
TEXT()
TEXT(RESTRICTION)
TEXT(ENTITY)
TEXT(ENTITY,ENTITY)
TEXT(ENTITY,ENTITY,...)
Restriction¶
-
/ENTITY
/ENTITY_COINDEX
Valid Expressions¶
ENTITY
or any number of FEATURE
s joined by ,
s.
ENTITY
FEATURE
FEATURE,FEATURE
FEATURE,FEATURE,...
Parse Nodes¶
There are five types of nodes in E-HowNet expression — Entity, Feature, Function, Restriction, and Root.

Major Nodes¶
-
class
EhnParseNode
The prototype of E-HowNet parsing nodes.
-
head
: str¶ The head of this node.
-
children
()¶ Yields all direct child nodes of this node.
-
descendant
()¶ Yields all descendant nodes (including self) of this node.
-
tree
() → treelib.Tree¶ Generates a tree representation of this node and all its descendant nodes.
-
Entity¶
-
class
EhnParseEntityBase
The base class of E-HowNet parsing entity nodes.
Subclasses:
EhnParseNormalEntity
A normal entity. Can be an anchor.EhnParseFunctionEntity
An entity with function head. Can be an anchor.EhnParseAnyEntity
A placeholder entity.EhnParseNameEntity
A name entity.EhnParseNumberEntity
A number entity.EhnParseTildeEntity
An entity refers to the parent entity.EhnParseCoindexEntity
An entity refers to an anchor entity.
Feature¶
-
class
EhnParseFeatureBase
The base class of E-HowNet parsing feature nodes.
Subclasses:
EhnParseNormalFeature
A normal feature.EhnParseFunctionFeature
An feature with function head.
-
property
value
¶ Can be either Entity or Restriction.
Function¶
-
class
EhnParseFunctionBase
The base class of E-HowNet parsing function nodes.
Subclasses:
-
property
arguments
¶ A list of Entities or Restriction
-
property
Restriction¶
-
class
EhnParseRestrictionBase
The base class of E-HowNet parsing function nodes.
Subclasses:
EhnParseRestriction
. Can be an anchor.
Root¶
ehn package¶
Subpackages
ehn.parse package¶
Subpackages
ehn.parse.node package¶
Please refer the tutorial “Parse Nodes”.
Submodules
ehn.parse.node.base module¶
Please refer the tutorial “Parse Nodes”.
-
class
ehn.parse.node.base.
EhnParseFunctionHead
(function)[source]¶ Bases:
object
-
property
head
¶
-
property
function
¶
-
property
ehn.parse.node.entity module¶
Please refer the tutorial “Parse Nodes”.
-
class
ehn.parse.node.entity.
EhnParseNormalEntity
(head, *features, anchor=None)[source]¶ Bases:
ehn.parse.node.base.EhnParseEntityBase
,ehn.parse.node.base.EhnParseStrHead
,ehn.parse.node.base.EhnParseFeatureBody
,ehn.parse.node.base.EhnParseAnchorBody
-
class
ehn.parse.node.entity.
EhnParseFunctionEntity
(function, *features, anchor=None)[source]¶ Bases:
ehn.parse.node.base.EhnParseEntityBase
,ehn.parse.node.base.EhnParseFunctionHead
,ehn.parse.node.base.EhnParseFeatureBody
,ehn.parse.node.base.EhnParseAnchorBody
-
class
ehn.parse.node.entity.
EhnParseAnyEntity
[source]¶ Bases:
ehn.parse.node.base.EhnParseEntityBase
-
property
head
¶
-
property
-
class
ehn.parse.node.entity.
EhnParseNameEntity
(head)[source]¶ Bases:
ehn.parse.node.base.EhnParseEntityBase
,ehn.parse.node.base.EhnParseStrHead
-
class
ehn.parse.node.entity.
EhnParseNumberEntity
(head)[source]¶ Bases:
ehn.parse.node.base.EhnParseEntityBase
,ehn.parse.node.base.EhnParseStrHead
-
class
ehn.parse.node.entity.
EhnParseTildeEntity
[source]¶ Bases:
ehn.parse.node.base.EhnParseEntityBase
-
property
head
¶
-
property
-
class
ehn.parse.node.entity.
EhnParseCoindexEntity
(head)[source]¶ Bases:
ehn.parse.node.base.EhnParseEntityBase
,ehn.parse.node.base.EhnParseStrHead
ehn.parse.node.feature module¶
Please refer the tutorial “Parse Nodes”.
-
class
ehn.parse.node.feature.
EhnParseNormalFeature
(head, value)[source]¶ Bases:
ehn.parse.node.base.EhnParseFeatureBase
,ehn.parse.node.base.EhnParseStrHead
,ehn.parse.node.feature.EhnParseFeatureCore
-
class
ehn.parse.node.feature.
EhnParseFunctionFeature
(function, value)[source]¶ Bases:
ehn.parse.node.base.EhnParseFeatureBase
,ehn.parse.node.base.EhnParseFunctionHead
,ehn.parse.node.feature.EhnParseFeatureCore
ehn.parse.node.other module¶
Please refer the tutorial “Parse Nodes”.
-
class
ehn.parse.node.other.
EhnParseRoot
(*features)[source]¶ Bases:
ehn.parse.node.base.EhnParseRootBase
,ehn.parse.node.base.EhnParseFeatureBody
-
property
head
¶
-
property
-
class
ehn.parse.node.other.
EhnParseFunction
(head, *arguments)[source]¶ Bases:
ehn.parse.node.base.EhnParseFunctionBase
,ehn.parse.node.base.EhnParseStrHead
-
property
arguments
¶
-
property
-
class
ehn.parse.node.other.
EhnParseRestriction
(value, anchor=None)[source]¶ Bases:
ehn.parse.node.base.EhnParseRestrictionBase
,ehn.parse.node.base.EhnParseAnchorBody
-
property
head
¶
-
property
value
¶
-
property
Submodules