"""
21.Extract rows containing category names
Extract the line that declares the category name in the article.
"""
import json
def get_uk_text(path):
with open(path) as f:
for line in f:
line_data = json.loads(line)
if line_data["title"] == "England":
data = line_data
break
return data["text"]
uk_text = get_uk_text("jawiki-country.json")
uk_text_list = uk_text.split("\n")
ans = [x for x in uk_text_list if "Category:" in x[:11]]
for a in ans:
print(a)
# [[Category:England|*]]
# [[Category:Commonwealth of Nations]]
# [[Category:Commonwealth Kingdom|*]]
# [[Category:G8 member countries]]
# [[Category:European Union member states|Former]]
# [[Category:Maritime nation]]
# [[Category:Existing sovereign country]]
# [[Category:Island country]]
# [[Category:A nation / territory established in 1801]]
Recommended Posts