我有一個我想分析和訪問節點的RDF/XML數據。 它看起來像這樣:使用Perl訪問RDF/XML/OWL文件節點
<!-- 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文件可以發現here。
我想要做的是做到以下幾點:它包含條目<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; }
我想我不僅應該不使用XML庫的解決方案受歡迎,而且_preferred_; [不要試圖將RDF解析爲XML](http://stackoverflow.com/a/17052385/1281433)。的確,RDF可以通過XML進行序列化,但是同一個RDF圖可以用不同的方式在XML中進行序列化,而對其中一個進行工作的XML解決方案不太可能適用於另一個。 RDF是基於圖表的表示形式,應該這樣對待。 –