-
Notifications
You must be signed in to change notification settings - Fork 15
/
dataset.php
131 lines (109 loc) · 4.71 KB
/
dataset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
Copyright (C) 2013 Michel Dumontier
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
class Dataset
{
public function __construct($rdf_factory)
{
if($rdf_factory === null) {
trigger_error("you must provide an instance of the rdf factory",E_USER_ERROR);
return false;
}
$this->setRDFFactory($rdf_factory);
}
function __destruct(){}
public function setRDFFactory($rdf_factory){$this->rdf_factory=$rdf_factory;return $this;}
public function getRDFFactory(){return $this->rdf_factory;}
public function setURI($uri){$this->uri = $uri;return $this;}
public function getURI() {return $this->uri;}
public function setPrefix($string){$this->prefix=$string;return $this;}
public function getPrefix(){return @$this->prefix;}
public function setTitle($string){$this->title = $string;return $this;}
public function getTitle() {return @$this->title;}
public function setDescription($string){$this->description = $string;return $this;}
public function getDescription() {return @$this->description;}
public function setPublisher($uri){$this->publisher = $uri;return $this;}
public function getPublisher() {return @$this->publisher;}
public function setHomepage($url){$this->homepage = $url;return $this;}
public function getHomepage() {return @$this->homepage;}
public function setSource($source_uri) {$this->source[] = $source;return $this;}
public function getSource(){return @$this->source;}
public function setResource($resource){$this->resource[] = $resource;return $this;}
public function getResource() {return @$this->resource;}
public function setRDFFile($rdf_file){$this->rdf_files[] = $rdf_file;return $this;}
public function getRDFFile() {return @$this->rdf_files;}
public function setSPARQLEndpoint($sparql_endpoint){$this->sparql_endpoint[] = $sparql_endpoint;return $this;}
public function getSPARQLEndpoint() {return @$this->sparql_endpoint;}
public function toRDF()
{
setLogLevelFromString('error');
if($this->getPrefix() === null and $this->getURI() === null) {
return '';
}
$date = date("Y-m-d");
$datetime = date("Y-m-d\TG:i:s\Z");
$dataset_uri = $this->getURI();
if($dataset_uri === null) {
// construct from prefix
$dataset_uri = "urn:".$this->getPrefix()."-".$date;
}
$f = $this->getRDFFactory();
$rdf = '';
$label =
($this->getTitle() === null ? "Dataset":$this->getTitle())
.($this->getPublisher() === null ? " generated by ".$this->getPublisher():"");
$rdf .= $f->QQuadL($dataset_uri,"rdfs:label",$label);
$rdf .= $f->QQuad($dataset_uri,"rdf:type","dc:Dataset");
if($this->getTitle() !== null) {
$rdf .= $f->QQuadL($dataset_uri,"dc:title",$this->getTitle());
}
if($this->getDescription() !== null) {
$rdf .= $f->QQuadL($dataset_uri,"dc:description",$this->getDescription());
}
if($this->getPublisher() !== null) {
$rdf .= (strstr($this->getPublisher(),"://")?
$f->QQuadO_URL($dataset_uri,"dc:publisher",$this->getPublisher())
:$f->QQuadL($dataset_uri,"dc:publisher",$this->getPublisher()));
}
if($this->getHomepage() !== null) {
$rdf .= $f->QQuadO_URL($dataset_uri,"foaf:page",$this->getHomepage());
}
if($this->getSource() !== null) {
foreach($this->getSource() as $source) {
$rdf .= $f->QQuadO_URL($dataset_uri,"dc:source",$source);
}
}
if($this->getResource() !== null) {
foreach($this->getResource() AS $resource) {
$rdf .= $f->QQuadO_URL($dataset_uri,"dcat:distribution",$resource);
}
}
if($this->getRDFFile() !== null) {
foreach($this->getRDFFile() AS $rdf_file) {
$rdf .= $f->QQuadO_URL($dataset_uri,"void:dataDump",$rdf_file);
}
}
if($this->getSPARQLEndpoint() !== null) {
foreach($this->getSPARQLEndpoint() AS $sparql) {
$rdf .= $f->QQuadO_URL($dataset_uri,"void:sparqlEndpoint",$sparql);
}
}
return $rdf;
}
}