Commits

Toby Inkster committed 505f25b Draft

very minimal RDFS inference

Comments (0)

Files changed (4)

examples/simple.pl

 @prefix lang: <http://ontologi.es/vido/languages#> .
 
 <#text1>
-	a void:Dataset, vido:ResultOfLineTransformation;
+	a void:Dataset;
 	dc:description "This is the target dataset we hope to produce."@en;
 	vido:lines_transformed_by <data:text/x-perl-script,uc$_>;
 	vido:source <#text2>.
 
 <#text2>
-	a void:Dataset, vido:FixedContent;
+	a void:Dataset;
 	dc:description "This is the source dataset."@en;
 	vido:content "foo\nbar\nbaz\n".
 
 	our $VERSION   = '0.001';
 }
 
+use RDF::TrineX::Functions qw( parse curie iri statement variable );
+use aliased 'RDF::Trine::Pattern';
+
 has model => (
 	is         => read_only,
 	isa        => 'RDF::Trine::Model',
+	trigger    => sub {
+		my $self = shift;
+		$self->_perform_inferences;
+	},
 );
 
+# This is by no means full RDFS inference; just the bits that are useful
+# for our purposes!
+sub _perform_inferences
+{
+	my $model = shift->model;
+	my $iter;
+	
+	# Load in the ontology.
+	# Path should not be hard-coded! File::ShareDir??
+	parse(
+		'ontologies/core.ttl',
+		as   => 'Turtle',
+		base => 'http://ontologi.es/vido/core',
+		into => $model,
+	);
+	
+	my $rdfs_domains = Pattern->new(
+		statement(variable('property'), curie('rdfs:domain'), variable('class')),
+		statement(variable('resource'), variable('property'), variable('x')),
+	);
+	$iter = $model->get_pattern($rdfs_domains);
+	while (my $result = $iter->next)
+	{
+		my $st = statement($result->{resource}, curie('rdf:type'), $result->{class});
+		$model->add_statement($st);
+	}
+
+	my $rdfs_ranges = Pattern->new(
+		statement(variable('property'), curie('rdfs:range'), variable('class')),
+		statement(variable('x'), variable('property'), variable('resource')),
+	);
+	$iter = $model->get_pattern($rdfs_ranges);
+	while (my $result = $iter->next)
+	{
+		my $st = statement($result->{resource}, curie('rdf:type'), $result->{class});
+		$model->add_statement($st);
+	}
+}
+
 __END__
 
 =head1 NAME

lib/Vido/Dataset.pm

 	
 	my @roles = 
 		uniq
+		grep { $_ ne 'Vido::Dataset::Dataset' }  # the exception
 		map  { my ($p, $s) = $_->qname; __PACKAGE__."::$s" }
 		grep { $_->uri =~ m{^http://ontologi\.es/vido/core\#} }
 		grep { $_->is_resource }

lib/Vido/Syntax.pm

 require Vido::Exception;
 
 use Syntax::Collector 0.004 -collect => q{
+
+use namespace::autoclean 0.11;
 use strict 0;
+use true 0;
 use warnings 0;
-use true 0;
+
 use Moose::Util::TypeConstraints 0 qw( class_type role_type duck_type enum );
 use MooseX::Types::Moose 0 qw(-all);
 use MooseX::Types::Path::Class 0 qw(File Dir);
+use Vido::Types 0 -all;
+
 use Scalar::Does 0.003 qw(does);
 use TryCatch 0;
-use Vido::Types 0 -all;
+
 use constant 0 { true => !!1, false => !!0 };
 use constant 0 { read_only => 'ro', read_write => 'rw' };
+
 };
 
 sub IMPORT