-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdcate.rdf.inc
executable file
·122 lines (110 loc) · 3.58 KB
/
sdcate.rdf.inc
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
<?php
/**
* @file
* Helper functions for writing DCAT.
*/
define('SDCATE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
define('SDCATE_RDF_TYPE', SDCATE_RDF . 'type');
define('SDCATE_XSD', 'http://www.w3.org/2001/XMLSchema#');
define('SDCATE_XSD_DTIME', SDCATE_XSD . 'dateTime');
define('SDCATE_XSD_DEC', SDCATE_XSD . 'decimal');
define('SDCATE_DCAT', 'http://www.w3.org/ns/dcat#');
define('SDCATE_DCAT_ACAT', SDCATE_DCAT . 'Catalog');
define('SDCATE_DCAT_ADSET', SDCATE_DCAT . 'Dataset');
define('SDCATE_DCAT_ADIST', SDCATE_DCAT . 'Distribution');
define('SDCATE_DCAT_DSET', SDCATE_DCAT . 'dataset');
define('SDCATE_DCAT_DIST', SDCATE_DCAT . 'distribution');
define('SDCATE_DCAT_CONTACT', SDCATE_DCAT . 'contactPoint');
define('SDCATE_DCAT_PAGE', SDCATE_DCAT . 'landingPage');
define('SDCATE_DCAT_TAG', SDCATE_DCAT . 'keyword');
define('SDCATE_DCAT_THEME', SDCATE_DCAT . 'theme');
define('SDCATE_DCAT_URL', SDCATE_DCAT . 'accessURL');
define('SDCATE_DCAT_SIZE', SDCATE_DCAT . 'byteSize');
define('SDCATE_DCAT_TYPE', SDCATE_DCAT . 'mediaType');
define('SDCATE_DT', 'http://purl.org/dc/terms/');
define('SDCATE_DT_CREAT', SDCATE_DT . 'issued');
define('SDCATE_DT_DESC', SDCATE_DT . 'description');
define('SDCATE_DT_GEO', SDCATE_DT . 'spatial');
define('SDCATE_DT_LANG', SDCATE_DT . 'language');
define('SDCATE_DT_MODIF', SDCATE_DT . 'modified');
define('SDCATE_DT_TITLE', SDCATE_DT . 'title');
define('SDCATE_DT_FORMAT', SDCATE_DT. 'format');
define('SDCATE_DT_PUBLISHER', SDCATE_DT. 'publisher');
define('SDCATE_FOAF', 'http://xmlns.com/foaf/0.1/');
define('SDCATE_FOAF_DOC', SDCATE_FOAF . 'Document');
define('SDCATE_FOAF_HOME', SDCATE_FOAF . 'homepage');
define('SDCATE_FOAF_NAME', SDCATE_FOAF . 'name');
/**
* Creates RDF triple.
*
* @param string $subject
* Subject of this triple as URI.
* @param string $predicate
* Predicate of this triple as URI.
* @param string $object
* Object of this triple as URI.
*
* @return string
* String representation of the triple.
*/
function sdcate_triple($subject, $predicate, $object) {
return "<$subject> <$predicate> <$object> . \n";
}
/**
* Create RDF triple.
*
* @param string $subject
* Subject of this triple as URI.
* @param string $predicate
* Predicate of this triple as URI.
* @param string $literal
* String to be added as object.
* @param string $lang
* Optional language identifier.
*
* @return string
* String representation of the triple.
*/
function sdcate_literal($subject, $predicate, $literal, $lang = '') {
$object = '"' . addcslashes($literal, "\\\'\"\n\r") . '"';
if (isset($lang) && !empty($lang)) {
$object .= '@' . $lang;
}
return "<$subject> <$predicate> $object .\n";
}
/**
* Create RDF triple.
*
* @param string $subject
* Subject of this triple as URI.
* @param string $predicate
* Predicate of this triple as URI.
* @param string $stamp
* Timestamp (in seconds since epoch).
*
* @return string
* String representation of the triple.
*/
function sdcate_date($subject, $predicate, $stamp) {
$object = '"' . date(DATE_ISO8601, $stamp) . '"';
$object .= '^^<' . SDCATE_XSD_DTIME . '>';
return "<$subject> <$predicate> $object .\n";
}
/**
* Create RDF triple.
*
* @param string $subject
* Subject of this triple as URI.
* @param string $predicate
* Predicate of this triple as URI.
* @param string $decimal
* Decimal as string.
*
* @return string
* String representation of the triple.
*/
function sdcate_decimal($subject, $predicate, $decimal) {
$object = '"' . $decimal . '"';
$object .= '^^<' . SDCATE_XSD_DEC . '>';
return "<$subject> <$predicate> $object .\n";
}