-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
170 lines (153 loc) · 5.02 KB
/
helper.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* User: Hans-Gert Gräbe
* last update: 2022-06-18
*/
/* ======= Sparql Endpoint as global variable ======== */
$sparql = new \EasyRdf\Sparql\Client('http://wumm.uni-leipzig.de:8891/sparql');
/* ======= helper function ======== */
function setNamespaces() {
\EasyRdf\RdfNamespace::set('bibo', 'http://purl.org/ontology/bibo/');
\EasyRdf\RdfNamespace::set('dc', 'http://purl.org/dc/elements/1.1/');
\EasyRdf\RdfNamespace::set('dcterms', 'http://purl.org/dc/terms/');
\EasyRdf\RdfNamespace::set('dbo', 'http://dbpedia.org/ontology/');
\EasyRdf\RdfNamespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
\EasyRdf\RdfNamespace::set('ical', 'http://www.w3.org/2002/12/cal/ical#');
\EasyRdf\RdfNamespace::set('owl', 'http://www.w3.org/2002/07/owl#');
\EasyRdf\RdfNamespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
\EasyRdf\RdfNamespace::set('swc', 'http://data.semanticweb.org/ns/swc/ontology#');
\EasyRdf\RdfNamespace::set('od', 'http://opendiscovery.org/rdf/Model#');
\EasyRdf\RdfNamespace::set('odp', 'http://opendiscovery.org/rdf/Person/');
\EasyRdf\RdfNamespace::set('tc', 'http://opendiscovery.org/rdf/Concept/');
\EasyRdf\RdfNamespace::set('bm', 'http://opendiscovery.org/rdf/BusinessModel/');
\EasyRdf\RdfNamespace::set('bmp', 'http://opendiscovery.org/rdf/BusinessModelPattern/');
}
function htmlEnv($out)
{
return '
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
</HEAD><BODY>
'.$out.'
</BODY></HTML>
';
}
function fixEncoding($out) {
return str_replace(
array("„","“","–"), array("„","”","–"), $out
);
}
function showLanguage($a,$sep) {
$out='';
$b=array();
foreach($a as $v) {
$l=$v->getLang();
if (empty($l)) { $l='en'; }
$b[$l]="$l: $v";
}
ksort($b);
return join($sep,$b);
}
function listPerLanguage($concept,$item) {
$lang=array();
foreach($concept->all($item) as $v) {
$l=$v->getLang();
if (empty($l)) { $l='en'; }
$lang[$l]=1;
}
ksort($lang);
$out='';
foreach($lang as $l => $value) {
$b=array();
foreach($concept->all($item,"literal",$l) as $v) {
$b[]="<li>$v</li>";
}
ksort($b);
$out.="$l:<ul>".join("\n",$b).'</ul>';
}
return $out;
}
function createLink($url,$text) {
return '<a href='.$url.'>'.$text.'</a>';
}
function createUniLink($url) {
return '<a href='.$url.'>'.$url.'</a>';
}
function genericLink() {
return '
<h4>This web site is part of the <a href="http://wumm.uni-leipzig.de">WUMM Demonstration Project</a></h4>
';
}
function showDate($s) {
return date("D d M Y",strtotime($s));
}
function multiline($s) {
return str_replace("\n","<br/>",$s);
}
/* ============== display blocks ============= */
function getAutoren($node) {
$s=array();
foreach ($node->all("dcterms:creator") as $a) {
$title=$a->get("foaf:title");
$name=$a->get("foaf:name");
if (!empty($title)) {
$name="$title $name" ;
}
array_push($s, '<span itemprop="creator">'.$name.'</span>');
}
return join(", ", $s);
}
function listBook($book) {
$uri=str_replace("http://opendiscovery.org/rdf/","",$book->getURI());
$autoren=getAutoren($book);
$titel=showLanguage($book->all("dcterms:title"),"<br/>");
$id=join("",$book->all("dcterms:creator")).$titel;
$abstract=multiline($book->get("dcterms:abstract"));
$publisher=$book->get("dc:publisher");
$year=join(", ",$book->all("dcterms:issued"));
$isbn=join(", ",$book->all("bibo:isbn"));
$asin=$book->get("bibo:asin");
$lang=$book->get("dc:language");
$externalLink=$book->get("rdfs:seeAlso");
$url=join(", ",array_map('createUniLink',$book->all("od:relatedLinks")));
$comment=$book->get("rdfs:comment");
$out='
<div itemscope itemtype="http://schema.org/Book" class="book">
<!-- ID: '.$id.' -->
<h4><a href="displayprop.php?uri='.$uri.'">'.$uri.'</a></h4>
<h4><div itemprop="title" class="title">'.$titel.'</div></h4>
<div class="author"><strong>Author(s):</strong> '. $autoren.'</div>';
if ($lang) {
$out.='
<div itemprop="language"><strong>Language:</strong> '.$lang.'</div>';
}
if ($publisher) {
$s=array($publisher);
if ($year) { $s[]=$year; }
if ($isbn) { $s[]="ISBN: $isbn";}
if ($asin) { $s[]="ASIN: $ain"; }
$out.='
<div itemprop="publisher"><strong>Publisher:</strong> '.join(", ",$s).'</div>';
}
if ($abstract) {
$out.='
<div itemprop="description" class="abstract">
<p><strong>Description:</strong><br/> '
. $abstract .'</p></div>';
}
if ($externalLink) {
$out.='
<div itemprop="link"><strong>External Link:</strong> '
.createUniLink($externalLink).'</div>';
}
if ($url) {
$out.='
<div><strong>Links:</strong> '.$url.'</div>';
}
if ($comment) {
$out.='
<div itemprop="comment"><strong>Comment:</strong> '.$comment.'</div>';
}
return $out;
}