テキストファイルから特定の単語を読み取り、それらをペアで表示するコードがあります(段落での出現に応じて-例:
Hi I am <PER>Rita</PER>.I live in <LOC>Canada</LOC>
Hi I am <PER>Jane</PER> and I do not live in <LOC>Canada<LOC/>
出力
Rita カナダ
Jane カナダ
(注: これは xml ファイルではありません。)ペア (Rita Canada)=1 [それらの間にピリオドがあるため] and (Jane Canada)=0 [それらの間に
ピリオド
が発生しないため] を出力したいです。
段落ごとに名前を出力する私のコード。終止符を特定するのを手伝ってもらえますか?
private static final Pattern personPattern = Pattern.compile("<PER>(.+?)</PER>");
private static final Pattern locationPattern = Pattern.compile("<LOC>(.+?)</LOC>");
for(File file : listOfFiles)
{
BufferedReader input = new BufferedReader(new FileReader(file));
String line = "";
while((line = input.readLine()) != null)
{
ArrayList<String> persons = new ArrayList<String>();
ArrayList<String> locations = new ArrayList<String>();
Matcher m_person = personPattern.matcher(line);
while(m_person.find())
{
persons.add(m_person.group(1));
}
Matcher m_location = locationPattern.matcher(line);
while(m_location.find())
{
locations.add(m_location.group(1));
}
for(int i = 0;i<persons.size();i++)
{
for(int j =0 ;j<locations.size();j++)
{
System.out.println(persons.get(i) + "\t" + locations.get(j));
}
}