为了使用python构建nlp应用程序,我正在尝试解析一个动词英语词典,因此我必须将它与我的nltk脚本合并,词典是一个lisp可读的属性列表文件,但我需要一个更简单的格式,如json文件或数据框。
该词典数据库的一个例子是:
;; Grid: 51.2#1#_th,src#abandon#abandon#abandon#abandon+ingly#(1.5,01269572,01188040,01269413,00345378)(1.6,01524319,01421290,01524047,00415625)###AD
(
:DEF_WORD "abandon"
:CLASS "51.2"
:WN_SENSE (("1.5" 01269572 01188040 01269413 00345378)
("1.6" 01524319 01421290 01524047 00415625))
:PROPBANK ("arg1 arg2")
:THETA_ROLES ((1 "_th,src"))
:LCS (go loc (* thing 2)
(away_from loc (thing 2) (at loc (thing 2) (* thing 4)))
(abandon+ingly 26))
:VAR_SPEC ((4 :optional) (2 (animate +)))
)
;; Grid: 45.4.a#1#_ag_th,instr(with)#abase#abase#abase#abase+ed#(1.5,01024949)(1.6,01228249)###AD
(
:DEF_WORD "abase"
:CLASS "45.4.a"
:WN_SENSE (("1.5" 01024949)
("1.6" 01228249))
:PROPBANK ("arg0 arg1 arg2(with)")
:THETA_ROLES ((1 "_ag_th,instr(with)"))
:LCS (cause (* thing 1)
(go ident (* thing 2)
(toward ident (thing 2) (at ident (thing 2) (abase+ed 9))))
((* with 19) instr (*head*) (thing 20)))
:VAR_SPEC ((1 (animate +)))
)
这里有完整的数据https://raw.githubusercontent.com/ihmc/lcs/master/verbs-english.lcs
我尝试过在本文中发表的想法,使用类似的东西用python解析lisp文件,但我得到了一种与我所寻找的格式不同的格式
inputdata = '''
(
:DEF_WORD "abandon"
:CLASS "51.2"
:WN_SENSE (("1.5" 01269572 01188040 01269413 00345378)
("1.6" 01524319 01421290 01524047 00415625))
:PROPBANK ("arg1 arg2")
:THETA_ROLES ((1 "_th,src"))
:LCS (go loc (* thing 2)
(away_from loc (thing 2) (at loc (thing 2) (* thing 4)))
(abandon+ingly 26))
:VAR_SPEC ((4 :optional) (2 (animate +)))
)
(
:DEF_WORD "abase"
:CLASS "45.4.a"
:WN_SENSE (("1.5" 01024949)
("1.6" 01228249))
:PROPBANK ("arg0 arg1 arg2(with)")
:THETA_ROLES ((1 "_ag_th,instr(with)"))
:LCS (cause (* thing 1)
(go ident (* thing 2)
(toward ident (thing 2) (at ident (thing 2) (abase+ed 9))))
((* with 19) instr (*head*) (thing 20)))
:VAR_SPEC ((1 (animate +)))
)'''
from pyparsing import OneOrMore, nestedExpr
data = OneOrMore(nestedExpr()).parseString(inputdata)
print (data)
我得到了如下输出:
[
[ ':DEF_WORD', '"abandon"',
':CLASS', '"51.2"',
':WN_SENSE', [
['"1.5"', '01269572', '01188040', '01269413', '00345378'],
['"1.6"', '01524319', '01421290', '01524047', '00415625']
],
':PROPBANK', ['"arg1 arg2"'],
':THETA_ROLES', [['1', '"_th,src"']],
':LCS', ['go', 'loc', ['*', 'thing', '2'],
['away_from', 'loc', ['thing', '2'],
['at', 'loc', ['thing', '2'], ['*', 'thing', '4']]], ['abandon+ingly', '26']],
':VAR_SPEC', [['4', ':optional'], ['2', ['animate', '+']]]]
,
[':DEF_WORD', '"abase"',
':CLASS', '"45.4.a"',
':WN_SENSE', [
['"1.5"', '01024949'],
['"1.6"', '01228249']
],
':PROPBANK', ['"arg0 arg1 arg2(with)"'],
':THETA_ROLES', [['1', '"_ag_th,instr(with)"']],
':LCS', ['cause', ['*', 'thing', '1'],
['go', 'ident', ['*', 'thing', '2'],
['toward', 'ident', ['thing', '2'],
['at', 'ident', ['thing', '2'],
['abase+ed', '9']]]],
[['*', 'with', '19'], 'instr', ['*head*'], ['thing', '20']]],
':VAR_SPEC', [['1', ['animate', '+']]]
]
]
我不确定如何处理这种输出格式,以便获得本词典中的例如θ_角色值或其他动词特征,我使用pandas和nltk将所有句子放在一个数组中,因此,我的想法是寻找在本词典中具有一种动词和特定θ_角色值或其他特征的句子。
暂无答案!
目前还没有任何答案,快来回答吧!