Beispiel #1
0
 def test_q25_pick_basic_info_template_nesting(self):
     article = "{{redirect|aiueo}}\n" + \
                 "{{基礎情報 国\n" + \
                 "|略名 = 某国\n" + \
                 "|入れ子 = {{あいう}}\n" + \
                 "}}\n" + \
                 "{{別テンプレート\n" + \
                 "|key = value\n" + \
                 "|key2 = value2\n" + \
                 "}}\n" + \
                 "\n"
     result = q25.pick_basic_info_template(article)
     expected = "{{基礎情報 国\n" + \
                 "|略名 = 某国\n" + \
                 "|入れ子 = {{あいう}}\n" + \
                 "}}"
     self.assertEqual(expected, result)
Beispiel #2
0
                \[\[(?!(ファイル|File|Media|Category):)   #ファイルでもカテゴリーでもない[[ ]]
                (?P<link>.+?)
                (\|(?P<disp>.+?))?
                \]\]
                """
    rec = re.compile(pattern, re.VERBOSE)
    pre = ""
    result = template
    # 記事名|表示名 のパターンなら表示名を優先する。
    while pre != result:
        pre = result
        match = rec.search(result)
        if match and match.group("disp"):
            result = rec.sub(r"\g<disp>", result, count=1)
        else:
            result = rec.sub(r"\g<link>", result, count=1)
    return result


if __name__ == "__main__":

    file = os.path.join(os.path.dirname(__file__),
                        r"..\DataSource\jawiki-country.json.gz")
    article = q20.get_article_from_gzip_json(file, "イギリス")
    template = q25.pick_basic_info_template(article)

    fixed = remove_markup_innerlink(template)

    result = (q25.to_dict_wiki_template(fixed))
    for k, v in result.items():
        print(k, ":", v)