RdfProperty.php
Go to the documentation of this file.
00001 <?php 00002 include_once("Namespaces.php"); 00003 00006 00026 class RdfProperty 00027 { 00028 /* Data structure of $triples looks like: 00029 00030 Array 00031 ( 00032 [/ontologies/inferred/] => Array 00033 ( 00034 [http://www.w3.org/2002/07/owl#equivalentClasses] => Array 00035 ( 00036 [0] => http://purl.org/dc/terms/Agent 00037 ) 00038 00039 ) 00040 ) 00041 */ 00042 00043 00045 public $triples = array(); 00046 00048 private $uri = ""; 00049 00051 private $ontologiesGraph = ""; 00052 00066 function __construct($propertyURI, $ontologiesGraph, $inferredOntologiesGraph, &$db) 00067 { 00068 $this->uri = $propertyURI; 00069 $this->ontologiesGraph = $ontologiesGraph; 00070 00071 $query = 00072 $db->build_sparql_query( 00073 "select ?g ?p ?o from named <$ontologiesGraph> from named <$inferredOntologiesGraph> where {graph ?g{<$propertyURI> ?p ?o.}}", 00074 array ('g', 'p', 'o'), FALSE); 00075 00076 $resultset = $db->query($query); 00077 00078 while(odbc_fetch_row($resultset)) 00079 { 00080 $g = odbc_result($resultset, 1); 00081 $p = odbc_result($resultset, 2); 00082 $o = odbc_result($resultset, 3); 00083 00084 if(!isset($this->triples[$g])) 00085 { 00086 $this->triples[$g] = array(); 00087 } 00088 00089 if(!isset($this->triples[$g][$p])) 00090 { 00091 $this->triples[$g][$p] = array(); 00092 } 00093 00094 array_push($this->triples[$g][$p], $o); 00095 } 00096 } 00097 00098 function __destruct() { } 00099 00110 public function getLabel() 00111 { 00112 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$iron . "prefLabel"])) 00113 { 00114 return $this->triples[$this->ontologiesGraph][Namespaces::$iron . "prefLabel"][0]; 00115 } 00116 00117 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$skos_2008 . "prefLabel"])) 00118 { 00119 return $this->triples[$this->ontologiesGraph][Namespaces::$skos_2008 . "prefLabel"][0]; 00120 } 00121 00122 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$skos_2004 . "prefLabel"])) 00123 { 00124 return $this->triples[$this->ontologiesGraph][Namespaces::$skos_2004 . "prefLabel"][0]; 00125 } 00126 00127 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$rdfs . "label"])) 00128 { 00129 return $this->triples[$this->ontologiesGraph][Namespaces::$rdfs . "label"][0]; 00130 } 00131 00132 // Find the base URI of the ontology 00133 $pos = strripos($this->uri, "#"); 00134 00135 if($pos === FALSE) 00136 { 00137 $pos = strripos($this->uri, "/"); 00138 } 00139 00140 if($pos !== FALSE) 00141 { 00142 $pos++; 00143 } 00144 00145 $resource = substr($this->uri, $pos, strlen($this->uri) - $pos); 00146 00147 return $resource; 00148 } 00149 00160 public function getDescription() 00161 { 00162 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$iron . "description"])) 00163 { 00164 return $this->triples[$this->ontologiesGraph][Namespaces::$iron . "description"][0]; 00165 } 00166 00167 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$skos_2008 . "definition"])) 00168 { 00169 return $this->triples[$this->ontologiesGraph][Namespaces::$skos_2008 . "definition"][0]; 00170 } 00171 00172 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$skos_2004 . "definition"])) 00173 { 00174 return $this->triples[$this->ontologiesGraph][Namespaces::$skos_2004 . "definition"][0]; 00175 } 00176 00177 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$rdfs . "comment"])) 00178 { 00179 return $this->triples[$this->ontologiesGraph][Namespaces::$rdfs . "comment"][0]; 00180 } 00181 00182 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$dcterms . "description"])) 00183 { 00184 return $this->triples[$this->ontologiesGraph][Namespaces::$dcterms . "description"][0]; 00185 } 00186 00187 if(isset($this->triples[$this->ontologiesGraph][Namespaces::$dc . "description"])) 00188 { 00189 return $this->triples[$this->ontologiesGraph][Namespaces::$dc . "description"][0]; 00190 } 00191 00192 return "No description available"; 00193 } 00194 } 00195 00197 00198 ?>
