perl - RDF::Redland::Model how to add tag <foaf::nick> -
i have loaded rdf::redland::model
parsed rdf/xml document , want add tag <foaf::nick>
in it. how can it?
update:
this code far:
my $st = rdf::redland::node->new_xml_literal("<foaf:nick>content</foaf:content>"); $self->{model}->add_typed_literal_statement($st); print $self->{model}->to_string;
and doesn't work. doing wrong?
rdf models don't contain tags (or xml elements); rdf model set of triples of form subject predicate object
. foaf:nick property relates foaf:person nickname. based on title of question, sounds want add triple something foaf:nick somenick
model. in case, documentation rdf::redland::model indicates you'll want either add
or add_typed_literal_statement
:
add subject predicate object
add new statement model subject, predicate , object. these can rdf::redland::node, rdf::redland::uri or perl uri objects.
add_typed_literal_statement subject predicate string [xml_language [datatype]]
add new statement model containing typed literal string object string (optional) xml language (xml:lang attribute) xml_language , (optional) datatype uri datatype. xml_language or datatype can either or both set undef.
in first case, appears you'd need create rdf::redland::node represent literal string nickname. there a constructor take string argument in second case, easier, can use string directly.
edit
now you've posted code, particular issue becomes clearer, though still haven't mentioned what's going wrong.
my $st = rdf::redland::node->new_xml_literal("<foaf:nick>content</foaf:content>"); $self->{model}->add_typed_literal_statement($st);
first, if understand you're trying do, xml content you've used isn't formed, opening , closing tags don't match (nick
not content
). more problematically, isn't how rdf works. rdf graph-oriented representation, basic concept statement of form
subject predicate object
and rdf graph, or model, set of these. viewing each statement directed labelled edge subject object, obtain graph. rdf models can serialized in number of formats, 1 of rdf/xml, 1 you're working with. however, i've pointed out in this answer, point of rdf api let work statements of rdf graph, , not concerned particular serialization of graph.
it sounds want add statement
$something foaf:nick "content"
to graph, subject haven't identified. according documentation linked , quoted above, add_typed_literal_statement
takes three arguments, not one, , third argument should string. second line should like:
$self->{model}->add_typed_literal_statement($subject,$foafnick,"content");
where $subject
, $foafnick
uri nodes. e.g., might (untested):
$subject = new rdf::redland::urinode("https://stackoverflow.com/users/400371"); $foafnick = new rdf::redland::urinode("http://xmlns.com/foaf/0.1/nick"); $self->{model}->add_typed_literal_statement($subject,$foafnick,"nikita");
to add triple
<https://stackoverflow.com/users/400371> foaf:nick "nikita"
to model.
Comments
Post a Comment