public function get_sparql_result($object_uri) { $assertions = array(); $query = "select * {\n\t\t\t<" . $object_uri . "> rdf:type ?type\n \t\t}"; $this->sparql_result = array(); $this->handler->data_query($query); if ($this->handler->data_num_rows()) { $result = $this->handler->data_result(); $type = $result[0]->type; if ($type) { if (isset($this->infos[$type]) && is_array($this->infos[$type])) { foreach ($this->infos[$type] as $pound => $elements) { foreach ($elements as $element) { if (is_string($element)) { if ($element == "http://www.w3.org/2004/02/skos/core#prefLabel") { $assertions[] = "\n\t\t\t\t\t\t\t\t\t<" . $object_uri . "> <" . $element . "> ?" . $this->classes[$type]->pmb_name . "_" . $this->properties[$element]->pmb_name; } else { $assertions[] = "\n\t\t\t\t\t\t\t\toptional {\n\t\t\t\t\t\t\t\t\t<" . $object_uri . "> <" . $element . "> ?" . $this->classes[$type]->pmb_name . "_" . $this->properties[$element]->pmb_name . "\n\t\t\t\t\t\t\t\t}"; } } else { if (is_array($element)) { foreach ($element as $property => $sub_property) { $assertions[] = "\n\t\t\t\t\t\t\t\toptional {\n\t\t\t\t\t\t\t\t\t<" . $object_uri . "> <" . $property . "> ?" . $this->properties[$property]->pmb_name . " .\n\t\t\t\t\t\t\t\t\t?" . $this->properties[$property]->pmb_name . " <" . $sub_property . "> ?" . $this->classes[$type]->pmb_name . "_" . $this->properties[$property]->pmb_name . "\n\t\t\t\t\t\t\t\t}"; } } } } } } } } if (count($assertions)) { $query = "select * {" . implode(" . ", $assertions) . "}"; if ($this->handler->data_query($query)) { if ($this->handler->data_num_rows()) { $rows = $this->handler->data_result(); //on parcours toutes les assertions utilies à l'indexation foreach ($rows as $row) { //on parcours la propriété infos pour retrouver les bons éléments foreach ($this->infos[$type] as $pound => $properties_uris) { $prefix = $this->classes[$type]->pmb_name . "_"; foreach ($properties_uris as $property_uri) { if (is_string($property_uri)) { $property_name = $this->properties[$property_uri]->pmb_name; $var_name = $prefix . $property_name; if (isset($row->{$var_name})) { if (!isset($this->sparql_result[$var_name][$row->{$var_name . "_lang"}])) { $this->sparql_result[$var_name][$row->{$var_name . "_lang"}] = array(); } if (!in_array($row->{$var_name}, $this->sparql_result[$var_name][$row->{$var_name . "_lang"}])) { $this->sparql_result[$var_name][$row->{$var_name . "_lang"}][] = $row->{$var_name}; } } } else { if (is_array($property_uri)) { foreach ($property_uri as $property => $sub_property) { $property_name = $this->properties[$property]->pmb_name; $var_name = $prefix . $property_name; if (isset($row->{$var_name})) { if (!isset($this->sparql_result[$var_name][$row->{$property_name}])) { $this->sparql_result[$var_name][$row->{$property_name}] = array(); } if (!isset($this->sparql_result[$var_name][$row->{$property_name}][$row->{$var_name . "_lang"}])) { $this->sparql_result[$var_name][$row->{$property_name}][$row->{$var_name . "_lang"}] = array(); } if (!in_array($row->{$var_name}, $this->sparql_result[$var_name][$row->{$property_name}][$row->{$var_name . "_lang"}])) { $this->sparql_result[$var_name][$row->{$property_name}][$row->{$var_name . "_lang"}][] = $row->{$var_name}; } } } } } } } } } } } }
public function get_skos_handler() { global $class_path; $onto_store_config = array('db_name' => DATA_BASE, 'db_user' => USER_NAME, 'db_pwd' => USER_PASS, 'db_host' => SQL_SERVER, 'store_name' => 'ontology', 'max_errors' => 100, 'store_strip_mb_comp_str' => 0); $data_store_config = array('db_name' => DATA_BASE, 'db_user' => USER_NAME, 'db_pwd' => USER_PASS, 'db_host' => SQL_SERVER, 'store_name' => 'rdfstore', 'max_errors' => 100, 'store_strip_mb_comp_str' => 0); $handler = new onto_handler($class_path . "/rdf/skos_pmb.rdf", "arc2", $onto_store_config, "arc2", $data_store_config, $this->get_skos_namespaces(), 'http://www.w3.org/2004/02/skos/core#prefLabel'); $handler->get_ontology(); return $handler; }