[redland-dev] newbie question using Perl bindings

Golda Velez gv at abra.info
Sat Dec 8 18:06:40 GMT 2007


On Friday 07 December 2007 16:49, rzeno wrote:
...
> # create a parser
> my $parser = new RDF::Redland::Parser("rdfxml","application/rdf+xml");
> 
> # load your data
> my $buri = new RDF::Redland::URI($base_url);
> my $furi = new RDF::Redland::URI("file:".$myfiledir."<your file name>");
> $parser->parse_into_model($furi,$buri,$model);
> 
Thanks for the advice!  I was using 

	$stream=$parser->parse_as_stream($uri,$uri);    

and that is where it was dying.  Although it said 'skipping' it dies in that 
command after printing the error

Redland error: property element 'Topic' has multiple object node elements, 
skipping.

So, I tried parse_into_model, with the same error :
-------------------------------------------------------------------------------------------------------
#!/usr/local/bin/perl

use RDF::Redland;

$data_file = "/w/abra/data/structure.rdf.u8";

$base_url = "";

warn "Creating storage for dmoz\n";
my $storage = new 
RDF::Redland::Storage("hashes","dmoz_cats","new='yes',hash-type='bdb',dir='.'");

die "Failed to create RDF::Redland::Storage\n" unless $storage;

warn "\nCreating model\n";
my $model=new RDF::Redland::Model($storage, "");
die "Failed to create RDF::Redland::Model for storage\n" unless $model;


my $base_uri = new RDF::Redland::URI($base_url);

my $data_uri = new RDF::Redland::URI("file:$data_file");

my $parser = new RDF::Redland::Parser("rdfxml","application/rdf+xml");

$parser->parse_into_model($data_uri, $base_uri, $model);

--
result: Redland error: property element 'Topic' has multiple object node 
elements, skipping.


I couldn't yet find the place on the dmoz site where it refers to a way to get 
around errors with Redland, I'll keep looking, or try rapper....thanks again 
for the advice!

--Golda


> On Fri, Dec 07, 2007 at 02:13:16PM -0700, Golda Velez wrote:
> > Hello Redland folks
> > 
> > I'm new to Redland so please feel free to direct me to further reading...
> > 
> > Trying to use the perl binding to parse the dmoz categories, like so
> > 
> > use RDF::Redland;
> > 
> > $data_file = "/w/abra/data/structure.rdf.u8";
> > 
> > my $uri = new RDF::Redland::URI("file:$data_file");
> > 
> > my $parser = new RDF::Redland::Parser("rdfxml","application/rdf+xml");
> > ------------------------------
> > 
> > dies with 
> > 
> > Redland error: property element 'Topic' has multiple object node elements, 
> > skipping.
> > ----------------------------
> > 
> > Am I even on the right track here?  About six years ago I wanted to do 
stuff 
> > with the dmoz categories and just wrote a regexp rough approximate parser, 
> > now I'd like to do it right...but I'm not sure I am using the right 
toolset. 
> > 
> > Thanks for any clue!
> >
> some info:
> - in the source package of redland-binding you can find some examples in the
> demos directory
> - apropos rdf::redland give you the list of the man pages and you can find
> there some explanation and examples
> - man rdf::redland and rdf::redland::XXX with XXX in storage, model, parser,
> query, ...
> - google, yahoo, ... for 'rdf' and 'redland', I find one useful link last 
year, :-)
> 
> This is *not* tested, see the man pages for details, but maybe help:
> 
> #!/usr/bin/perl -w
> use strict;
> use RDF::Redland;
> 
> # for me this is usually undef
> my $base_url = ...;
> # data directory
> my $myfiledir = ...;
> 
> # create a storage
> my $storage = new RDF::Redland::Storage("hashes", "test", 
> 													 "new='yes',hash-type='memory',dir='.'");
> 
> # create a model
> my $model = new RDF::Redland::Model($storage,"");
> 
> # create a parser
> my $parser = new RDF::Redland::Parser("rdfxml","application/rdf+xml");
> 
> # load your data
> my $buri = new RDF::Redland::URI($base_url);
> my $furi = new RDF::Redland::URI("file:".$myfiledir."<your file name>");
> $parser->parse_into_model($furi,$buri,$model);
> 
> # make your query
> my $query = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> 
> select distinct ?obj
> where {
>   [] rdf:type ?obj .
> }
> ";
> 
> my $q = new RDF::Redland::Query($query,undef,undef,"sparql");
> my $result = $model->query_execute($q);
> 
> # process the results, there are many ways, this is one
> while(!$result->finished){
> 	 for(my $i=0;$i<$result->bindings_count;$i++){
> 		  my $val = $result->binding_value($i);
> 		  my $name = $result->binding_name($i);
> 		  
>         # do something with $val and $name
> 
> 		  # I'm not sure here, :-)
> 		  $val = undef;
> 	 }
> 	 $result->next_result;
> }
> 
> # cleanup
> $result = undef;
> $q = undef;
> $furi = undef;
> $buri = undef;
> $parser = undef;
> $model = undef;
> $storage = undef;
> 
> ------------- please don't cut & past, rewrite it :-) -----------
> 
> PS: AFAIK dmoz rdf have some problems( syntax), see dmoz for details,
> explanation and how to avoid it( that was last year, I don't try again)
> 
> Best regards
> 
> -- 
> "We must be systematic, but we should keep our systems open."
>   -- Alfred North Whitehead, Modes of Thought --
> _______________________________________________
> redland-dev mailing list
> redland-dev at lists.librdf.org
> http://lists.librdf.org/mailman/listinfo/redland-dev
> 

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Golda Velez	520-440-1420		http://goldavelez.com
what I do: 	Tucson Superblog	http://btucson.com
		Search software		http://webglimpse.net
		Web hosting		http://iwhome.com

"Help organize the world - index your own corner of the web!"


More information about the redland-dev mailing list