[redland-dev] newbie question using Perl bindings

rzeno ruset.zeno at gmail.com
Fri Dec 7 23:49:03 GMT 2007


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 --


More information about the redland-dev mailing list