143 $alternative_pageid = array_key_exists('pageid', $page) ? $page['pageid'] : null; |
143 $alternative_pageid = array_key_exists('pageid', $page) ? $page['pageid'] : null; |
144 } |
144 } |
145 |
145 |
146 $revision_id = $page['lastrevid']; |
146 $revision_id = $page['lastrevid']; |
147 |
147 |
148 // Get the dbpedia uri by requesting dbpedia with sparkl |
148 // Get the dbpedia uri by requesting dbpedia with sparql |
149 |
|
150 |
|
151 /* |
|
152 // process language to extract the english label |
|
153 $english_label = null; |
|
154 if($status==Tag::$TAG_URL_STATUS_DICT["match"] || $status==Tag::$TAG_URL_STATUS_DICT["redirection"]){ |
|
155 if(array_key_exists("langlinks", $page)){ |
|
156 foreach ($page["langlinks"] as $ar) { |
|
157 if($ar["lang"]=="en"){ |
|
158 $english_label = $ar["*"]; |
|
159 break; |
|
160 } |
|
161 } |
|
162 } |
|
163 } |
|
164 // We create the dbpedia uri. |
|
165 $dbpedia_uri = null; |
|
166 if($english_label!=null && strpos($english_label, '#')===false){ |
|
167 $dbpedia_uri = WikiTagUtils::getDbpediaUri($english_label); |
|
168 } |
|
169 */ |
|
170 $dbpedia_uri = WikiTagUtils::getDbpediaUri($new_label); |
149 $dbpedia_uri = WikiTagUtils::getDbpediaUri($new_label); |
171 |
150 |
172 $wp_response = array( |
151 $wp_response = array( |
173 'new_label'=>$new_label, |
152 'new_label'=>$new_label, |
174 'alternative_label'=>$alternative_label, |
153 'alternative_label'=>$alternative_label, |
284 public static function getDbpediaUri($label, $params=[], $throw_error=true, $req_param="label") |
263 public static function getDbpediaUri($label, $params=[], $throw_error=true, $req_param="label") |
285 { |
264 { |
286 // Get lang from url |
265 // Get lang from url |
287 $dbp_url = $GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["dbpedia_sparql"]; |
266 $dbp_url = $GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["dbpedia_sparql"]; |
288 $lang = substr($dbp_url, 7, 2); |
267 $lang = substr($dbp_url, 7, 2); |
|
268 // filter with regexp to avoid results with "category:LABEL" or other "abc:LABEL" |
289 $query = 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' . FILTER (regex(?s, "^http\\\\://[^:]+$")) }'; |
269 $query = 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' . FILTER (regex(?s, "^http\\\\://[^:]+$")) }'; |
290 if($req_param=="pageid"){ |
270 if($req_param=="pageid"){ |
291 $query = 'select distinct * where { ?s dbpedia-owl:wikiPageID '.$label.' }'; |
271 $query = 'select distinct * where { ?s dbpedia-owl:wikiPageID '.$label.' }'; |
292 } |
272 } |
293 elseif ($req_param=="wikiurl"){ |
273 elseif ($req_param=="wikiurl"){ |
294 $query = 'select distinct * where { ?s foaf:isPrimaryTopicOf <'.$label.'> }'; |
274 $query = 'select distinct * where { ?s foaf:isPrimaryTopicOf <'.$label.'> }'; |
295 } |
275 } |
296 |
276 |
297 |
|
298 // filter with regexp to avoid results with "category:LABEL" or other "abc:LABEL" |
|
299 //"query" => 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' }', |
|
300 //"query" => 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' . FILTER (regex(?s, "^http\\\\://[^:]+$")) }', |
|
301 $params = [ |
277 $params = [ |
302 "query" => $query, |
278 "query" => $query, |
303 "format" => 'application/json', |
279 "format" => 'application/json', |
304 ]; |
280 ]; |
305 |
281 |