Thành viên:Tildebot/@

Từ điển mở Wiktionary

Thay các lần gọi {{term}} ở đây bằng {{@}}. {{@}} có nhiều tính năng hơn {{term}}, và các mục từ được nhập vào đây bởi PiedBot có rất nhiều lỗi gọi {{term}} (nhất là chính tả), nên tôi phải thực hiện việc này trong vài bước:

  1. Tập hợp lại các lần gọi {{term}} ở đây để biết cần tại ra tiêu bản @ nào. Xem {{@}}.
  2. Viết các biểu thức chính quy để đổi tiêu bản.
  3. Chạy replace.py dùng các biểu thức đo.

Mã nguồn[sửa]

!term.py[sửa]

import codecs, re, datetime, time
import wikipedia, pagegenerators

TEMPLATE = "term"
OUTPUT = "~/Documents/term-%s.wiki"
PAGES_FROM = 139500 # [[pompile]]

def collect():
    """Collect instances of {{term}} in articles at the Vietnamese-language
       Wiktionary."""
    site = wikipedia.getSite()
    term = wikipedia.Page(site, site.template_namespace() + ":" + TEMPLATE)
    gen = pagegenerators.ReferringPageGenerator(term, pagesFrom = PAGES_FROM,
                                                onlyTemplateInclusion = True)
    gen = pagegenerators.NamespaceFilterPageGenerator(gen, [0])
    output = codecs.open(OUTPUT % datetime.date.today(), "a", "utf-8")
    for page in gen:
        text = page.get()
        termRe = re.compile(r".*\{\{term\|.*")
        lines = termRe.findall(text)
        for line in lines:
            line = u"\03{lightpurple}%s\03{default}\t%s\n" % \
                   (unicode(page.title()), unicode(line))
#            print line
            wikipedia.output(line)
            output.write(u"%s\t%s\n" % (unicode(page.title()), unicode(line)))
        time.sleep(5)
    output.close()

def main():
    collect()

if __name__ == "__main__":
    main()

pagegenerators.py[sửa]

147c147
<                            onlyTemplateInclusion=False):
---
>                            onlyTemplateInclusion=False, pagesFrom=0):
151c151,152
<                                            onlyTemplateInclusion):
---
>                                            onlyTemplateInclusion,
>                                            pagesFrom=pagesFrom):

wikipedia.py[sửa]

854c854
<             onlyTemplateInclusion=False, redirectsOnly=False):
---
>             onlyTemplateInclusion=False, redirectsOnly=False, pagesFrom=0):
874c874
<         path = self.site().references_address(self.urlname())
---
>         path = self.site().references_address(self.urlname(), fr = pagesFrom)
4168,4169c4168,4169
<     def references_address(self, s):
<         return self.family.references_address(self.lang, s)
---
>     def references_address(self, s, fr = 0):
>         return self.family.references_address(self.lang, s, pages_from = fr)

family.py[sửa]

2489,2490c2489,2490
<     def references_address(self, code, name):
<         return '%s?title=%s:Whatlinkshere&target=%s&limit=%d' % (self.path(code), self.special_namespace_url(code), name, config.special_page_limit)
---
>     def references_address(self, code, name, pages_from = 0):
>         return '%s?title=%s:Whatlinkshere&target=%s&limit=%d&from=%d' % (self.path(code), self.special_namespace_url(code), name, config.special_page_limit, pages_from)

Biểu thức chính quy[sửa]

Để nhận các lần gọi {{term}} ở đầu định nghĩa, bao gồm phần nhiều từ khóa bị bỏ quên và những dấu chấm phẩy đằng sau tiêu bản. Nó cũng bao gồm những giới từ trong dấu ngoặc đơn; sẽ cần bỏ qua những nó.

(r"(\t#+ ?\{\{term\|.*)\}\}((?: ?[.,;]? ?\((?!(?:ở|thuộc|thuộc [^\)]+|bằng|về|của|chỉ|kẻ|để|đi|làm|bị|được|một|gồm|đã|do|theo|theo [^\)]+|có|có [^\)]+|số nhiều [^\)]+)\))[^\[(]*?\))+)( ?[.,;])?",
 r"\1; \2}}\3")
(u"# <(.+?)> (\w+)", lambda m: r"# {{@|%s}} %s" % (m.group(1), m.group(2).capitalize())),
(u"# <(.+?)> \[\[(\w+)\]\]", lambda m: u"# {{@|%s}} [[%s|%s]]" % (m.group(1), m.group(2), m.group(2).capitalize())),

Các sửa đổi[sửa]

Sai Đúng Tiêu bản hợp Chú thích
Id. ít dùng {{@ít dùng}}
Nghĩa ít dùng
Số nhiều số nhiều {{@số nhiều}} Có lẽ cần thay bằng {{plur}} nếu không có label nào khác.
Thường thường {{@&thường}} Cần mang những từ đằng sau (như là "vị ngữ") vào tiêu bản.
Từ mỹ,nghĩa mỹ Hoa Kỳ Mỹ {{@Mỹ}}
Từ mỹ, nghĩa mỹ
Từ Mỹ, nghĩa Mỹ
Từ mỹ, nghĩa mỹ
Từ mỹ
Nghĩa mỹ
Từ Anh, nghĩa Anh Anh Anh {{@Anh}}
Nghĩa Anh
Thuộc Cần mang ra khỏi tiêu bản và kẹp giữa dấu ngoặc đơn.
Người
Con
Cái
Trận
Nghĩa xấu xấu {{@xấu}}
Từ cũ, nghĩa cũ {{@cũ}}
Từ cũ; nghĩa cũ
Từ cũ nghĩa cũ
Irland, scotland Ireland Ireland, Scotland Scotland {{@Ireland}} {{@Scotland}}
Econ kinh tế học {{@kinh tế học}}
(econ) absolute value
Tech kỹ thuật {{@kỹ thuật}}
Từ hiếm,nghĩa hiếm hiếm {{@hiếm}}
Thần thoại,thần học thần thoại, thần học {{@thần thoại}} {{@thần học}} Cần phải phân biệt giữa thần thoại và thần học.
Địa lý,ddịa chất địa lý học, địa chất học {{@địa lý học}} {{địa chất học}} Chắc sẽ dùng "địa lý học".
Raddiô radio {{@radio}}
Từ cổ,nghĩa cổ cổ {{@cổ}}
Từ cổ, nghĩa cổ
Thể dục,thể thao thể dục, thể thao {{@thể dục}} {{thể thao}} Chắc sẽ dùng "thể thao".
Thể dục, thể thao
Thể dục thể thao
Quyền anh quyền Anh {{@quyền Anh}}
Ân-ddộ Ấn Độ Ấn Độ {{@Ấn Độ}}
Anh-Ân
Uc Úc Úc {{@Úc}}
Như {{like-entry}} Cần mang cả dòng vào tiêu bản.
Định ngữ ? ? Tính từ?
Ph. phương ngữ {{@phương ngữ}} "Ph.; kng."
Kng. khẩu ngữ {{@khẩu ngữ}}
Th ca thơ ca {{@thơ ca}}
Ca-na-đa Canada Canada {{@Canada}}
Từ mới, nghĩa mới mới {{@mới}}
Hoặc t. hoặc tính từ Cần phải tách ra phần {{-adj-}} riêng.

Xem thêm[sửa]