#!/bin/perl
#
# Squish/Algae test script
# usage: ./sqtest.pl --data=../samples/data2.rdf 
#
BEGIN {unshift @INC,('../../..','../..','..','/home/pldab/working/','/home/pldab/working/rudolf-perl/');}

use RDF::RDFWeb::SquishAlgae;
use strict;

my $datafile = "/home/pldab/working/rudolf-perl/samples/data.rdf"; 
print "Sample data: $datafile\n";

my $q = new RDF::RDFWeb::SquishAlgae;
my $q2 = new RDF::RDFWeb::SquishAlgae;

my $RDF='http://www.w3.org/1999/02/22-rdf-syntax-ns#';
my $DC= 'http://purl.org/dc/elements/1.1/';
my $DST ="http://www.w3.org/2001/06/dspace-swad-test#";
my $EG ="http://www.w3.org/2001/06/dspace-swad-examples#";

my $test1 = './test1-ds.rdf';


#########################################################################
# query in SquishQL format
my $iq = "SELECT ?x ?y FROM $test1 WHERE 
	 (rdf::type ?x ?y) 
	USING rdf as $RDF AND dc as $DC";

my @i = $q2->doalgae( $test1, $q->squish2algae( $iq ) );
print "\n\nQuery results:\n";
foreach my $hit (@i) {
  printf ( "object: %s type: %s\n\n",
 		$$hit{0}, $$hit{1} );
}

#########################################################################
# query in SquishQL format
my $pq1 = "SELECT ?x ?y  FROM $test1 WHERE 
	 (dst::partOf ?x ?y) 
	USING rdf as $RDF AND dc as $DC AND dst AS $DST";

my @i = $q->doalgae( $test1, $q->squish2algae( $pq1 ) );
print "\n\nQuery results:\n";

#
foreach my $hit (@i) {
  printf ( "object: %s is part of...: %s \n\n",
 		$$hit{0}, $$hit{1} );
}


#########################################################################
# from figure 8. of 'an object model from dspace', robert tansley 11 june 2001
#

# find objects ?x their rdf:type and dc:description where there is some
# object ?o which is dst:partOf ?x and that is consumed by an object ?t of
# rdf:type obj:101 # (transformation record type) where there is another resource ?y which
# dst:has_format of 'image/jpeg' dst:produced_by that transformation

my $complex1="
SELECT ?x ?o ?t  WHERE 
	(dst::consumed ?t ?o)
	(dst::partOf ?o ?x)
	(rdf::type ?x ?t)
USING rdf as $RDF AND dc as $DC AND dst AS $DST";

# more constraints...
#	(dc::description ?x ?d)
#	(dst::produced_by ?y ?t)
      
  
#my @i = $q->doalgae( $test1, $q->squish2algae( $complex1 ) );

#print "\n\n **notfinished** complex search results:\n";

#foreach my $hit (@i) {
#  printf ( "object: %s is part of...: %s \n\n",
# 		$$hit{0}, $$hit{1} );
#}


