我有一个要解析和访问节点的 RDF/XML 数据。它看起来像这样:
<!-- http://purl.obolibrary.org/obo/VO_0000185 -->
<owl:Class rdf:about="&obo;VO_0000185">
<rdfs:label>Influenza virus gene</rdfs:label>
<rdfs:subClassOf rdf:resource="&obo;VO_0000156"/>
<obo:IAO_0000117>YH</obo:IAO_0000117>
</owl:Class>
<!-- http://purl.obolibrary.org/obo/VO_0000186 -->
<owl:Class rdf:about="&obo;VO_0000186">
<rdfs:label>RNA vaccine</rdfs:label>
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<rdf:Description rdf:about="&obo;VO_0000001"/>
<owl:Restriction>
<owl:onProperty rdf:resource="&obo;BFO_0000161"/>
<owl:someValuesFrom rdf:resource="&obo;VO_0000728"/>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="&obo;VO_0000001"/>
<obo:IAO_0000116>Using RNA may eliminate the problem of having to tailor a vaccine for each individual patient with their specific immunity. The advantage of RNA is that it can be used for all immunity types and can be taken from a single cell. DNA vaccines need to produce RNA which then prompts the manufacture of proteins. However, RNA vaccine eliminates the step from DNA to RNA.</obo:IAO_0000116>
<obo:IAO_0000115>A vaccine that uses RNA(s) derived from a pathogen organism.</obo:IAO_0000115>
<obo:IAO_0000117>YH</obo:IAO_0000117>
</owl:Class>
完整的 RDF/XML 文件可以在这里找到。
我想要做的是执行以下操作:
- 查找包含条目的块
<rdfs:subClassOf rdf:resource="&obo;VO_0000001"/>
- 访问由以下定义的字面术语
<rdfs:label>...</rdfs:label>
因此,在上面的示例中,代码将通过第二个块并输出:“RNA 疫苗”。
我目前坚持使用以下代码。我无法访问节点的地方。正确的方法是什么?欢迎使用 XML::LibXML 以外的解决方案。
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use Carp;
use File::Basename;
use XML::LibXML 1.70;
my $filename = "VO.owl";
# Obtained from http://svn.code.sf.net/p/vaccineontology/code/trunk/src/ontology/VO.owl
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file( $filename );
foreach my $chunk ($doc->findnodes('/owl:Class')) {
my ($label) = $chunk->findnodes('./rdfs:label');
my ($subclass) = $chunk->findnodes('./rdfs:subClassOf');
print $label->to_literal;
print $subclass->to_literal;
}