Toby Inkster avatar Toby Inkster committed bc06903 Draft

the ability to create unions of graphs

Comments (0)

Files changed (5)

examples/simple.pl

 	vido:source [
 		dc:format "text/turtle";
 		vido:lines_transformed_by [
-			vido:content "chomp; sprintf(qq(<%s> a <Resource>. ), $_)" ;
+			vido:content "chomp; sprintf(qq(<http://example.com/%s> a <http://example.com/Resource>. ), $_)" ;
 			dc:description "This is a transformation applied to each line of a line-based format."@en;
 		];
 		vido:source [
 			vido:content "foo\nbar\nbaz\n";
 		];
 	].
+
+<#g2>
+	a void:Dataset, vido:Graph;
+	vido:source [
+		vido:content "<a> <b> <c> .";
+		dc:format "NTriples";
+	].
+
+<#union>
+	a void:Dataset;
+	vido:union_graph_of ( <#g1> <#g2> ).
+
 IN
 
-my $dataset = Vido::Dataset->new(
-	identifier => iri('http://example.net/#g1'),
-	universe   => $U,
+my $g = $U->get_dataset(
+	iri('http://example.net/#union'),
 );
 
-print serialize($dataset->graph, as => 'ntriples');
+#say $_->dataset_string for @{ $g->union_graph_of };
 
+print serialize($g->graph, as => 'nquads');
+
 	},
 );
 
+sub get_dataset
+{
+	my ($self, $node, @roles) = @_;
+	my $new = Vido::Dataset->new(
+		identifier   => $node,
+		universe     => $self,
+	);
+	Moose::Util::ensure_all_roles(
+		$new,
+		map { "Vido::Dataset::$_" } @roles,
+	) if @roles;
+	return $new;
+}
+
 # This is by no means full RDFS inference; just the bits that are useful
 # for our purposes!
 sub _perform_inferences

lib/Vido/Dataset/UnionGraph.pm

+package Vido::Dataset::UnionGraph;
+
+use Vido::Syntax -role;
+BEGIN {
+	our $AUTHORITY = 'cpan:TOBYINK';
+	our $VERSION   = '0.001';
+}
+
+has graph => (
+	is         => read_only,
+	isa        => class_type('RDF::Trine::Model'),
+	lazy_build => true,
+);
+
+has union_graph_of => (
+	is         => read_only,
+	isa        => ArrayRef[ role_type('Vido::Dataset::Graph') ],
+	lazy_build => true,
+);
+
+sub _build_graph
+{
+	my $self  = shift;
+	my $model = RDF::Trine::Model->new();
+	$model->add_iterator( $_->graph->as_stream )
+		for grep { $_->can('graph') } @{ $self->union_graph_of };
+	return $model;
+}
+
+sub _build_union_graph_of
+{
+	my $self = shift;
+	
+	my ($list) = $self->model->objects(
+		$self->identifier,
+		RDF::Trine::Node::Resource->new('http://ontologi.es/vido/core#union_graph_of'),
+	);
+	return [] unless $list;
+
+	return [
+		map { $self->universe->get_dataset($_) }
+		$self->model->get_list($list)
+	];
+}

lib/Vido/Syntax.pm

 			{
 				return $o->literal_value
 					if $o->is_literal && $type ~~ [qw/ literal string /];
+				
 				return $o->uri
 					if $o->is_resource && $type  ~~ [qw/ resource string /];
 				
-				if ($type eq 'object' and not $o->is_literal)
-				{
-					my $new = Vido::Dataset->new(
-						identifier   => $o,
-						universe     => $self->universe,
-					);
-					Moose::Util::ensure_all_roles(
-						$new,
-						map { "Vido::Dataset::$_" } @{ $args{ensure_all_roles} },
-					) if $args{ensure_all_roles};
-					return $new;
-				}
+				return $self->universe->get_dataset(
+					$o,
+					@{ $args{ensure_all_roles} || [] },
+				) if $type eq 'object' && !$o->is_literal;
 			}
 			
 			if (exists $args{fallback})

ontologies/core.ttl

 :Script rdfs:subClassOf :Dataset .
 :Graph rdfs:subClassOf :Dataset .
 :NamedGraph rdfs:subClassOf :Dataset, :Graph .
+:UnionGraph rdfs:subClassOf :Dataset .
 
 :content
 	a rdf:Property;
 	a rdf:Property;
 	rdfs:label "graph name";
 	rdfs:domain :NamedGraph.
+
+:union_graph_of
+	a rdf:Property;
+	rdfs:label "union graph of";
+	rdfs:domain :UnionGraph.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.