incubator-triplesoup-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r528394 [18/35] - in /incubator/triplesoup/donations/TRIPLES-3-RDFStore: ./ dbms/ dbms/client/ dbms/client/t/ dbms/dbmsproxy/ dbms/deamon/ dbms/doc/ dbms/include/ dbms/libdbms/ dbms/utils/ doc/ include/ lib/ lib/DBD/ lib/RDFStore/ lib/RDFSt...
Date Fri, 13 Apr 2007 08:56:16 GMT
Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/Generator.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/Generator.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/Generator.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/Generator.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,287 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+# * Changes:
+# *     version 0.1 - 2000/11/03 at 04:30 CEST
+# *     version 0.2
+# *             - added more magic keywords to 'reservedWords' list
+# *             - Modified createResource() accordingly to rdf-api-2000-10-30
+# *     version 0.3
+# *		- fixed bug in toPerlName() and dumpVocabulary() avoid grep regex checking
+# *		- fixed bugs when checking references/pointers (defined and ref() )
+# *     version 0.4
+# *		- fixed bug in dumpVocabulary() when matching input namespace (escape plus signs)
+# *		  and output full qualified package variable names of voc properties
+# *		- fixed bug in createVocabulary() when check package name
+# *		- fixed miss-spelling bug in toPerlName()
+# *             - fixed a few warnings
+# *		- updated accordingly to new RDFStore::Model
+# *	version 0.41
+# *		- updated to use RDFStore::Model new API
+# *
+
+package RDFStore::Vocabulary::Generator;
+{
+use vars qw ($VERSION);
+use strict;
+ 
+$VERSION = '0.41';
+use Carp;
+
+#bit funny Sergey assuems that we have already these pre-generated....
+use RDFStore::Vocabulary::RDFS;
+use RDFStore::Vocabulary::DC;
+use RDFStore::Vocabulary::DAML;
+
+sub new {
+	my ($pkg) = @_;
+
+    	my $self = {};
+
+	$self->{LICENSE} = qq|# *
+# *     Copyright (c) 2000-2004 Alberto Reggiori <areggiori\@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx\@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+|;
+	$self->{DEFAULT_PACKAGE_CLASS} = "UnspecifiedClass";
+	$self->{NS_IMPORT} = "use RDFStore::Model;\nuse Carp;\n";
+	$self->{DEFAULT_NODE_FACTORY} = "RDFStore::NodeFactory";
+	$self->{NS_COMMENT} = "# \n" .
+		"# This package provides convenient access to schema information.\n".
+		"# DO NOT MODIFY THIS FILE.\n".
+		"# It was generated automatically by RDFStore::Vocabulary::Generator\n#\n";
+	$self->{NS_NSDEF} = "# Namespace URI of this schema";
+	$self->{NS_ID} = "_Namespace";
+
+	# some obvious reserved words
+	$self->{reservedWords}=["package","use","require","BEGIN","END","sub","my","local",$self->{NS_ID}];
+
+    	bless $self,$pkg;
+};
+
+# Schema as input parameter
+# createVocabulary($packageClass, $all, $namespace, $outputDirectory, $factoryStr)
+sub createVocabulary {
+	croak "Model ".$_[2]." is not an instance of RDFStore::Model"
+		unless( (defined $_[2]) &&
+                	(ref($_[2])) && ($_[2]->isa("RDFStore::Model")) );
+
+	my $packageName = '';
+	my $className = '';
+
+	$_[5] = $_[0]->{DEFAULT_NODE_FACTORY}
+		unless(defined $_[5]);
+
+	if($_[1] =~ /::/) {
+		my @info = split("::",$_[1]);
+		$className = pop @info;
+		$packageName = join("::",@info);
+	} else {
+		$packageName = $_[1];
+		$className = $packageName;
+	};
+
+	print "Creating interface " . $className . " within package ". $packageName .  ( (defined $_[4]) ? " in ". $_[4] : ""),"\n";
+
+	my $packageDirectory;
+	if(!(defined $_[4])) {
+		$packageDirectory=undef;
+	} else {
+		$packageName = ""
+			if(!(defined $packageName));
+
+		croak "Invalid output directory: ".$_[4]
+			unless(-d $_[4]);
+
+		#make it
+		$packageDirectory = $packageName;
+		$packageDirectory = ''
+			unless($packageDirectory =~ s/\:\:/\//g);
+		$packageDirectory = $_[4].$packageDirectory;
+		`mkdir -p $packageDirectory`;
+	};
+    
+	my $out;
+	if( defined $_[4] ) {
+		open(OUT,">".$packageDirectory."/".$className.".pm");
+		$out=*OUT;
+	} else {
+		$out = *STDOUT;
+	};
+
+	$_[0]->dumpVocabulary( $out, ($packageName eq $className) ? $packageName : $packageName.'::'.$className , $className, $_[2], $_[3], $_[5] );
+	close($out);
+};
+
+sub toPerlName {
+	my $reserved=0;
+	map { $reserved=1 if($_ eq $_[1]); } @{$_[0]->{reservedWords}};
+	return "_".$_[1]
+		if($reserved);
+
+	$_[1] =~ s/[\+\-\.]/_/g;
+	$_[1] =~ s/^\d(.*)/_$1/g;
+	return $_[1];
+};
+
+sub dumpVocabulary {
+	my @els;
+	my ($ee) = $_[4]->elements;
+	for ( my $e = $ee->first; $ee->hasnext; $e= $ee->next ) {
+		push @els,$e->subject();
+		push @els,$e->object()
+			if($e->object->isa("RDFStore::Resource"));
+	};
+
+	# write resource declarations and definitions
+        my $r1;
+        my @v1;
+        my @pname;
+        my $ns_match = $_[5];
+        $ns_match =~ s/\+/\\\+/g;
+        foreach $r1 ( @els ) {
+                my $res = $r1->toString();
+                if($res =~ /^$ns_match/) {
+                        my $name=substr($res,length($_[5]));
+                        if(length($name) > 0) { #NS already included as a string
+                                my $isthere=0;
+                                map { $isthere=1 if($_ eq $name); } @v1;
+                                unless($isthere) {
+					push @v1,$name;
+        				push @pname,'$'.$_[0]->toPerlName($name);
+				};
+                	};
+        	};
+        };
+
+	my $out=$_[1]; 
+	print $out $_[0]->{LICENSE},"\n";
+	print $out "package ".$_[2].";\n{\n";
+	print $out "use vars qw ( \$VERSION ".join(" ",@pname)." );\n\$VERSION='$VERSION';\nuse strict;\n";
+	print $out $_[0]->{NS_IMPORT},"\n";
+	print $out $_[0]->{NS_COMMENT},"\n";
+	print $out $_[0]->{NS_NSDEF},"\n";
+	print $out '$'.$_[2].'::'.$_[0]->{NS_ID}.'= "'.$_[5].'";'."\n";
+	print $out "use $_[6];\n";
+	print $out '&setNodeFactory(new '.$_[6]."());\n";
+
+	print $out '
+sub createResource {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+
+	return $_[0]->createResource($'.$_[2].'::_Namespace,$_[1]);
+};
+sub setNodeFactory {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+';
+
+
+	# write resource declarations and definitions
+        my $r;
+        my @v;
+        #my $ns_match = $_[5];
+        #$ns_match =~ s/\+/\\\+/g;
+	my $destructors='';
+	foreach $r ( @els ) {
+		my $res = $r->toString();
+		if($res =~ /^$ns_match/) {
+			my $name=substr($res,length($_[5]));
+			if(length($name) > 0) { #NS already included as a string
+				my $isthere=0;
+				map { $isthere=1 if($_ eq $name); } @v;
+				unless($isthere) {
+					push @v,$name;
+					my $pname = $_[0]->toPerlName($name);
+					# comment?
+					my $tComment = $_[4]->find($r, $RDFStore::Vocabulary::RDFS::comment, undef )->elements->first;
+					$tComment= $_[4]->find($r, $RDFStore::Vocabulary::DAML::comment, undef )->elements->first
+						unless(	(defined $tComment) &&
+							(ref($tComment)) &&
+							($tComment->isa("RDFStore::Statement")) );
+					$tComment = $_[4]->find($r, $RDFStore::Vocabulary::DC::description, undef )->elements->first
+						unless(	(defined $tComment) &&
+							(ref($tComment)) &&
+							($tComment->isa("RDFStore::Statement")) );
+					if(defined $tComment) {
+						$tComment = $tComment->object->toString;
+						$tComment =~ s/\s/ /g;
+						print $out "\t# $tComment\n";
+          				};
+					print $out "\t\$$_[2]::".$pname.' = createResource($_[0], "'.$name."\");\n";
+					$destructors .= "\t\$$_[2]::".$pname." = undef;\n";
+				};
+          		};
+        	};
+        };
+	print $out "};\n";
+	print $out "sub END {\n";
+	print $out $destructors;
+	print $out "};\n1;\n};";
+};
+
+1;
+};
+
+__END__
+
+=head1 NAME
+
+RDFStore::Vocabulary::Generator - implementation of the Vocabulary Generator RDF API
+
+=head1 SYNOPSIS
+
+ use RDFStore::Vocabulary::Generator;
+my $generator = new RDFStore::Vocabulary::Generator();
+# see vocabulary-generator.pl
+$generator->createVocabulary($packageClass, $all, $namespace, $outputDirectory, $factoryStr);
+
+=head1 DESCRIPTION
+
+Generate Perl package with constants for resources defined in an RDF (Schema).
+
+
+=head1 METHODS
+
+=over 
+
+=item B<new()>
+ 
+
+ This is the constructor for RDFStore::Vocabulary::Generator.
+
+=item B<createVocabulary(PACKAGECLASS, SCHEMA, NAMESPACE, OUTPUTDIRECTORY, NODE_FACTORY )>
+
+ Generates a Perl 5 package (module) named PACKAGECLASS using SCHEMA in OUTPUTDIRECTORY using NODE_FACTORY.
+ Properties and resources are prefixed with NAMESPACE.
+
+=back
+
+=head1 SEE ALSO
+
+RDFStore::Vocabulary::RDF(3) RDFStore::Vocabulary::RDFS(3) RDFStore::Vocabulary::DC(3) RDFStore::Vocabulary::DAML(3)
+RDFStore::SchemaModel(3)
+
+=head1 AUTHOR
+
+	Alberto Reggiori <areggiori@webweaving.org>

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/OWL.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/OWL.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/OWL.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/OWL.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,128 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+
+package RDFStore::Vocabulary::OWL;
+{
+use vars qw ( $VERSION $Ontology $Class $Thing $Nothing $equivalentClass $disjointWith $equivalentProperty $sameAs $differentFrom $AllDifferent $distinctMembers $unionOf $intersectionOf $complementOf $oneOf $Restriction $onProperty $allValuesFrom $hasValue $someValuesFrom $minCardinality $maxCardinality $cardinality $ObjectProperty $DatatypeProperty $inverseOf $TransitiveProperty $SymmetricProperty $FunctionalProperty $InverseFunctionalProperty $AnnotationProperty $OntologyProperty $imports $versionInfo $priorVersion $backwardCompatibleWith $incompatibleWith $DeprecatedClass $DeprecatedProperty $DataRange );
+$VERSION='0.41';
+use strict;
+use RDFStore::Model;
+use Carp;
+
+# 
+# This package provides convenient access to schema information.
+# DO NOT MODIFY THIS FILE.
+# It was generated automatically by RDFStore::Vocabulary::Generator
+#
+
+# Namespace URI of this schema
+$RDFStore::Vocabulary::OWL::_Namespace= "http://www.w3.org/2002/07/owl#";
+use RDFStore::NodeFactory;
+&setNodeFactory(new RDFStore::NodeFactory());
+
+sub createResource {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+
+	return $_[0]->createResource($RDFStore::Vocabulary::OWL::_Namespace,$_[1]);
+};
+sub setNodeFactory {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+	$RDFStore::Vocabulary::OWL::Ontology = createResource($_[0], "Ontology");
+	$RDFStore::Vocabulary::OWL::Class = createResource($_[0], "Class");
+	$RDFStore::Vocabulary::OWL::Thing = createResource($_[0], "Thing");
+	$RDFStore::Vocabulary::OWL::Nothing = createResource($_[0], "Nothing");
+	$RDFStore::Vocabulary::OWL::equivalentClass = createResource($_[0], "equivalentClass");
+	$RDFStore::Vocabulary::OWL::disjointWith = createResource($_[0], "disjointWith");
+	$RDFStore::Vocabulary::OWL::equivalentProperty = createResource($_[0], "equivalentProperty");
+	$RDFStore::Vocabulary::OWL::sameAs = createResource($_[0], "sameAs");
+	$RDFStore::Vocabulary::OWL::differentFrom = createResource($_[0], "differentFrom");
+	$RDFStore::Vocabulary::OWL::AllDifferent = createResource($_[0], "AllDifferent");
+	$RDFStore::Vocabulary::OWL::distinctMembers = createResource($_[0], "distinctMembers");
+	$RDFStore::Vocabulary::OWL::unionOf = createResource($_[0], "unionOf");
+	$RDFStore::Vocabulary::OWL::intersectionOf = createResource($_[0], "intersectionOf");
+	$RDFStore::Vocabulary::OWL::complementOf = createResource($_[0], "complementOf");
+	$RDFStore::Vocabulary::OWL::oneOf = createResource($_[0], "oneOf");
+	$RDFStore::Vocabulary::OWL::Restriction = createResource($_[0], "Restriction");
+	$RDFStore::Vocabulary::OWL::onProperty = createResource($_[0], "onProperty");
+	$RDFStore::Vocabulary::OWL::allValuesFrom = createResource($_[0], "allValuesFrom");
+	$RDFStore::Vocabulary::OWL::hasValue = createResource($_[0], "hasValue");
+	$RDFStore::Vocabulary::OWL::someValuesFrom = createResource($_[0], "someValuesFrom");
+	$RDFStore::Vocabulary::OWL::minCardinality = createResource($_[0], "minCardinality");
+	$RDFStore::Vocabulary::OWL::maxCardinality = createResource($_[0], "maxCardinality");
+	$RDFStore::Vocabulary::OWL::cardinality = createResource($_[0], "cardinality");
+	$RDFStore::Vocabulary::OWL::ObjectProperty = createResource($_[0], "ObjectProperty");
+	$RDFStore::Vocabulary::OWL::DatatypeProperty = createResource($_[0], "DatatypeProperty");
+	$RDFStore::Vocabulary::OWL::inverseOf = createResource($_[0], "inverseOf");
+	$RDFStore::Vocabulary::OWL::TransitiveProperty = createResource($_[0], "TransitiveProperty");
+	$RDFStore::Vocabulary::OWL::SymmetricProperty = createResource($_[0], "SymmetricProperty");
+	$RDFStore::Vocabulary::OWL::FunctionalProperty = createResource($_[0], "FunctionalProperty");
+	$RDFStore::Vocabulary::OWL::InverseFunctionalProperty = createResource($_[0], "InverseFunctionalProperty");
+	$RDFStore::Vocabulary::OWL::AnnotationProperty = createResource($_[0], "AnnotationProperty");
+	$RDFStore::Vocabulary::OWL::OntologyProperty = createResource($_[0], "OntologyProperty");
+	$RDFStore::Vocabulary::OWL::imports = createResource($_[0], "imports");
+	$RDFStore::Vocabulary::OWL::versionInfo = createResource($_[0], "versionInfo");
+	$RDFStore::Vocabulary::OWL::priorVersion = createResource($_[0], "priorVersion");
+	$RDFStore::Vocabulary::OWL::backwardCompatibleWith = createResource($_[0], "backwardCompatibleWith");
+	$RDFStore::Vocabulary::OWL::incompatibleWith = createResource($_[0], "incompatibleWith");
+	$RDFStore::Vocabulary::OWL::DeprecatedClass = createResource($_[0], "DeprecatedClass");
+	$RDFStore::Vocabulary::OWL::DeprecatedProperty = createResource($_[0], "DeprecatedProperty");
+	$RDFStore::Vocabulary::OWL::DataRange = createResource($_[0], "DataRange");
+};
+sub END {
+	$RDFStore::Vocabulary::OWL::Ontology = undef;
+	$RDFStore::Vocabulary::OWL::Class = undef;
+	$RDFStore::Vocabulary::OWL::Thing = undef;
+	$RDFStore::Vocabulary::OWL::Nothing = undef;
+	$RDFStore::Vocabulary::OWL::equivalentClass = undef;
+	$RDFStore::Vocabulary::OWL::disjointWith = undef;
+	$RDFStore::Vocabulary::OWL::equivalentProperty = undef;
+	$RDFStore::Vocabulary::OWL::sameAs = undef;
+	$RDFStore::Vocabulary::OWL::differentFrom = undef;
+	$RDFStore::Vocabulary::OWL::AllDifferent = undef;
+	$RDFStore::Vocabulary::OWL::distinctMembers = undef;
+	$RDFStore::Vocabulary::OWL::unionOf = undef;
+	$RDFStore::Vocabulary::OWL::intersectionOf = undef;
+	$RDFStore::Vocabulary::OWL::complementOf = undef;
+	$RDFStore::Vocabulary::OWL::oneOf = undef;
+	$RDFStore::Vocabulary::OWL::Restriction = undef;
+	$RDFStore::Vocabulary::OWL::onProperty = undef;
+	$RDFStore::Vocabulary::OWL::allValuesFrom = undef;
+	$RDFStore::Vocabulary::OWL::hasValue = undef;
+	$RDFStore::Vocabulary::OWL::someValuesFrom = undef;
+	$RDFStore::Vocabulary::OWL::minCardinality = undef;
+	$RDFStore::Vocabulary::OWL::maxCardinality = undef;
+	$RDFStore::Vocabulary::OWL::cardinality = undef;
+	$RDFStore::Vocabulary::OWL::ObjectProperty = undef;
+	$RDFStore::Vocabulary::OWL::DatatypeProperty = undef;
+	$RDFStore::Vocabulary::OWL::inverseOf = undef;
+	$RDFStore::Vocabulary::OWL::TransitiveProperty = undef;
+	$RDFStore::Vocabulary::OWL::SymmetricProperty = undef;
+	$RDFStore::Vocabulary::OWL::FunctionalProperty = undef;
+	$RDFStore::Vocabulary::OWL::InverseFunctionalProperty = undef;
+	$RDFStore::Vocabulary::OWL::AnnotationProperty = undef;
+	$RDFStore::Vocabulary::OWL::OntologyProperty = undef;
+	$RDFStore::Vocabulary::OWL::imports = undef;
+	$RDFStore::Vocabulary::OWL::versionInfo = undef;
+	$RDFStore::Vocabulary::OWL::priorVersion = undef;
+	$RDFStore::Vocabulary::OWL::backwardCompatibleWith = undef;
+	$RDFStore::Vocabulary::OWL::incompatibleWith = undef;
+	$RDFStore::Vocabulary::OWL::DeprecatedClass = undef;
+	$RDFStore::Vocabulary::OWL::DeprecatedProperty = undef;
+	$RDFStore::Vocabulary::OWL::DataRange = undef;
+};
+1;
+};

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDF.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDF.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDF.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDF.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,93 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+
+package RDFStore::Vocabulary::RDF;
+{
+use vars qw ( $VERSION $type $Property $Statement $subject $predicate $object $Bag $Seq $Alt $value $List $nil $first $rest $XMLLiteral );
+$VERSION='0.41';
+use strict;
+use RDFStore::Model;
+use Carp;
+
+# 
+# This package provides convenient access to schema information.
+# DO NOT MODIFY THIS FILE.
+# It was generated automatically by RDFStore::Vocabulary::Generator
+#
+
+# Namespace URI of this schema
+$RDFStore::Vocabulary::RDF::_Namespace= "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+use RDFStore::NodeFactory;
+&setNodeFactory(new RDFStore::NodeFactory());
+
+sub createResource {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+
+	return $_[0]->createResource($RDFStore::Vocabulary::RDF::_Namespace,$_[1]);
+};
+sub setNodeFactory {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+	# The subject is an instance of a class.
+	$RDFStore::Vocabulary::RDF::type = createResource($_[0], "type");
+	# The class of RDF properties.
+	$RDFStore::Vocabulary::RDF::Property = createResource($_[0], "Property");
+	# The class of RDF statements.
+	$RDFStore::Vocabulary::RDF::Statement = createResource($_[0], "Statement");
+	# The subject of the subject RDF statement.
+	$RDFStore::Vocabulary::RDF::subject = createResource($_[0], "subject");
+	# The predicate of the subject RDF statement.
+	$RDFStore::Vocabulary::RDF::predicate = createResource($_[0], "predicate");
+	# The object of the subject RDF statement.
+	$RDFStore::Vocabulary::RDF::object = createResource($_[0], "object");
+	# The class of unordered containers.
+	$RDFStore::Vocabulary::RDF::Bag = createResource($_[0], "Bag");
+	# The class of ordered containers.
+	$RDFStore::Vocabulary::RDF::Seq = createResource($_[0], "Seq");
+	# The class of containers of alternatives.
+	$RDFStore::Vocabulary::RDF::Alt = createResource($_[0], "Alt");
+	# Idiomatic property used for structured values.
+	$RDFStore::Vocabulary::RDF::value = createResource($_[0], "value");
+	# The class of RDF Lists.
+	$RDFStore::Vocabulary::RDF::List = createResource($_[0], "List");
+	# The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it.
+	$RDFStore::Vocabulary::RDF::nil = createResource($_[0], "nil");
+	# The first item in the subject RDF list.
+	$RDFStore::Vocabulary::RDF::first = createResource($_[0], "first");
+	# The rest of the subject RDF list after the first item.
+	$RDFStore::Vocabulary::RDF::rest = createResource($_[0], "rest");
+	# The class of XML literal values.
+	$RDFStore::Vocabulary::RDF::XMLLiteral = createResource($_[0], "XMLLiteral");
+};
+sub END {
+	$RDFStore::Vocabulary::RDF::type = undef;
+	$RDFStore::Vocabulary::RDF::Property = undef;
+	$RDFStore::Vocabulary::RDF::Statement = undef;
+	$RDFStore::Vocabulary::RDF::subject = undef;
+	$RDFStore::Vocabulary::RDF::predicate = undef;
+	$RDFStore::Vocabulary::RDF::object = undef;
+	$RDFStore::Vocabulary::RDF::Bag = undef;
+	$RDFStore::Vocabulary::RDF::Seq = undef;
+	$RDFStore::Vocabulary::RDF::Alt = undef;
+	$RDFStore::Vocabulary::RDF::value = undef;
+	$RDFStore::Vocabulary::RDF::List = undef;
+	$RDFStore::Vocabulary::RDF::nil = undef;
+	$RDFStore::Vocabulary::RDF::first = undef;
+	$RDFStore::Vocabulary::RDF::rest = undef;
+	$RDFStore::Vocabulary::RDF::XMLLiteral = undef;
+};
+1;
+};

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFS.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFS.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFS.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFS.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,93 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+
+package RDFStore::Vocabulary::RDFS;
+{
+use vars qw ( $VERSION $Resource $Class $subClassOf $subPropertyOf $comment $Literal $label $domain $range $seeAlso $isDefinedBy $Container $ContainerMembershipProperty $member $Datatype );
+$VERSION='0.41';
+use strict;
+use RDFStore::Model;
+use Carp;
+
+# 
+# This package provides convenient access to schema information.
+# DO NOT MODIFY THIS FILE.
+# It was generated automatically by RDFStore::Vocabulary::Generator
+#
+
+# Namespace URI of this schema
+$RDFStore::Vocabulary::RDFS::_Namespace= "http://www.w3.org/2000/01/rdf-schema#";
+use RDFStore::NodeFactory;
+&setNodeFactory(new RDFStore::NodeFactory());
+
+sub createResource {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+
+	return $_[0]->createResource($RDFStore::Vocabulary::RDFS::_Namespace,$_[1]);
+};
+sub setNodeFactory {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+	# The class resource, everything.
+	$RDFStore::Vocabulary::RDFS::Resource = createResource($_[0], "Resource");
+	# The class of classes.
+	$RDFStore::Vocabulary::RDFS::Class = createResource($_[0], "Class");
+	# The subject is a subclass of a class.
+	$RDFStore::Vocabulary::RDFS::subClassOf = createResource($_[0], "subClassOf");
+	# The subject is a subproperty of a property.
+	$RDFStore::Vocabulary::RDFS::subPropertyOf = createResource($_[0], "subPropertyOf");
+	# A description of the subject resource.
+	$RDFStore::Vocabulary::RDFS::comment = createResource($_[0], "comment");
+	# The class of literal values, eg. textual strings and integers.
+	$RDFStore::Vocabulary::RDFS::Literal = createResource($_[0], "Literal");
+	# A human-readable name for the subject.
+	$RDFStore::Vocabulary::RDFS::label = createResource($_[0], "label");
+	# A domain of the subject property.
+	$RDFStore::Vocabulary::RDFS::domain = createResource($_[0], "domain");
+	# A range of the subject property.
+	$RDFStore::Vocabulary::RDFS::range = createResource($_[0], "range");
+	# Further information about the subject resource.
+	$RDFStore::Vocabulary::RDFS::seeAlso = createResource($_[0], "seeAlso");
+	# The defininition of the subject resource.
+	$RDFStore::Vocabulary::RDFS::isDefinedBy = createResource($_[0], "isDefinedBy");
+	# The class of RDF containers.
+	$RDFStore::Vocabulary::RDFS::Container = createResource($_[0], "Container");
+	# The class of container membership properties, rdf:_1, rdf:_2, ...,                     all of which are sub-properties of 'member'.
+	$RDFStore::Vocabulary::RDFS::ContainerMembershipProperty = createResource($_[0], "ContainerMembershipProperty");
+	# A member of the subject resource.
+	$RDFStore::Vocabulary::RDFS::member = createResource($_[0], "member");
+	# The class of RDF datatypes.
+	$RDFStore::Vocabulary::RDFS::Datatype = createResource($_[0], "Datatype");
+};
+sub END {
+	$RDFStore::Vocabulary::RDFS::Resource = undef;
+	$RDFStore::Vocabulary::RDFS::Class = undef;
+	$RDFStore::Vocabulary::RDFS::subClassOf = undef;
+	$RDFStore::Vocabulary::RDFS::subPropertyOf = undef;
+	$RDFStore::Vocabulary::RDFS::comment = undef;
+	$RDFStore::Vocabulary::RDFS::Literal = undef;
+	$RDFStore::Vocabulary::RDFS::label = undef;
+	$RDFStore::Vocabulary::RDFS::domain = undef;
+	$RDFStore::Vocabulary::RDFS::range = undef;
+	$RDFStore::Vocabulary::RDFS::seeAlso = undef;
+	$RDFStore::Vocabulary::RDFS::isDefinedBy = undef;
+	$RDFStore::Vocabulary::RDFS::Container = undef;
+	$RDFStore::Vocabulary::RDFS::ContainerMembershipProperty = undef;
+	$RDFStore::Vocabulary::RDFS::member = undef;
+	$RDFStore::Vocabulary::RDFS::Datatype = undef;
+};
+1;
+};

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFStoreContext.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFStoreContext.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFStoreContext.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RDFStoreContext.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,54 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+
+package RDFStore::Vocabulary::RDFStoreContext;
+{
+use vars qw ( $VERSION $Context $EmptyContext );
+$VERSION='0.41';
+use strict;
+use RDFStore::Model;
+use Carp;
+
+# 
+# This package provides convenient access to schema information.
+# DO NOT MODIFY THIS FILE.
+# It was generated automatically by RDFStore::Vocabulary::Generator
+#
+
+# Namespace URI of this schema
+$RDFStore::Vocabulary::RDFStoreContext::_Namespace= "http://rdfstore.sourceforge.net/contexts/";
+use RDFStore::NodeFactory;
+&setNodeFactory(new RDFStore::NodeFactory());
+
+sub createResource {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+
+	return $_[0]->createResource($RDFStore::Vocabulary::RDFStoreContext::_Namespace,$_[1]);
+};
+sub setNodeFactory {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+	# Context
+	$RDFStore::Vocabulary::RDFStoreContext::Context = createResource($_[0], "Context");
+	# Empty (NULL) Context
+	$RDFStore::Vocabulary::RDFStoreContext::EmptyContext = createResource($_[0], "EmptyContext");
+};
+sub END {
+	$RDFStore::Vocabulary::RDFStoreContext::Context = undef;
+	$RDFStore::Vocabulary::RDFStoreContext::EmptyContext = undef;
+};
+1;
+};

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RSS.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RSS.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RSS.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDFStore/Vocabulary/RSS.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,77 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+
+package RDFStore::Vocabulary::RSS;
+{
+use vars qw ( $VERSION $channel $image $item $items $textinput $title $link $url $description $name );
+$VERSION='0.41';
+use strict;
+use RDFStore::Model;
+use Carp;
+
+# 
+# This package provides convenient access to schema information.
+# DO NOT MODIFY THIS FILE.
+# It was generated automatically by RDFStore::Vocabulary::Generator
+#
+
+# Namespace URI of this schema
+$RDFStore::Vocabulary::RSS::_Namespace= "http://purl.org/rss/1.0/";
+use RDFStore::NodeFactory;
+&setNodeFactory(new RDFStore::NodeFactory());
+
+sub createResource {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+
+	return $_[0]->createResource($RDFStore::Vocabulary::RSS::_Namespace,$_[1]);
+};
+sub setNodeFactory {
+	croak "Factory ".$_[0]." is not an instance of RDFStore::NodeFactory"
+		unless( (defined $_[0]) &&
+                	( (ref($_[0])) && ($_[0]->isa("RDFStore::NodeFactory")) ) );
+	# An information syndication channel
+	$RDFStore::Vocabulary::RSS::channel = createResource($_[0], "channel");
+	$RDFStore::Vocabulary::RSS::image = createResource($_[0], "image");
+	# An item for syndication.
+	$RDFStore::Vocabulary::RSS::item = createResource($_[0], "item");
+	# A collection of items.
+	$RDFStore::Vocabulary::RSS::items = createResource($_[0], "items");
+	# A text input for syndication.
+	$RDFStore::Vocabulary::RSS::textinput = createResource($_[0], "textinput");
+	# A descriptive title for the channel.
+	$RDFStore::Vocabulary::RSS::title = createResource($_[0], "title");
+	# The URL to which an HTML rendering of the channel title will link.
+	$RDFStore::Vocabulary::RSS::link = createResource($_[0], "link");
+	# The URL of the image to used in the 'src' attribute of the channel's image tag when rendered as HTML.
+	$RDFStore::Vocabulary::RSS::url = createResource($_[0], "url");
+	# The URL to which an HTML rendering of the channel title will link.
+	$RDFStore::Vocabulary::RSS::description = createResource($_[0], "description");
+	# The text input field's (variable) name.
+	$RDFStore::Vocabulary::RSS::name = createResource($_[0], "name");
+};
+sub END {
+	$RDFStore::Vocabulary::RSS::channel = undef;
+	$RDFStore::Vocabulary::RSS::image = undef;
+	$RDFStore::Vocabulary::RSS::item = undef;
+	$RDFStore::Vocabulary::RSS::items = undef;
+	$RDFStore::Vocabulary::RSS::textinput = undef;
+	$RDFStore::Vocabulary::RSS::title = undef;
+	$RDFStore::Vocabulary::RSS::link = undef;
+	$RDFStore::Vocabulary::RSS::url = undef;
+	$RDFStore::Vocabulary::RSS::description = undef;
+	$RDFStore::Vocabulary::RSS::name = undef;
+};
+1;
+};

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDQL/Parser.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDQL/Parser.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDQL/Parser.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/RDQL/Parser.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,1246 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+# * Changes:
+# *     version 0.1
+# *		- first hacked version: pure perl RDQL/SquishQL top-down LL(1) parser with some extesnions:
+# *                  * LIKE operator in AND clause
+# *                  * free-text triple matching like (?x, ?y, %"whatever"%)
+# *     version 0.2
+# *    		- added SELECT DISTINCT 
+# *    		- added SPARQL PREFIX support and default/built-in prefixes
+# *    		- added # and // style comments
+# *    		- added SPARQL QNAME like support
+# *		- added ?prefix:var QName support to vars
+# *		- added SPARQL CONSTRUCT support
+# *		- added SPARQL $var support
+# *		- added getQueryType() method
+# *		- added SPARQL DESCRIBE support
+# *		- fixed bug in Literal() when matching floating point numbers
+# *		- updated constraints and removed AND keyword to be SPARQL compatible
+# *		- added not standard RDQL/SPARQL DELETE support
+# *		- added default SPARQL PREFIX op: <http://www.w3.org/2001/sw/DataAccess/operations> and PREFIX fn: <http://www.w3.org/2004/07/xpath-functions>
+# *		- updated and simplified constraints productions to reflect latest SPARQL spec
+# *		- constraints are now stacked into a RPN
+# *		- added full SPARQL graph-patterns and grouping
+# *		- added SPARQL FROM NAMED support
+# *		- added SPARQL LIMIT support
+# *		- added SPARQL OFFSET support
+# *		- added SPARQL ORDER BY support
+# *
+
+package RDQL::Parser;
+{
+
+use vars qw ( $VERSION );
+use strict;
+use Carp;
+
+$VERSION = '0.2';
+
+sub parse ($$);
+sub MatchAndEat ($$);
+sub error ($$);
+sub Select ($);
+sub Construct ($);
+sub Describe ($);
+#sub Ask ($);
+sub OrderBy ($);
+sub Limit ($);
+sub Offset ($);
+sub Delete ($);
+sub From ($);
+sub FromNamed ($);
+sub GraphPattern ($);
+sub GraphAndPattern ($);
+sub PatternElement ($);
+sub GroupGraphPattern ($);
+sub SourceGraphPattern ($);
+sub OptionalGraphPattern ($);
+sub Var ($);
+sub URIOrQName ($);
+sub Literal ($);
+sub TriplePattern ($);
+sub VarOrURIOrQName ($);
+sub VarOrURIOrQNameOrLiteral ($);
+sub Constraint ($);
+sub Prefixes ($);
+sub PrefixDecl ($);
+sub ConditionalOrExpression ($);
+sub ConditionalAndExpression ($);
+sub StringEqualityExpression ($);
+sub PatternLiteral ($);
+sub EqualityExpression ($);
+sub RelationalExpression ($);
+sub AdditiveExpression ($);
+sub MultiplicativeExpression ($);
+sub UnaryExpression ($);
+sub UnaryExpressionNotPlusMinus ($);
+sub PrimaryExpression ($);
+sub FunctionCall ($);
+sub ArgList ($);
+
+# some useful default prefixes
+%RDQL::Parser::default_prefixes= (
+	'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
+	'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
+	'http://purl.org/rss/1.0/' => 'rss',
+	'http://www.daml.org/2001/03/daml+oil#' => 'daml',
+	'http://purl.org/dc/elements/1.1/' => 'dc',
+	'http://purl.org/dc/terms/' => 'dcq',
+	'http://xmlns.com/foaf/0.1/' => 'foaf',
+	'http://www.w3.org/2001/XMLSchema#' => 'xsd',
+	'http://www.w3.org/2002/07/owl#' => 'owl',
+	# these two are SPARQL special - perhaps should not mix up with other namespaces? avoid to aoverride them?
+	'http://www.w3.org/2001/sw/DataAccess/operations' => 'op',
+	'http://www.w3.org/2004/07/xpath-functions' => 'fn'
+	);
+
+sub new {
+	my $self = {
+		prefixes		=>	{},
+		sources			=>	[],
+		from_named		=>	[],
+		resultVars		=>	[],
+		constructPatterns	=>	[],
+		describes		=>	[],
+		graphPatterns		=>	[],
+		order_by		=>	[]
+		};
+
+	map {
+		$self->{'prefixes'}->{ $RDQL::Parser::default_prefixes{ $_ } } = $_ ;
+	} keys %RDQL::Parser::default_prefixes;
+
+	bless $self, shift;
+	};
+
+sub MatchAndEat ($$) {
+	my($class,$lit)=@_;
+
+	# eat single line comments
+	while( $class->{'query_string'} =~ s/^\s*(#|\/\/).*// ) {};
+
+	# eat multi-line comments
+	if( $class->{'query_string'} =~ s/^\s*\/\*// ) {
+		while( $class->{'query_string'} !~ s/^\s*\*\/// ) {
+			$class->{'query_string'} =~ s/^\s*(.)\s*//;
+			};
+		};
+
+	return $class->{'query_string'} =~ s/^\s*\Q$lit\E\s*//i;
+};
+
+sub error($$) {
+	my($class,$msg)=@_;
+	croak "error: $msg: ".$class->{'query_string'}."\n";
+};
+
+sub parse($$) {
+	my($class,$query) = @_;
+
+	$class->{'query_string'} = $query;
+
+	$class->{'context'}=[];
+	$class->{'graph_patterns_pointer'} = []; #to check undeflow???
+	
+	while( MatchAndEat $class,'prefix' ) {
+		PrefixDecl $class;
+		};
+
+	if( MatchAndEat $class,'select' ) {
+		$class->{'queryType'} = 'SELECT';
+		Select $class;
+	} elsif( MatchAndEat $class,'construct' ) {
+		$class->{'queryType'} = 'CONSTRUCT';
+		Construct $class;
+	} elsif( MatchAndEat $class,'describe' ) {
+		$class->{'queryType'} = 'DESCRIBE';
+		Describe $class;
+	} elsif( MatchAndEat $class,'ask' ) {
+		$class->{'queryType'} = 'ASK';
+		#Ask $class;
+	} elsif( MatchAndEat $class,'delete' ) {
+		$class->{'queryType'} = 'DELETE';
+		Delete $class;
+	} else {
+		error $class,'Expecting SELECT, CONSTRUCT, DESCRIBE, ASK or DELETE token'
+			if($class->{'query_string'} ne '');
+		};
+
+	while( MatchAndEat $class,'prefix' ) {
+		PrefixDecl $class;
+		};
+
+	while(	MatchAndEat $class,'source' or
+		MatchAndEat $class,'from' ) {
+		if( MatchAndEat $class,'named' ) {
+			FromNamed $class;
+		} else {
+			From $class;
+			};
+		};
+
+	GraphPattern $class
+		if( MatchAndEat $class,'where');
+
+	while(	MatchAndEat $class,'order' and
+		MatchAndEat $class,'by' ) {
+		OrderBy $class;
+		};
+
+	Limit $class
+		if(MatchAndEat $class,'limit');
+
+	Offset $class
+		if(MatchAndEat $class,'offset');
+
+	# eat this up anyway to keep legacy RDQL queries working...
+        Prefixes $class
+		if(MatchAndEat $class,'using');
+
+	$class->{'query_string'} =~ s/^\s*//;
+	$class->{'query_string'} =~ s/\s*$//;
+
+	error $class,'illegal input'
+		if($class->{'query_string'} ne '');
+
+	delete($class->{'query_string'});
+	delete($class->{'context'});
+	delete($class->{'graph_patterns_pointer'});
+
+	#use Data::Dumper;
+	#print STDERR Dumper($class);
+
+	return $class;
+	};
+
+sub Select($) {
+	my($class) = @_;
+
+	$class->{'distinct'} = ( MatchAndEat $class,'distinct' ) ? 1 : 0;
+	push @{ $class->{'context'} }, 'select';
+	if( MatchAndEat $class,'*') {
+		push @{$class->{resultVars}},'*';
+	} elsif( Var $class ) {
+		do {
+			MatchAndEat $class,',';
+			} while ( Var $class );
+	};
+	pop @{ $class->{'context'} };
+};
+
+sub OrderBy($) {
+	my($class) = @_;
+
+	push @{ $class->{'context'} }, 'order by';
+
+	if( MatchAndEat $class,'asc' ) {
+		ConditionalOrExpression $class;
+
+		push @{ $class->{'order_by'} }, 'ASC';
+	} elsif( MatchAndEat $class,'desc' ) {
+		ConditionalOrExpression $class;
+
+		push @{ $class->{'order_by'} }, 'DESC';
+	} else {
+		if ( Var $class ) {
+		} elsif ( FunctionCall $class ) {
+		} else {
+			ConditionalOrExpression $class;
+			};
+
+		push @{ $class->{'order_by'} }, 'ASC';
+		};
+
+	pop @{ $class->{'context'} };
+};
+
+sub Limit($) {
+	my($class) = @_;
+
+	push @{ $class->{'context'} }, 'limit';
+
+	error $class,"limit requires an integer value"
+		unless( Literal $class );
+
+	error $class,"limit is invalid"
+		unless(	$class->{'limit'} >= 0 );
+
+	pop @{ $class->{'context'} };
+};
+
+sub Offset($) {
+	my($class) = @_;
+
+	push @{ $class->{'context'} }, 'offset';
+
+	error $class,"offset requires an integer value"
+		unless( Literal $class );
+
+	error $class,"offset is invalid"
+		unless(	$class->{'offset'} >= 0 );
+
+	pop @{ $class->{'context'} };
+};
+
+sub Construct($) {
+	my($class) = @_;
+
+	$class->{'distinct'} = 0; #useless? see DBD::RDFStore driver
+	push @{ $class->{'context'} }, 'construct';
+	if( MatchAndEat $class,'*') {
+		push @{$class->{constructPatterns}},'*';
+	} elsif( TriplePattern $class ) {
+	} else {
+		if( MatchAndEat $class,'{' ) {
+			# we do not deal with nested Groups yet...
+			while ( TriplePattern $class ) {
+                		MatchAndEat $class,',';
+                		};
+
+			error $class,"missing right brace"
+				unless( MatchAndEat $class,'}' );
+		} else {
+			error $class,"missing left brace";
+			};
+		};
+	pop @{ $class->{'context'} };
+	};
+
+sub Describe($) {
+	my($class) = @_;
+
+	$class->{'distinct'} = 0; #useless? see DBD::RDFStore driver
+	push @{ $class->{'context'} }, 'describe';
+	if( MatchAndEat $class,'*') {
+		push @{$class->{describes}},'*';
+	} elsif( VarOrURIOrQName $class ) {
+		do {
+			MatchAndEat $class,',';
+			} while ( VarOrURIOrQName $class );
+		};
+	pop @{ $class->{'context'} };
+	};
+
+sub Delete($) {
+	my($class) = @_;
+
+	$class->{'distinct'} = 0;
+	push @{$class->{resultVars}},'*'
+		if( MatchAndEat $class,'*');
+	};
+
+sub Var($) {
+	my($class) = @_;
+
+	if($class->{'query_string'} =~ s/^\s*[\?\$]([a-zA-Z0-9_\.:]+)\s*//) {
+		my $var = '?'.$1; # we force ?var style anyway
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'select' ) {
+			push @{$class->{resultVars}}, $var
+				unless(grep /^\Q$var\E$/,@{$class->{resultVars}});
+			};
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'describe' ) {
+			push @{$class->{describes}},$var
+				unless(grep /^\Q$var\E$/,@{$class->{describes}});
+			};
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'triples' ) {
+			push @{$class->{triple_pattern}}, $var;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'constraints' ) {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, $var;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+			push @{ $class->{'order_by'} }, $var;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'named_graph' ) {
+			$class->{'graph_name'} = $var;
+		};
+
+		return 1;
+	};
+	return 0;
+};
+
+sub FromNamed($) {
+	my($class) = @_;
+
+	push @{ $class->{'context'} }, 'from_named';
+	if( URIOrQName $class ) {
+		do {
+                        MatchAndEat $class,',';
+                        } while ( URIOrQName $class );
+	} else {
+		error $class, "malformed URI or QName";
+	};
+	pop @{ $class->{'context'} };
+	};
+
+sub From($) {
+	my($class) = @_;
+
+	push @{ $class->{'context'} }, 'source';
+	if( URIOrQName $class ) {
+		do {
+                        MatchAndEat $class,',';
+                        } while ( URIOrQName $class );
+	} else {
+		error $class, "malformed URI or QName";
+	};
+	pop @{ $class->{'context'} };
+	};
+
+sub URIOrQName($) {
+	my($class) = @_;
+
+	# the following covers also RDFStore/RDQL extensions for simple OR <URI1 , URI2 , URI3 ....>, 
+	# <pp:ff , pp1:ff> and <"string a" , "literal b" .... "literal n">
+	#if($class->{'query_string'} =~ s/^\s*((\<[^>]*\>)|([a-zA-Z0-9\-_$\.]+:[a-zA-Z0-9\-_$\.]+)|([a-zA-Z0-9\-_$\.]+:))\s*//) {
+	if($class->{'query_string'} =~ s/^\s*(\<[^>]*\>)\s*//) { #not yet the above - but we are NOT RDQL compliant then - no QNames (need to fix all the DBD driver too then)
+		# in the old RDQL syntax we do not deal with prefixes here yet but directly in the DBD::RDFStore driver code instead
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'triples' ) {
+			push @{$class->{triple_pattern}}, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'from_named' ) {
+			push @{$class->{from_named}}, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'source' ) {
+			push @{$class->{sources}}, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'constraints' ) {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+			push @{ $class->{'order_by'} }, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'named_graph' ) {
+			$class->{'graph_name'} = $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'describe' ) {
+			push @{$class->{describes}},$1
+				unless(grep /^\Q$1\E$/,@{$class->{describes}});
+			};
+		return 1;
+	} elsif($class->{'query_string'} =~ s/^\s*([a-zA-Z0-9\-_$\.]+)?:([a-zA-Z0-9\-_$\.]+)\s*//) {
+		# I am lazy, and do not want to fix DBD::RDFStore driver code too...
+		my $qn;
+		if($1) {
+			# look up for a prefix if there
+			if( exists $class->{'prefixes'}->{$1} ) {
+				$qn = '<'. $class->{'prefixes'}->{$1} .$2.'>';
+			} else {
+				# otherwise should say unbound prefix in new SPARQL with pre-PREFIX syntax
+				error $class,"Unbound prefix $1 ";
+				};
+		} else {
+			# try to use default one
+			$qn = '<'.( ( exists $class->{'prefixes'}->{'#default'} ) ? $class->{'prefixes'}->{'#default'} : $1 ).$2.'>';
+			};
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'triples' ) {
+			push @{$class->{triple_pattern}}, $qn;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'from_named' ) {
+			push @{$class->{from_named}}, $qn;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'source' ) {
+			push @{$class->{sources}}, $qn;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'constraints' ) {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, $qn;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+			push @{ $class->{'order_by'} }, $qn;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'named_graph' ) {
+			$class->{'graph_name'} = $qn;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'describe' ) {
+			push @{$class->{describes}},$qn
+				unless(grep /^\Q$qn\E$/,@{$class->{describes}});
+			};
+		return 1;
+		};
+	return 0;
+};
+
+sub Literal($) {
+	my($class) = @_;
+
+	if(	($class->{'query_string'} =~ s/^\s*(([0-9]+\.[0-9]*([eE][+-]?[0-9]+)?[fFdD]?)|(\.[0-9]+([eE][+-]?[0-9]+)?[fFdD]?)|([0-9]+[eE][+-]?[0-9]+[fFdD]?)|([0-9]+([eE][+-]?[0-9]+)?[fFdD]))\s*//) or
+		#($class->{'query_string'} =~ s/^\s*(%?\'((([^\'\\\n\r])|(\\([ntbrf\\'\"])|([0-7][0-7?)|([0-3][0-7][0-7]))))\'%?)\s*//) or
+		($class->{'query_string'} =~ s/^\s*(%?[\"\']((([^\"\'\\\n\r])|(\\([ntbrf\\'\"])|([0-7][0-7?)|([0-3][0-7][0-7])))*)[\"\'](\@([a-z0-9]+(-[a-z0-9]+)?))?%?)\s*//) or
+		($class->{'query_string'} =~ s/^\s*([0-9]+)\s*//) or
+		($class->{'query_string'} =~ s/^\s*(0[xX]([0-9",a-f,A-F])+)\s*//) or
+		#($class->{'query_string'} =~ s/^\s*(0[0-7]*)\s*//) or
+		($class->{'query_string'} =~ s/^\s*(true|false)\s*//) or
+		($class->{'query_string'} =~ s/^\s*(null)\s*//) ) {
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'triples' ) {
+			push @{$class->{triple_pattern}}, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'constraints' ) {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+			push @{ $class->{'order_by'} }, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'named_graph' ) {
+			$class->{'graph_name'} = $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'limit' ) {
+			$class->{'limit'} = $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'offset' ) {
+			$class->{'offset'} = $1;
+		};
+		return 1;
+	};
+	return 0;
+};
+
+sub GraphPattern($) {
+	my($class) = @_;
+
+	GraphAndPattern $class;
+	while( MatchAndEat $class,'UNION' ) { # we might have an issue with UNION and AND 'expression' constraints if no braces - to be checked
+		GraphAndPattern $class;
+
+		push @{$class->{'graphPatterns'}}, 'UNION';
+		};
+	};
+
+sub GraphAndPattern($) {
+	my($class) = @_;
+
+	# shall we check if previous on stack is an empty block, and use that one instead? Or how can we evaluate empty blocks?
+	push @{$class->{'graphPatterns'}}, {
+		'triplePatterns' =>	[],
+		'constraints'	 =>	[],
+		'optional'	 => 	( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'optional' ) ? 1 : 0
+		};
+	push @{ $class->{'graph_patterns_pointer'} }, $#{$class->{'graphPatterns'}};
+
+        while( PatternElement $class ) {
+		MatchAndEat $class,',';
+		};
+
+	pop @{ $class->{'graph_patterns_pointer'} };
+	};
+
+sub PatternElement($) {
+	my($class) = @_;
+
+	if( TriplePattern $class ) {
+	} elsif( GroupGraphPattern $class ) {
+	} elsif( SourceGraphPattern $class ) {
+	} elsif( OptionalGraphPattern $class ) {
+	} elsif( MatchAndEat $class,'and' ) {
+		Constraint $class;
+
+		$class->{'graphPatterns'}->[$#{$class->{'graphPatterns'}}]->{'constraints_optional'} = ( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'optional' ) ? 1 : 0;
+	} else {
+		return 0;
+		};
+	return 1;
+	};
+
+sub GroupGraphPattern($) {
+	my($class) = @_;
+
+	if( MatchAndEat $class,'{' ) {
+		GraphPattern $class;
+
+		error $class,"missing right brace"
+			unless( MatchAndEat $class,'}' );
+
+		push @{$class->{'graphPatterns'}}, 'AND';
+
+		return 1;
+	} else {
+		return 0;
+		};
+	};
+
+# SOURCE is just a modifier how to process a triple-pattern
+sub SourceGraphPattern($) {
+	my($class) = @_;
+
+	if( MatchAndEat $class,'graph' ) {
+		push @{ $class->{'context'} }, 'named_graph';
+
+		# need to add GRAPH * - what does it really mean in the triple-pattern?
+		error $class,"malformed GRAPH clause"
+			unless( VarOrURIOrQName $class ); #context
+
+		PatternElement $class;
+
+		delete($class->{'graph_name'});
+
+		pop @{ $class->{'context'} };
+
+		return 1;
+	} else {
+		return 0;
+		};
+	};
+
+# optionals are just a modifier how to process triple-patterns or blocks (triple-patterns+constraints)
+# NOTE: for triple-patterns we allocate the 1st element of the array to flag (0/1) whether or not it is OPTIONAL
+sub OptionalGraphPattern($) {
+	my($class) = @_;
+
+	if( MatchAndEat $class,'optional' ) {
+		push @{ $class->{'context'} }, 'optional';
+
+		PatternElement $class;
+
+		pop @{ $class->{'context'} };
+
+		return 1;
+	} else {
+		return 0;
+		};
+	};
+
+sub TriplePattern($) {
+	my($class) = @_;
+
+	if( MatchAndEat $class,'(' ) {
+		$class->{triple_pattern}=[ ( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'optional' ) ? 1 : 0 ];
+
+		push @{ $class->{'context'} }, 'triples';
+
+		error $class,"malformed subject variable, URI or QName"
+			unless VarOrURIOrQName $class; #subject
+
+		MatchAndEat $class,',';
+		error $class,"malformed predicate variable, URI or QName"
+			unless VarOrURIOrQName $class; #predicate
+
+		MatchAndEat $class,',';
+		error $class,"malformed object variable, URI, QName or literal"
+			unless VarOrURIOrQNameOrLiteral $class; #object
+
+		MatchAndEat $class,',';
+		unless( VarOrURIOrQNameOrLiteral $class ) { #context
+			push @{$class->{triple_pattern}}, $class->{'graph_name'}
+				if( exists $class->{'graph_name'} );
+			};
+
+		error $class,"missing right round bracket"
+			unless( MatchAndEat $class,')' );
+
+		if(	( ( $#{ $class->{'context'} } - 1 ) >= 0 ) and
+			$class->{'context'}->[ $#{ $class->{'context'} } - 1 ] eq 'construct' and
+			$class->{constructPatterns}->[0] ne '*' ) {
+			push @{$class->{constructPatterns}}, $class->{triple_pattern};
+		} else {
+			push @{$class->{'graphPatterns'}->[ $class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}] ]->{triplePatterns}}, $class->{triple_pattern};
+			};
+
+		delete($class->{triple_pattern});
+
+		pop @{ $class->{'context'} };
+
+		return 1;
+	} else {
+		return 0;
+		};
+	};
+
+sub VarOrURIOrQName($) {
+	my($class) = @_;
+
+	return ( Var $class or URIOrQName $class );
+};
+
+sub VarOrURIOrQNameOrLiteral($) {
+	my($class) = @_;
+
+	return ( Var $class or URIOrQName $class or Literal $class );
+};
+
+sub Prefixes($) {
+	my($class) = @_;
+
+	while( PrefixDecl $class ) {
+		MatchAndEat $class,',';
+		};
+};
+
+sub PrefixDecl($) {
+	my($class) = @_;
+	if($class->{'query_string'} =~ s/^\s*(\w[\w\d]*)?:\s+\<([A-Za-z][^>]*)\>\s*//i) {
+		return 0
+			if( $1 eq 'fn' or $1 eq 'op'); #ignore overrride of special ones??
+		$class->{prefixes}->{ ($1) ? $1 : '#default' }=$2;
+		return 1;
+	} elsif($class->{'query_string'} =~ s/^\s*(\w[\w\d]*)\s+FOR\s+\<([A-Za-z][^>]*)\>\s*//i) {
+		return 0
+			if(	( $1 eq 'fn' and $2 ne $class->{prefixes}->{'fn'} ) or
+				( $1 eq 'op' and $2 ne $class->{prefixes}->{'op'} ) ); #ignore overrride of special ones??
+		$class->{prefixes}->{$1}=$2;
+		return 1;
+		};
+	return 0;
+	};
+
+sub Constraint($) {
+	my($class) = @_;
+
+	push @{ $class->{'context'} }, 'constraints';
+
+	ConditionalOrExpression $class;
+	while(  MatchAndEat $class,',' or
+                MatchAndEat $class,'and') {
+                ConditionalOrExpression $class;
+        	};
+
+	pop @{ $class->{'context'} };
+	};
+
+# we skip ConditionalXorExpression...
+sub ConditionalOrExpression($) {
+	my($class) = @_;
+
+	ConditionalAndExpression $class;
+	while( MatchAndEat $class,'||' ) {
+		ConditionalAndExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+			push @{ $class->{'order_by'} }, '||';
+		} else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '||';
+			};
+	};
+};
+
+sub ConditionalAndExpression($) {
+	my($class) = @_;
+
+	StringEqualityExpression $class;
+	while( MatchAndEat $class,'&&' ) {
+		StringEqualityExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                        push @{ $class->{'order_by'} }, '&&';
+                } else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '&&';
+                        };
+	};
+};
+
+sub StringEqualityExpression($) {
+	my($class) = @_;
+
+	EqualityExpression $class;
+	my $true=1;
+	while( $true ) {
+		if( MatchAndEat $class,'eq' ) {
+			EqualityExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                        	push @{ $class->{'order_by'} }, 'eq';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, 'eq';
+                        	};
+		} elsif( MatchAndEat $class,'ne' ) {
+			EqualityExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                        	push @{ $class->{'order_by'} }, 'ne';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, 'ne';
+                        	};
+		} elsif(	( MatchAndEat $class,'=~' ) ||
+				( MatchAndEat $class,'LIKE' ) ) { # pattern is like [m]/pattern/[i][m][s][x]
+			PatternLiteral $class; # should some pattern literal
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                        	push @{ $class->{'order_by'} }, '=~';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '=~';
+                        	};
+		} elsif( MatchAndEat $class,'!~' ) {
+			PatternLiteral $class; # should some pattern literal
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                        	push @{ $class->{'order_by'} }, '!~';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '!~';
+                        	};
+		} else {
+			$true=0;
+		};
+	};
+};
+
+sub PatternLiteral($) {
+	my($class) = @_;
+
+	if( $class->{'query_string'} =~ s/([m]?\/(.*)\/[i]?[m]?[s]?[x]?)// ) {
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'constraints' ) {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, $1;
+		} elsif( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                       	push @{ $class->{'order_by'} }, $1;
+                        };
+		};
+	};
+
+sub EqualityExpression($) {
+	my($class) = @_;
+
+	RelationalExpression $class;
+	my $true=1;
+	while( $true ) {
+		if( MatchAndEat $class,'==' ) {
+			RelationalExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                       		push @{ $class->{'order_by'} }, '==';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '==';
+                        	};
+		} elsif( MatchAndEat $class,'!=' ) {
+			RelationalExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                       		push @{ $class->{'order_by'} }, '!=';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '!=';
+                        	};
+		} else {
+			$true=0;
+		};
+	};
+};
+
+sub RelationalExpression($) {
+	my($class) = @_;
+
+	AdditiveExpression $class;
+	if( MatchAndEat $class,'>=' or MatchAndEat $class,'>=' ) {
+		AdditiveExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                	push @{ $class->{'order_by'} }, '>=';
+                } else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '>=';
+                       	};
+	} elsif( MatchAndEat $class,'<=' or MatchAndEat $class,'<=' ) {
+		AdditiveExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                	push @{ $class->{'order_by'} }, '<=';
+                } else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '<=';
+                       	};
+	} elsif( MatchAndEat $class,'<' ) {
+		AdditiveExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                	push @{ $class->{'order_by'} }, '<';
+                } else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '<';
+                       	};
+	} elsif( MatchAndEat $class,'>' ) {
+		AdditiveExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                	push @{ $class->{'order_by'} }, '>';
+                } else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '>';
+                       	};
+	};
+};
+
+sub AdditiveExpression($) {
+	my($class) = @_;
+
+	MultiplicativeExpression $class;
+	my $true=1;
+	while( $true ) {
+		if( MatchAndEat $class,'+' ) {
+			MultiplicativeExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                		push @{ $class->{'order_by'} }, '+';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '+';
+                       		};
+		} elsif( MatchAndEat $class,'-' ) {
+			MultiplicativeExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                		push @{ $class->{'order_by'} }, '-';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '-';
+                       		};
+		} else {
+			$true=0;
+		};
+	};
+};
+
+sub MultiplicativeExpression($) {
+	my($class) = @_;
+
+	UnaryExpression $class;
+	my $true=1;
+	while( $true ) {
+		if( MatchAndEat $class,'*' ) {
+			UnaryExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                		push @{ $class->{'order_by'} }, '*';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '*';
+                       		};
+		} elsif( MatchAndEat $class,'/' ) {
+			UnaryExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                		push @{ $class->{'order_by'} }, '/';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '/';
+                       		};
+		} elsif( MatchAndEat $class,'%' ) {
+			UnaryExpression $class;
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                		push @{ $class->{'order_by'} }, '%';
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '%';
+                       		};
+		} else {
+			$true=0;
+		};
+	};
+};
+
+sub UnaryExpression($) {
+	my($class) = @_;
+
+	UnaryExpressionNotPlusMinus $class;
+};
+
+sub UnaryExpressionNotPlusMinus($) {
+	my($class) = @_;
+
+	if( MatchAndEat $class,'~' ) {
+		UnaryExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                	push @{ $class->{'order_by'} }, '~';
+                } else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '~';
+                       	};
+	} elsif ( MatchAndEat $class,'!' ) {
+		UnaryExpression $class;
+		if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                	push @{ $class->{'order_by'} }, '!';
+                } else {
+			push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, '!';
+                       	};
+	} else {
+		PrimaryExpression $class;
+	};
+};
+
+sub PrimaryExpression($) {
+	my($class) = @_;
+
+	if( MatchAndEat $class,'(' ) {
+
+		ConditionalOrExpression $class;
+
+		error $class,"missing right round bracket"
+			unless( MatchAndEat $class,')' );
+
+	} else {
+		unless(	Var $class or URIOrQName $class or Literal $class ) {
+			FunctionCall $class;
+		};
+	};
+};
+
+sub FunctionCall($) {
+	my($class) = @_;
+
+	if(	( MatchAndEat $class,'&' ) &&
+		($class->{'query_string'} =~ s/^\s*([a-zA-Z0-9\-_$\.]+)?:([a-zA-Z0-9\-_$\.]+)\s*//) ) {
+		#	if( $1 ne 'fn' and $1 ne 'op' );
+
+		# look up for a prefix if there
+		# NOTE: otherwise should say unbound prefix in new SPARQL with pre-PREFIX syntax
+		my $qn;
+		if( exists $class->{'prefixes'}->{ ($1) ? $1 : '#default' } ) {
+			$qn = $class->{'prefixes'}->{ ($1) ? $1 : '#default' } . $2 ;
+		} else {
+			error $class,"Unsupported function call $1:$2";
+			};
+
+		if( MatchAndEat $class,'(' ) {
+
+			ArgList $class;
+
+			error $class,"missing right round bracket"
+				unless( MatchAndEat $class,')' );
+
+			if( $class->{'context'}->[ $#{ $class->{'context'} } ] eq 'order by' ) {
+                		push @{ $class->{'order_by'} }, ( '&', $qn );
+                	} else {
+				push @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }, ( '&', $qn );
+                       		};
+			};
+
+		return 1;
+	} else {
+		return 0;
+                };
+	};
+
+sub ArgList($) {
+	my($class) = @_;
+
+	if( Var $class or URIOrQName $class or Literal $class ) {
+		my $true=1;
+		while( $true ) {
+			if( MatchAndEat $class,',' ) {
+
+				unless( Var $class or URIOrQName $class or Literal $class ) {
+					$true=0;
+
+				};
+			} else {
+				$true=0;
+			};
+		};
+	};
+};
+
+# see SPARQL spec http://www.w3.org/TR/rdf-sparql-query/ - generally it can be SELECT, CONSTRUCT, DESCRIBE or ASK
+sub getQueryType {
+	my($class) = @_;
+
+	return $class->{'queryType'};
+	};
+
+sub serialize {
+	my($class, $fh, $syntax) = @_;
+
+	if(	(! $syntax ) ||
+                ( $syntax =~ m/N-Triples/i) ) {
+		# not yet supported ?
+                return
+			if($#{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{constraints} }>=0);
+		foreach my $tp ( @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{triplePatterns} } ) {
+			return
+				if( ($#{$tp}==3) || #Quads not there yet
+			            (     ($tp->[2] =~ m/^%/) && #my free-text extensions
+                                          ($tp->[2] =~ m/%$/) ) );
+			};
+
+		# convert
+		my @nt;
+		foreach my $tp ( @{ $class->{'graphPatterns'}->[$class->{'graph_patterns_pointer'}->[$#{$class->{'graph_patterns_pointer'}}]]->{triplePatterns} } ) {
+			my @tp;
+			map {
+				my $ff = $class->{'query_string'};
+				$ff =~ s/^[\?\$](.+)$/_:$1/;
+				$ff =~ s/[\$:]/-/g;
+				if(	($ff =~ m/^<(([^\:]+)\:{1,2}([^>]+))>$/) &&
+					(defined $2) &&
+					(exists $class->{prefixes}->{$2}) ) {
+					push @tp, '<'.$class->{prefixes}->{$2}.$3.'>';
+				} else {
+					push @tp, $ff;
+					};
+			} @{$tp};
+			push @tp, '.';
+			push @nt, join(' ',@tp);
+			};
+		if($fh) {
+			print $fh join("\n",@nt);
+			return 1;
+		} else {
+			return join("\n",@nt);
+			};
+        } else {
+                croak "Unknown serialization syntax '$syntax'";
+                };
+	};
+
+sub DESTROY {
+	my($class) = @_;
+
+};
+
+1;
+};
+
+__END__
+
+=head1 NAME
+
+RDQL::Parser - A simple top-down LL(1) RDQL and SPARQL parser
+
+=head1 SYNOPSIS
+
+	use RDQL::Parser;
+	my $parser = RDQL::Parser->new();
+	my $query = <<QUERY;
+
+	PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+	PREFIX rss: <http://purl.org/rss/1.0/>
+        SELECT
+           ?title ?link
+        FROM
+           <http://xmlhack.com/rss10.php>
+        WHERE
+	   (?item, rdf:type <rss:item>)
+	   (?item, rss:title, ?title)
+	   (?item, rss:link ?link)
+
+        QUERY;
+
+        $parser->parse($query); #parse the query
+
+	# I.e.
+	$parser = bless( {
+                 'distinct' => 0,
+                 'constructPatterns' => [],
+                 'prefixes' => {
+                                 'fn' => 'http://www.w3.org/2004/07/xpath-functions',
+                                 'op' => 'http://www.w3.org/2001/sw/DataAccess/operations',
+                                 'owl' => 'http://www.w3.org/2002/07/owl#',
+                                 'dcq' => 'http://purl.org/dc/terms/',
+                                 'dc' => 'http://purl.org/dc/elements/1.1/',
+                                 'foaf' => 'http://xmlns.com/foaf/0.1/',
+                                 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
+                                 'rss' => 'http://purl.org/rss/1.0/',
+                                 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+                                 'xsd' => 'http://www.w3.org/2001/XMLSchema#',
+                                 'daml' => 'http://www.daml.org/2001/03/daml+oil#'
+                               },
+                 'graphPatterns' => [
+                                      {
+                                        'constraints' => [],
+                                        'optional' => 0,
+                                        'triplePatterns' => [
+                                                              [
+                                                                0,
+                                                                '?item',
+                                                                '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>',
+                                                                '<rss:item>'
+                                                              ],
+                                                              [
+                                                                0,
+                                                                '?item',
+                                                                '<http://purl.org/rss/1.0/title>',
+                                                                '?title'
+                                                              ],
+                                                              [
+                                                                0,
+                                                                '?item',
+                                                                '<http://purl.org/rss/1.0/link>',
+                                                                '?link'
+                                                              ]
+                                                            ]
+                                      }
+                                    ],
+                 'sources' => [
+                                '<http://xmlhack.com/rss10.php>'
+                              ],
+                 'describes' => [],
+                 'queryType' => 'SELECT',
+                 'resultVars' => [
+                                   '?title',
+                                   '?link'
+                                 ],
+               }, 'RDQL::Parser' );
+
+	$parser->serialize(*STDOUT, 'N-Triples'); #print on STDOUT the RDQL query as N-Triples if possible (or an error)
+
+=head1 DESCRIPTION
+
+ RDQL::Parser - A simple top-down LL(1) RDQL and SPARQL parser - see http://www.w3.org/TR/rdf-sparql-query/ and http://www.w3.org/Submission/2004/SUBM-RDQL-20040109/
+
+=head1 CONSTRUCTORS
+
+=item $parser = new RDQL::Parser;
+
+=head1 METHODS
+
+=item parse( PARSER, QUERY )
+
+ If use Data::Dumper(3) to actually dumpo out the content of the PARSER variable after invoching the parse() method it lokks like:
+
+ $VAR1 = bless( {
+                 'distinct' => 0,
+                 'constructPatterns' => [],
+                 'prefixes' => {
+                                 'fn' => 'http://www.w3.org/2004/07/xpath-functions',
+                                 'op' => 'http://www.w3.org/2001/sw/DataAccess/operations',
+                                 'owl' => 'http://www.w3.org/2002/07/owl#',
+                                 'dcq' => 'http://purl.org/dc/terms/',
+                                 'dc' => 'http://purl.org/dc/elements/1.1/',
+                                 'foaf' => 'http://xmlns.com/foaf/0.1/',
+                                 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
+                                 'rss' => 'http://purl.org/rss/1.0/',
+                                 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+                                 'xsd' => 'http://www.w3.org/2001/XMLSchema#',
+                                 'daml' => 'http://www.daml.org/2001/03/daml+oil#'
+                               },
+                 'graphPatterns' => [
+                                      {
+                                        'constraints' => [],
+                                        'optional' => 0,
+                                        'triplePatterns' => [
+                                                              [
+                                                                0,
+                                                                '?item',
+                                                                '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>',
+                                                                '<rss:item>'
+                                                              ],
+                                                              [
+                                                                0,
+                                                                '?item',
+                                                                '<http://purl.org/rss/1.0/title>',
+                                                                '?title'
+                                                              ],
+                                                              [
+                                                                0,
+                                                                '?item',
+                                                                '<http://purl.org/rss/1.0/link>',
+                                                                '?link'
+                                                              ]
+                                                            ]
+                                      }
+                                    ],
+                 'sources' => [
+                                '<http://xmlhack.com/rss10.php>'
+                              ],
+                 'describes' => [],
+                 'queryType' => 'SELECT',
+                 'resultVars' => [
+                                   '?title',
+                                   '?link'
+                                 ],
+               }, 'RDQL::Parser' );
+
+=head1 NOTES
+
+	The RDQL implementation is actually an extension of the original RDQL spec (http://www.w3.org/Submission/2004/SUBM-RDQL-20040109/)
+	to allow more SQL-like Data Manipulation Language (DML) features like DELETE and INSERT - which is much more close to the original rdfdb
+	query language which SquishQL/RDQL are inspired to (see http://www.guha.com/rdfdb).
+	
+	As well as the SPARQL one....?
+
+=head1 SEE ALSO
+
+DBD::RDFStore(3)
+
+http://www.w3.org/TR/rdf-sparql-query/
+http://www.w3.org/Submission/2004/SUBM-RDQL-20040109/
+http://ilrt.org/discovery/2002/04/query/
+http://www.hpl.hp.com/semweb/doc/tutorial/RDQL/
+http://rdfstore.sourceforge.net/documentation/papers/HPL-2002-110.pdf
+
+=head1 FAQ
+
+=item I<What's the difference between RDQL and SquishQL?>
+
+=item None :-) The former is a bit of an extension of the original SquishQL proposal defining a proper BNF to the query language; the only practical difference is that triple patterns in the WHERE clause are expressed in a different order s,p,o for RDQL while SquishQL uses '(p s o)' without commas. In addition the URIs are expressed with angle brackets on RDQL while SquishQL do not. For more about differences between the two languages see http://rdfstore.sourceforge.net/documentation/papers/HPL-2002-110.pdf
+
+=item I<Is RDQL::Parser compliant to RDQL BNF?>
+
+=item Yes
+
+=item I<Is RDQL::Parser compliant to SquishQL syntax ?>
+
+=item Not yet :)
+
+=item I<What are RDQL::Parser extensions to RDQL BNF?>
+
+=item RDQL::Parser leverage on RDFStore(3) to run proper free-text UTF-8 queries over literals; the two main extensions are
+
+=item * LIKE operator in AND clause
+
+=item * free-text triple matching like (?x, ?y, %"whatever"%)
+
+=head1 AUTHOR
+
+	Alberto Reggiori <areggiori@webweaving.org>
+	Andy Seaborne <andy_seaborne@hp.com> is the original author of RDQL
+	Libby Miller <libby.miller@bristol.ac.uk> is the original author of SquishQL

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/Util/BLOB.pm
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/Util/BLOB.pm?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/Util/BLOB.pm (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/lib/Util/BLOB.pm Fri Apr 13 01:56:01 2007
@@ -0,0 +1,121 @@
+# *
+# *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+# *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+# *
+# * NOTICE
+# *
+# * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+# * file you should have received together with this source code. If you did not get a
+# * a copy of such a license agreement you can pick up one at:
+# *
+# *     http://rdfstore.sourceforge.net/LICENSE
+# *
+# * Changes:
+# *     version 0.1 - 2002/04/26 at 15:30 CEST
+# *
+
+package Util::BLOB;
+{
+use vars qw ($VERSION);
+use strict;
+
+use Carp;
+ 
+$VERSION = '0.1';
+
+use Storable qw ( thaw nfreeze ); #used for BLOBs
+
+$Util::BLOB::Storable_magicnumber = nfreeze(\'_blob_:');
+$Util::BLOB::Storable_magicnumber_unpacked = unpack("H*", $Util::BLOB::Storable_magicnumber );
+sub deserialise {
+	my ($content) = @_;
+
+	if ($content =~ s/^$Util::BLOB::Storable_magicnumber_unpacked//) {
+		$content = pack("H*", $content );
+        	eval {
+        		$Storable::canonical=1;
+                	$content = thaw($content);
+        		$Storable::canonical=0;
+                	};
+                if($@) {
+                	warn "Util::BLOB::deserialise: ".$@;
+                        return;
+                        };
+		};
+	return $content;
+	};
+
+sub serialise {
+	my ($value) = @_;
+   
+        if(     (defined $value) &&
+                (ref($value)) ) {
+                eval {
+        		$Storable::canonical=1;
+                	$value = $Util::BLOB::Storable_magicnumber . nfreeze( $value );
+        		$Storable::canonical=0;
+                	};
+                if($@) {
+                	warn "Util::BLOB::serialise: ".$@;
+                        return;
+                        };
+		$value = unpack("H*", $value );
+                };
+	return $value;
+        };
+
+sub isBLOB {
+	my ($content) = @_;
+
+        if(     (defined $content) &&
+                (ref($content)) ) {
+		return 1;
+	} else {
+		return ($content =~ /^$Util::BLOB::Storable_magicnumber_unpacked/);
+		};
+	};
+
+1;
+};
+
+__END__
+
+=head1 NAME
+
+Util::BLOB - Simple interface to de/serialise perl references with Storable
+
+=head1 SYNOPSIS
+
+	use Util::BLOB;
+	my $blobbed = serialise( $blob );
+	my $blob = deserialise( $blobbed );
+	print "is a BLOB"
+		if(isBLOB($blobbed));
+
+=head1 DESCRIPTION
+
+Simple perl object/reference de/searialisation using Storable. See RDFStore::Literal(3) and RDFStore::Resource(3)
+
+=head1 METHODS
+
+=over 4
+
+=item serialise ( BLOB )
+
+Freeze the given perl object or reference to a string; the string is HEX packed to safely be converted to UTF-8 in RDFStore(3).
+
+=item deserialise ( BLOB )
+
+Thaw the given string to a perl object or reference; the string is HEX unpacked before being thawed.
+
+=item isBLOB ( CONTENT )
+
+Return true if the CONTENT passed to it is actually a BLOB (perl object reference or frozen string)
+
+=head1 SEE ALSO
+
+RDFStore::Literal(3) Storable(3) RDFStore::Resource(3)
+
+=head1 AUTHOR
+
+	Alberto Reggiori <areggiori@webweaving.org>

Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/my_compress.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/my_compress.c?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/my_compress.c (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/my_compress.c Fri Apr 13 01:56:01 2007
@@ -0,0 +1,302 @@
+/*
+  *
+  *     Copyright (c) 2000-2006 Alberto Reggiori <areggiori@webweaving.org>
+  *                        Dirk-Willem van Gulik <dirkx@webweaving.org>
+  *
+  * NOTICE
+  *
+  * This product is distributed under a BSD/ASF like license as described in the 'LICENSE'
+  * file you should have received together with this source code. If you did not get a
+  * a copy of such a license agreement you can pick up one at:
+  *
+  *     http://rdfstore.sourceforge.net/LICENSE
+  *
+  * $Id: my_compress.c,v 1.5 2006/06/19 10:10:21 areggiori Exp $
+  */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <string.h>
+
+#include "rdfstore_compress.h"
+#include "my_compress.h"
+
+
+/* RLE+VLE like de/encoder
+ *
+ * DISCLAIMER: I have no idea whether the following algorithm is under any existing patent
+ *
+ *
+ * First byte
+ *     bit     value   meaning
+ *     0..3    ...     lenght of run (len)
+ *     4-5     00      len is between 0 .. 15, no other bytes
+ *             10      len is continued in next byte, next is LSB (short int)
+ *             01      len is continued in next 3 bytes (long int)
+ *                        * first is upper nibble of MSB
+ *                        * next is lower nibble of MSB
+ *                        * next+1 is upper nibble of LSB
+ *                        * next+2 is lower nibble of LSB
+ *             11      len is continued in next 7 bytes (64 bit int, not implemented yet...)
+ *     6       set     the byte just *after* the run len (see bit 4 and 5) gives the variable-length (up to 127)
+ *             unset   no var len
+ *     7       set     run of len bytes set to the byte value after the run len
+ *             unset   no run, next len bytes are to be copied as-is i.e. "literal bytes"; such bytes could be repeated for a
+ *                     a given variable-length given in the next byte (up to 127) if bit 6 is set
+ */
+
+/*
+ *
+ * (compress|expand)_mine (
+ *	len		in buffer
+ *	buff		unsigned char buffer
+ *
+ *	len-ptr 	will contain out size 
+ *	outbuff 	will contain compressed/decompressed data
+ *			must be big enough ! if set to 'NULL' just
+ *			the size will be calculated... (deleted as
+ *			it takes (some) cycles.
+ *	)
+ */
+unsigned int
+compress_mine (
+	unsigned char * in,
+	unsigned char * out,
+	unsigned int insize
+) {
+	register unsigned int i,j,vlen,l,len,comp,best_match;
+	unsigned int matches[MAXVARLENGTH];
+	double ratio;
+
+	for(i=0,j=0; i<insize; ) {
+		comp=0;
+		best_match=0;
+		len=1;
+		vlen=1;
+
+		/* look for the "best" repeated code; the loop can be repeated up to 2*vlen */
+		for(	vlen=1;
+			(	(i+(vlen*2) < insize) &&
+				(vlen<=MAXVARLENGTH) );
+			vlen++ ) {
+			matches[ vlen-1 ]=0;
+			/* check if there is at least *two* matches for vlen sequence to compress */
+			if(memcmp( in+i, in+i+vlen, vlen ) == 0 ) {
+				matches[ vlen-1 ]=1;
+				/* look for more matches to compress */
+				for( 	len=2, matches[ vlen-1 ]=2;
+					( i+(len*vlen)+vlen < insize ) && 
+					(len < MAXRUNLENGTH) &&
+					( memcmp( in+i, in+i+(len*vlen), vlen ) == 0 ); 
+					matches[ vlen-1 ]++, len++ ) { };
+				/* we should check if the compression is good enough vlen/len << 1/100 (or take the best one) */
+				ratio= (double)vlen / (double)len;
+				if ( ratio <= OPTIMAL ) {
+/*
+printf("GOT OPTIMAL i=%u j=%u value %u/%u: %f << %f\n",i,j,vlen,len,ratio,OPTIMAL);
+*/
+					comp=1;
+					break;
+				};
+
+				if(	(best_match == 0) ||
+					(ratio < ( (double)best_match / (double)matches[ best_match-1 ] ) ) )
+					best_match = vlen;
+			};
+		};
+                if(comp == 0) {
+			/* is there any good/best match? */
+			if (	( best_match > 0 ) &&
+				( matches[ best_match-1 ] > 1 ) ) { /* do compress len>1 */
+				vlen = best_match;
+				len = matches[ best_match-1 ];
+				ratio= (double)vlen / (double)len;
+				comp=1;
+			} else {
+
+				/* the following is for "literal bytes"; we do store dict entries also for literals to refer them if the are at least 1 byte long */
+				vlen=1; /* force this */
+
+				for(    len=1;
+                                        (len+i < insize) &&
+                                        (len < MAXVARLENGTH) &&
+					(len < MAXRUNLENGTH);
+                                        len++) {
+					if(len==1) {
+						if(in[i]==in[i+len]) {
+							break;
+						};
+					} else if( memchr( in+i, in[i+len], len ) != NULL ) {
+						break;
+					};
+				};
+
+/*
+{
+unsigned int w=0;
+printf("LITERAL BYTES insize=%u i=%u j=%u len=%u \n",insize,i,j,len);
+printf("LITERAL BYTES insize=%u i=%u j=%u len=%u : ",insize,i,j,len); w=0; while (w<len) { printf("%x,", in[ i+w ]); w++; }; printf("\n");
+};
+*/
+			};
+		};
+
+		if (len == 0)
+			fprintf(stderr,"Compressing: RLE len=0\n");
+
+		if ( vlen > MAXVARLENGTH)
+			fprintf(stderr,"Var length too high!!!\n");
+
+		l = j;
+		if (len > 4095 ) {
+			out[ l ] = 32 + ((len >> 24) & 15);
+                        out[ l+1 ] = (len>>16) & 0xffff;
+                        out[ l+2 ] = (len>>8) & 0xffff;
+                        out[ l+3 ] = len & 0xffff;
+                        j+=3;
+			if(vlen>1) {
+				out[ l+4 ] = vlen & 127; /* see MAXVARLENGTH */
+                        	j++;
+				out[ l ] |= 64; /* having vlen>1 */
+			};
+                } else if (len > 15 ) {
+			out[ l ] = 16 + ((len >> 8) & 15);
+                        out[ l+1 ] = len & 0xff;
+                        j++;
+			if(vlen>1) {
+				out[ l+2 ] = vlen & 127;
+                        	j++;
+				out[ l ] |= 64;
+			};
+                } else {
+                        out[ l ] = len & 15;
+			if(vlen>1) {
+				out[ l+1 ] = vlen & 127;
+                        	j++;
+				out[ l ] |= 64;
+			};
+                };
+
+		j++;
+		if ( comp ) {
+			out[ l ] |= 128;
+/*
+printf("COMPRESSING for i=%u j=%u insize=%u vlen=%u len=%u comp=%u ratio=%f\n",i,j,insize,vlen,len,comp,ratio);
+*/
+			/* just the repeated bytes */
+			bcopy(in+i,out+j,vlen);
+
+			j+=vlen;
+		} else {
+/*
+printf("NOT COMPRESSING for i=%u j=%u insize=%u vlen=%u len=%u comp=%u\n",i,j,insize,vlen,len,comp);
+*/
+			if (len==1) {
+				out[j] = in[i];
+			} else {
+				bcopy(in+i,out+j,len);
+			};
+
+			j+=len;
+		}; /* non-compressed else */
+		i+=(len*vlen); /* hop on for the next ones... */
+
+/*
+{
+unsigned int w=0;
+printf(">>>COMPRESSED STRING so far insize=%u i=%u j=%u : ",insize,i,j); w=0; while (w<j) { printf("%x,", out[ w ]); w++; }; printf("\n");
+};
+*/
+
+	}; /* for loop */	
+/*
+	printf("compressed string is %u bytes\n",j);
+*/
+
+	/*
+	 * pad to sensible length (in the hope it makes
+	 * the db storage a bit faster .... if we do not
+	 * have to increase the size of the stored block
+	 * for each and every change.. 
+	 *
+	 * 	for(;j % 32;j++) out[j]='\0'; 
+	 */
+
+	return j;
+};
+
+unsigned int
+expand_mine ( 
+	unsigned char * in,
+	unsigned char * out,
+	unsigned int insize
+) {
+	register unsigned int i,j,c,len,vlen,k;
+
+	for(i=0,j=0; i<insize;) {
+		/* work out run length */
+		c = in[i]; 
+
+		if (!c) 
+			break; /* no compress, no length */
+
+		if ( c & 32 ) {
+			len = c & 31;
+			len = ( len << 8 ) + in[ ++i ];
+			len = ( len << 8 ) + in[ ++i ];
+			len = ( len << 8 ) + in[ ++i ];
+		} else {
+			len = c & 15;
+			if ( c & 16 ) 
+				len = ( len << 8 ) + in[ ++i ];
+		};
+
+		if ( c & 64 ) {
+			vlen=in[ ++i ];
+		} else {
+			vlen=1;
+		};
+
+		if (len == 0) {
+			fprintf(stderr,"Bug: RLE len=0\n");
+			break;
+		};
+		i++;
+		if (c & 128) {
+			if (vlen>1) {
+/*
+printf("DECOMPRESSING for i=%u j=%u insize=%u vlen=%u len=%u\n",i,j,insize,vlen,len);
+*/
+
+                        	for(k=0; k<len;k++) {
+                                	bcopy(in+i,out+(j+(k*vlen)),vlen);
+                                };
+                                i+=vlen;
+                        } else {
+/*
+printf("DECOMPRESSING for i=%u j=%u insize=%u vlen=%u len=%u\n",i,j,insize,vlen,len);
+*/
+                                if(in[i] == 0) {
+                                        bzero(out+j, len);
+                                } else {
+                                        memset(out+j, in[i], len);
+                                };
+                                i+=vlen;
+                        };
+		} else {
+/*
+printf("EXPANDING literal bytes for i=%u j=%u vlen=%u len=%u insize=%u\n",i,j,vlen,len,insize);
+*/
+                	bcopy(in+i,out+j,len);
+			i+=len;
+		};
+		j+=(len*vlen);
+	}; /* for */
+
+/*
+	printf("decompressed string is %u bytes\n",j);
+*/
+	return j;
+};



Mime
View raw message