这是我从 Stanford CoreNLP 获得的输出 XML 文件的一部分:
<collapsed-ccprocessed-dependencies>
<dep type="nn">
<governor idx="25">Mullen</governor>
<dependent idx="24">Ms.</dependent>
</dep>
<dep type="nsubj">
<governor idx="26">said</governor>
<dependent idx="25">Mullen</dependent>
</dep>
</collapsed-ccprocessed-dependencies>
</sentence>
</sentences>
<coreference>
<coreference>
<mention representative="true">
<sentence>1</sentence>
<start>1</start>
<end>2</end>
<head>1</head>
</mention>
<mention>
<sentence>1</sentence>
<start>33</start>
<end>34</end>
<head>33</head>
</mention>
</coreference>
</coreference>
<mention representative="true">
<sentence>1</sentence>
<start>6</start>
<end>9</end>
<head>8</head>
</mention>
<mention>
<sentence>1</sentence>
<start>10</start>
<end>11</end>
<head>10</head>
</mention>
</coreference>
<coreference>
如何使用 Perl 解析它,以便得到如下内容:
1. sentence 1, head 1
sentence 1, head 33
2. sentence 1, head 8
sentence 1, head 10
我尝试过使用 XML::Simple,但输出不容易理解。这是我所做的:使用 XML::Simple;使用 Data::Dumper;
$outfile = $filename.".xml";
$xml = new XML::Simple;
$data = $xml -> XMLin($outfile);
print Dumper($data);