EasyRDF (php library): how to extract all the attributes and literals in RDF/XML?

271 Views Asked by At

With EasyRDF(PHP library), how to extract all the attributes and literals in XML/RDF?

I tried EasyRdf_Literal_XML::create(); and EasyRdf_Parser_RdfXml::parse(); EasyRdf_Literal_XML::domParse(); but I don't understand the poor documentation very well.

RDF/XML data ($input in the code below) looks like

<rdf:RDF>
  <rdf:Description rdf:about="http://dbpedia.org/resource/1964">
    <owl:sameAs rdf:resource="http://dbpedia.org/resource/1964"/>
    <rdf:Description rdf:about="http://dbpedia.org/resourc/1964_AD">
      <dbo:wikiPageRedirects rdf:resource="http://dbpedia.org  
        /resource/1964"/>
    </rdf:Description>
    <dbo:abstract xml:lang="nl">Het jaar 1964 is een jaartal volgens    
      de christelijke jaartelling.</dbo:abstract>
    <rdfs:comment xml:lang="es">1964 (MCMLXIV) fue un año bisiesto 
      comenzando en miércoles</rdfs:comment>
  </rdf:Description>
</rdf:RDF>

Here is the first code to start with:

# Put data ($input) in the format of RDF/XML ($format) in $graph

try {
   $graph = EasyRdf_Graph::newAndLoad($input, $format);
  } 
catch (Exception $error) {
    $error->getMessage();
    return array('RDF loading problem (No RDF available or RDF data problem');
  }

$xml = EasyRdf_Literal_XML::create($graph);
$a =  EasyRdf_Parser_RdfXml::parse($xml);

Now, I would like to extract and count (even the nesting ones)

1) all the attributes

  • rdf:about="http://dbpedia.org/resource/1964"
  • rdf:resource="http://dbpedia.org/resource/1964"
  • rdf:about="http://dbpedia.org/resourc/1964_AD"
  • rdf:resource="http://dbpedia.org/resource/1964"

4 counts

2) all the literals

  • Het jaar 1964 is een jaartal volgens de christelijke jaartelling.
  • 1964 (MCMLXIV) fue un año bisiesto comenzando en miércoles

2 counts

0

There are 0 best solutions below