Changeset View
Changeset View
Standalone View
Standalone View
pology/lang/ko/language.py
- This file was added.
1 | # -*- coding: UTF-8 -* | ||||
---|---|---|---|---|---|
2 | | ||||
3 | """ | ||||
4 | Rules with dynamically generated regex. Some rules are adopted from ko-po-check. | ||||
5 | | ||||
6 | @author: Shinjo Park <kde@peremen.name> | ||||
7 | @original-author: Changwoo Ryu <cwryu@debian.org> | ||||
8 | @license: GPLv3+ | ||||
9 | """ | ||||
10 | | ||||
11 | import re | ||||
12 | | ||||
13 | from pology import datadir, _, n_ | ||||
14 | from pology.diff import adapt_spans | ||||
15 | | ||||
16 | PLURAL_JOSA_RE = ur'(도|로|만|에|은|을|이|의)' | ||||
17 | # 많이 등장하는 명사만 쓴다 | ||||
18 | PLURAL_NOUN_RE = ur'(값|개발자|것|기능|기술|그림|글자|답변|디렉터리|메시지|' \ | ||||
19 | ur'문서|문자|분|사람|사진|설정|언어|점|질문|파일|팀|패키지|' \ | ||||
20 | ur'폴더|프로그램|플러그인|항목|활동)' | ||||
21 | PLURAL_EXCEPT = ur'(핸들|번들)' + PLURAL_JOSA_RE | ||||
22 | | ||||
23 | PLURAL_R = re.compile(ur'(' + | ||||
24 | ur'[\uac00-\ud7a3]+\(들\)' + ur'|' + | ||||
25 | PLURAL_NOUN_RE + ur'들' + ur'|' + | ||||
26 | ur'[\uac00-\ud7a3]+들' + PLURAL_JOSA_RE + ur'\s' + ur')', re.UNICODE) | ||||
27 | PLURAL_EXCLUDE = re.compile(PLURAL_EXCEPT, re.UNICODE) | ||||
28 | | ||||
29 | def redundant_plural (msgstr, msg, cat): | ||||
30 | """ | ||||
31 | 불필요한 복수형 표현을 검사한다. | ||||
32 | | ||||
33 | 임의의 복수형 표현을 찾아내기는 매우 힘들다. 다음 휴리스틱으로만 검사. | ||||
34 | (0) (들)이라고 쓰여진 경우 | ||||
35 | (1) 일단 알려진 명사에 대한 복수형태를 찾고 | ||||
36 | (2) 들+조사 형태로 끝나는 경우를 찾는다 | ||||
37 | | ||||
38 | @return: type V3C hook | ||||
39 | @rtype: C{(msgstr, msg, cat) -> spans} | ||||
40 | """ | ||||
41 | | ||||
42 | return check(PLURAL_R, PLURAL_EXCLUDE, msgstr, msg, cat, u"Unnecessary plural '%(match)s'.") | ||||
43 | | ||||
44 | SYLLABLE_WITH_T_RIEUL = '[%s]' % ''.join([unicode(c) for c in | ||||
45 | range(0xAC00 + 8, 0xD7A4, 28)]) | ||||
46 | SYLLABLE_WITH_T_SSANGSIOS = '[%s]' % \ | ||||
47 | ''.join([unicode(c) for c in | ||||
48 | range(0xAC00 + 0x14, 0xD7A4, 28)]) | ||||
49 | GEOSIPNIDA_R = re.compile('\S+' + SYLLABLE_WITH_T_RIEUL + u' 것입니다') | ||||
50 | # 과거형인 "-했을 것입니다"는 예외 | ||||
51 | GEOSIPNIDA_EXCLUDE = re.compile('\S+' + SYLLABLE_WITH_T_SSANGSIOS + u'을 것입니다') | ||||
52 | | ||||
53 | def hal_geosipnida (msgstr, msg, cat): | ||||
54 | """ | ||||
55 | ...할 것입니다 | ||||
56 | | ||||
57 | @return: type V3C hook | ||||
58 | @rtype: C{(msgstr, msg, cat) -> spans} | ||||
59 | """ | ||||
60 | | ||||
61 | return check(GEOSIPNIDA_R, GEOSIPNIDA_EXCLUDE, msgstr, msg, cat, "Try to revise '%(word)s'.") | ||||
62 | | ||||
63 | def check(r, exclude, msgstr, msg, cat, errmsg): | ||||
64 | | ||||
65 | spans = [] | ||||
66 | matches = list(r.finditer(msgstr)) | ||||
67 | for m in matches: | ||||
68 | p1, p2 = m.span() | ||||
69 | if exclude and exclude.match(msgstr[p1:p2].strip()): | ||||
70 | continue | ||||
71 | spans.append((p1, p2, _(u"@info", errmsg, match=msgstr[p1:p2].strip()))) | ||||
72 | | ||||
73 | return spans |