I have an remote RDF file from where I want to fetch some data. It is on remote server and the example data is working 100% fine, but soon I parse my file it starts giving the error. I am using Easy RDF library.
Here is the example they are providing:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
?>
<html>
<head>
<title>Basic FOAF example</title>
</head>
<body>
<?php
$foaf = EasyRdf_Graph::newAndLoad('http://njh.me/foaf.rdf');
$me = $foaf->primaryTopic();
?>
<p>
My name is: <?= $me->get('foaf:name') ?>
</p>
</body>
</html>
Here is my example from where i am getting an error.
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
?>
<html>
<head>
<title>Basic FOAF example</title>
</head>
<body>
<?php
$foaf = EasyRdf_Graph::newAndLoad('http://gutenberg.readingroo.ms/cache/generated/4500/pg4500.rdf');
$me = $foaf->primaryTopic();
?>
<p>
My name is: <?= $me->get('dcterms:title') ?>
</p>
</body>
</html>
Error i am getting:
My name is:
Fatal error: Call to a member function get() on a non-object in D:\xampp\htdocs\giftcardbooks\easyrdf\examples\basic.php on line 31
My ultimate goal is to get values from the RDF file. using its nodes and child. please have a look and help me out from it.
The documentation is far from complete, and it is very hard to find anything relevant in this topic. All you can do for further understanding is digging into the code, or asking your question here: https://groups.google.com/forum/#!forum/easyrdf.
The
primaryTopic()
approach will never workAccording to the Graph class, the
primaryTopic()
does this:Which means it is looking for a resource which is in some kind of relation with
foaf:primaryTopic
. Yourget()
call returnsnull
, since your RDF does not contain a resource like that.Currently this works for me with your RDF
An alternative approach to get the
$book
:Since the book is a root node, it will be the first resource in the graph...
I don't think there is a way to get the book using
pgterms:ebook
It is because EasyRdf does not recognizes that as a type. I think that is because it is not defined anywhere as an
rdfs:Class
, it is just used, but that's just a guess, to make it sure you have to check the code. Thedcterms:title
is not a type either, but it can be used as a resource property...Parse as XML
It is much easier to parse your RDF file with an XML parser:
I think there is an issue in the EasyRdf or in your RDF file, but I could not find a way to get the name using EasyRdf. The
dcterms:creator
had anrdf:type
ofpgterms:agent
, but it had no other properties nor had the agent... I could not find out what's the problem. I checked the$graph->resources()
and the value of the missing properties were under generated IDs which seemed to have no contact with the$ebook
. So I guess the parsing went not so well. This can be an EasyRdf error, or this can be a problem with the RDF file itself. I'll ask about it in the discussion forum, maybe they provide an answer.