<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person rdf:ID="me">
<foaf:name>Kjetil Kjernsmo</foaf:name>
<foaf:nick>KjetilK</foaf:nick>
</foaf:Person>
</rdf:RDF>
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
<http://www.kjetil.kjernsmo.net/foaf.rdf#me>
a foaf:Person ;
foaf:name "Kjetil Kjernsmo";
foaf:nick "KjetilK" .
Do not think about RDF just in XML terms!
$model->add_statement(
new RDF::Redland::URINode('http://www.kjetil.kjernsmo.net/foaf.rdf#me',
new RDF::Redland::URINode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
new RDF::Redland::URINode('http://xmlns.com/foaf/0.1/Person')
);
$model->add_statement(
new RDF::Redland::URINode('http://www.kjetil.kjernsmo.net/foaf.rdf#me',
new RDF::Redland::URINode('http://xmlns.com/foaf/0.1/name'),
new RDF::Redland::LiteralNode('Kjetil Kjernsmo')
);
$model->add_statement(
new RDF::Redland::URINode('http://www.kjetil.kjernsmo.net/foaf.rdf#me',
new RDF::Redland::URINode('http://xmlns.com/foaf/0.1/nick'),
new RDF::Redland::LiteralNode('KjetilK')
);
$model->add_statement(
new RDF::Redland::URINode('http://www.daml.org/airport/OSL',
new RDF::Redland::URINode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
new RDF::Redland::URINode('http://www.daml.org/2001/10/html/airport-ont#Airport')
);
$model->add_statement(
new RDF::Redland::URINode('http://www.daml.org/airport/OSL',
new RDF::Redland::URINode('http://www.daml.org/2001/10/html/airport-ont#name'),
new RDF::Redland::LiteralNode('Gardermoen')
);
$model->add_statement(
new RDF::Redland::URINode('http://www.daml.org/airport/OSL',
new RDF::Redland::URINode('http://www.daml.org/2001/10/html/airport-ont#iataCode'),
new RDF::Redland::LiteralNode('OSL')
);
my $rdf = RDF::Helper->new(
BaseInterface => 'RDF::Redland',
BaseURI => 'http://www.kjetil.kjernsmo.net/foaf.rdf',
Namespaces => {
foaf => 'http://purl.org/dc/elements/1.1/',
rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
air => 'http://www.daml.org/2001/10/html/airport-ont#'
}
);
$rdf->assert_resource('#me', 'rdf:type', 'foaf:Person');
$rdf->assert_literal('#me', 'foaf:name', 'Kjetil Kjernsmo');
$rdf->assert_literal('#me', 'foaf:nick', 'KjetilK');
$rdf->assert_resource('http://www.daml.org/airport/OSL',
'rdf:type', 'air:Airport');
$rdf->assert_literal('http://www.daml.org/airport/OSL',
'air:name', 'Gardermoen');
$rdf->assert_literal('http://www.daml.org/airport/OSL',
'air:iataCode', 'OSL');
SPARQL is a query language for RDF graphs. W3C Candidate Recommendation.
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name WHERE {
?user foaf:nick "kjetilk" .
?user foaf:name ?name . }
Running the query is simply:
my $query=new RDF::Redland::Query($string, undef, undef, "sparql");
my $results=$query->execute($model);
You can serialise it to XML (W3C work), JSON or just work on the Perl data structure.