擅长:python、mysql、java
<p>这是:</p>
<pre><code>#!/usr/bin/env python3
import xml.etree.ElementTree as ET
tree = ET.parse('output.xml')
root = tree.getroot()
print(" PERS-PERS -")
for phrase in root:
if phrase.tag == 'PHRASE':
collected_names = []
for elt in phrase:
if elt.tag == 'en':
if 'x' in elt.attrib and elt.attrib['x'] == 'PERS':
collected_names += [elt.text]
if len(collected_names) >= 2:
print(collected_names[0] + " - " + collected_names[1])
</code></pre>
<p>将输出:</p>
<pre><code>$ ./test_script
PERS-PERS -
John - Alex
Nick - Anna
</code></pre>
<p>但我不确定这正是你想要的。你知道吗</p>