ConverterTsv.php
Go to the documentation of this file.
00001 <?php 00002 00005 00030 class ConverterTsv extends WebService 00031 { 00033 private $db; 00034 00036 private $conneg; 00037 00039 private $dtdURL; 00040 00042 private $text; 00043 00045 private $docmime; 00046 00048 private $type; 00049 00051 private $tsvResources; 00052 00054 private $baseURI; 00055 00057 private $errorMessages = ""; 00058 00060 private $requester_ip = ""; 00061 00063 private $registered_ip = ""; 00064 00066 private $delimiter = ""; 00067 00069 public static $supportedSerializations = 00070 array ("application/rdf+xml", "application/rdf+n3", "application/*", "text/tsv", "text/csv", "text/xml", "text/*", 00071 "*/*"); 00072 00074 private $errorMessenger = 00075 '{ 00076 "ws": "/ws/converter/irv/", 00077 "_200": { 00078 "id": "WS-CONVERTER-IRV-200", 00079 "level": "Warning", 00080 "name": "No data to convert", 00081 "description": "No data to convert" 00082 }, 00083 "_201": { 00084 "id": "WS-CONVERTER-IRV-201", 00085 "level": "Warning", 00086 "name": "Document mime not supported (supported mimes: text/tsv, text/csv and text/xml)", 00087 "description": "Document mime not supported (supported mimes: text/tsv, text/csv and text/xml)" 00088 }, 00089 "_300": { 00090 "id": "WS-CONVERTER-IRV-300", 00091 "level": "Warning", 00092 "name": "Parsing Errors", 00093 "description": "Parsing Errors" 00094 }, 00095 "_301": { 00096 "id": "WS-CONVERTER-IRV-301", 00097 "level": "Warning", 00098 "name": "No TSV data converted", 00099 "description": "No TSV data converted" 00100 } 00101 }'; 00102 00103 00122 function __construct($document = "", $docmime = "text/tsv", $delimiter = "\t", 00123 $base_uri = "http://www.baseuri.com/resource/", $registered_ip, $requester_ip) 00124 { 00125 parent::__construct(); 00126 00127 $this->text = $document; 00128 $this->baseURI = $base_uri; 00129 $this->docmime = $docmime; 00130 $this->delimiter = $delimiter; 00131 00132 $this->requester_ip = $requester_ip; 00133 00134 if($registered_ip == "") 00135 { 00136 $this->registered_ip = $requester_ip; 00137 } 00138 else 00139 { 00140 $this->registered_ip = $registered_ip; 00141 } 00142 00143 if(strtolower(substr($this->registered_ip, 0, 4)) == "self") 00144 { 00145 $pos = strpos($this->registered_ip, "::"); 00146 00147 if($pos !== FALSE) 00148 { 00149 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2)); 00150 00151 $this->registered_ip = $requester_ip . "::" . $account; 00152 } 00153 else 00154 { 00155 $this->registered_ip = $requester_ip; 00156 } 00157 } 00158 00159 $this->tsvResources = array(); 00160 00161 $this->uri = $this->wsf_base_url . "/wsf/ws/converter/tsv/"; 00162 $this->title = "TSV/CSV Converter Web Service"; 00163 $this->crud_usage = new CrudUsage(FALSE, TRUE, FALSE, FALSE); 00164 $this->endpoint = $this->wsf_base_url . "/ws/converter/tsv/"; 00165 00166 $this->dtdURL = "converter/bitsvbtex.dtd"; 00167 00168 $this->errorMessenger = json_decode($this->errorMessenger); 00169 } 00170 00171 function __destruct() 00172 { 00173 parent::__destruct(); 00174 00175 if(isset($this->db)) 00176 { 00177 $this->db->close(); 00178 } 00179 } 00180 00191 protected function validateQuery() { return; } 00192 00203 public function pipeline_getError() { return ($this->conneg->error); } 00204 00215 public function pipeline_getResultset() 00216 { 00217 if($this->docmime == "text/xml") 00218 { 00219 return ($this->text); 00220 } 00221 else 00222 { 00223 $xml = new ProcessorXML(); 00224 00225 $resultset = $xml->createResultset(); 00226 00227 foreach($this->tsvResources as $uri => $properties) 00228 { 00229 $subject = $xml->createSubject("http://www.w3.org/2002/07/owl#Thing", $this->baseURI . $this->uriEncode($uri)); 00230 00231 foreach($properties as $propertyValue) 00232 { 00233 $propertyValue[1] = trim($propertyValue[1]); 00234 00235 // check if the object of the TSV is a reference to another subject of the same document 00236 if(substr($propertyValue[0], 0, 1) == "{" 00237 && substr($propertyValue[0], strlen($propertyValue[0]) - 1, 1) == "}") 00238 { 00239 $property = $this->get_domain($this->baseURI) . "/ontology#" . $this->uriEncode($propertyValue[0]); 00240 $value = $this->baseURI . $this->uriEncode($propertyValue[1]); 00241 00242 $pred = $xml->createPredicate($property); 00243 $object = $xml->createObject("http://www.w3.org/2002/07/owl#Thing", $value); 00244 00245 $pred->appendChild($object); 00246 $subject->appendChild($pred); 00247 } 00248 else 00249 { 00250 $property = $this->get_domain($this->baseURI) . "/ontology#" . $this->uriEncode($propertyValue[0]); 00251 $value = $propertyValue[1]; 00252 00253 $pred = $xml->createPredicate($property); 00254 $object = $xml->createObjectContent($value); 00255 00256 $pred->appendChild($object); 00257 $subject->appendChild($pred); 00258 } 00259 } 00260 00261 $resultset->appendChild($subject); 00262 } 00263 00264 return ($this->injectDoctype($xml->saveXML($resultset))); 00265 } 00266 } 00267 00280 private function get_domain($url) 00281 { 00282 if(strlen($url) > 8) 00283 { 00284 $pos = strpos($url, "/", 8); 00285 00286 if($pos === FALSE) 00287 { 00288 return $url; 00289 } 00290 else 00291 { 00292 return substr($url, 0, $pos); 00293 } 00294 } 00295 else 00296 { 00297 return $url; 00298 } 00299 } 00300 00313 public function injectDoctype($xmlDoc) 00314 { 00315 $posHeader = strpos($xmlDoc, '"?>') + 3; 00316 $xmlDoc = substr($xmlDoc, 0, $posHeader) 00317 . "\n<!DOCTYPE resultset PUBLIC \"-//Bibliographic Knowledge Network//Converter TSV DTD 0.1//EN\" \"" 00318 . $this->dtdBaseURL . $this->dtdURL . "\">" . substr($xmlDoc, $posHeader, strlen($xmlDoc) - $posHeader); 00319 00320 return ($xmlDoc); 00321 } 00322 00323 00342 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00343 { 00344 $this->conneg = 00345 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, ConverterTsv::$supportedSerializations); 00346 00347 // No text to process? Throw an error. 00348 if($this->text == "") 00349 { 00350 $this->conneg->setStatus(400); 00351 $this->conneg->setStatusMsg("Bad Request"); 00352 $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name); 00353 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws, 00354 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "", 00355 $this->errorMessenger->_200->level); 00356 } 00357 00358 if($this->docmime != "text/csv" && $this->docmime != "text/tsv" && $this->docmime != "text/xml") 00359 { 00360 $this->conneg->setStatus(400); 00361 $this->conneg->setStatusMsg("Bad Request"); 00362 $this->conneg->setStatusMsgExt($this->errorMessenger->_201->name); 00363 $this->conneg->setError($this->errorMessenger->_201->id, $this->errorMessenger->ws, 00364 $this->errorMessenger->_201->name, $this->errorMessenger->_201->description, "", 00365 $this->errorMessenger->_201->level); 00366 } 00367 } 00368 00387 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00388 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); } 00389 00400 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); } 00401 00412 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); } 00413 00426 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); } 00427 00438 public function pipeline_serialize() 00439 { 00440 $rdf_part = ""; 00441 00442 switch($this->conneg->getMime()) 00443 { 00444 case "text/tsv": 00445 case "text/csv": 00446 $tsv = ""; 00447 $xml = new ProcessorXML(); 00448 $xml->loadXML($this->pipeline_getResultset()); 00449 00450 $subjects = $xml->getSubjects(); 00451 00452 foreach($subjects as $subject) 00453 { 00454 $subjectURI = $xml->getURI($subject); 00455 $subjectType = $xml->getType($subject); 00456 00457 $tsv .= str_replace($this->delimiter, urlencode($this->delimiter), $subjectURI) . $this->delimiter 00458 . "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" . $this->delimiter 00459 . str_replace($this->delimiter, urlencode($this->delimiter), $subjectType) . "\n"; 00460 00461 $predicates = $xml->getPredicates($subject); 00462 00463 foreach($predicates as $predicate) 00464 { 00465 $objects = $xml->getObjects($predicate); 00466 00467 foreach($objects as $object) 00468 { 00469 $objectType = $xml->getType($object); 00470 $predicateType = $xml->getType($predicate); 00471 $objectContent = $xml->getContent($object); 00472 00473 if($objectType == "rdfs:Literal") 00474 { 00475 $objectValue = $xml->getContent($object); 00476 $tsv .= str_replace($this->delimiter, urlencode($this->delimiter), $subjectURI) . $this->delimiter 00477 . str_replace($this->delimiter, urlencode($this->delimiter), $predicateType) . $this->delimiter 00478 . str_replace($this->delimiter, urlencode($this->delimiter), $objectValue) . "\n"; 00479 } 00480 else 00481 { 00482 $objectURI = $xml->getURI($object); 00483 $tsv .= str_replace($this->delimiter, urlencode($this->delimiter), $subjectURI) . $this->delimiter 00484 . str_replace($this->delimiter, urlencode($this->delimiter), $predicateType) . $this->delimiter 00485 . str_replace($this->delimiter, urlencode($this->delimiter), $objectURI) . "\n"; 00486 } 00487 } 00488 } 00489 } 00490 00491 return ($tsv); 00492 break; 00493 00494 case "application/rdf+n3": 00495 $xml = new ProcessorXML(); 00496 $xml->loadXML($this->pipeline_getResultset()); 00497 00498 $subjects = $xml->getSubjects(); 00499 00500 foreach($subjects as $subject) 00501 { 00502 $subjectURI = $xml->getURI($subject); 00503 $subjectType = $xml->getType($subject); 00504 00505 $rdf_part .= "\n <$subjectURI> a <$subjectType> ;\n"; 00506 00507 $predicates = $xml->getPredicates($subject); 00508 00509 foreach($predicates as $predicate) 00510 { 00511 $objects = $xml->getObjects($predicate); 00512 00513 foreach($objects as $object) 00514 { 00515 $objectType = $xml->getType($object); 00516 $predicateType = $xml->getType($predicate); 00517 $objectContent = $xml->getContent($object); 00518 00519 if($objectType == "rdfs:Literal") 00520 { 00521 $objectValue = $xml->getContent($object); 00522 $rdf_part .= " <$predicateType> \"\"\"" . str_replace(array( "\\" ), "\\\\", $objectValue) 00523 . "\"\"\" ;\n"; 00524 } 00525 else 00526 { 00527 $objectURI = $xml->getURI($object); 00528 $rdf_part .= " <$predicateType> <$objectURI> ;\n"; 00529 } 00530 } 00531 } 00532 00533 if(strlen($rdf_part) > 0) 00534 { 00535 $rdf_part = substr($rdf_part, 0, strlen($rdf_part) - 2) . ".\n"; 00536 } 00537 } 00538 00539 return ($rdf_part); 00540 break; 00541 00542 case "application/rdf+xml": 00543 $xml = new ProcessorXML(); 00544 $xml->loadXML($this->pipeline_getResultset()); 00545 00546 $subjects = $xml->getSubjects(); 00547 00548 $namespaces = array(); 00549 00550 $nsId = 0; 00551 00552 foreach($subjects as $subject) 00553 { 00554 $subjectURI = $xml->getURI($subject); 00555 $subjectType = $xml->getType($subject); 00556 00557 $ns = $this->getNamespace($subjectType); 00558 $stNs = $ns[0]; 00559 $stExtension = $ns[1]; 00560 00561 if(!isset($namespaces[$stNs])) 00562 { 00563 $namespaces[$stNs] = "ns" . $nsId; 00564 $nsId++; 00565 } 00566 00567 $rdf_part .= "\n <" . $namespaces[$stNs] . ":" . $stExtension . " rdf:about=\"". 00568 $this->xmlEncode($subjectURI)."\">\n"; 00569 00570 $predicates = $xml->getPredicates($subject); 00571 00572 foreach($predicates as $predicate) 00573 { 00574 $objects = $xml->getObjects($predicate); 00575 00576 foreach($objects as $object) 00577 { 00578 $objectType = $xml->getType($object); 00579 $predicateType = $xml->getType($predicate); 00580 00581 if($objectType == "rdfs:Literal") 00582 { 00583 $objectValue = $xml->getContent($object); 00584 00585 $ns = $this->getNamespace($predicateType); 00586 $ptNs = $ns[0]; 00587 $ptExtension = $ns[1]; 00588 00589 if(!isset($namespaces[$ptNs])) 00590 { 00591 $namespaces[$ptNs] = "ns" . $nsId; 00592 $nsId++; 00593 } 00594 00595 $rdf_part .= " <" . $namespaces[$ptNs] . ":" . $ptExtension . ">" 00596 . $this->xmlEncode($objectValue) . "</" . $namespaces[$ptNs] . ":" . $ptExtension . ">\n"; 00597 } 00598 else 00599 { 00600 $objectURI = $xml->getURI($object); 00601 00602 $ns = $this->getNamespace($predicateType); 00603 $ptNs = $ns[0]; 00604 $ptExtension = $ns[1]; 00605 00606 if(!isset($namespaces[$ptNs])) 00607 { 00608 $namespaces[$ptNs] = "ns" . $nsId; 00609 $nsId++; 00610 } 00611 00612 $rdf_part .= " <" . $namespaces[$ptNs] . ":" . $ptExtension 00613 . " rdf:resource=\"".$this->xmlEncode($objectURI)."\" />\n"; 00614 } 00615 } 00616 } 00617 00618 $rdf_part .= " </" . $namespaces[$stNs] . ":" . $stExtension . ">\n"; 00619 } 00620 00621 $rdf_header = 00622 "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:wsf=\"http://purl.org/ontology/wsf#\""; 00623 00624 foreach($namespaces as $ns => $prefix) 00625 { 00626 $rdf_header .= " xmlns:$prefix=\"$ns\""; 00627 } 00628 00629 $rdf_header .= ">\n\n"; 00630 00631 $rdf_part = $rdf_header . $rdf_part; 00632 00633 return ($rdf_part); 00634 break; 00635 } 00636 } 00637 00646 public function pipeline_serialize_reification() { return ""; } 00647 00658 public function ws_serialize() 00659 { 00660 // Check for parsing errors 00661 if($this->tsvParsingError() === TRUE) 00662 { 00663 $this->conneg->setStatus(400); 00664 $this->conneg->setStatusMsg("Bad Request"); 00665 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name); 00666 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws, 00667 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description, $this->errorMessages, 00668 $this->errorMessenger->_300->level); 00669 00670 return; 00671 } 00672 else 00673 { 00674 switch($this->conneg->getMime()) 00675 { 00676 case "text/tsv": 00677 case "text/csv": 00678 return $this->pipeline_serialize(); 00679 break; 00680 00681 case "application/rdf+n3": 00682 $rdf_document = ""; 00683 $rdf_document .= "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"; 00684 $rdf_document .= "@prefix wsf: <http://purl.org/ontology/wsf#> .\n"; 00685 00686 $rdf_document .= $this->pipeline_serialize(); 00687 00688 $rdf_document .= $this->pipeline_serialize_reification(); 00689 00690 return $rdf_document; 00691 break; 00692 00693 case "application/rdf+xml": 00694 $rdf_document = ""; 00695 $rdf_document .= "<?xml version=\"1.0\"?>\n"; 00696 00697 $rdf_document .= $this->pipeline_serialize(); 00698 00699 $rdf_document .= $this->pipeline_serialize_reification(); 00700 00701 $rdf_document .= "</rdf:RDF>"; 00702 00703 return $rdf_document; 00704 break; 00705 00706 case "text/xml": 00707 return $this->pipeline_getResultset(); 00708 break; 00709 } 00710 } 00711 } 00712 00725 private function getNamespace($uri) 00726 { 00727 $pos = strpos($uri, "#"); 00728 00729 if($pos !== FALSE) 00730 { 00731 return array (substr($uri, 0, $pos) . "#", substr($uri, $pos + 1, strlen($uri) - ($pos + 1))); 00732 } 00733 else 00734 { 00735 $pos = strrpos($uri, "/"); 00736 00737 if($pos !== FALSE) 00738 { 00739 return array (substr($uri, 0, $pos) . "/", substr($uri, $pos + 1, strlen($uri) - ($pos + 1))); 00740 } 00741 } 00742 00743 return (FALSE); 00744 } 00745 00746 00759 private function uriEncode($uri) 00760 { 00761 $uri = preg_replace("|[^a-zA-z0-9]|", " ", $uri); 00762 $uri = preg_replace("/\s+/", " ", $uri); 00763 $uri = str_replace(" ", "_", $uri); 00764 00765 return ($uri); 00766 } 00767 00768 00781 public function ws_respond($content) 00782 { 00783 // First send the header of the request 00784 $this->conneg->respond(); 00785 00786 // second, send the content of the request 00787 00788 // Make sure there is no error. 00789 if($this->conneg->getStatus() == 200) 00790 { 00791 echo $content; 00792 } 00793 00794 $this->__destruct(); 00795 } 00796 00807 private function tsvParsingError() { return FALSE; 00808 00809 /* 00810 $validClasses = array("bkn:Affiliation", "bkn:Bibliography", "bkn:Biography", "bkn:CurriculumVitae", "bkn:Department", "bkn:Homepage", "bkn:Honor", "bkn:Interview", "bkn:Library", "bkn:Memorial", "bkn:News", "bkn:Obituary", "bkn:PhotoGallery", "bkn:PreprintBibliography", "bkn:Profile", "bkn:Publisher", "bkn:Quotes", "bkn:Relation", "bkn:Society", "bkn:University", "bkn-base:Astrophysics", "bkn-base:Biology", "bkn-base:BooleanFunctions", "bkn-base:CirclePackings", "bkn-base:CoarseGeometry", "bkn-base:ComputerScience", "bkn-base:ConformalGeometry", "bkn-base:Economics", "bkn-base:GameTheory", "bkn-base:Geometry", "bkn-base:Mathematics", "bkn-base:Probabilities", "bkn-base:RandomWalks", "bkn-base:SchrammLoewnerEvolutions", "bkn-base:Statistics", "bibo:AcademicArticle", "bibo:Article", "bibo:Book", "bibo:BookSection", "bibo:Chapter", "bibo:CollectedDocument", "bibo:Collection", "bibo:Document", "bibo:DocumentPart", "bibo:EditedBook", "bibo:Email", "bibo:Excerpt", "bibo:Issue", "bibo:Journal", "bibo:Letter", "bibo:Magazine", "bibo:Manual", "bibo:Manuscript", "bibo:Newspaper", "bibo:Note", "bibo:Patent", "bibo:Periodical", "bibo:Proceedings", "bibo:Quote", "bibo:ReferenceSource", "bibo:Report", "bibo:Series", "bibo:Slide", "bibo:Slideshow", "bibo:Standard", "bibo:Thesis", "bibo:Webpage", "bibo:Website", "foaf:Agent", "foaf:Organization", "foaf:Person", "bio:Death", "umbel:SubjectConcept", "bkn:Software", "bkn:Service", "bkn:Job", "bkn:Mactutor", "bibo:Transcript", "bkn:Encyclopedia"); 00811 00812 $validProperties = array("bkn:ar", "bkn:mscmr", "bkn:arxiv","bkn:authorTex","bkn:titleTex","bkn:euclid","bkn:mrClass","bkn:mrNumber","bkn:url","bkn:position","bkn:affiliatedTo","bkn:affiliation","bkn:agent","bkn:associatedDepartment","bibo:abstract","bibo:asin","bibo:chapter","bibo:coden","bibo:doi","bibo:eanucc13","bibo:edition","bibo:eissn","bibo:gtin14","bibo:identifier","bibo:isbn10","bibo:isbn13","bibo:issn","bibo:lccn","bibo:locator","bibo:number","bibo:oclcnum","bibo:pageEnd","bibo:pages","bibo:pageStart","bibo:pmid","bibo:prefixName","bibo:section","bibo:shortDescription","bibo:shortTitle","bibo:sici","bibo:suffixName","bibo:upc","bibo:volume","bibo:annotates","bibo:degree","bibo:distributor","bibo:editor","bibo:interviewee","bibo:interviewer","bibo:issuer","bibo:owner","bibo:reproducedIn","bibo:reviewOf","bibo:status","bibo:transcriptOf","bibo:translationOf","bibo:translator","address:localityName","dcterms:created","dcterms:date","dcterms:dateAccepted","dcterms:dateCopyrighted","dcterms:dateSubmitted","dcterms:description","dcterms:issued","dcterms:modified","dcterms:publisher","dcterms:title","dcterms:contributor","dcterms:creator","dcterms:format","dcterms:hasPart","dcterms:isPartOf","dcterms:language","dcterms:license","dcterms:mediator","dcterms:publisher","dcterms:replaces","dcterms:requires","dcterms:rightsHolder","dcterms:type","foaf:accountName","foaf:birthdate","foaf:family_name","foaf:gender","foaf:givenname","foaf:name","foaf:nick","foaf:phone","foaf:topic_interest","foaf:depiction","foaf:homepage","foaf:interest","foaf:knows","foaf:logo","foaf:made","foaf:member","foaf:page","foaf:weblog","foaf:workInfoHomepage","bio:event","skos:note","rdf:type","rdfs:seeAlso","umbel:isAbout", "bio:date", "skos:prefLabel", "skos:altLabel"); 00813 00814 00815 $nbErrors = 0; 00816 */ 00817 /* 00818 Array 00819 ( 00820 [http_www_math_cornell_edu_People_Faculty_kesten_html] => Array 00821 ( 00822 [0] => Array 00823 ( 00824 [0] => rdf:type 00825 [1] => {bkn:Homepage} 00826 ) 00827 00828 [1] => Array 00829 ( 00830 [0] => bkn:url 00831 [1] => http://www.math.cornell.edu/People/Faculty/kesten.html 00832 ) 00833 00834 ) 00835 ) 00836 */ 00837 /* 00838 $bknTemps = array(); 00839 00840 foreach($this->tsvResources as $uri => $properties) 00841 { 00842 foreach($properties as $propertyValue) 00843 { 00844 if($propertyValue[0] == "rdf:type") 00845 { 00846 $propertyValue[1] = substr($propertyValue[1], 1, strlen($propertyValue[1]) - 2 ); 00847 00848 // Check if it is a BKN-TEMP property or class. 00849 if(substr($propertyValue[1], 0, 9) == "bkn-temp:") 00850 { 00851 array_push($bknTemps, array($propertyValue[1], "http://www.w3.org/2000/01/rdf-schema#Class")); 00852 } 00853 else 00854 { 00855 // Check if this is a valid Class 00856 if(array_search($propertyValue[1], $validClasses) === FALSE) 00857 { 00858 $this->errorMessages .= "<b>Error:</b> the use of the Class <b><$propertyValue[1]></b> is invalid when describing resource <b><$uri></b>.<br /><br />\n"; 00859 $nbErrors++; 00860 } 00861 } 00862 } 00863 else 00864 { 00865 // Check if it is a BKN-TEMP property or class. 00866 if(substr($propertyValue[0], 0, 9) == "bkn-temp:") 00867 { 00868 array_push($bknTemps, array($propertyValue[0], "http://www.w3.org/2000/01/rdf-schema#Property")); 00869 } 00870 else 00871 { 00872 // Check if this is a valid Property 00873 if(array_search($propertyValue[0], $validProperties) === FALSE) 00874 { 00875 $this->errorMessages .= "<b>Error:</b> the use of the Property <b><$propertyValue[0]></b> is invalid when describing resource <b><$uri></b>.<br /><br />\n"; 00876 $nbErrors++; 00877 } 00878 } 00879 } 00880 } 00881 } 00882 00883 // Handle the BKN-TEMPS classes and properties 00884 if(count($bknTemps) > 0) 00885 { 00886 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host); 00887 00888 $bknTempsN3 = "@prefix bkn-temp: <http://purl.org/ontology/bkn/temp#> .\n"; 00889 00890 foreach($bknTemps as $temp) 00891 { 00892 $bknTempsN3 .= "$temp[0] a <$temp[1]> .\n"; 00893 } 00894 00895 00896 $this->db->query("DB.DBA.TTLP_MT('".$bknTempsN3."', 'http://purl.org/ontology/bkn/temp#', 'http://purl.org/ontology/bkn/temp#')"); 00897 00898 $this->db->close(); 00899 } 00900 00901 if($this->errorMessages != "") 00902 { 00903 $this->errorMessages = "<b>$nbErrors errors.</b><br /><br />\n".$this->errorMessages; 00904 00905 return(TRUE); 00906 } 00907 00908 return(FALSE); */ 00909 } 00910 00919 public function process() 00920 { 00921 if($this->conneg->getStatus() == 200) 00922 { 00923 switch($this->docmime) 00924 { 00925 case "text/tsv": 00926 case "text/csv": 00927 $parser = new TsvParser($this->text, $this->delimiter); 00928 00929 $this->tsvResources = $parser->resources; 00930 00931 if(count($this->tsvResources) <= 0) 00932 { 00933 $this->conneg->setStatus(400); 00934 $this->conneg->setStatusMsg("Bad Request"); 00935 $this->conneg->setStatusMsgExt($this->errorMessenger->_301->name); 00936 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws, 00937 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, "", 00938 $this->errorMessenger->_301->level); 00939 } 00940 break; 00941 00942 case "text/xml": break; 00943 } 00944 } 00945 } 00946 } 00947 00949 00950 ?>
