Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cedict reader #138

Merged
merged 8 commits into from
Nov 15, 2017
Merged

Cedict reader #138

merged 8 commits into from
Nov 15, 2017

Conversation

jlowryduda
Copy link
Contributor

No description provided.

DATE_RANGE_REGEX = re.compile(r'(.+?)\s\(.+\d.+\),') # date range
PAREN_REGEX = re.compile(r'\(.+?\)') # parenthesis
CHINESE_CHAR_REGEX = re.compile(r'([\u4e00-\u9fff]+[\|·]?)+') # Chinese characters
BRACKETS_REGEX = re.compile(r'\[.+\]') # pronunciation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this regex is too greedy and should have a ? on it like PAREN_REGEX does.

I believe that in this definition:

一甲 一甲 [yi1 jia3] /1st rank or top three candidates who passed the imperial examination (i.e. 狀元|状元[zhuang4 yuan2], 榜眼[bang3 yan3], and 探花[tan4 hua1], respectively)/

it will match this text:

[zhuang4 yuan2], 榜眼[bang3 yan3], and 探花[tan4 hua1]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular definition would actually have everything inside the parentheses removed before matching the brackets, but the problem was true for a couple of other definitions, so I changed it.

LINE_REGEX = re.compile(r'(.+)\s(.+)\[.+\]\s/(.+)/') # separate traditional and simplified words
DATE_RANGE_REGEX = re.compile(r'(.+?)\s\(.+\d.+\),') # date range
PAREN_REGEX = re.compile(r'\(.+?\)') # parenthesis
CHINESE_CHAR_REGEX = re.compile(r'([\u4e00-\u9fff]+[\|·]?)+') # Chinese characters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to exclude the range from U+3400..U+4DBF, which appears in definitions such as:

㐌 㐌 [ta1] /variant of 它[ta1]/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, it also excludes the other CJK extensions with codepoints U+20000 and up, but CEDICT never uses those anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was correct for a couple of definitions, so I ended up switching to regex.compile('([\p{IsIdeo}]+[\|·]?)+'), per your suggestion.

@rspeer rspeer merged commit 620b713 into master Nov 15, 2017
@rspeer rspeer deleted the cedict-reader branch November 15, 2017 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants