| 1 | package FAIR::ProjectorMetadata; | ||
| 2 | $FAIR::ProjectorMetadata::VERSION = '1.0'; | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | use strict; | ||
| 8 | use Moose; | ||
| 9 | use UUID::Generator::PurePerl; | ||
| 10 | use RDF::Trine::Store::Memory; | ||
| 11 | use RDF::Trine::Model; | ||
| 12 | |||
| 13 | with 'FAIR::CoreFunctions'; | ||
| 14 | |||
| 15 | has 'model' => ( | ||
| 16 | isa => "RDF::Trine::Model", | ||
| 17 | is => "rw", | ||
| 18 | default => sub {my $store = RDF::Trine::Store::Memory->new(); return RDF::Trine::Model->new($store)} | ||
| 19 | ); | ||
| 20 | |||
| 21 | has 'NS' => ( | ||
| 22 | is => 'rw', | ||
| 23 | ); | ||
| 24 | |||
| 25 | sub createProjection { | ||
| 26 | my ($self, $formats, $URL, $SOURCE, $subtemplate, $type, $predicate, $objecttemplate, $otype, $availableFormats) = @_; # | ||
| 27 | my $NS = $self->NS; | ||
| 28 | my $model = $self->model; | ||
| 29 | |||
| 30 | push @{$formats->{"$availableFormats"}}, $URL; | ||
| 31 | my $statement; | ||
| 32 | |||
| 33 | #$statement = statement($URL, $NS->dcat('distribution'), $URL); | ||
| 34 | #$model->add_statement($statement); | ||
| 35 | # | ||
| 36 | #$statement = statement($URL, $NS->rdf('type'), $NS->dcat('Distribution')); | ||
| 37 | #$model->add_statement($statement); | ||
| 38 | # | ||
| 39 | #$statement = statement($URL, $NS->rdf('type'), $NS->dctypes('Dataset')); | ||
| 40 | #$model->add_statement($statement); | ||
| 41 | |||
| 42 | #$statement = statement($URL, $NS->dc('format'), $format); | ||
| 43 | #$model->add_statement($statement); | ||
| 44 | |||
| 45 | $statement = statement($URL, $NS->rdf('type'), $NS->fair('Projector')); | ||
| 46 | $model->add_statement($statement); | ||
| 47 | |||
| 48 | |||
| 49 | #if (($format =~ /turtle/) || ($format =~ /rdf/) || ($format =~ /quads/)) { | ||
| 50 | # $statement = statement($URL, $NS->rdf('type'), $NS->void('Dataset')); | ||
| 51 | # $model->add_statement($statement); | ||
| 52 | #} | ||
| 53 | |||
| 54 | $statement = statement($URL, $NS->dcat('downloadURL'), $URL); | ||
| 55 | $model->add_statement($statement); | ||
| 56 | |||
| 57 | $self->ProjectionMap($URL, $SOURCE, $subtemplate, $type, $predicate, $objecttemplate, $otype); | ||
| 58 | |||
| 59 | # | ||
| 60 | #$statement = statement($TPF, $NS->rdf('subjectClass'), 'phi:PHIBO_00022'); | ||
| 61 | #$model->add_statement($statement); | ||
| 62 | #$statement = statement($TPF, $NS->rdf('predicate'), $predicate); | ||
| 63 | #$model->add_statement($statement); | ||
| 64 | |||
| 65 | # return nothing - the value of $model is now different | ||
| 66 | return $formats; | ||
| 67 | |||
| 68 | } | ||
| 69 | |||
| 70 | sub ProjectionMap{ | ||
| 71 | my ($self, $URL, $SOURCE, $subtemplate, $type, $predicate, $objecttemplate, $otype) = @_; | ||
| 72 | my $uuid = UUID::Generator::PurePerl->new(); | ||
| 73 | $uuid = $uuid->generate_v1(); | ||
| 74 | my $NS = $self->NS(); | ||
| 75 | |||
| 76 | my $model = $self->model; | ||
| 77 | |||
| 78 | my $SRC = "http://datafairport.org/local/Source$uuid"; | ||
| 79 | my $MAP = "http://datafairport.org/local/Mappings$uuid"; | ||
| 80 | my $SMAP = "http://datafairport.org/local/SubjectMap$uuid"; | ||
| 81 | my $POMAP = "http://datafairport.org/local/POMap$uuid"; | ||
| 82 | my $OMAP = "http://datafairport.org/local/ObjectMap$uuid"; | ||
| 83 | my $SMAP2 = "http://datafairport.org/local/SubjectMap2$uuid"; | ||
| 84 | |||
| 85 | |||
| 86 | my $statement; | ||
| 87 | # Mapping | ||
| 88 | # <CSV> rml:isSourceOf <SRC> | ||
| 89 | # <SRC> rml:source <CSV> | ||
| 90 | $statement = statement($URL, $NS->rml('source'), $SOURCE); | ||
| 91 | $model->add_statement($statement); | ||
| 92 | |||
| 93 | # <MAP> rml:logicalSource <SRC> | ||
| 94 | $statement = statement($MAP, $NS->rml('logicalSource'), $URL); | ||
| 95 | $model->add_statement($statement); | ||
| 96 | |||
| 97 | |||
| 98 | # <SRC> rml:hasMapping <MAP> | ||
| 99 | $statement = statement($URL, $NS->rml('hasMapping'), $MAP); | ||
| 100 | $model->add_statement($statement); | ||
| 101 | # <SRC> rml:referenceFormulation ql:CSV | ||
| 102 | $statement = statement($URL, $NS->rml('referenceFormulation'), $NS->ql('TriplePatternFragments')); | ||
| 103 | $model->add_statement($statement); | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | # <MAP> rr:subjectMap <SMAP> | ||
| 108 | $statement = statement($MAP, $NS->rr('subjectMap'), $SMAP); | ||
| 109 | $model->add_statement($statement); | ||
| 110 | # <SMAP> rr:template "http://something/{ID}" | ||
| 111 | |||
| 112 | |||
| 113 | my $templateurl = RDF::Trine::Node::Literal->new($subtemplate); | ||
| 114 | $statement = statement($SMAP, $NS->rr('template'), $templateurl); | ||
| 115 | $model->add_statement($statement); | ||
| 116 | |||
| 117 | $statement = statement($SMAP, $NS->rr('class'), $type); | ||
| 118 | $model->add_statement($statement); | ||
| 119 | |||
| 120 | |||
| 121 | |||
| 122 | # <MAP> rr:predicateObjectMap <POMAP> | ||
| 123 | $statement = statement($MAP, $NS->rr('predicateObjectMap'), $POMAP); | ||
| 124 | $model->add_statement($statement); | ||
| 125 | # | ||
| 126 | # <POMAP> rr:predicate {$predicate} | ||
| 127 | $statement = statement($POMAP, $NS->rr('predicate'), $predicate); | ||
| 128 | $model->add_statement($statement); | ||
| 129 | # <POMAP> rr:objectMap <OMAP> | ||
| 130 | $statement = statement($POMAP, $NS->rr('objectMap'), $OMAP); | ||
| 131 | $model->add_statement($statement); | ||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | # | ||
| 136 | # <OMAP> rr:parentTriplesMap <OBJMAP> | ||
| 137 | $statement = statement($OMAP, $NS->rr('parentTriplesMap'), $SMAP2); | ||
| 138 | $model->add_statement($statement); | ||
| 139 | # <OMAP> rr:subjecctMap <SMAP2> | ||
| 140 | # <SMAP2> rr:template "http://somethingelse/{out} | ||
| 141 | if ($otype =~ /\#string/){ | ||
| 142 | $templateurl = RDF::Trine::Node::Literal->new("{value}"); | ||
| 143 | } else { | ||
| 144 | $templateurl = RDF::Trine::Node::Literal->new($objecttemplate); | ||
| 145 | } | ||
| 146 | $statement = statement($SMAP2, $NS->rr('template'), $templateurl); | ||
| 147 | $model->add_statement($statement); | ||
| 148 | |||
| 149 | $statement = statement($SMAP2, $NS->rr('class'), $otype); | ||
| 150 | $model->add_statement($statement); | ||
| 151 | |||
| 152 | |||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | 1; | ||
| 157 | |||
| 158 | __END__ | ||
| 159 | |||
| 160 | =pod | ||
| 161 | |||
| 162 | =encoding UTF-8 | ||
| 163 | |||
| 164 | =head1 NAME | ||
| 165 | |||
| 166 | FAIR::ProjectorMetadata | ||
| 167 | |||
| 168 | =head1 VERSION | ||
| 169 | |||
| 170 | version 1.0 | ||
| 171 | |||
| 172 | =head1 Name FAIR::ProjectorMetadata | ||
| 173 | |||
| 174 | =head1 Description | ||
| 175 | |||
| 176 | Projector Metadata includes things like the RML model, and stuff | ||
| 177 | |||
| 178 | =head1 AUTHOR | ||
| 179 | |||
| 180 | Mark Denis Wilkinson (markw [at] illuminae [dot] com) | ||
| 181 | |||
| 182 | =head1 COPYRIGHT AND LICENSE | ||
| 183 | |||
| 184 | This software is Copyright (c) 2016 by Mark Denis Wilkinson. | ||
| 185 | |||
| 186 | This is free software, licensed under: | ||
| 187 | |||
| 188 | The Apache License, Version 2.0, January 2004 | ||
| 189 | |||
| 190 | =cut |