use strict;
use utf8;
use Encode;

open(WIKI, "<:encoding(utf8)", "jawiki-latest-abstract.xml");
#open(WIKI, "<:encoding(utf8)", "10000.xml"); #for test

my $meishi = encode("shiftjis", "名詞");
my $utf8title;
my $title;
while (my $line = <WIKI>) {
	my $utf8 = $line;
	if ($utf8 =~ m/title|abstract/) {
		if ($utf8 =~ m!<title>Wikipedia: (.*?)(?: ?[（(].*?[）)])?</title>!) {
			$utf8title = $1;
		} elsif ($utf8 =~ m!<abstract>.*?（([ぁ-んァ-ンー ・]*).*?）.*?</abstract>!) {
			my $hit = $1;
			$hit =~ s/ //g;
			$hit =~ s/・//g;
			$hit =~ tr/ァ-ン/ぁ-ん/;
			my $yomi = encode("shiftjis", $hit);
			$utf8title =~ s/&amp;/&/g;
			$utf8title =~ s/&quot;/"/g; #"
			$utf8title =~ s/^.*?一覧.*$//g; #"
			$utf8title =~ s/^.*?登場人物.*$//g; #"
			$title = encode("shiftjis", $utf8title);
			if ($title and $yomi) {
				#if ($utf8title =~ m/^[一-龠々]+$/) { #kanji
				#unless ($utf8title =~ m/^[一-龠々]+$/) { #not kanji
					print $yomi, "\t", $title, "\t", $meishi, "\n";
				#}
			}
		}
	}
}
close(WIKI);
