Skip to content
Snippets Groups Projects
Commit fa68ff3c authored by alangrafu's avatar alangrafu
Browse files

Adding priorities when selecting a type from multiple candidates

parent 367e8889
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ class Utils{ ...@@ -87,7 +87,7 @@ class Utils{
foreach($aux as $w){ foreach($aux as $w){
$row = array(); $row = array();
foreach($w as $k => $v){ foreach($w as $k => $v){
$row[$k]['value'] = $v['value']; $row[$k]['value'] = $v['value'];
if($v['type'] == 'uri'){ if($v['type'] == 'uri'){
$row[$k]['curie'] = Utils::uri2curie($v['value']); $row[$k]['curie'] = Utils::uri2curie($v['value']);
...@@ -358,11 +358,11 @@ class Utils{ ...@@ -358,11 +358,11 @@ class Utils{
if(!isset($value['value'])){ if(!isset($value['value'])){
$array[$key] = Utils::internalize($value); $array[$key] = Utils::internalize($value);
/*if($firstKeyAppearance){ /*if($firstKeyAppearance){
$firstKeyAppearance = false; $firstKeyAppearance = false;
$array['_first']=$array[$key]; $array['_first']=$array[$key];
}*/ }*/
}else{ }else{
if($value['uri'] == 1){ if(isset($value['uri']) && $value['uri'] == 1){
$value['value'] = preg_replace("|^".$conf['ns']['local']."|", $conf['basedir'], $value['value']); $value['value'] = preg_replace("|^".$conf['ns']['local']."|", $conf['basedir'], $value['value']);
$value['curie'] = Utils::uri2curie($value['value']); $value['curie'] = Utils::uri2curie($value['value']);
$array[$key] = $value; $array[$key] = $value;
...@@ -417,6 +417,39 @@ class Utils{ ...@@ -417,6 +417,39 @@ class Utils{
} }
public static function getModelandView($t, $extension){
global $conf;
//Defining default views and models
$curieType="";
$modelFile = $conf['model']['default'].$conf['model']['extension'].".".$extension;
$viewFile = $conf['view']['default'].$conf['view']['extension'].".".$extension;
//Get the first class available
/* TODO: Allow user to priotize
* which class should be used
* Example: URI is foaf:Person and ex:Student
* If both, prefer ex:Student
*/
$typesAndValues = array();
foreach($t as $v){
$curie = Utils::uri2curie($v);
$typesAndValues[$curie] = 0;
if(isset($conf['types']['priorities'][$curie]) && $conf['types']['priorities'][$curie] >= 0){
$typesAndValues[$curie] = $conf['types']['priorities'][$curie];
}
}
arsort($typesAndValues);
foreach($typesAndValues as $v => $w){
$auxViewFile = $conf['view']['directory'].$v.$conf['view']['extension'].".".$extension;
$auxModelFile = $conf['model']['directory'].$v.$conf['model']['extension'].".".$extension;
if(file_exists($auxModelFile) && file_exists($auxViewFile) && $v != null){
$viewFile = $v.$conf['view']['extension'].".".$extension;
$modelFile = $v.$conf['model']['extension'].".".$extension;
break;
}
}
return array($modelFile, $viewFile);
}
} }
......
...@@ -37,12 +37,14 @@ $conf['special']['class'] = 'classes/BasicSpecialFunction.php'; ...@@ -37,12 +37,14 @@ $conf['special']['class'] = 'classes/BasicSpecialFunction.php';
//Frontpage when user goes to http://example.org/ //Frontpage when user goes to http://example.org/
$conf['root'] = 'special/index'; $conf['root'] = 'special/index';
$conf['extension_connector'] = '.';
//Priority for rdfs:Resource (default). Priorities should be >=0
$conf['types']['priorities']['rdfs:Resource'] = -1;
//Debug //Debug
$conf['debug'] = false; $conf['debug'] = false;
$conf['extension_connector'] = '.';
include_once('settings.inc.php'); include_once('settings.inc.php');
$conf['view']['standard']['baseUrl'] = $conf['basedir']; $conf['view']['standard']['baseUrl'] = $conf['basedir'];
......
...@@ -108,28 +108,8 @@ $acceptContentType = $format; ...@@ -108,28 +108,8 @@ $acceptContentType = $format;
//Check if files for model and view exist //Check if files for model and view exist
$t=Queries::getClass($uri, $endpoints['local']); $t=Queries::getClass($uri, $endpoints['local']);
//Defining default views and models list($modelFile, $viewFile) = Utils::getModelandView($t, $extension);
$curieType="";
$modelFile = $conf['model']['default'].$conf['model']['extension'].".".$extension;
$viewFile = $conf['view']['default'].$conf['view']['extension'].".".$extension;
//Get the first class available
/* TODO: Allow user to priotize
* which class should be used
* Example: URI is foaf:Person and ex:Student
* If both, prefer ex:Student
*/
foreach($t as $v){
$curieType = Utils::uri2curie($v);
$auxViewFile = $conf['view']['directory'].$curieType.$conf['view']['extension'].".".$extension;
$auxModelFile = $conf['model']['directory'].$curieType.$conf['model']['extension'].".".$extension;
if(file_exists($auxModelFile) && file_exists($auxViewFile) && $curieType != null){
$viewFile = $curieType.$conf['view']['extension'].".".$extension;
$modelFile = $curieType.$conf['model']['extension'].".".$extension;
break;
}
}
$base = $conf['view']['standard']; $base = $conf['view']['standard'];
$base['type'] = $modelFile; $base['type'] = $modelFile;
$base['this']['value'] = $uri; $base['this']['value'] = $uri;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment