-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmidori_parseutils.py
More file actions
35 lines (24 loc) · 1003 Bytes
/
Copy pathmidori_parseutils.py
File metadata and controls
35 lines (24 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from pyparsing import *
# define grammar
tagmark = Literal('[').suppress()
posmark = Literal(']').suppress()
commark = Literal('`').suppress()
jp_word = CharsNotIn('{}][`').setResultsName("words", listAllMatches = True)
tag = tagmark + jp_word.setResultsName("tags", listAllMatches = True)
pos = posmark + jp_word.setResultsName("pos", listAllMatches = True)
comment = commark + jp_word.setResultsName("comment", listAllMatches = True)
segment = jp_word | tag | pos | comment
segsep = Suppress(Word('}',exact=1))
# Compound
sep = Suppress(Word('{',exact=1))
meaning = Group(delimitedList(segment, segsep))
parser = delimitedList(meaning, sep)
# Kanji
stem = ending = CharsNotIn('{}][`.')
katakana = Word(srange(r"[\0x30A0-\0x30FF]"))
hiragana = Word(srange(r"[\0x3040-\0x309F]"))
brkmark = Literal('.').suppress()
kunword = Group(stem("stem") + Optional(brkmark + hiragana("ending")))
kun = delimitedList(kunword, sep)
on = delimitedList(katakana, sep)
meanings = delimitedList(jp_word, sep)