279 } |
279 } |
280 |
280 |
281 /** |
281 /** |
282 * Builds DbPedia URI |
282 * Builds DbPedia URI |
283 */ |
283 */ |
284 public static function getDbpediaUri($label, $params=[], $throw_error=true) |
284 public static function getDbpediaUri($label, $params=[], $throw_error=true, $req_param="label") |
285 { |
285 { |
286 // Get lang from url |
286 // Get lang from url |
287 $dbp_url = $GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["dbpedia_sparql"]; |
287 $dbp_url = $GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["dbpedia_sparql"]; |
288 $lang = substr($dbp_url, 7, 2); |
288 $lang = substr($dbp_url, 7, 2); |
|
289 $query = 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' . FILTER (regex(?s, "^http\\\\://[^:]+$")) }'; |
|
290 if($req_param=="pageid"){ |
|
291 $query = 'select distinct * where { ?s dbpedia-owl:wikiPageID '.$label.' }'; |
|
292 } |
|
293 elseif ($req_param=="wikiurl"){ |
|
294 $query = 'select distinct * where { ?s foaf:isPrimaryTopicOf <'.$label.'> }'; |
|
295 } |
|
296 |
|
297 |
289 // filter with regexp to avoid results with "category:LABEL" or other "abc:LABEL" |
298 // filter with regexp to avoid results with "category:LABEL" or other "abc:LABEL" |
290 //"query" => 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' }', |
299 //"query" => 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' }', |
291 //"query" => 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' . FILTER (regex(?s, "^http\\\\://[^:]+$")) }', |
300 //"query" => 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' . FILTER (regex(?s, "^http\\\\://[^:]+$")) }', |
292 $params = [ |
301 $params = [ |
293 "query" => 'select distinct * where { ?s rdfs:label "'.$label.'"@'.$lang.' . FILTER (regex(?s, "^http\\\\://[^:]+$")) }', |
302 "query" => $query, |
294 "format" => 'application/json', |
303 "format" => 'application/json', |
295 ]; |
304 ]; |
296 |
305 |
297 $params_str = ''; |
306 $params_str = ''; |
298 foreach ($params as $key => $value) { |
307 foreach ($params as $key => $value) { |