public function processInterface()
 {
     // Make sure there was no conneg error prior to this process call
     if ($this->ws->conneg->getStatus() == 200) {
         /*
           In the future, this single query should be used for that ALL purpose.
           There is currently a bug in virtuoso that doesnt return anything in the resultset (virtuoso v5.0.10)
           if one of the OPTIONAL pattern is not existing in the triple store (so, OPTIONAL doesn't work)
           
           sparql
           select * 
           from named </wsf/datasets/>
           from named </wsf/>
           where
           {
             graph </wsf/>
             {
               ?access <http://purl.org/ontology/wsf#registeredIP> "174.129.251.47::1" ;
               <http://purl.org/ontology/wsf#read> "True" ;
               <http://purl.org/ontology/wsf#datasetAccess> ?dataset .
             }
             
             graph </wsf/datasets/> 
             {
               ?dataset a <http://rdfs.org/ns/void#Dataset> ;
               <http://purl.org/dc/terms/created> ?created.
           
               OPTIONAL{?dataset <http://purl.org/dc/terms/title> ?title.}
               OPTIONAL{?dataset <http://purl.org/dc/terms/description> ?description.}
               OPTIONAL{?dataset <http://purl.org/dc/terms/creator> ?creator.}
               OPTIONAL{?dataset <http://purl.org/dc/terms/modified> ?modified.}
             }    
           };
         */
         $query = "";
         $nbDatasets = 0;
         if ($this->ws->datasetUri == "all") {
             $query = "  select distinct ?dataset ?title ?description ?creator ?created ?modified ?contributor ?meta\n                    from named <" . $this->ws->wsf_graph . ">\n                    from named <" . $this->ws->wsf_graph . "datasets/>\n                    where\n                    {\n                      graph <" . $this->ws->wsf_graph . ">\n                      {\n                        ?access <http://purl.org/ontology/wsf#registeredIP> ?ip ;\n                              <http://purl.org/ontology/wsf#read> \"True\" ;\n                        <http://purl.org/ontology/wsf#datasetAccess> ?dataset .\n                        filter( str(?ip) = \"" . $this->ws->registered_ip . "\" or str(?ip) = \"0.0.0.0\") .\n                      }\n                      \n                      graph <" . $this->ws->wsf_graph . "datasets/>\n                      {\n                        ?dataset a <http://rdfs.org/ns/void#Dataset> ;\n                        <http://purl.org/dc/terms/created> ?created.\n                    \n                        OPTIONAL{?dataset <http://purl.org/ontology/wsf#meta> ?meta.}\n                        OPTIONAL{?dataset <http://purl.org/dc/terms/title> ?title.}\n                        OPTIONAL{?dataset <http://purl.org/dc/terms/description> ?description.}\n                        OPTIONAL{?dataset <http://purl.org/dc/terms/modified> ?modified.}\n                        OPTIONAL{?dataset <http://purl.org/dc/terms/contributor> ?contributor.}\n                        OPTIONAL{?dataset <http://purl.org/dc/terms/creator> ?creator.}\n                      }    \n                    } ORDER BY ?title";
             $resultset = @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array("\n", "\r", "\t"), " ", $query), array("dataset", "title", "description", "creator", "created", "modified", "contributor", "meta"), FALSE));
             if (odbc_error()) {
                 $this->ws->conneg->setStatus(500);
                 $this->ws->conneg->setStatusMsg("Internal Error");
                 $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_300->name);
                 $this->ws->conneg->setError($this->ws->errorMessenger->_300->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_300->name, $this->ws->errorMessenger->_300->description, odbc_errormsg(), $this->ws->errorMessenger->_300->level);
                 return;
             } else {
                 $dataset = "";
                 $title = "";
                 $description = "";
                 $creator = "";
                 $created = "";
                 $modified = "";
                 $contributors = array();
                 $meta = "";
                 while (odbc_fetch_row($resultset)) {
                     $dataset2 = odbc_result($resultset, 1);
                     if ($dataset2 != $dataset && $dataset != "") {
                         $subject = new Subject($dataset);
                         $subject->setType(Namespaces::$void . "Dataset");
                         if ($title != "") {
                             $subject->setDataAttribute(Namespaces::$dcterms . "title", $title);
                         }
                         if ($description != "") {
                             $subject->setDataAttribute(Namespaces::$dcterms . "description", $description);
                         }
                         if ($creator != "") {
                             $subject->setObjectAttribute(Namespaces::$dcterms . "creator", $creator, null, "sioc:User");
                         }
                         if ($created != "") {
                             $subject->setDataAttribute(Namespaces::$dcterms . "created", $created);
                         }
                         if ($modified != "") {
                             $subject->setDataAttribute(Namespaces::$dcterms . "modified", $modified);
                         }
                         foreach ($contributors as $contributor) {
                             if ($contributor != "") {
                                 $subject->setObjectAttribute(Namespaces::$dcterms . "contributor", $contributor, null, "sioc:User");
                             }
                         }
                         $this->ws->rset->addSubject($subject);
                         $nbDatasets++;
                         $contributors = array();
                     }
                     $dataset = $dataset2;
                     $title = odbc_result($resultset, 2);
                     $description = $this->ws->db->odbc_getPossibleLongResult($resultset, 3);
                     $creator = odbc_result($resultset, 4);
                     $created = odbc_result($resultset, 5);
                     $modified = odbc_result($resultset, 6);
                     array_push($contributors, odbc_result($resultset, 7));
                     $meta = odbc_result($resultset, 8);
                 }
                 $metaDescription = array();
                 // We have to add the meta information if available
                 /*
                             if($meta != "" && $this->ws->addMeta == "true")
                             {
                               $query = "select ?p ?o (str(DATATYPE(?o))) as ?otype (LANG(?o)) as ?olang
                                       from <" . $this->ws->wsf_graph . "datasets/>
                                       where
                                       {
                                         <$meta> ?p ?o.
                                       }";
                 
                               $resultset =
                                 @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query),
                                   array ('p', 'o', 'otype', 'olang'), FALSE));
                 
                               $contributors = array();
                 
                               if(odbc_error())
                               {
                                 $this->ws->conneg->setStatus(500);
                                 $this->ws->conneg->setStatusMsg("Internal Error");
                                 $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_305->name);
                                 $this->ws->conneg->setError($this->ws->errorMessenger->_305->id, $this->ws->errorMessenger->ws,
                                   $this->ws->errorMessenger->_305->name, $this->ws->errorMessenger->_305->description, odbc_errormsg(),
                                   $this->ws->errorMessenger->_305->level);
                 
                                 return;
                               }
                               else
                               {
                                 while(odbc_fetch_row($resultset))
                                 {
                                   $predicate = odbc_result($resultset, 1);
                                   $object = $this->ws->db->odbc_getPossibleLongResult($resultset, 2);
                                   $otype = odbc_result($resultset, 3);
                                   $olang = odbc_result($resultset, 4);
                 
                                   if(isset($metaDescription[$predicate]))
                                   {
                                     array_push($metaDescription[$predicate], $object);
                                   }
                                   else
                                   {
                                     $metaDescription[$predicate] = array( $object );
                 
                                     if($olang && $olang != "")
                                     {
                                       // If a language is defined for an object, we force its type to be xsd:string
                                       $metaDescription[$predicate]["type"] = "http://www.w3.org/2001/XMLSchema#string";
                                     }
                                     else
                                     {
                                       $metaDescription[$predicate]["type"] = $otype;
                                     }
                                   }
                                 }
                               }
                 
                               unset($resultset);
                             }*/
                 if ($dataset != "") {
                     $subject = new Subject($dataset);
                     $subject->setType(Namespaces::$void . "Dataset");
                     if ($title != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "title", $title);
                     }
                     if ($description != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "description", $description);
                     }
                     if ($creator != "") {
                         $subject->setObjectAttribute(Namespaces::$dcterms . "creator", $creator, null, "sioc:User");
                     }
                     if ($created != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "created", $created);
                     }
                     if ($modified != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "modified", $modified);
                     }
                     foreach ($contributors as $contributor) {
                         if ($contributor != "") {
                             $subject->setObjectAttribute(Namespaces::$dcterms . "contributor", $contributor, null, "sioc:User");
                         }
                     }
                     $this->ws->rset->addSubject($subject);
                     $nbDatasets++;
                 }
                 unset($resultset);
             }
         } else {
             $dataset = $this->ws->datasetUri;
             $query = "select ?title ?description ?creator ?created ?modified ?meta\n                  from named <" . $this->ws->wsf_graph . "datasets/>\n                  where\n                  {\n                    graph <" . $this->ws->wsf_graph . "datasets/>\n                    {\n                      <{$dataset}> a <http://rdfs.org/ns/void#Dataset> ;\n                      <http://purl.org/dc/terms/created> ?created.\n                      \n                      OPTIONAL{<{$dataset}> <http://purl.org/dc/terms/title> ?title.} .\n                      OPTIONAL{<{$dataset}> <http://purl.org/dc/terms/description> ?description.} .\n                      OPTIONAL{<{$dataset}> <http://purl.org/dc/terms/creator> ?creator.} .\n                      OPTIONAL{<{$dataset}> <http://purl.org/dc/terms/modified> ?modified.} .\n                      OPTIONAL{<{$dataset}> <http://purl.org/ontology/wsf#meta> ?meta.} .\n                    }\n                  } ORDER BY ?title";
             $resultset = @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array("\n", "\r", "\t"), " ", $query), array('title', 'description', 'creator', 'created', 'modified', 'meta'), FALSE));
             if (odbc_error()) {
                 $this->ws->conneg->setStatus(500);
                 $this->ws->conneg->setStatusMsg("Internal Error");
                 $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_301->name);
                 $this->ws->conneg->setError($this->ws->errorMessenger->_301->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_301->name, $this->ws->errorMessenger->_301->description, odbc_errormsg(), $this->ws->errorMessenger->_301->level);
                 return;
             } else {
                 if (odbc_fetch_row($resultset)) {
                     $title = odbc_result($resultset, 1);
                     $description = $this->ws->db->odbc_getPossibleLongResult($resultset, 2);
                     $creator = odbc_result($resultset, 3);
                     $created = odbc_result($resultset, 4);
                     $modified = odbc_result($resultset, 5);
                     $meta = odbc_result($resultset, 6);
                     unset($resultset);
                     /*
                                   $metaDescription = array();
                     
                                   // We have to add the meta information if available
                                   if($meta != "" && $this->ws->addMeta == "true")
                                   {
                                     $query = "select ?p ?o (str(DATATYPE(?o))) as ?otype (LANG(?o)) as ?olang
                                             from <" . $this->ws->wsf_graph . "datasets/>
                                             where
                                             {
                                               <$meta> ?p ?o.
                                             }";
                     
                                     $resultset =
                                       @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query),
                                         array ('p', 'o', 'otype', 'olang'), FALSE));
                     
                                     $contributors = array();
                     
                                     if(odbc_error())
                                     {
                                       $this->ws->conneg->setStatus(500);
                                       $this->ws->conneg->setStatusMsg("Internal Error");
                                       $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_302->name);
                                       $this->ws->conneg->setError($this->ws->errorMessenger->_302->id, $this->ws->errorMessenger->ws,
                                         $this->ws->errorMessenger->_302->name, $this->ws->errorMessenger->_302->description, odbc_errormsg(),
                                         $this->ws->errorMessenger->_302->level);
                     
                                       return;
                                     }
                                     else
                                     {
                                       while(odbc_fetch_row($resultset))
                                       {
                                         $predicate = odbc_result($resultset, 1);
                                         $object = $this->ws->db->odbc_getPossibleLongResult($resultset, 2);
                                         $otype = odbc_result($resultset, 3);
                                         $olang = odbc_result($resultset, 4);
                     
                                         if(isset($metaDescription[$predicate]))
                                         {
                                           array_push($metaDescription[$predicate], $object);
                                         }
                                         else
                                         {
                                           $metaDescription[$predicate] = array( $object );
                     
                                           if($olang && $olang != "")
                                           {
                                             // If a language is defined for an object, we force its type to be xsd:string 
                                             $metaDescription[$predicate]["type"] = "http://www.w3.org/2001/XMLSchema#string";
                                           }
                                           else
                                           {
                                             $metaDescription[$predicate]["type"] = $otype;
                                           }
                                         }
                                       }
                                     }
                     
                                     unset($resultset);
                                   }*/
                     // Get all contributors (users that have CUD perissions over the dataset)
                     $query = "select ?contributor \n                      from <" . $this->ws->wsf_graph . "datasets/>\n                      where\n                      {\n                        <{$dataset}> a <http://rdfs.org/ns/void#Dataset> ;\n                        <http://purl.org/dc/terms/contributor> ?contributor.\n                      }";
                     $resultset = @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array("\n", "\r", "\t"), " ", $query), array('contributor'), FALSE));
                     $contributors = array();
                     if (odbc_error()) {
                         $this->ws->conneg->setStatus(500);
                         $this->ws->conneg->setStatusMsg("Internal Error");
                         $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_303->name);
                         $this->ws->conneg->setError($this->ws->errorMessenger->_303->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_303->name, $this->ws->errorMessenger->_303->description, odbc_errormsg(), $this->ws->errorMessenger->_303->level);
                         return;
                     } elseif (odbc_fetch_row($resultset)) {
                         array_push($contributors, odbc_result($resultset, 1));
                     }
                     $subject = new Subject($dataset);
                     $subject->setType(Namespaces::$void . "Dataset");
                     if ($title != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "title", $title);
                     }
                     if ($description != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "description", $description);
                     }
                     if ($creator != "") {
                         $subject->setObjectAttribute(Namespaces::$dcterms . "creator", $creator, null, "sioc:User");
                     }
                     if ($created != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "created", $created);
                     }
                     if ($modified != "") {
                         $subject->setDataAttribute(Namespaces::$dcterms . "modified", $modified);
                     }
                     foreach ($contributors as $contributor) {
                         if ($contributor != "") {
                             $subject->setObjectAttribute(Namespaces::$dcterms . "contributor", $contributor, null, "sioc:User");
                         }
                     }
                     $this->ws->rset->addSubject($subject);
                     $nbDatasets++;
                 }
             }
         }
         if ($nbDatasets == 0 && $this->ws->datasetUri != "all") {
             $this->ws->conneg->setStatus(400);
             $this->ws->conneg->setStatusMsg("Bad Request");
             $this->ws->conneg->setStatusMsgExt("This dataset doesn't exist in this WSF");
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_304->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_304->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_304->name, $this->ws->errorMessenger->_304->description, "", $this->ws->errorMessenger->_304->level);
         }
     }
 }
 public function processInterface()
 {
     // Make sure there was no conneg error prior to this process call
     if ($this->ws->conneg->getStatus() == 200) {
         $this->ws->validateQuery();
         // If the query is still valid
         if ($this->ws->conneg->getStatus() == 200) {
             if (strtolower($this->ws->mode) == "dataset") {
                 $query = "  select distinct ?dataset \n                    from <" . $this->ws->wsf_graph . "> \n                    where \n                    { \n                      { \n                        ?access <http://purl.org/ontology/wsf#registeredIP> \"" . $this->ws->registered_ip . "\" ; \n                              <http://purl.org/ontology/wsf#datasetAccess> ?dataset . \n                      } \n                      UNION \n                      { \n                        ?access <http://purl.org/ontology/wsf#registeredIP> \"0.0.0.0\" ; \n                              <http://purl.org/ontology/wsf#create> ?create ; \n                              <http://purl.org/ontology/wsf#read> ?read ; \n                              <http://purl.org/ontology/wsf#update> ?update ; \n                              <http://purl.org/ontology/wsf#delete> ?delete ; \n                              <http://purl.org/ontology/wsf#datasetAccess> ?dataset .\n                        filter( str(?create) = \"True\" or str(?read) = \"True\" or str(?update) = \"True\" or str(?delete) = \"True\").\n                      }\n                    }";
                 $resultset = @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array("\n", "\r", "\t"), " ", $query), array(), FALSE));
                 if (odbc_error()) {
                     $this->ws->conneg->setStatus(500);
                     $this->ws->conneg->setStatusMsg("Internal Error");
                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_300->name);
                     $this->ws->conneg->setError($this->ws->errorMessenger->_300->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_300->name, $this->ws->errorMessenger->_300->description, odbc_errormsg(), $this->ws->errorMessenger->_300->level);
                     return;
                 }
                 $subject = new Subject("bnode:" . md5(microtime()));
                 $subject->setType("rdf:Bag");
                 while (odbc_fetch_row($resultset)) {
                     $dataset = odbc_result($resultset, 1);
                     $subject->setObjectAttribute("rdf:li", $dataset, null, "void:Dataset");
                 }
                 $this->ws->rset->addSubject($subject);
             } elseif (strtolower($this->ws->mode) == "ws") {
                 $query = "  select distinct ?ws from <" . $this->ws->wsf_graph . ">\n                    where\n                    {\n                      ?wsf a <http://purl.org/ontology/wsf#WebServiceFramework> ;\n                            <http://purl.org/ontology/wsf#hasWebService> ?ws .\n                    }";
                 $resultset = @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array("\n", "\r", "\t"), " ", $query), array(), FALSE));
                 if (odbc_error()) {
                     $this->ws->conneg->setStatus(500);
                     $this->ws->conneg->setStatusMsg("Internal Error");
                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_301->name);
                     $this->ws->conneg->setError($this->ws->errorMessenger->_301->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_301->name, $this->ws->errorMessenger->_301->description, odbc_errormsg(), $this->ws->errorMessenger->_301->level);
                     return;
                 }
                 $subject = new Subject("bnode:" . md5(microtime()));
                 $subject->setType("rdf:Bag");
                 while (odbc_fetch_row($resultset)) {
                     $ws = odbc_result($resultset, 1);
                     $subject->setObjectAttribute("rdf:li", $ws, null, "wsf:WebService");
                 }
                 $this->ws->rset->addSubject($subject);
             } else {
                 if (strtolower($this->ws->mode) == "access_user") {
                     $query = "  select ?access ?datasetAccess ?create ?read ?update ?delete ?registeredIP " . ($this->ws->targetWebservice == "all" ? "?webServiceAccess" : "") . "\n                      from <" . $this->ws->wsf_graph . ">\n                      where\n                      {\n                        {\n                          ?access a <http://purl.org/ontology/wsf#Access> ;\n                                <http://purl.org/ontology/wsf#registeredIP> \"" . $this->ws->registered_ip . "\" ;\n                                <http://purl.org/ontology/wsf#create> ?create ;\n                                <http://purl.org/ontology/wsf#read> ?read ;\n                                <http://purl.org/ontology/wsf#update> ?update ;\n                                <http://purl.org/ontology/wsf#delete> ?delete ;\n                                <http://purl.org/ontology/wsf#datasetAccess> ?datasetAccess ;\n                                " . ($this->ws->targetWebservice == "all" ? "<http://purl.org/ontology/wsf#webServiceAccess> ?webServiceAccess ;" : "") . "\n                                " . ($this->ws->targetWebservice != "none" && $this->ws->targetWebservice != "all" ? "<http://purl.org/ontology/wsf#webServiceAccess> <" . $this->ws->targetWebservice . "> ;" : "") . "\n                                <http://purl.org/ontology/wsf#registeredIP> ?registeredIP .\n                        }\n                        union\n                        {\n                          ?access a <http://purl.org/ontology/wsf#Access> ;\n                                <http://purl.org/ontology/wsf#registeredIP> \"0.0.0.0\" ;\n                                <http://purl.org/ontology/wsf#create> ?create ;\n                                <http://purl.org/ontology/wsf#read> ?read ;\n                                <http://purl.org/ontology/wsf#update> ?update ;\n                                <http://purl.org/ontology/wsf#delete> ?delete ;\n                                <http://purl.org/ontology/wsf#datasetAccess> ?datasetAccess ;                      \n                                " . ($this->ws->targetWebservice == "all" ? "<http://purl.org/ontology/wsf#webServiceAccess> ?webServiceAccess ;" : "") . "\n                                " . ($this->ws->targetWebservice != "none" && $this->ws->targetWebservice != "all" ? "<http://purl.org/ontology/wsf#webServiceAccess> <" . $this->ws->targetWebservice . "> ;" : "") . "\n                                <http://purl.org/ontology/wsf#registeredIP> ?registeredIP .\n                                \n                          filter( str(?create) = \"True\" or str(?read) = \"True\" or str(?update) = \"True\" or str(?delete) = \"True\").\n                        }\n                      }";
                 } else {
                     $query = "  select ?access ?registeredIP ?create ?read ?update ?delete " . ($this->ws->targetWebservice == "all" ? "?webServiceAccess" : "") . " \n                      from <" . $this->ws->wsf_graph . ">\n                      where\n                      {\n                        ?access a <http://purl.org/ontology/wsf#Access> ;\n                              <http://purl.org/ontology/wsf#registeredIP> ?registeredIP ;\n                              <http://purl.org/ontology/wsf#create> ?create ;\n                              <http://purl.org/ontology/wsf#read> ?read ;\n                              <http://purl.org/ontology/wsf#update> ?update ;\n                              <http://purl.org/ontology/wsf#delete> ?delete ;\n                              " . ($this->ws->targetWebservice == "all" ? "<http://purl.org/ontology/wsf#webServiceAccess> ?webServiceAccess ;" : "") . "\n                              " . ($this->ws->targetWebservice != "none" && $this->ws->targetWebservice != "all" ? "<http://purl.org/ontology/wsf#webServiceAccess> <" . $this->ws->targetWebservice . "> ;" : "") . "\n                              <http://purl.org/ontology/wsf#datasetAccess> <" . $this->ws->dataset . "> .\n                      }";
                 }
                 $resultset = @$this->ws->db->query($this->ws->db->build_sparql_query(str_replace(array("\n", "\r", "\t"), " ", $query), array(), FALSE));
                 if (odbc_error()) {
                     $this->ws->conneg->setStatus(500);
                     $this->ws->conneg->setStatusMsg("Internal Error");
                     if (strtolower($this->ws->mode) == "access_user" || strtolower($this->ws->mode) == "access_dataset") {
                         $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_302->name);
                         $this->ws->conneg->setError($this->ws->errorMessenger->_302->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_302->name, $this->ws->errorMessenger->_302->description, odbc_errormsg(), $this->ws->errorMessenger->_302->level);
                     } else {
                         $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_303->name);
                         $this->ws->conneg->setError($this->ws->errorMessenger->_303->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_303->name, $this->ws->errorMessenger->_303->description, odbc_errormsg(), $this->ws->errorMessenger->_303->level);
                     }
                     return;
                 }
                 $accessPreviousId = "";
                 $subject = null;
                 while (odbc_fetch_row($resultset)) {
                     $accessId = odbc_result($resultset, 1);
                     if ($accessPreviousId != $accessId) {
                         if ($subject != null) {
                             $this->ws->rset->addSubject($subject);
                         }
                         $subject = new Subject($accessId);
                         $subject->setType("wsf:Access");
                         $accessPreviousId = $accessId;
                         $lastElement = "";
                         if (strtolower($this->ws->mode) == "access_user") {
                             $subject->setObjectAttribute("wsf:datasetAccess", odbc_result($resultset, 2), null, "void:Dataset");
                             $subject->setDataAttribute("wsf:create", odbc_result($resultset, 3));
                             $subject->setDataAttribute("wsf:read", odbc_result($resultset, 4));
                             $subject->setDataAttribute("wsf:update", odbc_result($resultset, 5));
                             $subject->setDataAttribute("wsf:delete", odbc_result($resultset, 6));
                             $subject->setDataAttribute("wsf:registeredIP", odbc_result($resultset, 7));
                             if ($this->ws->targetWebservice == "all") {
                                 $subject->setObjectAttribute("wsf:webServiceAccess", odbc_result($resultset, 8), null, "wsf:WebService");
                             }
                         } else {
                             $subject->setDataAttribute("wsf:registeredIP", odbc_result($resultset, 2));
                             $subject->setDataAttribute("wsf:create", odbc_result($resultset, 3));
                             $subject->setDataAttribute("wsf:read", odbc_result($resultset, 4));
                             $subject->setDataAttribute("wsf:update", odbc_result($resultset, 5));
                             $subject->setDataAttribute("wsf:delete", odbc_result($resultset, 6));
                             if ($this->ws->targetWebservice == "all") {
                                 $subject->setObjectAttribute("wsf:webServiceAccess", odbc_result($resultset, 7), null, "wsf:WebService");
                             }
                         }
                     } else {
                         if (strtolower($this->ws->mode) == "access_user") {
                             $subject->setObjectAttribute("wsf:webServiceAccess", odbc_result($resultset, 8), null, "wsf:WebService");
                         } else {
                             $subject->setObjectAttribute("wsf:webServiceAccess", odbc_result($resultset, 7), null, "wsf:WebService");
                         }
                     }
                 }
                 // Add the last subject
                 $this->ws->rset->addSubject($subject);
             }
         }
     }
 }
 /**
  * Get a subject by its URI
  * 
  * @param mixed $uri URI of the subject to get from the resultset.
  * @return Subject instance that match the input URI. Returns FALSE if no subject
  *         match the input URI.
  */
 public function getSubjectByUri($uri)
 {
     foreach ($this->resultset as $dataset => $subjects) {
         foreach ($subjects as $suri => $s) {
             if ($suri == $uri) {
                 $subject = new Subject($uri);
                 $subject->setSubject($s);
                 return $subject;
             }
         }
     }
     return FALSE;
 }
 public function processInterface()
 {
     // Make sure there was no conneg error prior to this process call
     if ($this->ws->conneg->getStatus() == 200) {
         $ch = curl_init();
         // Normalize the query to remove the return carriers and line feeds
         // This is performed to help matching the regular expressions patterns.
         $this->query = str_replace(array("\r", "\n"), " ", $this->query);
         // remove the possible starting "sparql"
         $this->query = preg_replace("/^[\\s\t]*sparql[\\s\t]*/Uim", "", $this->query);
         // Check if there is a prolog to this SPARQL query.
         // First check if there is a "base" declaration
         preg_match("/^[\\s\t]*base[\\s\t]*<.*>/Uim", $this->query, $matches, PREG_OFFSET_CAPTURE);
         $baseOffset = -1;
         if (count($matches) > 0) {
             $baseOffset = $matches[0][1] + strlen($matches[0][0]);
         }
         // Second check for all possible "prefix" clauses
         preg_match_all("/[\\s\t]*prefix[\\s\t]*.*:.*<.*>/Uim", $this->query, $matches, PREG_OFFSET_CAPTURE);
         $lastPrefixOffset = -1;
         if (count($matches) > 0) {
             $lastPrefixOffset = $matches[0][count($matches[0]) - 1][1] + strlen($matches[0][count($matches[0]) - 1][0]);
         }
         $prologEndOffset = -1;
         if ($lastPrefixOffset > -1) {
             $prologEndOffset = $lastPrefixOffset;
         } elseif ($baseOffset > -1) {
             $prologEndOffset = $baseOffset;
         }
         $noPrologQuery = $this->query;
         if ($prologEndOffset != -1) {
             $noPrologQuery = substr($this->query, $prologEndOffset);
         }
         // Now extract prefixes references
         $prefixes = array();
         preg_match_all("/[\\s\t]*prefix[\\s\t]*(.*):(.*)<(.*)>/Uim", $this->query, $matches, PREG_OFFSET_CAPTURE);
         if (count($matches[0]) > 0) {
             for ($i = 0; $i < count($matches[1]); $i++) {
                 $p = str_replace(array(" ", " "), "", $matches[1][$i][0]) . ":" . str_replace(array(" ", " "), "", $matches[2][$i][0]);
                 $iri = $matches[3][$i][0];
                 $prefixes[$p] = $iri;
             }
         }
         // Drop any SPARUL queries
         // Reference: http://www.w3.org/Submission/SPARQL-Update/
         if (preg_match_all("/^[\\s\t]*modify[\\s\t]*/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/^[\\s\t]*delete[\\s\t]*/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/^[\\s\t]*insert[\\s\t]*/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/^[\\s\t]*load[\\s\t]*/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/^[\\s\t]*clear[\\s\t]*/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/^[\\s\t]*create[\\s\t]*/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/^[\\s\t]*drop[\\s\t]*/Uim", $noPrologQuery, $matches) > 0) {
             $this->ws->conneg->setStatus(400);
             $this->ws->conneg->setStatusMsg("Bad Request");
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_203->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_203->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_203->name, $this->ws->errorMessenger->_203->description, "", $this->ws->errorMessenger->_203->level);
             return;
         }
         // Detect any CONSTRUCT clause
         $this->isConstructQuery = FALSE;
         if (preg_match_all("/^[\\s\t]*construct[\\s\t]*/Uim", $noPrologQuery, $matches) > 0) {
             $this->isConstructQuery = TRUE;
             /*
             $this->ws->conneg->setStatus(400);
             $this->ws->conneg->setStatusMsg("Bad Request");
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_204->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_204->id, $this->ws->errorMessenger->ws,
               $this->ws->errorMessenger->_204->name, $this->ws->errorMessenger->_204->description, "",
               $this->ws->errorMessenger->_204->level);
             
             return;               
             */
         }
         // Drop any SPARQL query with a GRAPH clause which are not bound by one, or a series, of FROM NAMED clauses
         if ((preg_match_all("/[\\s\t]*graph[\\s\t]*</Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/[\\s\t]*graph[\\s\t]*\\?/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/[\\s\t]*graph[\\s\t]*\$/Uim", $noPrologQuery, $matches) > 0 || preg_match_all("/[\\s\t]*graph[\\s\t]*[a-zA-Z0-9\\-_]*:/Uim", $noPrologQuery, $matches) > 0) && (preg_match_all("/([\\s\t]*from[\\s\t]*named[\\s\t]*<(.*)>[\\s\t]*)/Uim", $noPrologQuery, $matches) <= 0 && preg_match_all("/[\\s\t]*(from[\\s\t]*named)[\\s\t]*([^\\s\t<]*):(.*)[\\s\t]*/Uim", $noPrologQuery, $matches) <= 0)) {
             $this->ws->conneg->setStatus(400);
             $this->ws->conneg->setStatusMsg("Bad Request");
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_205->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_205->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_205->name, $this->ws->errorMessenger->_205->description, "", $this->ws->errorMessenger->_205->level);
             return;
         }
         $graphs = array();
         // Validate DESCRIBE query.
         // The only thing we have to check here, is to get the graph IRI if the DESCRIBE is immediately using
         // IRIRef clause. Possibilities are:
         // "DESCRIBE <test>" -- IRI_REF
         // "DESCRIBE a:" -- PrefixedName
         $this->isDescribeQuery = FALSE;
         if (preg_match("/^[\\s\t]*describe[\\s\t]*/Uim", $noPrologQuery, $matches) > 0) {
             $this->isDescribeQuery = TRUE;
         }
         preg_match_all("/^[\\s\t]*describe[\\s\t]*<(.*)>/Uim", $noPrologQuery, $matches);
         if (count($matches[0]) > 0) {
             array_push($graphs, $matches[1][0]);
         }
         preg_match_all("/^[\\s\t]*describe[\\s\t]*([^<\\s\t]*):(.*)[\\s\t]*/Uim", $noPrologQuery, $matches);
         if (count($matches[0]) > 0) {
             for ($i = 0; $i < count($matches[0]); $i++) {
                 $p = $matches[1][$i] . ":";
                 if (isset($prefixes[$p])) {
                     $d = $prefixes[$p] . $matches[2][$i];
                     array_push($graphs, $d);
                 }
             }
         }
         // Get all the "from" and "from named" clauses so that we validate if the user has access to them.
         // Check for the clauses that uses direct IRI_REF
         preg_match_all("/([\\s\t]*from[\\s\t]*<(.*)>[\\s\t]*)/Uim", $noPrologQuery, $matches);
         foreach ($matches[2] as $match) {
             array_push($graphs, $match);
         }
         preg_match_all("/([\\s\t]*from[\\s\t]*named[\\s\t]*<(.*)>[\\s\t]*)/Uim", $noPrologQuery, $matches);
         foreach ($matches[2] as $match) {
             array_push($graphs, $match);
         }
         // Check for the clauses that uses PrefixedName
         preg_match_all("/[\\s\t]*(from|from[\\s\t]*named)[\\s\t]*([^\\s\t<]*):(.*)[\\s\t]*/Uim", $noPrologQuery, $matches);
         if (count($matches[0]) > 0) {
             for ($i = 0; $i < count($matches[0]); $i++) {
                 $p = $matches[2][$i] . ":";
                 if (isset($prefixes[$p])) {
                     $d = $prefixes[$p] . $matches[3][$i];
                     array_push($graphs, $d);
                 }
             }
         }
         if ($this->ws->dataset == "" && count($graphs) <= 0) {
             $this->ws->conneg->setStatus(400);
             $this->ws->conneg->setStatusMsg("Bad Request");
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_201->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_201->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_201->name, $this->ws->errorMessenger->_201->description, "", $this->ws->errorMessenger->_201->level);
             return;
         }
         // Validate all graphs of the query for the IP of the requester of this query.
         // If one of the graph is not accessible to the user, we just return
         // an error for this SPARQL query.
         foreach ($graphs as $graph) {
             if (substr($graph, strlen($graph) - 12, 12) == "reification/") {
                 $graph = substr($graph, 0, strlen($graph) - 12);
             }
             $ws_av = new AuthValidator($this->ws->requester_ip, $graph, $this->ws->uri);
             $ws_av->pipeline_conneg("*/*", $this->ws->conneg->getAcceptCharset(), $this->ws->conneg->getAcceptEncoding(), $this->ws->conneg->getAcceptLanguage());
             $ws_av->process();
             if ($ws_av->pipeline_getResponseHeaderStatus() != 200) {
                 $this->ws->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
                 $this->ws->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
                 $this->ws->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
                 $this->ws->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice, $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description, $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
                 return;
             }
         }
         /*
           if registered_ip != requester_ip, this means that the query is sent by a registered system
           on the behalf of someone else. In this case, we want to make sure that that system 
           (the one that send the actual query) has access to the same datasets. Otherwise, it means that
           it tries to personificate that registered_ip user.
           
           Validate all graphs of the query. If one of the graph is not accessible to the system, we just return
           and error for this SPARQL query.  
         */
         if ($this->ws->registered_ip != $this->ws->requester_ip) {
             foreach ($graphs as $graph) {
                 if (substr($graph, strlen($graph) - 12, 12) == "reification/") {
                     $graph = substr($graph, 0, strlen($graph) - 12);
                 }
                 $ws_av = new AuthValidator($this->ws->registered_ip, $graph, $this->ws->uri);
                 $ws_av->pipeline_conneg("*/*", $this->ws->conneg->getAcceptCharset(), $this->ws->conneg->getAcceptEncoding(), $this->ws->conneg->getAcceptLanguage());
                 $ws_av->process();
                 if ($ws_av->pipeline_getResponseHeaderStatus() != 200) {
                     $this->ws->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
                     $this->ws->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
                     $this->ws->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
                     $this->ws->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice, $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description, $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
                     return;
                 }
             }
         }
         // Determine the query format
         $queryFormat = "";
         if ($this->ws->conneg->getMime() == "application/sparql-results+json" || $this->ws->conneg->getMime() == "application/sparql-results+xml" || $this->ws->conneg->getMime() == "text/html" || $this->isDescribeQuery === TRUE || $this->isConstructQuery === TRUE) {
             $queryFormat = $this->ws->conneg->getMime();
         } elseif ($this->ws->conneg->getMime() == "text/xml" || $this->ws->conneg->getMime() == "application/json" || $this->ws->conneg->getMime() == "application/rdf+xml" || $this->ws->conneg->getMime() == "application/rdf+n3" || $this->ws->conneg->getMime() == "application/iron+json" || $this->ws->conneg->getMime() == "application/iron+csv") {
             $queryFormat = "application/sparql-results+xml";
         }
         // Add a limit to the query
         // Disable limits and offset for now until we figure out what to do (not limit on triples, but resources)
         //      $this->query .= " limit ".$this->ws->limit." offset ".$this->ws->offset;
         curl_setopt($ch, CURLOPT_URL, $this->ws->db_host . ":" . $this->ws->triplestore_port . "/sparql?default-graph-uri=" . urlencode($this->ws->dataset) . "&query=" . urlencode($this->query) . "&format=" . urlencode($queryFormat));
         //curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Accept: " . $queryFormat ));
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_HEADER, TRUE);
         $xml_data = curl_exec($ch);
         $header = substr($xml_data, 0, strpos($xml_data, "\r\n\r\n"));
         $data = substr($xml_data, strpos($xml_data, "\r\n\r\n") + 4, strlen($xml_data) - (strpos($xml_data, "\r\n\r\n") - 4));
         curl_close($ch);
         // check returned message
         $httpMsgNum = substr($header, 9, 3);
         $httpMsg = substr($header, 13, strpos($header, "\r\n") - 13);
         if ($httpMsgNum == "200") {
             $this->ws->sparqlContent = $data;
         } else {
             $this->ws->conneg->setStatus($httpMsgNum);
             $this->ws->conneg->setStatusMsg($httpMsg);
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_300->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_300->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_300 > name, $this->ws->errorMessenger->_300->description, $data, $this->ws->errorMessenger->_300->level);
             $this->ws->sparqlContent = "";
             return;
         }
         // If a DESCRIBE query as been requested by the user, then we simply returns what is returned by
         // the triple store. We don't have any convertion to do here.
         if ($this->isDescribeQuery === TRUE) {
             return;
         }
         // If a CONSTRUCT query as been requested by the user, then we simply returns what is returned by
         // the triple store. We don't have any convertion to do here.
         if ($this->isConstructQuery === TRUE) {
             return;
         }
         if ($this->ws->conneg->getMime() == "text/xml" || $this->ws->conneg->getMime() == "application/rdf+n3" || $this->ws->conneg->getMime() == "application/rdf+xml" || $this->ws->conneg->getMime() == "application/json" || $this->ws->conneg->getMime() == "application/iron+json" || $this->ws->conneg->getMime() == "application/iron+csv") {
             // Read the XML file and populate the recordInstances variables
             $xml = $this->xml2ary($this->ws->sparqlContent);
             if (isset($xml["sparql"]["_c"]["results"]["_c"]["result"])) {
                 $currentSubjectUri = "";
                 $subject = null;
                 $sourceDataset = "";
                 $isPartOfFound = FALSE;
                 $g;
                 foreach ($xml["sparql"]["_c"]["results"]["_c"]["result"] as $result) {
                     $s = "";
                     $p = "";
                     $o = "";
                     $g = "";
                     $valueBoundType = "";
                     foreach ($result["_c"]["binding"] as $binding) {
                         $boundVariable = $binding["_a"]["name"];
                         $keys = array_keys($binding["_c"]);
                         $boundType = $keys[0];
                         $boundValue = $binding["_c"][$boundType]["_v"];
                         switch ($boundVariable) {
                             case "s":
                                 $s = $boundValue;
                                 break;
                             case "p":
                                 $p = $boundValue;
                                 if ($p == Namespaces::$dcterms . "isPartOf") {
                                     $isPartOfFound = TRUE;
                                 }
                                 break;
                             case "o":
                                 $o = $boundValue;
                                 $valueBoundType = $boundType;
                                 break;
                             case "g":
                                 $g = $boundValue;
                                 break;
                         }
                     }
                     if ($currentSubject != $s) {
                         if ($subject != null) {
                             if ($g != "" && $isPartOfFound === FALSE) {
                                 $subject->setObjectAttribute(Namespaces::$dcterms . "isPartOf", $g);
                                 $isPartOfFound = FALSE;
                             }
                             $this->ws->rset->addSubject($subject);
                         }
                         $subject = new Subject($s);
                         $currentSubject = $s;
                     }
                     // process URI
                     if ($valueBoundType == "uri" || $valueBoundType == "bnode") {
                         if ($p == Namespaces::$rdf . "type") {
                             $subject->setType($o);
                         } else {
                             $subject->setObjectAttribute($p, $o);
                         }
                     }
                     // Process Literal
                     if ($valueBoundType == "literal") {
                         $subject->setDataAttribute($p, $o);
                     }
                 }
                 // Add the last subject to the resultset.
                 if ($subject != null) {
                     if ($g != "" && $isPartOfFound === FALSE) {
                         $subject->setObjectAttribute(Namespaces::$dcterms . "isPartOf", $g);
                         $isPartOfFound = FALSE;
                     }
                     $this->ws->rset->addSubject($subject);
                 }
             }
             if (count($this->ws->rset->getResultset()) <= 0) {
                 $this->ws->conneg->setStatus(400);
                 $this->ws->conneg->setStatusMsg("Bad Request");
                 $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_301->name);
                 $this->ws->conneg->setError($this->ws->errorMessenger->_301->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_301->name, $this->ws->errorMessenger->_301->description, "", $this->ws->errorMessenger->_301->level);
             }
         }
     }
 }
 public function processInterface()
 {
     // Make sure there was no conneg error prior to this process call
     if ($this->ws->conneg->getStatus() == 200) {
         // Starts the OWLAPI process/bridge
         require_once $this->ws->owlapiBridgeURI;
         // Create the OWLAPI session object that could have been persisted on the OWLAPI instance.
         // Second param "false" => we re-use the pre-created session without destroying the previous one
         // third param "0" => it nevers timeout.
         if ($this->ws->OwlApiSession == null) {
             $this->ws->OwlApiSession = java_session("OWLAPI", false, 0);
         }
         $ontology;
         try {
             $ontology = new OWLOntology($this->ws->ontologyUri, $this->ws->OwlApiSession, TRUE);
             $ontology->setLanguage($this->ws->lang);
             if (strtolower($this->ws->owlapiReasoner) == "pellet") {
                 $ontology->usePelletReasoner();
             } elseif (strtolower($this->ws->owlapiReasoner) == "hermit") {
                 $ontology->useHermitReasoner();
             } elseif (strtolower($this->ws->owlapiReasoner) == "factpp") {
                 $ontology->useFactppReasoner();
             }
         } catch (Exception $e) {
             if (strtolower($this->ws->function) != "getserializedclasshierarchy" && strtolower($this->ws->function) != "getserializedpropertyhierarchy" && strtolower($this->ws->function) != "getironxmlschema" && strtolower($this->ws->function) != "getironjsonschema" && strtolower($this->ws->function) != "getloadedontologies") {
                 $this->returnError(400, "Bad Request", "_300");
                 return;
             }
         }
         if (isset($ontology)) {
             if ($this->ws->useReasoner) {
                 $ontology->useReasoner();
             } else {
                 $ontology->stopUsingReasoner();
             }
         }
         if (isset($this->ws->parameters["direct"]) && $this->ws->parameters["direct"] != "") {
             $this->ws->parameters["direct"] = strtolower($this->ws->parameters["direct"]);
             if ($this->ws->parameters["direct"] == "false" || $this->ws->parameters["direct"] == "0" || $this->ws->parameters["direct"] == "off") {
                 $this->ws->parameters["direct"] = false;
             } else {
                 $this->ws->parameters["direct"] = true;
             }
         }
         switch (strtolower($this->ws->function)) {
             case "getserialized":
                 $this->ws->conneg->setStatus(200);
                 $this->ws->conneg->setStatusMsg("OK");
                 $this->ws->getSerialized = $ontology->getSerialization();
                 return;
                 break;
             case "getclass":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 $class = $ontology->_getClass($this->ws->parameters["uri"]);
                 if ($class == null) {
                     $this->returnError(400, "Bad Request", "_205");
                 } else {
                     $subject = new Subject($this->ws->parameters["uri"]);
                     $subject->setSubject($ontology->_getClassDescription($class));
                     $this->ws->rset->addSubject($subject);
                 }
                 break;
             case "getclasses":
                 $limit = -1;
                 $offset = 0;
                 if (isset($this->ws->parameters["limit"])) {
                     $limit = $this->ws->parameters["limit"];
                 }
                 if (isset($this->ws->parameters["offset"])) {
                     $offset = $this->ws->parameters["offset"];
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $classes = $ontology->getClassesUri($limit, $offset);
                         foreach ($classes as $class) {
                             $subject = new Subject($class);
                             $subject->setType("owl:Class");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     case "descriptions":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getClassesDescription($limit, $offset)));
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getnamedindividual":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 $namedIndividual = $ontology->_getNamedIndividual($this->ws->parameters["uri"]);
                 if ($namedIndividual == null) {
                     $this->returnError(400, "Bad Request", "_206");
                 } else {
                     $subject = new Subject($this->ws->parameters["uri"]);
                     $subject->setSubject($ontology->_getNamedIndividualDescription($namedIndividual));
                     $this->ws->rset->addSubject($subject);
                 }
                 break;
             case "getnamedindividuals":
                 $limit = -1;
                 $offset = 0;
                 $direct = true;
                 if (isset($this->ws->parameters["limit"])) {
                     $limit = $this->ws->parameters["limit"];
                 }
                 if (isset($this->ws->parameters["offset"])) {
                     $offset = $this->ws->parameters["offset"];
                 }
                 if (isset($this->ws->parameters["direct"])) {
                     switch ($this->ws->parameters["direct"]) {
                         case "0":
                             $direct = false;
                             break;
                         case "1":
                             $direct = true;
                             break;
                     }
                 }
                 $classUri = "all";
                 if (!isset($this->ws->parameters["classuri"])) {
                     $classUri = $this->ws->parameters["classuri"];
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $namedindividuals = $ontology->getNamedIndividualsUri($classUri, $direct, $limit, $offset);
                         foreach ($namedindividuals as $ni) {
                             $subject = new Subject($ni);
                             $subject->setType("owl:NamedIndividual");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     case "descriptions":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getNamedIndividualsDescription($classUri, $direct, $limit, $offset)));
                         break;
                     case "list":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getNamedIndividualsDescription($classUri, $direct, $limit, $offset, TRUE)));
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201", "Mode provided: " . $this->ws->parameters["mode"]);
                         return;
                         break;
                 }
                 break;
             case "getsubclasses":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $classes = $ontology->getSubClassesUri($this->ws->parameters["uri"], $this->ws->parameters["direct"]);
                         foreach ($classes as $class) {
                             $subject = new Subject($class);
                             $subject->setType("owl:Class");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     case "descriptions":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getSubClassesDescription($this->ws->parameters["uri"], $this->ws->parameters["direct"])));
                         break;
                     case "hierarchy":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getSubClassesDescription($this->ws->parameters["uri"], TRUE, TRUE)));
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getsuperclasses":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $classes = $ontology->getSuperClassesUri($this->ws->parameters["uri"], $this->ws->parameters["direct"]);
                         foreach ($classes as $class) {
                             $subject = new Subject($class);
                             $subject->setType("owl:Class");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     case "descriptions":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getSuperClassesDescription($this->ws->parameters["uri"], $this->ws->parameters["direct"])));
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getequivalentclasses":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $classes = $ontology->getEquivalentClassesUri($this->ws->parameters["uri"]);
                         foreach ($classes as $class) {
                             $subject = new Subject($class);
                             $subject->setType("owl:Class");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     case "descriptions":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getEquivalentClassesDescription($this->ws->parameters["uri"])));
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getdisjointclasses":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $classes = $ontology->getDisjointClassesUri($this->ws->parameters["uri"]);
                         foreach ($classes as $class) {
                             $subject = new Subject($class);
                             $subject->setType("owl:Class");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     case "descriptions":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getDisjointClassesDescription($this->ws->parameters["uri"])));
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getontologies":
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $ontologies = $ontology->getOntologiesUri();
                         foreach ($ontologies as $ontology) {
                             $subject = new Subject($ontology);
                             $subject->setType("owl:Ontology");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getloadedontologies":
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         $ontologies = OWLOntology::getLoadedOntologiesUri($this->ws->OwlApiSession);
                         foreach ($ontologies as $ontology) {
                             $subject = new Subject($ontology);
                             $subject->setType("owl:Ontology");
                             $this->ws->rset->addSubject($subject);
                         }
                         break;
                     case "descriptions":
                         $this->ws->rset->setResultset(array($this->ws->ontologyUri => OWLOntology::getLoadedOntologiesDescription($this->ws->OwlApiSession)));
                         break;
                     default:
                         $this->ws->conneg->setStatus(400);
                         $this->ws->conneg->setStatusMsg("Bad Request");
                         $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_201->name);
                         $this->ws->conneg->setError($this->ws->errorMessenger->_201->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_201->name, $this->ws->errorMessenger->_201->description, "", $this->ws->errorMessenger->_201->level);
                         return;
                         break;
                 }
                 break;
             case "getserializedclasshierarchy":
                 $sch = $this->generationSerializedClassHierarchy($this->ws->OwlApiSession);
                 $subject = new Subject($this->ws->ontologyUri);
                 $subject->setType("owl:Ontology");
                 $subject->setDataAttribute(Namespaces::$wsf . "serializedClassHierarchy", $sch);
                 $this->ws->rset->addSubject($subject);
                 break;
             case "getserializedpropertyhierarchy":
                 $sch = $this->generationSerializedPropertyHierarchy($this->ws->OwlApiSession);
                 $subject = new Subject($this->ws->ontologyUri);
                 $subject->setType("owl:Ontology");
                 $subject->setDataAttribute(Namespaces::$wsf . "serializedPropertyHierarchy", $sch);
                 $this->ws->rset->addSubject($subject);
                 break;
             case "getironxmlschema":
                 $subjectTriples = $ontology->getClassesDescription($limit, $offset);
                 $schema = '<schema><version>0.1</version><typeList>';
                 $prefixes = array();
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= "<" . $this->ironPrefixize($uri, $prefixes) . ">";
                     $schema .= "<description>" . $this->ws->xmlEncode($this->getDescription($subject)) . "</description>";
                     $schema .= "<prefLabel>" . $this->ws->xmlEncode($this->getLabel($uri, $subject)) . "</prefLabel>";
                     foreach ($subject as $predicate => $values) {
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$rdfs . "subClassOf":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<subTypeOf>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</subTypeOf>";
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= "<displayControl>" . $this->ws->xmlEncode($displayControl) . "</displayControl>";
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= "<ignoredBy>" . $this->ws->xmlEncode($ignoredBy) . "</ignoredBy>";
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= "<shortLabel>" . $this->ws->xmlEncode($value["value"]) . "</shortLabel>";
                                     break;
                                 case Namespaces::$sco . "mapMarkerImageUrl":
                                     $schema .= "<mapMarkerImageUrl>" . $this->ws->xmlEncode($value["value"]) . "</mapMarkerImageUrl>";
                                     break;
                                 case Namespaces::$sco . "relationBrowserNodeType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<relationBrowserNodeType>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</relationBrowserNodeType>";
                                     break;
                             }
                         }
                     }
                     $schema .= "</" . $this->ironPrefixize($uri, $prefixes) . ">";
                 }
                 $schema .= "</typeList>";
                 $schema .= "<attributeList>";
                 $subjectTriples = $ontology->getPropertiesDescription(TRUE);
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= "<" . $this->ironPrefixize($uri, $prefixes) . ">";
                     $schema .= "<description>" . $this->ws->xmlEncode($this->getDescription($subject)) . "</description>";
                     $schema .= "<prefLabel>" . $this->ws->xmlEncode($this->getLabel($uri, $subject)) . "</prefLabel>";
                     $schema .= "<type>" . Namespaces::$owl . "DatatypeProperty</type>";
                     foreach ($subject as $predicate => $values) {
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$rdfs . "domain":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<allowedType>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</allowedType>";
                                     break;
                                 case Namespaces::$rdfs . "range":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<allowedValue><type>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</type></allowedValue>";
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= "<displayControl>" . $this->ws->xmlEncode($displayControl) . "</displayControl>";
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= "<ignoredBy>" . $this->ws->xmlEncode($ignoredBy) . "</ignoredBy>";
                                     break;
                                 case Namespaces::$sco . "comparableWith":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<comparableWith>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</comparableWith>";
                                     break;
                                 case Namespaces::$sco . "unitType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<unitType>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</unitType>";
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= "<shortLabel>" . $this->ws->xmlEncode($value["value"]) . "</shortLabel>";
                                     break;
                                 case Namespaces::$sco . "minCardinality":
                                     $schema .= "<minCardinality>" . $this->ws->xmlEncode($value["value"]) . "</minCardinality>";
                                     break;
                                 case Namespaces::$sco . "maxCardinality":
                                     $schema .= "<maxCardinality>" . $this->ws->xmlEncode($value["value"]) . "</maxCardinality>";
                                     break;
                                 case Namespaces::$sco . "cardinality":
                                     $schema .= "<cardinality>" . $this->ws->xmlEncode($value["value"]) . "</cardinality>";
                                     break;
                                 case Namespaces::$sco . "orderingValue":
                                     $schema .= "<orderingValue>" . $this->ws->xmlEncode($value["value"]) . "</orderingValue>";
                                     break;
                                 case Namespaces::$rdfs . "subPropertyOf":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<subPropertyOf>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</subPropertyOf>";
                                     break;
                                 case Namespaces::$iron . "allowedValue":
                                     $schema .= "<allowedValue><primitive>" . $this->ws->xmlEncode($value["value"]) . "</primitive></allowedValue>";
                                     break;
                             }
                         }
                     }
                     $schema .= "</" . $this->ironPrefixize($uri, $prefixes) . ">";
                 }
                 $subjectTriples = $ontology->getPropertiesDescription(FALSE, FALSE, TRUE);
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= "<" . $this->ironPrefixize($uri, $prefixes) . ">";
                     $schema .= "<description>" . $this->ws->xmlEncode($this->getDescription($subject)) . "</description>";
                     $schema .= "<prefLabel>" . $this->ws->xmlEncode($this->getLabel($uri, $subject)) . "</prefLabel>";
                     $schema .= "<type>" . Namespaces::$owl . "AnnotationProperty</type>";
                     foreach ($subject as $predicate => $values) {
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$rdfs . "domain":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<allowedType>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</allowedType>";
                                     break;
                                 case Namespaces::$rdfs . "range":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<allowedValue><type>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</type></allowedValue>";
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= "<displayControl>" . $this->ws->xmlEncode($displayControl) . "</displayControl>";
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= "<ignoredBy>" . $this->ws->xmlEncode($ignoredBy) . "</ignoredBy>";
                                     break;
                                 case Namespaces::$sco . "comparableWith":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<comparableWith>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</comparableWith>";
                                     break;
                                 case Namespaces::$sco . "unitType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<unitType>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</unitType>";
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= "<shortLabel>" . $this->ws->xmlEncode($value["value"]) . "</shortLabel>";
                                     break;
                                 case Namespaces::$sco . "minCardinality":
                                     $schema .= "<minCardinality>" . $this->ws->xmlEncode($value["value"]) . "</minCardinality>";
                                     break;
                                 case Namespaces::$sco . "maxCardinality":
                                     $schema .= "<maxCardinality>" . $this->ws->xmlEncode($value["value"]) . "</maxCardinality>";
                                     break;
                                 case Namespaces::$sco . "cardinality":
                                     $schema .= "<cardinality>" . $this->ws->xmlEncode($value["value"]) . "</cardinality>";
                                     break;
                                 case Namespaces::$sco . "orderingValue":
                                     $schema .= "<orderingValue>" . $this->ws->xmlEncode($value["value"]) . "</orderingValue>";
                                     break;
                                 case Namespaces::$rdfs . "subPropertyOf":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<subPropertyOf>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</subPropertyOf>";
                                     break;
                                 case Namespaces::$iron . "allowedValue":
                                     $schema .= "<allowedValue><primitive>" . $this->ws->xmlEncode($value["value"]) . "</primitive></allowedValue>";
                                     break;
                             }
                         }
                     }
                     $schema .= "</" . $this->ironPrefixize($uri, $prefixes) . ">";
                 }
                 $subjectTriples = $ontology->getPropertiesDescription(FALSE, TRUE);
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= "<" . $this->ironPrefixize($uri, $prefixes) . ">";
                     $schema .= "<description>" . $this->ws->xmlEncode($this->getDescription($subject)) . "</description>";
                     $schema .= "<prefLabel>" . $this->ws->xmlEncode($this->getLabel($uri, $subject)) . "</prefLabel>";
                     $schema .= "<type>" . Namespaces::$owl . "ObjectProperty</type>";
                     foreach ($subject as $predicate => $values) {
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$rdfs . "domain":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<allowedType>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</allowedType>";
                                     break;
                                 case Namespaces::$rdfs . "range":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<allowedValue><type>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</type></allowedValue>";
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= "<displayControl>" . $this->ws->xmlEncode($displayControl) . "</displayControl>";
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= "<ignoredBy>" . $this->ws->xmlEncode($ignoredBy) . "</ignoredBy>";
                                     break;
                                 case Namespaces::$sco . "comparableWith":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<comparableWith>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</comparableWith>";
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= "<shortLabel>" . $this->ws->xmlEncode($value["value"]) . "</shortLabel>";
                                     break;
                                 case Namespaces::$sco . "minCardinality":
                                     $schema .= "<minCardinality>" . $this->ws->xmlEncode($value["value"]) . "</minCardinality>";
                                     break;
                                 case Namespaces::$sco . "maxCardinality":
                                     $schema .= "<maxCardinality>" . $this->ws->xmlEncode($value["value"]) . "</maxCardinality>";
                                     break;
                                 case Namespaces::$sco . "cardinality":
                                     $schema .= "<cardinality>" . $this->ws->xmlEncode($value["value"]) . "</cardinality>";
                                     break;
                                 case Namespaces::$sco . "unitType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= "<unitType>" . $this->ws->xmlEncode($this->ironPrefixize($value["uri"], $prefixes)) . "</unitType>";
                                     break;
                                 case Namespaces::$sco . "orderingValue":
                                     $schema .= "<orderingValue>" . $this->ws->xmlEncode($value["value"]) . "</orderingValue>";
                                     break;
                                 case Namespaces::$iron . "allowedValue":
                                     $schema .= "<allowedValue><primitive>" . $this->ws->xmlEncode($value["value"]) . "</primitive></allowedValue>";
                                     break;
                             }
                         }
                     }
                     $schema .= "</" . $this->ironPrefixize($uri, $prefixes) . ">";
                 }
                 $schema .= "</attributeList>";
                 $schema .= "<prefixList>";
                 foreach ($prefixes as $prefix => $ns) {
                     $schema .= "    <{$prefix}>{$ns}</{$prefix}>";
                 }
                 $schema .= "</prefixList>";
                 $schema .= "</schema>";
                 $subjectTriples = "";
                 $subject = new Subject($this->ws->ontologyUri);
                 $subject->setType("owl:Ontology");
                 $subject->setDataAttribute(Namespaces::$wsf . "serializedIronXMLSchema", str_replace('&amp;', '&amp;amp;', str_replace(array("\\", "&", "<", ">"), array("%5C", "&amp;", "&lt;", "&gt;"), $schema)));
                 $this->ws->rset->addSubject($subject);
                 /*
                           <schema>
                             <version>0.1</version>
                             <prefLabel>PEG schema</prefLabel>
                             <prefixList>
                               <sco>http://purl.org/ontology/sco#</sco>
                             </prefixList>
                             <typeList>
                               <peg_Neighborhood>
                                 <subTypeOf>pegf_Organization</subTypeOf>
                                 <description>Neighborhood community organization</description>
                                 <prefLabel>neighborhood</prefLabel>
                                 <displayControl>sRelationBrowser</displayControl>
                               </peg_Neighborhood>
                             </typeList>
                             <attributeList>
                               <peg_neighborhoodNumber>
                                 <prefLabel>neighborhood number</prefLabel>
                                 <description>Neighborhood identification number</description>
                                 <allowedType>Neighborhood</allowedType>
                                 <allowedType>City</allowedType>
                                 <allowedType>Province</allowedType>
                                 <allowedType>Country</allowedType>
                                 <allowedValue>
                                   <primitive>String</primitive>
                                 </allowedValue>
                                 <maxValues>1</maxValues>
                               </peg_neighborhoodNumber>
                             </attributeList>
                           </schema>
                 */
                 break;
             case "getironjsonschema":
                 $subjectTriples = $ontology->getClassesDescription($limit, $offset);
                 $schema = '{ "schema": { "version": "0.1", "typeList": {';
                 $prefixes = array();
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= '"' . $this->ironPrefixize($uri, $prefixes) . '": {';
                     $schema .= '"description": "' . $this->ws->jsonEncode($this->getDescription($subject)) . '",';
                     $schema .= '"prefLabel": "' . $this->ws->jsonEncode($this->getLabel($uri, $subject)) . '",';
                     foreach ($subject as $predicate => $values) {
                         switch ($predicate) {
                             case Namespaces::$rdfs . "subClassOf":
                                 $schema .= '"subTypeOf": [';
                                 break;
                             case Namespaces::$sco . "displayControl":
                                 $schema .= '"displayControl": [';
                                 break;
                             case Namespaces::$sco . "ignoredBy":
                                 $schema .= '"ignoredBy": [';
                                 break;
                             case Namespaces::$sco . "shortLabel":
                                 $schema .= '"shortLabel": [';
                                 break;
                             case Namespaces::$sco . "color":
                                 $schema .= '"color": [';
                                 break;
                             case Namespaces::$sco . "mapMarkerImageUrl":
                                 $schema .= '"mapMarkerImageUrl": [';
                                 break;
                             case Namespaces::$sco . "relationBrowserNodeType":
                                 $schema .= '"relationBrowserNodeType": [';
                                 break;
                         }
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$rdfs . "subClassOf":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($displayControl) . '",';
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($ignoredBy) . '",';
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "color":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "mapMarkerImageUrl":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "relationBrowserNodeType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                             }
                         }
                         switch ($predicate) {
                             case Namespaces::$rdfs . "subClassOf":
                             case Namespaces::$sco . "displayControl":
                             case Namespaces::$sco . "ignoredBy":
                             case Namespaces::$sco . "shortLabel":
                             case Namespaces::$sco . "color":
                             case Namespaces::$sco . "mapMarkerImageUrl":
                             case Namespaces::$sco . "relationBrowserNodeType":
                                 $schema = rtrim($schema, ",");
                                 $schema .= '],';
                                 break;
                         }
                     }
                     $schema = rtrim($schema, ",");
                     $schema .= "},";
                 }
                 $schema = rtrim($schema, ",");
                 $schema .= "},";
                 $schema .= '"attributeList": {';
                 $subjectTriples = $ontology->getPropertiesDescription(TRUE);
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= '"' . $this->ironPrefixize($uri, $prefixes) . '": {';
                     $schema .= '"description": "' . $this->ws->jsonEncode($this->getDescription($subject)) . '",';
                     $schema .= '"prefLabel": "' . $this->ws->jsonEncode($this->getLabel($uri, $subject)) . '",';
                     $schema .= '"type": "' . Namespaces::$owl . 'DatatypeProperty",';
                     foreach ($subject as $predicate => $values) {
                         switch ($predicate) {
                             case Namespaces::$iron . "allowedValue":
                                 $schema .= '"allowedValue": {"primitive": "' . $this->ws->jsonEncode($value["value"]) . '"},';
                                 break;
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema .= '"subPropertyOf": [';
                                 break;
                             case Namespaces::$rdfs . "domain":
                                 $schema .= '"allowedType": [';
                                 break;
                             case Namespaces::$rdfs . "range":
                                 $schema .= '"allowedValue": [';
                                 break;
                             case Namespaces::$sco . "displayControl":
                                 $schema .= '"displayControl": [';
                                 break;
                             case Namespaces::$sco . "ignoredBy":
                                 $schema .= '"ignoredBy": [';
                                 break;
                             case Namespaces::$sco . "comparableWith":
                                 $schema .= '"comparableWith": [';
                                 break;
                             case Namespaces::$sco . "unitType":
                                 $schema .= '"unitType": [';
                                 break;
                             case Namespaces::$sco . "shortLabel":
                                 $schema .= '"shortLabel": [';
                                 break;
                             case Namespaces::$sco . "orderingValue":
                                 $schema .= '"orderingValue": [';
                                 break;
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema .= '"subPropertyOf": [';
                                 break;
                         }
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$sco . "minCardinality":
                                     $schema .= '"minCardinality": "' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "maxCardinality":
                                     $schema .= '"maxCardinality": "' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "cardinality":
                                     $schema .= '"cardinality": "' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$rdfs . "domain":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$rdfs . "range":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '{ "type": "' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '"},';
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($displayControl) . '",';
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($ignoredBy) . '",';
                                     break;
                                 case Namespaces::$sco . "comparableWith":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$sco . "unitType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "orderingValue":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$rdfs . "subPropertyOf":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                             }
                         }
                         switch ($predicate) {
                             case Namespaces::$rdfs . "domain":
                             case Namespaces::$rdfs . "range":
                             case Namespaces::$sco . "displayControl":
                             case Namespaces::$sco . "ignoredBy":
                             case Namespaces::$sco . "comparableWith":
                             case Namespaces::$sco . "unitType":
                             case Namespaces::$sco . "shortLabel":
                             case Namespaces::$sco . "orderingValue":
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema = rtrim($schema, ",");
                                 $schema .= '],';
                                 break;
                         }
                     }
                     $schema = rtrim($schema, ",");
                     $schema .= "},";
                 }
                 $subjectTriples = $ontology->getPropertiesDescription(FALSE, FALSE, TRUE);
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= '"' . $this->ironPrefixize($uri, $prefixes) . '": {';
                     $schema .= '"description": "' . $this->ws->jsonEncode($this->getDescription($subject)) . '",';
                     $schema .= '"prefLabel": "' . $this->ws->jsonEncode($this->getLabel($uri, $subject)) . '",';
                     $schema .= '"type": "' . Namespaces::$owl . 'AnnotationProperty",';
                     foreach ($subject as $predicate => $values) {
                         switch ($predicate) {
                             case Namespaces::$rdfs . "domain":
                                 $schema .= '"allowedType": [';
                                 break;
                             case Namespaces::$rdfs . "range":
                                 $schema .= '"allowedValue": [';
                                 break;
                             case Namespaces::$iron . "allowedValue":
                                 $schema .= '"allowedValue": {"primitive": "' . $this->ws->jsonEncode($value["value"]) . '"},';
                                 break;
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema .= '"subPropertyOf": [';
                                 break;
                             case Namespaces::$sco . "displayControl":
                                 $schema .= '"displayControl": [';
                                 break;
                             case Namespaces::$sco . "ignoredBy":
                                 $schema .= '"ignoredBy": [';
                                 break;
                             case Namespaces::$sco . "comparableWith":
                                 $schema .= '"comparableWith": [';
                                 break;
                             case Namespaces::$sco . "unitType":
                                 $schema .= '"unitType": [';
                                 break;
                             case Namespaces::$sco . "shortLabel":
                                 $schema .= '"shortLabel": [';
                                 break;
                             case Namespaces::$sco . "orderingValue":
                                 $schema .= '"orderingValue": [';
                                 break;
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema .= '"subPropertyOf": [';
                                 break;
                         }
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$rdfs . "domain":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$rdfs . "range":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '{ "type": "' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '"},';
                                     break;
                                 case Namespaces::$sco . "minCardinality":
                                     $schema .= '"minCardinality": "' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "maxCardinality":
                                     $schema .= '"maxCardinality": "' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "cardinality":
                                     $schema .= '"cardinality": "' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($displayControl) . '",';
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($ignoredBy) . '",';
                                     break;
                                 case Namespaces::$sco . "comparableWith":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$sco . "unitType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "orderingValue":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$rdfs . "subPropertyOf":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                             }
                         }
                         switch ($predicate) {
                             case Namespaces::$rdfs . "domain":
                             case Namespaces::$rdfs . "range":
                             case Namespaces::$sco . "displayControl":
                             case Namespaces::$sco . "ignoredBy":
                             case Namespaces::$sco . "comparableWith":
                             case Namespaces::$sco . "unitType":
                             case Namespaces::$sco . "shortLabel":
                             case Namespaces::$sco . "orderingValue":
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema = rtrim($schema, ",");
                                 $schema .= '],';
                                 break;
                         }
                     }
                     $schema = rtrim($schema, ",");
                     $schema .= "},";
                 }
                 $subjectTriples = $ontology->getPropertiesDescription(FALSE, TRUE);
                 foreach ($subjectTriples as $uri => $subject) {
                     $this->manageIronPrefixes($uri, $prefixes);
                     $schema .= '"' . $this->ironPrefixize($uri, $prefixes) . '": {';
                     $schema .= '"description": "' . $this->ws->jsonEncode($this->getDescription($subject)) . '",';
                     $schema .= '"prefLabel": "' . $this->ws->jsonEncode($this->getLabel($uri, $subject)) . '",';
                     $schema .= '"type": "' . Namespaces::$owl . 'ObjectProperty",';
                     foreach ($subject as $predicate => $values) {
                         switch ($predicate) {
                             case Namespaces::$rdfs . "domain":
                                 $schema .= '"allowedType": [';
                                 break;
                             case Namespaces::$rdfs . "range":
                                 $schema .= '"allowedValue": [';
                                 break;
                             case Namespaces::$sco . "displayControl":
                                 $schema .= '"displayControl": [';
                                 break;
                             case Namespaces::$sco . "ignoredBy":
                                 $schema .= '"ignoredBy": [';
                                 break;
                             case Namespaces::$sco . "comparableWith":
                                 $schema .= '"comparableWith": [';
                                 break;
                             case Namespaces::$sco . "unitType":
                                 $schema .= '"unitType": [';
                                 break;
                             case Namespaces::$sco . "shortLabel":
                                 $schema .= '"shortLabel": [';
                                 break;
                             case Namespaces::$sco . "orderingValue":
                                 $schema .= '"orderingValue": [';
                                 break;
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema .= '"subPropertyOf": [';
                                 break;
                         }
                         foreach ($values as $value) {
                             switch ($predicate) {
                                 case Namespaces::$iron . "allowedValue":
                                     $schema .= '{"primitive": "' . $this->ws->jsonEncode($value["value"]) . '"},';
                                     break;
                                 case Namespaces::$rdfs . "domain":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$rdfs . "range":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '{ "type": "' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '"},';
                                     break;
                                 case Namespaces::$sco . "displayControl":
                                     if (isset($value["uri"])) {
                                         $displayControl = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $displayControl = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($displayControl) . '",';
                                     break;
                                 case Namespaces::$sco . "ignoredBy":
                                     if (isset($value["uri"])) {
                                         $ignoredBy = substr($value["uri"], strripos($value["uri"], "#") + 1);
                                     } else {
                                         $ignoredBy = $value["value"];
                                     }
                                     $schema .= '"' . $this->ws->jsonEncode($ignoredBy) . '",';
                                     break;
                                 case Namespaces::$sco . "comparableWith":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$sco . "shortLabel":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$sco . "unitType":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                                 case Namespaces::$sco . "orderingValue":
                                     $schema .= '"' . $this->ws->jsonEncode($value["value"]) . '",';
                                     break;
                                 case Namespaces::$rdfs . "subPropertyOf":
                                     $this->manageIronPrefixes($value["uri"], $prefixes);
                                     $schema .= '"' . $this->ws->jsonEncode($this->ironPrefixize($value["uri"], $prefixes)) . '",';
                                     break;
                             }
                         }
                         switch ($predicate) {
                             case Namespaces::$rdfs . "domain":
                             case Namespaces::$rdfs . "range":
                             case Namespaces::$sco . "displayControl":
                             case Namespaces::$sco . "ignoredBy":
                             case Namespaces::$sco . "comparableWith":
                             case Namespaces::$sco . "unitType":
                             case Namespaces::$sco . "shortLabel":
                             case Namespaces::$sco . "orderingValue":
                             case Namespaces::$rdfs . "subPropertyOf":
                                 $schema = rtrim($schema, ",");
                                 $schema .= '],';
                                 break;
                         }
                     }
                     $schema = rtrim($schema, ",");
                     $schema .= "},";
                 }
                 $schema = rtrim($schema, ",");
                 $schema .= "},";
                 $schema .= '"prefixList": {';
                 foreach ($prefixes as $prefix => $ns) {
                     $schema .= "    \"{$prefix}\": \"{$ns}\",";
                 }
                 $schema = rtrim($schema, ",");
                 $schema .= "}";
                 $schema .= "}";
                 $schema .= "}";
                 $subjectTriples = "";
                 $subject = new Subject($this->ws->ontologyUri);
                 $subject->setType("owl:Ontology");
                 $subject->setDataAttribute(Namespaces::$wsf . "serializedIronJSONSchema", $schema);
                 $this->ws->rset->addSubject($subject);
                 /*
                       
                   {
                       "schema": {
                           "version": "0.1",
                           "typeList": {
                               "bibo_ThesisDegree": {
                                   "description": "The academic degree of a Thesis",
                                   "prefLabel": "Thesis degree",
                                   "subTypeOf": [
                                       "owl_Thing"
                                   ]
                               },
                               "0_1_Agent": {
                                   "description": "No description available",
                                   "prefLabel": "Agent",
                                   "subTypeOf": [
                                       "owl_Thing"
                                   ]
                               },
                               "bibo_Event": {
                                   "description": "No description available",
                                   "prefLabel": "Event",
                                   "subTypeOf": [
                                       "owl_Thing"
                                   ]
                               }
                           },
                       
                           "attributeList": {
                               "bibo_sici": {
                                   "description": "No description available",
                                   "prefLabel": "sici",
                                   "allowedValue": {
                                       "primitive": "String"
                                   },
                                   "subPropertyOf": [
                                       "bibo_identifier"
                                   ]
                               },
                       
                               "terms_rights": {
                                   "description": "No description available",
                                   "prefLabel": "rights",
                                   "subPropertyOf": [
                                       "owl_topObjectProperty"
                                   ]
                               },
                               "0_1_based_near": {
                                   "description": "No description available",
                                   "prefLabel": "based_near",
                                   "subPropertyOf": [
                                       "owl_topObjectProperty"
                                   ]
                               }
                           },
                           "prefixList": {
                               "bibo": "http://purl.org/ontology/bibo/",
                               "owl": "http://www.w3.org/2002/07/owl#",
                               "0_1": "http://xmlns.com/foaf/0.1/",
                               "event_owl": "http://purl.org/NET/c4dm/event.owl#",
                               "rdf_schema": "http://www.w3.org/2000/01/rdf-schema#",
                               "22_rdf_syntax_ns": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                               "terms": "http://purl.org/dc/terms/",
                               "basic": "http://prismstandard.org/namespaces/1.2/basic/",
                               "schema": "http://schemas.talis.com/2005/address/schema#"
                           }
                       }
                   }    
                 */
                 break;
             case "getproperty":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 $property = $ontology->_getProperty($this->ws->parameters["uri"]);
                 if ($property == NULL) {
                     $this->returnError(400, "Bad Request", "_204");
                 } else {
                     $subject = new Subject($this->ws->parameters["uri"]);
                     $subject->setSubject($ontology->_getPropertyDescription($property));
                     $this->ws->rset->addSubject($subject);
                 }
                 break;
             case "getproperties":
                 $limit = -1;
                 $offset = 0;
                 if (isset($this->ws->parameters["limit"])) {
                     $limit = $this->ws->parameters["limit"];
                 }
                 if (isset($this->ws->parameters["offset"])) {
                     $offset = $this->ws->parameters["offset"];
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $properties = $ontology->getPropertiesUri(TRUE, FALSE, FALSE, $limit, $offset);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:DatatypeProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             case "objectproperty":
                                 $properties = $ontology->getPropertiesUri(FALSE, TRUE, FALSE, $limit, $offset);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:ObjectProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             case "annotationproperty":
                                 $properties = $ontology->getPropertiesUri(FALSE, FALSE, TRUE, $limit, $offset);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:AnnotationProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     case "descriptions":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getPropertiesDescription(TRUE, FALSE, FALSE, $limit, $offset)));
                                 break;
                             case "objectproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getPropertiesDescription(FALSE, TRUE, FALSE, $limit, $offset)));
                                 break;
                             case "annotationproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getPropertiesDescription(FALSE, FALSE, TRUE, $limit, $offset)));
                                 break;
                             case "all":
                                 // @TODO: property handle possible punned properties (properties that have the same URI but that are of different property types)
                                 $subjectTriples = array();
                                 $subjectTriples = array_merge($subjectTriples, $ontology->getPropertiesDescription(TRUE, FALSE, FALSE, $limit, $offset));
                                 $subjectTriples = array_merge($subjectTriples, $ontology->getPropertiesDescription(FALSE, TRUE, FALSE, $limit, $offset));
                                 // Check if the annotatio properties got punned. If they did, then ignore returning the annotation property.
                                 $annotationProperties = $ontology->getPropertiesDescription(FALSE, FALSE, TRUE, $limit, $offset);
                                 foreach ($annotationProperties as $uri => $property) {
                                     if (!isset($subjectTriples[$uri])) {
                                         $subjectTriples[$uri] = $property;
                                     }
                                 }
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $subjectTriples));
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getsubproperties":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $properties = $ontology->getSubPropertiesUri((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], TRUE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:DatatypeProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             case "objectproperty":
                                 $properties = $ontology->getSubPropertiesUri((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], FALSE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:ObjectProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     case "descriptions":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getSubPropertiesDescription((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], TRUE)));
                                 break;
                             case "objectproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getSubPropertiesDescription((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], FALSE)));
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getsuperproperties":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $properties = $ontology->getSuperPropertiesUri((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], TRUE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:DatatypeProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             case "objectproperty":
                                 $properties = $ontology->getSuperPropertiesUri((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], FALSE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:ObjectProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     case "descriptions":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getSuperPropertiesDescription((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], TRUE)));
                                 break;
                             case "objectproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getSuperPropertiesDescription((string) $this->ws->parameters["uri"], $this->ws->parameters["direct"], FALSE)));
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getequivalentproperties":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $properties = $ontology->getEquivalentPropertiesUri((string) $this->ws->parameters["uri"], TRUE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:DatatypeProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             case "objectproperty":
                                 $properties = $ontology->getEquivalentPropertiesUri((string) $this->ws->parameters["uri"], FALSE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:ObjectProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     case "descriptions":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getEquivalentPropertiesDescription((string) $this->ws->parameters["uri"], TRUE)));
                                 break;
                             case "objectproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getEquivalentPropertiesDescription((string) $this->ws->parameters["uri"], FALSE)));
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             case "getdisjointproperties":
                 if (!isset($this->ws->parameters["uri"]) || $this->ws->parameters["uri"] == "") {
                     $this->returnError(400, "Bad Request", "_202");
                     return;
                 }
                 switch (strtolower($this->ws->parameters["mode"])) {
                     case "uris":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $properties = $ontology->getDisjointPropertiesUri((string) $this->ws->parameters["uri"], TRUE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:DatatypeProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             case "objectproperty":
                                 $properties = $ontology->getDisjointPropertiesUri((string) $this->ws->parameters["uri"], FALSE);
                                 foreach ($properties as $property) {
                                     $subject = new Subject($property);
                                     $subject->setType("owl:ObjectProperty");
                                     $this->ws->rset->addSubject($subject);
                                 }
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     case "descriptions":
                         switch (strtolower($this->ws->parameters["type"])) {
                             case "dataproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getDisjointPropertiesDescription((string) $this->ws->parameters["uri"], TRUE)));
                                 break;
                             case "objectproperty":
                                 $this->ws->rset->setResultset(array($this->ws->ontologyUri => $ontology->getDisjointPropertiesDescription((string) $this->ws->parameters["uri"], FALSE)));
                                 break;
                             default:
                                 $this->returnError(400, "Bad Request", "_203");
                                 return;
                                 break;
                         }
                         break;
                     default:
                         $this->returnError(400, "Bad Request", "_201");
                         return;
                         break;
                 }
                 break;
             default:
                 $this->ws->conneg->setStatus(400);
                 $this->ws->conneg->setStatusMsg("Bad Request");
                 $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_200->name);
                 $this->ws->conneg->setError($this->ws->errorMessenger->_200->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_200->name, $this->ws->errorMessenger->_200->description, "This function is not defined\n              for this endpoint:" . $this->ws->function, $this->ws->errorMessenger->_200->level);
                 return;
                 break;
         }
     }
 }
 public function processInterface()
 {
     // Make sure there was no conneg error prior to this process call
     if ($this->ws->conneg->getStatus() == 200) {
         $solr = new Solr($this->ws->wsf_solr_core, $this->ws->solr_host, $this->ws->solr_port, $this->ws->fields_index_folder);
         $solrQuery = "";
         // Get all datasets accessible to that user
         $accessibleDatasets = array();
         $ws_al = new AuthLister("access_user", "", $this->ws->registered_ip, $this->ws->wsf_local_ip, "none");
         $ws_al->pipeline_conneg($this->ws->conneg->getAccept(), $this->ws->conneg->getAcceptCharset(), $this->ws->conneg->getAcceptEncoding(), $this->ws->conneg->getAcceptLanguage());
         $ws_al->process();
         $xml = new ProcessorXML();
         $xml->loadXML($ws_al->pipeline_getResultset());
         $accesses = $xml->getSubjectsByType("wsf:Access");
         foreach ($accesses as $access) {
             $predicates = $xml->getPredicatesByType($access, "wsf:datasetAccess");
             $objects = $xml->getObjects($predicates->item(0));
             $datasetUri = $xml->getURI($objects->item(0));
             $predicates = $xml->getPredicatesByType($access, "wsf:read");
             $objects = $xml->getObjects($predicates->item(0));
             $read = $xml->getContent($objects->item(0));
             if (strtolower($read) == "true" && array_search($datasetUri, $accessibleDatasets) === FALSE) {
                 array_push($accessibleDatasets, $datasetUri);
             }
         }
         unset($ws_al);
         /*
           if registered_ip != requester_ip, this means that the query is sent by a registered system
           on the behalf of someone else. In this case, we want to make sure that that system 
           (the one that send the actual query) has access to the same datasets. Otherwise, it means that
           it tries to personificate that registered_ip user.
         */
         if ($this->ws->registered_ip != $this->ws->requester_ip) {
             // Get all datasets accessible to that system
             $accessibleDatasetsSystem = array();
             $ws_al = new AuthLister("access_user", "", $this->ws->requester_ip, $this->ws->wsf_local_ip, "none");
             $ws_al->pipeline_conneg($this->ws->conneg->getAccept(), $this->ws->conneg->getAcceptCharset(), $this->ws->conneg->getAcceptEncoding(), $this->ws->conneg->getAcceptLanguage());
             $ws_al->process();
             $xml = new ProcessorXML();
             $xml->loadXML($ws_al->pipeline_getResultset());
             $accesses = $xml->getSubjectsByType("wsf:Access");
             foreach ($accesses as $access) {
                 $predicates = $xml->getPredicatesByType($access, "wsf:datasetAccess");
                 $objects = $xml->getObjects($predicates->item(0));
                 $datasetUri = $xml->getURI($objects->item(0));
                 $predicates = $xml->getPredicatesByType($access, "wsf:read");
                 $objects = $xml->getObjects($predicates->item(0));
                 $read = $xml->getContent($objects->item(0));
                 if (strtolower($read) == "true") {
                     array_push($accessibleDatasetsSystem, $datasetUri);
                 }
             }
             unset($ws_al);
             /*
               Finally we use the intersection of the two set of dataset URIs as the list of accessible
               datasets to include for the query.
             */
             $accessibleDatasets = array_intersect($accessibleDatasets, $accessibleDatasetsSystem);
         }
         if (count($accessibleDatasets) <= 0) {
             $this->ws->conneg->setStatus(400);
             $this->ws->conneg->setStatusMsg("Bad Request");
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_300->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_300->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_300->name, $this->ws->errorMessenger->_300->description, "", $this->ws->errorMessenger->_300->level);
             return;
         }
         $queryParam = "*:*";
         if ($this->ws->query != "") {
             $queryParam = urlencode($this->ws->query);
         }
         $distanceQueryRevelencyBooster = "";
         if ($this->ws->geoEnabled && isset($this->ws->resultsLocationAggregator[0]) && isset($this->ws->resultsLocationAggregator[1]) && ($this->ws->distanceFilter || $this->ws->rangeFilter)) {
             // Here, "^0" is added to zero-out the boost (revelency) value of the keyword
             // in this query, we simply want to aggregate the results related to their
             // distance of the center point.
             //$distanceQueryRevelencyBooster = '^0 AND _val_:"recip(dist(2, lat, long, '.$this->ws->resultsLocationAggregator[0].', '.$this->ws->resultsLocationAggregator[1].'), 1, 1, 0)"^100';
             $distanceQueryRevelencyBooster = '^0 AND _val_:"recip(geodist(geohash, ' . $this->ws->resultsLocationAggregator[0] . ', ' . $this->ws->resultsLocationAggregator[1] . '), 1, 1, 0)"^100';
         }
         $boostingRules = "";
         // Types boosting rules
         if ($this->ws->typesBoost != "") {
             $boostRules = explode(";", $this->ws->typesBoost);
             foreach ($boostRules as $key => $rule) {
                 $boost = explode("^", $rule);
                 $type = str_replace(array("%3B", "%5E"), array(";", "^"), $boost[0]);
                 $modifier = $boost[1];
                 $boostingRules .= '&bq=type:"' . urlencode($type) . '"^' . $modifier;
                 if (strtolower($this->ws->inference) == "on") {
                     $boostingRules .= '&bq=inferred_type:"' . urlencode($type) . '"^' . $modifier;
                 }
             }
             $insertOR = TRUE;
         }
         // Datasets boosting rules
         if ($this->ws->datasetsBoost != "") {
             $boostRules = explode(";", $this->ws->datasetsBoost);
             foreach ($boostRules as $key => $rule) {
                 $boost = explode("^", $rule);
                 $dataset = str_replace(array("%3B", "%5E"), array(";", "^"), $boost[0]);
                 $modifier = $boost[1];
                 $boostingRules .= '&bq=dataset:"' . urlencode($dataset) . '"^' . $modifier;
             }
             $insertOR = TRUE;
         }
         // Attributes & Attributes/values boosting rules
         if ($this->ws->attributesBoost != "") {
             $boostRules = explode(";", $this->ws->attributesBoost);
             foreach ($boostRules as $key => $rule) {
                 $isAttributeValue = FALSE;
                 if (strpos($rule, '::') !== FALSE) {
                     $isAttributeValue = TRUE;
                 }
                 $boost = explode("^", $rule);
                 $attribute = str_replace(array("%3B", "%5E"), array(";", "^"), $boost[0]);
                 $modifier = $boost[1];
                 if ($isAttributeValue) {
                     $attribute = explode("::", $attribute);
                     $attributeValue = $attribute[1];
                     $attribute = $attribute[0];
                     $indexedFields = array();
                     if (file_exists($this->ws->fields_index_folder . "fieldsIndex.srz")) {
                         $indexedFields = unserialize(file_get_contents($this->ws->fields_index_folder . "fieldsIndex.srz"));
                     }
                     // Fix the reference to some of the core attributes
                     $isCoreAttribute = $this->isCoreAttribute($attribute, $attribute);
                     // If it is not a core attribute, check if we have to make that attribute
                     // single-valued. We check that by checking if a single_valued version
                     // of that field is currently used in the Solr index.
                     $singleValuedDesignator = "";
                     if (!$isCoreAttribute && (array_search(urlencode($attribute . "_attr_" . $this->ws->lang . "_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_date_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_int_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_float_single_valued"), $indexedFields) !== FALSE)) {
                         $singleValuedDesignator = "_single_valued";
                     }
                     $attributeFound = FALSE;
                     // Get the Solr field ID for this attribute
                     if (!$isCoreAttribute) {
                         // Check if it is an object property, and check if the pattern of this object property
                         // is using URIs as values
                         $valuesAsURI = FALSE;
                         if (stripos($attribute, "[uri]") !== FALSE) {
                             $valuesAsURI = TRUE;
                             $attribute = str_replace("[uri]", "", $attribute);
                         }
                         $attribute = urlencode($attribute);
                         if (array_search($attribute . "_attr_date" . $singleValuedDesignator, $indexedFields) !== FALSE) {
                             $attribute = urlencode($attribute) . "_attr_date" . $singleValuedDesignator;
                         } elseif (array_search($attribute . "_attr_int" . $singleValuedDesignator, $indexedFields) !== FALSE) {
                             $attribute = urlencode($attribute) . "_attr_int" . $singleValuedDesignator;
                         } elseif (array_search($attribute . "_attr_float" . $singleValuedDesignator, $indexedFields) !== FALSE) {
                             $attribute = urlencode($attribute) . "_attr_float" . $singleValuedDesignator;
                         } elseif (array_search($attribute . "_attr_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE && $valuesAsURI === FALSE) {
                             $attribute = urlencode($attribute) . "_attr_" . $this->ws->lang . $singleValuedDesignator;
                         } elseif (array_search($attribute . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE) {
                             // Check if the value of that filter is a URI or not.
                             if ($valuesAsURI) {
                                 $attribute = urlencode($attribute) . "_attr_obj_uri";
                             } else {
                                 $attribute = urlencode($attribute) . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator;
                             }
                         }
                     }
                     $boostingRules .= '&bq=' . $attribute . ':"' . urlencode($attributeValue) . '"^' . $modifier;
                 } else {
                     $boostingRules .= '&bq=attribute:"' . urlencode($attribute) . '"^' . $modifier;
                 }
             }
         }
         // Attributes phrases boosting rules
         if ($this->ws->attributesPhraseBoost != "") {
             $boostRules = explode(";", $this->ws->attributesPhraseBoost);
             $indexedFields = array();
             if (file_exists($this->ws->fields_index_folder . "fieldsIndex.srz")) {
                 $indexedFields = unserialize(file_get_contents($this->ws->fields_index_folder . "fieldsIndex.srz"));
             }
             foreach ($boostRules as $key => $rule) {
                 if ($rule == '') {
                     continue;
                 }
                 $boost = explode("^", $rule);
                 $attribute = str_replace(array("%3B", "%5E"), array(";", "^"), $boost[0]);
                 $modifier = $boost[1];
                 $isCoreAttribute = $this->isCoreAttribute($attribute, $attribute);
                 $singleValuedDesignator = "";
                 if (!$isCoreAttribute) {
                     if (array_search(urlencode($attribute . "_attr_" . $this->ws->lang . "_single_valued"), $indexedFields) !== FALSE) {
                         $singleValuedDesignator = "_single_valued";
                     }
                     if (array_search($attribute . "_attr_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE && $valuesAsURI === FALSE) {
                         $attribute = str_replace($attribute, urlencode($attribute) . "_attr_" . $this->ws->lang . $singleValuedDesignator, $attribute);
                         $attributeFound = TRUE;
                     } elseif (array_search($attribute . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE) {
                         $attribute = str_replace($attribute . ":", urlencode($attribute) . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator . ":", $attribute);
                         $attributeFound = TRUE;
                     }
                 }
                 $boostingRules .= '&pf=' . urlencode($attribute) . '^' . $modifier;
             }
             $boostingRules .= '&qs=' . $this->ws->phraseBoostDistance;
         }
         $restrictionRules = '';
         // Define properties restricted for search and their boost
         if (!empty($this->ws->searchRestrictions)) {
             $restrictionRules .= '&qf=';
             $restrictions = explode(';', $this->ws->searchRestrictions);
             foreach ($restrictions as $restriction) {
                 if (empty($restriction)) {
                     continue;
                 }
                 $modifier = 1;
                 $attribute = $restriction;
                 if (strpos($restriction, '^')) {
                     $res = explode('^', $restriction);
                     $modifier = $res[1];
                     $attribute = $res[0];
                 }
                 $indexedFields = array();
                 if (file_exists($this->ws->fields_index_folder . "fieldsIndex.srz")) {
                     $indexedFields = unserialize(file_get_contents($this->ws->fields_index_folder . "fieldsIndex.srz"));
                 }
                 // Fix the reference to some of the core attributes
                 $isCoreAttribute = $this->isCoreAttribute($attribute, $attribute);
                 // If it is not a core attribute, check if we have to make that attribute
                 // single-valued. We check that by checking if a single_valued version
                 // of that field is currently used in the Solr index.
                 $singleValuedDesignator = "";
                 if (!$isCoreAttribute && (array_search(urlencode($attribute . "_attr_" . $this->ws->lang . "_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_date_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_int_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_float_single_valued"), $indexedFields) !== FALSE)) {
                     $singleValuedDesignator = "_single_valued";
                 }
                 $attributeFound = FALSE;
                 // Get the Solr field ID for this attribute
                 if (!$isCoreAttribute) {
                     $attribute = urlencode($attribute);
                     /*
                      @NOTE: here we can only include fields that uses the "solr.StopFilterFactory" setting in their
                             defined workflow. Otherwise, if a stopword is used in the search query, 0 results
                             will always be returned with the eDisMax query parser.
                     */
                     if (array_search($attribute . "_attr_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE) {
                         $attribute = urlencode($attribute) . "_attr_" . $this->ws->lang . $singleValuedDesignator;
                         $attributeFound = TRUE;
                     } elseif (array_search($attribute . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE) {
                         $attribute = urlencode($attribute) . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator;
                         $attributeFound = TRUE;
                     }
                 } else {
                     $attributeFound = TRUE;
                 }
                 if ($attributeFound) {
                     $restrictionRules .= $attribute . '^' . $modifier . ' ';
                 }
             }
         }
         $restrictionRules = rtrim($restrictionRules);
         $solrQuery = "q=" . $queryParam . $distanceQueryRevelencyBooster . $boostingRules . $restrictionRules . "&start=" . $this->ws->page . "&rows=" . $this->ws->items . (strtolower($this->ws->includeAggregates) == "true" ? "&facet=true" . "&facet.sort=count" . "&facet.limit=-1" . "&facet.field=type" . "&facet.field=attribute" . (strtolower($this->ws->inference) == "on" ? "&facet.field=inferred_type" : "") . "&facet.field=dataset&facet.mincount=1" : "");
         if (strtolower($this->ws->datasets) == "all") {
             $datasetList = "";
             foreach ($accessibleDatasets as $key => $dataset) {
                 if ($key == 0) {
                     $solrQuery .= "&fq=dataset:%22" . urlencode($dataset) . "%22";
                 } else {
                     $solrQuery .= " OR dataset:%22" . urlencode($dataset) . "%22";
                 }
             }
         } else {
             $datasets = explode(";", $this->ws->datasets);
             $solrQuery .= "&fq=dataset:%22%22";
             foreach ($datasets as $dataset) {
                 // Check if the dataset is accessible to the user
                 if (array_search($dataset, $accessibleDatasets) !== FALSE) {
                     // Decoding potentially encoded ";" characters
                     $dataset = str_replace(array("%3B", "%3b"), ";", $dataset);
                     $solrQuery .= " OR dataset:%22" . urlencode($dataset) . "%22";
                 }
             }
         }
         if ($this->ws->types != "all") {
             // Lets include the information to facet per type.
             $types = explode(";", $this->ws->types);
             $nbProcessed = 0;
             foreach ($types as $type) {
                 // Decoding potentially encoded ";" characters
                 $type = str_replace(array("%3B", "%3b"), ";", $type);
                 if ($nbProcessed == 0) {
                     $solrQuery .= "&fq=type:%22" . urlencode($type) . "%22";
                 } else {
                     $solrQuery .= " OR type:%22" . urlencode($type) . "%22";
                 }
                 $nbProcessed++;
                 if (strtolower($this->ws->inference) == "on") {
                     $solrQuery .= " OR inferred_type:%22" . urlencode($type) . "%22";
                 }
             }
         }
         if ($this->ws->extendedFilters != "") {
             // Get the fields (attributes) from the extended attributes query
             preg_match_all("/([#%\\.A-Za-z0-9_\\-\\[\\]]+):[\\(\"#%\\.A-Za-z0-9_\\-\\+*]+/Uim", $this->ws->extendedFilters, $matches);
             $attributes = $matches[1];
             $indexedFields = array();
             if (file_exists($this->ws->fields_index_folder . "fieldsIndex.srz")) {
                 $indexedFields = unserialize(file_get_contents($this->ws->fields_index_folder . "fieldsIndex.srz"));
             }
             $attributes = array_unique($attributes);
             foreach ($attributes as $attribute) {
                 $attribute = urldecode($attribute);
                 if ($attribute == "dataset") {
                     // Make sure the user has access to this dataset
                     // Get all the dataset values referenced in the extended filters
                     $usedDatasets = array();
                     preg_match_all("/dataset:[\"(](.*)[\")]/Uim", $this->ws->extendedFilters, $matches);
                     $usedDatasets = array_merge($usedDatasets, $matches[1]);
                     preg_match_all("/dataset:([^\"()]*)[\\s\$)]+/Uim", $this->ws->extendedFilters, $matches);
                     $usedDatasets = array_merge($usedDatasets, $matches[1]);
                     $usedDatasets = array_unique($usedDatasets);
                     // Make sure that all defined dataset extended filters are accessible to the requester
                     foreach ($usedDatasets as $key => $usedDataset) {
                         // Unescape values (remove "\" from the Solr query)
                         $usedDataset = str_replace('\\', '', $usedDataset);
                         if (array_search($usedDataset, $accessibleDatasets) === FALSE) {
                             $this->ws->conneg->setStatus(400);
                             $this->ws->conneg->setStatusMsg("Bad Request");
                             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_309->name);
                             $this->ws->conneg->setError($this->ws->errorMessenger->_309->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_309->name, $this->ws->errorMessenger->_309->description, "Unaccessible dataset: " . $usedDataset, $this->ws->errorMessenger->_309->level);
                             return;
                         }
                     }
                 }
                 // Fix the reference to some of the core attributes
                 $coreAttribute = "";
                 $isCoreAttribute = $this->isCoreAttribute($attribute, $coreAttribute);
                 // If it is not a core attribute, check if we have to make that attribute
                 // single-valued. We check that by checking if a single_valued version
                 // of that field is currently used in the Solr index.
                 $singleValuedDesignator = "";
                 if (!$isCoreAttribute && (array_search(urlencode($attribute . "_attr_" . $this->ws->lang . "_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_date_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_int_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_float_single_valued"), $indexedFields) !== FALSE)) {
                     $singleValuedDesignator = "_single_valued";
                 }
                 $attributeFound = FALSE;
                 // Get the Solr field ID for this attribute
                 if ($isCoreAttribute) {
                     $attribute = urlencode($attribute);
                     $this->ws->extendedFilters = str_replace($attribute, $coreAttribute, $this->ws->extendedFilters);
                     $attributeFound = TRUE;
                 } else {
                     // Check if it is an object property, and check if the pattern of this object property
                     // is using URIs as values
                     $valuesAsURI = FALSE;
                     if (stripos($attribute, "[uri]") !== FALSE) {
                         $valuesAsURI = TRUE;
                         $attribute = str_replace("[uri]", "", $attribute);
                     }
                     $attribute = urlencode($attribute);
                     if (array_search($attribute . "_attr_date" . $singleValuedDesignator, $indexedFields) !== FALSE) {
                         $this->ws->extendedFilters = str_replace($attribute, urlencode($attribute) . "_attr_date" . $singleValuedDesignator, $this->ws->extendedFilters);
                         $attributeFound = TRUE;
                     } elseif (array_search($attribute . "_attr_int" . $singleValuedDesignator, $indexedFields) !== FALSE) {
                         $this->ws->extendedFilters = str_replace($attribute, urlencode($attribute) . "_attr_int" . $singleValuedDesignator, $this->ws->extendedFilters);
                         $attributeFound = TRUE;
                     } elseif (array_search($attribute . "_attr_float" . $singleValuedDesignator, $indexedFields) !== FALSE) {
                         $this->ws->extendedFilters = str_replace($attribute, urlencode($attribute) . "_attr_float" . $singleValuedDesignator, $this->ws->extendedFilters);
                         $attributeFound = TRUE;
                     } elseif (array_search($attribute . "_attr_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE && $valuesAsURI === FALSE) {
                         $this->ws->extendedFilters = str_replace($attribute, urlencode($attribute) . "_attr_" . $this->ws->lang . $singleValuedDesignator, $this->ws->extendedFilters);
                         $attributeFound = TRUE;
                     } elseif (array_search($attribute . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator, $indexedFields) !== FALSE) {
                         // Check if the value of that filter is a URI or not.
                         if ($valuesAsURI) {
                             $this->ws->extendedFilters = str_replace($attribute . "[uri]:", urlencode($attribute) . "_attr_obj_uri:", $this->ws->extendedFilters);
                         } else {
                             $this->ws->extendedFilters = str_replace($attribute . ":", urlencode($attribute) . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator . ":", $this->ws->extendedFilters);
                         }
                         $attributeFound = TRUE;
                     }
                 }
                 if ($attributeFound === FALSE) {
                     $this->ws->conneg->setStatus(400);
                     $this->ws->conneg->setStatusMsg("Bad Request");
                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_310->name);
                     $this->ws->conneg->setError($this->ws->errorMessenger->_310->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_310->name, $this->ws->errorMessenger->_310->description, "Undefined filter: " . urldecode($attribute), $this->ws->errorMessenger->_310->level);
                     return;
                 }
             }
             $solrQuery .= "&fq=" . $this->ws->extendedFilters;
         }
         if ($this->ws->attributes != "all") {
             // Lets include the information to facet per type.
             $attributes = explode(";", $this->ws->attributes);
             $nbProcessed = 0;
             $indexedFields = array();
             if (file_exists($this->ws->fields_index_folder . "fieldsIndex.srz")) {
                 $indexedFields = unserialize(file_get_contents($this->ws->fields_index_folder . "fieldsIndex.srz"));
             }
             foreach ($attributes as $attribute) {
                 $attributeValue = explode("::", $attribute);
                 $attribute = urldecode($attributeValue[0]);
                 // Skip possible "dataset" field request. This is handled bia the "dataset" parameter
                 // of this web service endpoint.
                 if ($attribute == "dataset") {
                     continue;
                 }
                 if (isset($attributeValue[1]) && $attributeValue[1] != "") {
                     // Fix the reference to some of the core attributes
                     $coreAttr = $this->isCoreAttribute($attribute, $attribute);
                     // Special handling for some core attributes
                     switch (urldecode($attributeValue[0])) {
                         case "prefLabel":
                         case Namespaces::$iron . "prefLabel":
                             // Check if we are performing an autocompletion task on the pref label
                             $label = urldecode($attributeValue[1]);
                             if (substr($label, strlen($label) - 2) == "**") {
                                 $attribute = "prefLabelAutocompletion_" . $this->ws->lang;
                                 $attributeValue[1] = urlencode(strtolower(str_replace(" ", "\\ ", substr($label, 0, strlen($label) - 1))));
                             }
                             break;
                         case "lat":
                         case Namespaces::$geo . "lat":
                             if (!is_numeric(urldecode($attributeValue[1]))) {
                                 // If the value is not numeric, we skip that attribute/value.
                                 // Otherwise an exception will be raised by Solr.
                                 continue;
                             }
                             break;
                         case "long":
                         case Namespaces::$geo . "long":
                             if (!is_numeric(urldecode($attributeValue[1]))) {
                                 // If the value is not numeric, we skip that attribute/value.
                                 // Otherwise an exception will be raised by Solr.
                                 continue;
                             }
                             break;
                     }
                     // A filtering value as been defined for this attribute.
                     $val = urldecode($attributeValue[1]);
                     // If it is not a core attribute, check if we have to make that attribute
                     // single-valued. We check that by checking if a single_valued version
                     // of that field is currently used in the Solr index.
                     $singleValuedDesignator = "";
                     if (!$coreAttr && (array_search(urlencode($attribute . "_attr_" . $this->ws->lang . "_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_date_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_int_single_valued"), $indexedFields) !== FALSE || array_search(urlencode($attribute . "_attr_float_single_valued"), $indexedFields) !== FALSE)) {
                         $singleValuedDesignator = "_single_valued";
                     }
                     if ($nbProcessed == 0) {
                         if ($coreAttr) {
                             switch ($attribute) {
                                 case "type":
                                     if (strtolower($this->ws->inference) == "on") {
                                         $solrQuery .= "&fq=((type:" . urlencode($this->escapeSolrValue($val)) . ") OR (inferred_type:" . urlencode($this->escapeSolrValue($val)) . "))";
                                     } else {
                                         $solrQuery .= "&fq=(type:" . urlencode($this->escapeSolrValue($val)) . ")";
                                     }
                                     break;
                                 case "located_in":
                                     $solrQuery .= "&fq=(located_in:" . urlencode($this->escapeSolrValue($val)) . ")";
                                     break;
                                 default:
                                     $solrQuery .= "&fq=(" . $attribute . ":" . urlencode($this->arrangeSolrValue($val)) . ")";
                                     break;
                             }
                         } else {
                             $solrQuery .= "&fq=(";
                         }
                     } else {
                         if ($coreAttr) {
                             switch ($attribute) {
                                 case "type":
                                     if (strtolower($this->ws->inference) == "on") {
                                         $solrQuery .= " " . $this->ws->attributesBooleanOperator . " ((type:" . urlencode($this->escapeSolrValue($val)) . ") OR (inferred_type:" . urlencode($this->escapeSolrValue($val)) . "))";
                                     } else {
                                         $solrQuery .= " " . $this->ws->attributesBooleanOperator . " (type:" . urlencode($this->escapeSolrValue($val)) . ")";
                                     }
                                     break;
                                 case "located_in":
                                     $solrQuery .= " " . $this->ws->attributesBooleanOperator . " (located_in:" . urlencode($this->escapeSolrValue($val)) . ")";
                                     break;
                                 default:
                                     $solrQuery .= " " . $this->ws->attributesBooleanOperator . " (" . $attribute . ":" . urlencode($this->escapeSolrValue($this->arrangeSolrValue($val))) . ")";
                                     break;
                             }
                         } else {
                             if (substr($solrQuery, strlen($solrQuery) - 3) != "fq=") {
                                 $solrQuery .= " " . $this->ws->attributesBooleanOperator . " (";
                             } else {
                                 $solrQuery .= "(";
                             }
                         }
                     }
                     $addOR = FALSE;
                     $empty = TRUE;
                     // We have to detect if the fields are existing in Solr, otherwise Solr will throw
                     // "undefined fields" errors, and there is no way to ignore them and process
                     // the query anyway.
                     if (!$coreAttr && array_search(urlencode($attribute), $indexedFields) !== FALSE) {
                         $solrQuery .= "(" . urlencode(urlencode($attribute)) . ":" . urlencode($this->escapeSolrValue($this->arrangeSolrValue($val))) . ")";
                         $addOR = TRUE;
                         $empty = FALSE;
                     }
                     if (array_search(urlencode($attribute . "_attr_" . $this->ws->lang . $singleValuedDesignator), $indexedFields) !== FALSE) {
                         if ($addOR) {
                             $solrQuery .= " OR ";
                         }
                         $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_" . $this->ws->lang . $singleValuedDesignator . ":" . urlencode($this->escapeSolrValue($this->arrangeSolrValue($val))) . ")";
                         $addOR = TRUE;
                         $empty = FALSE;
                     }
                     if (array_search(urlencode($attribute . "_attr_int" . $singleValuedDesignator), $indexedFields) !== FALSE) {
                         if ($addOR) {
                             $solrQuery .= " OR ";
                         }
                         if (is_numeric($val)) {
                             $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_int" . $singleValuedDesignator . ":" . $val . ")";
                         } else {
                             // Extract the FROM and TO numbers range
                             $numbers = explode(" TO ", trim(str_replace(" to ", " TO ", $val), "[]"));
                             if ($numbers[0] != "*") {
                                 if (!is_numeric($numbers[0])) {
                                     $this->ws->conneg->setStatus(400);
                                     $this->ws->conneg->setStatusMsg("Bad Request");
                                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_306->name);
                                     $this->ws->conneg->setError($this->ws->errorMessenger->_306->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_306->name, $this->ws->errorMessenger->_306->description, "", $this->ws->errorMessenger->_306->level);
                                     return;
                                 }
                             }
                             if ($numbers[1] != "*") {
                                 if (!is_numeric($numbers[1])) {
                                     $this->ws->conneg->setStatus(400);
                                     $this->ws->conneg->setStatusMsg("Bad Request");
                                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_306->name);
                                     $this->ws->conneg->setError($this->ws->errorMessenger->_306->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_306->name, $this->ws->errorMessenger->_306->description, "", $this->ws->errorMessenger->_306->level);
                                     return;
                                 }
                             }
                             $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_int" . $singleValuedDesignator . ":" . urlencode("[" . $numbers[0] . " TO " . $numbers[1] . "]") . ")";
                         }
                         $addOR = TRUE;
                         $empty = FALSE;
                     }
                     if (array_search(urlencode($attribute . "_attr_float" . $singleValuedDesignator), $indexedFields) !== FALSE) {
                         if ($addOR) {
                             $solrQuery .= " OR ";
                         }
                         if (is_numeric($val)) {
                             $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_float" . $singleValuedDesignator . ":" . $val . ")";
                         } else {
                             // Extract the FROM and TO numbers range
                             $numbers = explode(" TO ", trim(str_replace(" to ", " TO ", $val), "[]"));
                             if ($numbers[0] != "*") {
                                 if (!is_numeric($numbers[0])) {
                                     $this->ws->conneg->setStatus(400);
                                     $this->ws->conneg->setStatusMsg("Bad Request");
                                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_306->name);
                                     $this->ws->conneg->setError($this->ws->errorMessenger->_306->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_306->name, $this->ws->errorMessenger->_306->description, "", $this->ws->errorMessenger->_306->level);
                                     return;
                                 }
                             }
                             if ($numbers[1] != "*") {
                                 if (!is_numeric($numbers[1])) {
                                     $this->ws->conneg->setStatus(400);
                                     $this->ws->conneg->setStatusMsg("Bad Request");
                                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_306->name);
                                     $this->ws->conneg->setError($this->ws->errorMessenger->_306->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_306->name, $this->ws->errorMessenger->_306->description, "", $this->ws->errorMessenger->_306->level);
                                     return;
                                 }
                             }
                             $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_float" . $singleValuedDesignator . ":" . urlencode("[" . $numbers[0] . " TO " . $numbers[1] . "]") . ")";
                         }
                         $addOR = TRUE;
                         $empty = FALSE;
                     }
                     if (array_search(urlencode($attribute . "_attr_date" . $singleValuedDesignator), $indexedFields) !== FALSE) {
                         if ($addOR) {
                             $solrQuery .= " OR ";
                         }
                         $dateFrom = "";
                         $dateTo = "NOW";
                         // Check if it is a range query
                         if (substr($val, 0, 1) == "[" && substr($val, strlen($val) - 1, 1) == "]") {
                             // Extract the FROM and TO dates range
                             $dates = explode(" TO ", trim(str_replace(" to ", " TO ", $val), "[]"));
                             if ($dates[0] != "*") {
                                 $dateFrom = $this->safeDate($dates[0]);
                                 if ($dateFrom === FALSE) {
                                     $this->ws->conneg->setStatus(400);
                                     $this->ws->conneg->setStatusMsg("Bad Request");
                                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_305->name);
                                     $this->ws->conneg->setError($this->ws->errorMessenger->_305->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_305->name, $this->ws->errorMessenger->_305->description, "", $this->ws->errorMessenger->_305->level);
                                     return;
                                 }
                             }
                             if ($dates[1] != "*") {
                                 $dateTo = $this->safeDate($dates[1]);
                                 if ($dateTo === FALSE) {
                                     $this->ws->conneg->setStatus(400);
                                     $this->ws->conneg->setStatusMsg("Bad Request");
                                     $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_305->name);
                                     $this->ws->conneg->setError($this->ws->errorMessenger->_305->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_305->name, $this->ws->errorMessenger->_305->description, "", $this->ws->errorMessenger->_305->level);
                                     return;
                                 }
                             }
                         } else {
                             // If no range is defined, we consider the input date to be the initial date to use
                             // until now.
                             $dateFrom = $this->safeDate($val);
                             if ($dateFrom === FALSE) {
                                 $this->ws->conneg->setStatus(400);
                                 $this->ws->conneg->setStatusMsg("Bad Request");
                                 $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_305->name);
                                 $this->ws->conneg->setError($this->ws->errorMessenger->_305->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_305->name, $this->ws->errorMessenger->_305->description, "", $this->ws->errorMessenger->_305->level);
                                 return;
                             }
                         }
                         $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_date" . $singleValuedDesignator . ":" . urlencode("[" . $dateFrom . " TO " . $dateTo) . "]" . ")";
                         $addOR = TRUE;
                         $empty = FALSE;
                     }
                     if (array_search(urlencode($attribute . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator), $indexedFields) !== FALSE) {
                         if ($addOR) {
                             $solrQuery .= " OR ";
                         }
                         $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_obj_" . $this->ws->lang . $singleValuedDesignator . ":" . urlencode($this->escapeSolrValue($val)) . ")";
                         $addOR = TRUE;
                         $empty = FALSE;
                     }
                     if (array_search(urlencode($attribute . "_attr_obj_uri"), $indexedFields) !== FALSE) {
                         if ($addOR) {
                             $solrQuery .= " OR ";
                         }
                         $solrQuery .= "(" . urlencode(urlencode($attribute)) . "_attr_obj_uri:" . urlencode($this->escapeURIValue($val)) . ")";
                         $addOR = TRUE;
                         $empty = FALSE;
                     }
                     if ($nbProcessed == 0) {
                         if (!$coreAttr) {
                             if ($empty) {
                                 $solrQuery = substr($solrQuery, 0, strlen($solrQuery) - 1);
                             } else {
                                 $solrQuery .= ")";
                             }
                         }
                     } else {
                         if (!$coreAttr) {
                             if (substr($solrQuery, strlen($solrQuery) - 4) != "fq=(") {
                                 if ($empty) {
                                     $solrQuery = substr($solrQuery, 0, strlen($solrQuery) - 5);
                                 } else {
                                     $solrQuery .= ")";
                                 }
                             } else {
                                 $solrQuery = substr($solrQuery, 0, strlen($solrQuery) - 1);
                             }
                         }
                     }
                 } else {
                     if ($nbProcessed == 0) {
                         $solrQuery .= "&fq=(attribute:%22" . urlencode($attribute) . "%22)";
                     } else {
                         $solrQuery .= " " . $this->ws->attributesBooleanOperator . " (attribute:%22" . urlencode($attribute) . "%22)";
                     }
                 }
                 $nbProcessed++;
             }
         }
         // Check if this query is geo-enabled and if a distance-filter is requested
         if ($this->ws->geoEnabled && $this->ws->distanceFilter != "") {
             /*
               $params[0] == latitude
               $params[1] == longitude
               $params[2] == distance
               $params[3] == (0) distance in kilometers, (1) distance in miles
             */
             $params = explode(";", $this->ws->distanceFilter);
             $earthRadius = 6371;
             if ($params[3] == 1) {
                 $earthRadius = 3963.205;
             }
             $solrQuery .= "&fq={!frange l=0 u=" . $params[2] . "}hsin(" . $params[0] . "," . $params[1] . " , lat_rad, long_rad, " . $earthRadius . ")";
         }
         // Check if this query is geo-enabled and if a range-filter is requested
         if ($this->ws->geoEnabled && $this->ws->rangeFilter != "") {
             /*
               $params[0] == latitude top-left
               $params[1] == longitude top-left
               $params[2] == latitude bottom-right
               $params[3] == longitude bottom-right
             */
             $params = explode(";", $this->ws->rangeFilter);
             // Make sure the ranges are respected according to the way the cartesian coordinate
             // system works.
             $p1 = $params[0];
             $p2 = $params[2];
             $p3 = $params[1];
             $p4 = $params[3];
             if ($params[0] > $params[2]) {
                 $p1 = $params[2];
                 $p2 = $params[0];
             }
             if ($params[1] > $params[3]) {
                 $p3 = $params[3];
                 $p4 = $params[1];
             }
             $solrQuery .= "&fq=lat:[" . $p1 . " TO " . $p2 . "]&fq=long:[" . $p3 . " TO " . $p4 . "]";
         }
         // Add the attribute/value aggregates if needed
         if (count($this->ws->aggregateAttributes) > 0 && strtolower($this->ws->includeAggregates) == "true") {
             foreach ($this->ws->aggregateAttributes as $attribute) {
                 $solrQuery .= "&facet.field=" . urlencode(urlencode($attribute));
                 $solrQuery .= "&f." . urlencode(urlencode($attribute)) . ".facet.limit=" . $this->ws->aggregateAttributesNb;
             }
         }
         // Only return these fields in the resultset
         if (count($this->ws->includeAttributesList) > 0) {
             if (strtolower($this->ws->includeAttributesList[0]) == "none") {
                 $solrQuery .= "&fl=";
                 $solrQuery .= "uri ";
                 $solrQuery .= "type ";
                 $solrQuery .= "inferred_type ";
                 $solrQuery .= "dataset ";
                 $solrQuery .= "prefLabelAutocompletion_" . $this->ws->lang . "";
             } else {
                 $solrQuery .= "&fl=";
                 foreach ($this->ws->includeAttributesList as $atl) {
                     if ($atl != "none") {
                         $isCoreAttribute = $this->isCoreAttribute($atl, $atl);
                         if (!$isCoreAttribute) {
                             $solrQuery .= urlencode(urlencode($atl)) . "_attr_" . $this->ws->lang . " ";
                             $solrQuery .= urlencode(urlencode($atl)) . "_attr_obj_" . $this->ws->lang . " ";
                             $solrQuery .= urlencode(urlencode($atl)) . "_attr_obj_uri ";
                         } else {
                             $solrQuery .= $atl . " ";
                         }
                     }
                 }
                 // Also add the core attributes to the mixte
                 $solrQuery .= "uri ";
                 $solrQuery .= "type ";
                 $solrQuery .= "inferred_type ";
                 $solrQuery .= "dataset ";
                 $solrQuery .= "prefLabelAutocompletion_" . $this->ws->lang . "";
             }
         }
         // Remove possible left-over introduced by the procedure above for some rare usecases.
         $solrQuery = str_replace("fq= OR ", "fq=", $solrQuery);
         $solrQuery = str_replace("fq= AND ", "fq=", $solrQuery);
         // Set the default field of the search
         $solrQuery .= "&df=all_text_" . $this->ws->lang;
         // The the sorting parameter
         if (count($this->ws->sort) > 0) {
             $indexedFields = array();
             if (file_exists($this->ws->fields_index_folder . "fieldsIndex.srz")) {
                 $indexedFields = unserialize(file_get_contents($this->ws->fields_index_folder . "fieldsIndex.srz"));
                 $solrQuery .= "&sort=";
                 foreach ($this->ws->sort as $sortProperty => $order) {
                     $lSortProperty = strtolower($sortProperty);
                     if ($lSortProperty == "preflabel") {
                         $sortProperty = "prefLabelAutocompletion_" . $this->ws->lang;
                     } else {
                         if ($lSortProperty == "type") {
                             $sortProperty = "type_single_valued";
                         } else {
                             if ($lSortProperty != "uri" && $lSortProperty != "dataset" && $lSortProperty != "score") {
                                 $uSortProperty = urlencode($sortProperty);
                                 if (array_search($uSortProperty . "_attr_date_single_valued", $indexedFields) !== FALSE) {
                                     $sortProperty = urlencode($uSortProperty) . "_attr_date_single_valued";
                                 } else {
                                     if (array_search($uSortProperty . "_attr_float_single_valued", $indexedFields) !== FALSE) {
                                         $sortProperty = urlencode($uSortProperty) . "_attr_float_single_valued";
                                     } else {
                                         if (array_search($uSortProperty . "_attr_int_single_valued", $indexedFields) !== FALSE) {
                                             $sortProperty = urlencode($uSortProperty) . "_attr_int_single_valued";
                                         } else {
                                             if (array_search($uSortProperty . "_attr_obj_" . $this->ws->lang . "_single_valued", $indexedFields) !== FALSE) {
                                                 $sortProperty = urlencode($uSortProperty) . "_attr_obj_" . $this->ws->lang . "_single_valued";
                                             } else {
                                                 if (array_search($uSortProperty . "_attr_" . $this->ws->lang . "_single_valued", $indexedFields) !== FALSE) {
                                                     $sortProperty = urlencode($uSortProperty) . "_attr_" . $this->ws->lang . "_single_valued";
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $solrQuery .= $sortProperty . " " . $order . ",";
                 }
                 $solrQuery = rtrim($solrQuery, ",");
             }
         }
         if (!empty($this->ws->includeScores)) {
             $solrQuery .= '&fl=' . urlencode('* score');
         }
         // Specify the default search operator
         if ($this->ws->defaultOperator != 'and') {
             if (strpos($this->ws->defaultOperator, '::') !== FALSE) {
                 $orOp = explode('::', $this->ws->defaultOperator .= '&q.op=AND');
                 if ($orOp[0] == 'or') {
                     $solrQuery .= '&q.op=OR';
                     $solrQuery .= '&mm=' . $orOp[1];
                 }
             } else {
                 if ($this->ws->defaultOperator == 'or') {
                     $solrQuery .= '&q.op=OR';
                 }
             }
         } else {
             $solrQuery .= '&q.op=AND';
         }
         // Check if we enable the spellchecker
         if ($this->ws->spellcheck === TRUE) {
             $solrQuery .= '&spellcheck=true';
         }
         // Specifies that the query parser is eDisMax
         $solrQuery .= '&defType=edismax';
         $resultset = $solr->select($solrQuery);
         if ($resultset === FALSE) {
             $this->ws->conneg->setStatus(400);
             $this->ws->conneg->setStatusMsg("Bad Request");
             $this->ws->conneg->setStatusMsgExt($this->ws->errorMessenger->_311->name);
             $this->ws->conneg->setError($this->ws->errorMessenger->_311->id, $this->ws->errorMessenger->ws, $this->ws->errorMessenger->_311->name, $this->ws->errorMessenger->_311->description, $solr->errorMessage . '[Debugging information: ]' . $solr->errorMessageDebug, $this->ws->errorMessenger->_311->level);
             return;
         }
         // Create the internal representation of the resultset.
         $domResultset = new DomDocument("1.0", "utf-8");
         $domResultset->loadXML($resultset);
         $xpath = new DOMXPath($domResultset);
         // Get the number of results
         $founds = $xpath->query("*[@numFound]");
         foreach ($founds as $found) {
             $nbResources = $found->attributes->getNamedItem("numFound")->nodeValue;
             break;
         }
         // If no results are returned, check if spellchecking was enabled, if it was then
         // try to get the spell suggestions & the the collation
         if ($nbResources <= 0 && $this->ws->spellcheck === TRUE) {
             // Try to get the collation
             $collation = $xpath->query("//*/lst[@name='suggestions']//str[@name='collation']");
             if ($collation->length > 0) {
                 $collation = $collation->item(0)->nodeValue;
             }
             $subject = new Subject($this->ws->uri . "suggestions/" . md5(microtime()));
             $subject->setType(Namespaces::$wsf . "SpellSuggestion");
             $subject->setDataAttribute(Namespaces::$wsf . "collation", $collation);
             $this->ws->rset->addSubject($subject);
             // Try to get the suggested terms
             $suggestedWords = $xpath->query("//*/lst[@name='suggestions']/lst");
             foreach ($suggestedWords as $sw) {
                 $misspelledWord = $sw->getAttribute('name');
                 $suggestion = $xpath->query("arr[@name='suggestion']/lst", $sw);
                 foreach ($suggestion as $word_frequency) {
                     $word = $word_frequency->getElementsByTagName('str')->item(0)->nodeValue;
                     $frequency = $word_frequency->getElementsByTagName('int')->item(0)->nodeValue;
                     $subject = new Subject($this->ws->uri . "suggestions/" . md5(microtime()));
                     $subject->setType(Namespaces::$wsf . "SpellSuggestion");
                     $subject->setDataAttribute(Namespaces::$wsf . "misspelledWord", $misspelledWord);
                     $subject->setDataAttribute(Namespaces::$wsf . "suggestion", $word);
                     $subject->setDataAttribute(Namespaces::$wsf . "frequency", $frequency);
                     $this->ws->rset->addSubject($subject);
                 }
             }
         }
         // Get all the "type" facets with their counts
         $founds = $xpath->query("//*/lst[@name='facet_fields']//lst[@name='type']/int");
         // Set types aggregates
         foreach ($founds as $found) {
             $subject = new Subject($this->ws->uri . "aggregate/" . md5(microtime()));
             $subject->setType(Namespaces::$aggr . "Aggregate");
             $subject->setObjectAttribute(Namespaces::$aggr . "property", Namespaces::$rdf . "type");
             $subject->setObjectAttribute(Namespaces::$aggr . "object", $found->attributes->getNamedItem("name")->nodeValue);
             $subject->setDataAttribute(Namespaces::$aggr . "count", $found->nodeValue);
             $this->ws->rset->addSubject($subject);
         }
         // Set types aggregates for inferred types
         if (strtolower($this->ws->inference) == "on") {
             // Get all the "inferred_type" facets with their counts
             $founds = $xpath->query("//*/lst[@name='facet_fields']//lst[@name='inferred_type']/int");
             // Get types counts
             foreach ($founds as $found) {
                 $subject = new Subject($this->ws->uri . "aggregate/" . md5(microtime()));
                 $subject->setType(Namespaces::$aggr . "Aggregate");
                 $subject->setObjectAttribute(Namespaces::$aggr . "property", Namespaces::$rdf . "type");
                 $subject->setObjectAttribute(Namespaces::$aggr . "object", $found->attributes->getNamedItem("name")->nodeValue);
                 $subject->setDataAttribute(Namespaces::$aggr . "count", $found->nodeValue);
                 $this->ws->rset->addSubject($subject);
             }
         }
         // Set the dataset aggregates
         $founds = $xpath->query("//*/lst[@name='facet_fields']//lst[@name='dataset']/int");
         foreach ($founds as $found) {
             $subject = new Subject($this->ws->uri . "aggregate/" . md5(microtime()));
             $subject->setType(Namespaces::$aggr . "Aggregate");
             $subject->setObjectAttribute(Namespaces::$aggr . "property", Namespaces::$void . "Dataset");
             $subject->setObjectAttribute(Namespaces::$aggr . "object", $found->attributes->getNamedItem("name")->nodeValue);
             $subject->setDataAttribute(Namespaces::$aggr . "count", $found->nodeValue);
             $this->ws->rset->addSubject($subject);
         }
         // Set the attributes aggregates
         $founds = $xpath->query("//*/lst[@name='facet_fields']//lst[@name='attribute']/int");
         foreach ($founds as $found) {
             $subject = new Subject($this->ws->uri . "aggregate/" . md5(microtime()));
             $subject->setType(Namespaces::$aggr . "Aggregate");
             $subject->setObjectAttribute(Namespaces::$aggr . "property", Namespaces::$rdf . "Property");
             $subject->setObjectAttribute(Namespaces::$aggr . "object", $found->attributes->getNamedItem("name")->nodeValue);
             $subject->setDataAttribute(Namespaces::$aggr . "count", $found->nodeValue);
             $this->ws->rset->addSubject($subject);
         }
         // Set all the attributes/values aggregates
         foreach ($this->ws->aggregateAttributes as $attribute) {
             $founds = $xpath->query("//*/lst[@name='facet_fields']//lst[@name='" . urlencode($attribute) . "']/int");
             foreach ($founds as $found) {
                 $subject = new Subject($this->ws->uri . "aggregate/" . md5(microtime()));
                 $subject->setType(Namespaces::$aggr . "Aggregate");
                 $subject->setObjectAttribute(Namespaces::$aggr . "property", str_replace(array("_attr_uri_label_facets", "_attr_facets", "_attr_obj_uri"), "", urldecode($attribute)));
                 if ($this->ws->aggregateAttributesObjectType == "uri") {
                     $subject->setObjectAttribute(Namespaces::$aggr . "object", $found->attributes->getNamedItem("name")->nodeValue);
                 } elseif ($this->ws->aggregateAttributesObjectType == "literal") {
                     $subject->setDataAttribute(Namespaces::$aggr . "object", $found->attributes->getNamedItem("name")->nodeValue);
                 } elseif ($this->ws->aggregateAttributesObjectType == "uriliteral") {
                     $values = explode("::", $found->attributes->getNamedItem("name")->nodeValue);
                     $subject->setObjectAttribute(Namespaces::$aggr . "object", $values[0]);
                     $subject->setDataAttribute(Namespaces::$aggr . "object", $values[1]);
                 }
                 $subject->setDataAttribute(Namespaces::$aggr . "count", $found->nodeValue);
                 $this->ws->rset->addSubject($subject);
             }
         }
         // Set all the results
         $resultsDom = $xpath->query("//doc");
         foreach ($resultsDom as $result) {
             // get URI
             $resultURI = $xpath->query("str[@name='uri']", $result);
             $uri = "";
             if ($resultURI->length > 0) {
                 $uri = $resultURI->item(0)->nodeValue;
             } else {
                 continue;
             }
             $subject = new Subject($uri);
             // get Dataset URI
             $resultDatasetURI = $xpath->query("str[@name='dataset']", $result);
             if ($resultDatasetURI->length > 0) {
                 $subject->setObjectAttribute(Namespaces::$dcterms . "isPartOf", $resultDatasetURI->item(0)->nodeValue);
             }
             // get records preferred label
             $resultPrefLabelURI = $xpath->query("str[@name='prefLabel_" . $this->ws->lang . "']", $result);
             if ($resultPrefLabelURI->length > 0) {
                 $subject->setPrefLabel($resultPrefLabelURI->item(0)->nodeValue);
             }
             // get records aternative labels
             $resultAltLabelURI = $xpath->query("arr[@name='altLabel_" . $this->ws->lang . "']/str", $result);
             for ($i = 0; $i < $resultAltLabelURI->length; ++$i) {
                 $subject->setAltLabel($resultAltLabelURI->item($i)->nodeValue);
             }
             // Get possible Lat/Long and shapes descriptions
             // First check if there is a polygonCoordinates pr a polylineCoordinates attribute for that record
             // If there is one, then we simply ignore the lat/long coordinates since they come from these
             // attributes and that we don't want to duplicate that information.
             $skipLatLong = FALSE;
             $resultPolygonCoordinates = $xpath->query("arr[@name='polygonCoordinates']/str", $result);
             if ($resultPolygonCoordinates->length > 0) {
                 foreach ($resultPolygonCoordinates as $value) {
                     $subject->setDataAttribute(Namespaces::$sco . "polygonCoordinates", $value->nodeValue);
                 }
                 $skipLatLong = TRUE;
             }
             $resultPolylineCoordinates = $xpath->query("arr[@name='polylineCoordinates']/str", $result);
             if ($resultPolylineCoordinates->length > 0) {
                 foreach ($resultPolylineCoordinates as $value) {
                     $subject->setDataAttribute(Namespaces::$sco . "polylineCoordinates", $value->nodeValue);
                 }
                 $skipLatLong = TRUE;
             }
             if (!$skipLatLong) {
                 $resultDescriptionLat = $xpath->query("arr[@name='lat']/double", $result);
                 if ($resultDescriptionLat->length > 0) {
                     $subject->setDataAttribute(Namespaces::$geo . "lat", $resultDescriptionLat->item(0)->nodeValue);
                 }
                 $resultDescriptionLong = $xpath->query("arr[@name='long']/double", $result);
                 if ($resultDescriptionLong->length > 0) {
                     $subject->setDataAttribute(Namespaces::$geo . "long", $resultDescriptionLong->item(0)->nodeValue);
                 }
             }
             // Set possible score
             if (!empty($this->ws->includeScores)) {
                 $score = $xpath->query("float[@name='score']", $result);
                 if ($score->length > 0) {
                     $subject->setDataAttribute(Namespaces::$wsf . "score", $score->item(0)->nodeValue);
                 }
             }
             // get possible locatedIn URI(s)
             $resultLocatedIn = $xpath->query("arr[@name='located_in']/str", $result);
             if ($resultLocatedIn->length > 0) {
                 $subject->setObjectAttribute(Namespaces::$geoname . "locatedIn", $resultLocatedIn->item(0)->nodeValue);
             }
             // get records description
             $resultDescriptionURI = $xpath->query("arr[@name='description_" . $this->ws->lang . "']/str", $result);
             if ($resultDescriptionURI->length > 0) {
                 $subject->setDescription($resultDescriptionURI->item(0)->nodeValue);
             }
             // Get all dynamic fields attributes that are multi-valued
             $resultProperties = $xpath->query("arr", $result);
             $objectPropertyLabels = array();
             $objectPropertyUris = array();
             foreach ($resultProperties as $property) {
                 $attribute = $property->getAttribute("name");
                 // Check what kind of attribute it is
                 $attributeType = $this->getSolrAttributeType($attribute);
                 // Get the URI of the attribute
                 $attributeURI = urldecode(str_replace($attributeType, "", $attribute));
                 // Exclude the attributes that have to be ignored by the Search endpoint
                 // when creating the new resultset.
                 if (array_search($attributeURI, $this->ws->searchExcludedAttributes) !== FALSE) {
                     continue;
                 }
                 if ($attributeURI == Namespaces::$rdf . "type") {
                     continue;
                 }
                 switch ($attributeType) {
                     case "_attr_" . $this->ws->lang:
                         $values = $property->getElementsByTagName("str");
                         foreach ($values as $value) {
                             $subject->setDataAttribute($attributeURI, $value->nodeValue);
                         }
                         break;
                     case "_attr_date":
                         $values = $property->getElementsByTagName("date");
                         foreach ($values as $value) {
                             $subject->setDataAttribute($attributeURI, $value->nodeValue, Datatypes::$date);
                         }
                         break;
                     case "_attr_int":
                         $values = $property->getElementsByTagName("int");
                         foreach ($values as $value) {
                             $subject->setDataAttribute($attributeURI, $value->nodeValue, Datatypes::$int);
                         }
                         break;
                     case "_attr_float":
                         $values = $property->getElementsByTagName("float");
                         foreach ($values as $value) {
                             $subject->setDataAttribute($attributeURI, $value->nodeValue, Datatypes::$float);
                         }
                         break;
                     case "_attr_obj_" . $this->ws->lang:
                         $values = $property->getElementsByTagName("str");
                         foreach ($values as $value) {
                             if (!is_array($objectPropertyLabels[$attributeURI])) {
                                 $objectPropertyLabels[$attributeURI] = array();
                             }
                             array_push($objectPropertyLabels[$attributeURI], $value->nodeValue);
                         }
                         break;
                     case "_attr_obj_uri":
                         $values = $property->getElementsByTagName("str");
                         foreach ($values as $value) {
                             if (!is_array($objectPropertyUris[$attributeURI])) {
                                 $objectPropertyUris[$attributeURI] = array();
                             }
                             array_push($objectPropertyUris[$attributeURI], $value->nodeValue);
                         }
                         break;
                     case "_reify_attr":
                     case "_reify_attr_obj":
                     case "_reify_obj":
                     case "_reify_value_" . $this->ws->lang:
                         // @todo Implement reification in Search result. This means that reified statements should appears in the resultsets.
                         break;
                 }
             }
             // Get all dynamic fields attributes that are single-valued and for which the value is a string
             $resultProperties = $xpath->query("str", $result);
             foreach ($resultProperties as $property) {
                 $attribute = $property->getAttribute("name");
                 // Check what kind of attribute it is
                 $attributeType = $this->getSolrAttributeType($attribute);
                 // Get the URI of the attribute
                 $attributeURI = urldecode(str_replace($attributeType, "", $attribute));
                 if ($attributeType == "_attr_" . $this->ws->lang . "_single_valued") {
                     $subject->setDataAttribute($attributeURI, $property->nodeValue);
                 }
             }
             // Get all dynamic fields attributes that are single-valued and for which the value is a date
             $resultProperties = $xpath->query("date", $result);
             foreach ($resultProperties as $property) {
                 $attribute = $property->getAttribute("name");
                 // Check what kind of attribute it is
                 $attributeType = $this->getSolrAttributeType($attribute);
                 // Get the URI of the attribute
                 $attributeURI = urldecode(str_replace($attributeType, "", $attribute));
                 if ($attributeType == "_attr_date_single_valued") {
                     $subject->setDataAttribute($attributeURI, $property->nodeValue, Datatypes::$date);
                 }
             }
             // Get all dynamic fields attributes that are single-valued and for which the value is a integer
             $resultProperties = $xpath->query("int", $result);
             foreach ($resultProperties as $property) {
                 $attribute = $property->getAttribute("name");
                 // Check what kind of attribute it is
                 $attributeType = $this->getSolrAttributeType($attribute);
                 // Get the URI of the attribute
                 $attributeURI = urldecode(str_replace($attributeType, "", $attribute));
                 if ($attributeType == "_attr_int_single_valued") {
                     $subject->setDataAttribute($attributeURI, $property->nodeValue, Datatypes::$int);
                 }
             }
             // Get all dynamic fields attributes that are single-valued and for which the value is a float
             $resultProperties = $xpath->query("float", $result);
             foreach ($resultProperties as $property) {
                 $attribute = $property->getAttribute("name");
                 // Check what kind of attribute it is
                 $attributeType = $this->getSolrAttributeType($attribute);
                 // Get the URI of the attribute
                 $attributeURI = urldecode(str_replace($attributeType, "", $attribute));
                 if ($attributeType == "_attr_float_single_valued") {
                     $subject->setDataAttribute($attributeURI, $property->nodeValue, Datatypes::$float);
                 }
             }
             foreach ($objectPropertyUris as $attributeUri => $objectUris) {
                 foreach ($objectUris as $key => $objectUri) {
                     if (isset($objectPropertyLabels[$attributeUri][$key])) {
                         $subject->setObjectAttribute($attributeUri, $objectUri, array(Namespaces::$wsf . "objectLabel" => array($label = $objectPropertyLabels[$attributeUri][$key])));
                     } else {
                         $subject->setObjectAttribute($attributeUri, $objectUri);
                     }
                 }
             }
             unset($objectPropertyUris);
             unset($objectPropertyLabels);
             // Get the types of the resource.
             $resultTypes = $xpath->query("arr[@name='type']/str", $result);
             for ($i = 0; $i < $resultTypes->length; ++$i) {
                 if ($resultTypes->item($i)->nodeValue != "-") {
                     $subject->setType($resultTypes->item($i)->nodeValue);
                 }
             }
             $this->ws->rset->addSubject($subject, $resultDatasetURI->item(0)->nodeValue);
         }
     }
 }