ConverterBibtex.php
Go to the documentation of this file.
00001 <?php 00002 00005 00030 class ConverterBibtex 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 $bibItems; 00049 00051 private $baseURI; 00052 00054 private $errorMessages = ""; 00055 00057 public static $supportedSerializations = 00058 array ("application/rdf+xml", "application/rdf+n3", "application/*", "text/xml", "application/x-bibtex", "text/*", 00059 "*/*"); 00060 00062 private $enhancedBibtex = FALSE; 00063 00065 private $requester_ip = ""; 00066 00068 private $registered_ip = ""; 00069 00071 private $bibTypes = array ( // Standard BIBTEX 00072 "book" => "bibo:Book", "booklet" => "bibo:Book", "misc" => "bibo:Document", "article" => "bibo:Article", 00073 "inbook" => "bibo:Chapter", "manual" => "bibo:Manual", "inproceedings" => "bibo:Article", 00074 "conference" => "bibo:Article", "unpublished" => "bibo:Document", "masterthesis" => "bibo:Thesis", 00075 "phdthesis" => "bibo:Thesis", "proceedings" => "bibo:Proceedings", "techreport" => "bibo:Report", 00076 "incollection" => "bibo:BookSection", "heading" => "bibo:Collection", "subject" => "umbel:SubjectConcept", 00077 "person" => "foaf:Person"); 00078 00080 private $bibTypesAdditionalProperties = array ( // Standard BIBTEX 00081 "unpublished" => array ("bibo:status", "http://purl.org/ontology/bibo/status/unpublished"), 00082 "masterthesis" => array ("bibo:degree", "http://purl.org/ontology/bibo/degrees/ma"), 00083 "phdthesis" => array ("bibo:degree", "http://purl.org/ontology/bibo/degrees/phd")); 00084 00085 /* 00086 Dropped from core: - howpublished 00087 - key 00088 - annote 00089 */ 00090 00091 /* 00092 BIBTYPES (custom): HEADING, PERSON, SUBJECTS 00093 00094 HEADING ??? 00095 ID ??? 00096 KEY_AU ??? 00097 AUTHOR_AR ??? 00098 AUTHOR_ID_MR ??? (not used) 00099 BUT ??? 00100 POST (what posted refers to?) 00101 HOWPUBLISHED (same as publisher?) 00102 HOWPUBLISHED_AR (what AR refers to?) 00103 00104 00105 FJOURNAL (why duplicating journal for fjournal (only a change in the name); This should appears in the description of the journal itself.) 00106 MRREVIEWER 00107 00108 */ 00109 00111 private $bibProperties = array ( // Standard BIBTEX 00112 "title" => "dcterms:title", "author" => "dcterms:creator", "booktitle" => "dcterms:title", 00113 "publisher" => "dcterms:publisher", "year" => "dcterms:date", "month" => "dcterms:date", "isbn" => "bibo:isbn", 00114 "editor" => "bibo:editor", "institution" => "dcterms:contributor", "volume" => "bibo:volume", "url" => "bkn:url", 00115 "type" => "dcterms:type", "series" => "dcterms:isPartOf", 00116 // "school" => "rdfs:seeAlso", 00117 "pages" => "bibo:pages", "organization" => "bibo:organizer", "number" => "bibo:number", "note" => "skos:note", 00118 "journal" => "dcterms:isPartOf", "edition" => "bibo:edition", "chapter" => "bibo:chapter", 00119 "address" => "address:localityName", 00120 // "eprint" => "rdfs:seeAlso", 00121 "eprint" => "bkn:eprint", "crossref" => "dcterms:isPartOf", "name" => "foaf:name", "homepage" => "foaf:homepage", 00122 "last_updated" => "dcterms:modified", "bibliography" => "foaf:page", "honor" => "foaf:page", 00123 "born_date" => "foaf:birthdate", "death_date" => "bio:event", "image" => "foaf:page", "memorial" => "foaf:page", 00124 "biography" => "foaf:page", "url" => "bkn:url", "author_tex" => "bkn:authorTex", "title_tex" => "bkn:titleTex", 00125 "coden" => "bibo:coden", "sici" => "bibo:sici", "mrclass" => "bkn:mrClass", "mrnumber" => "bkn:mrNumber", 00126 "arxiv" => "bkn:arxiv", "euclid" => "bkn:euclid", "id_ar" => "bkn:ar", "msc_mr" => "bkn:mscmr", 00127 "comment" => "skos:note", "comment_post" => "skos:note", "rev" => "dcterms:modified", "date" => "dcterms:date", 00128 "subjectTitle" => "skos:prefLabel", "subjects" => "umbel:isAbout", 00129 // "howpublished" => "dcterms:publisher", 00130 // "howpublished_ar" => "dcterms:publisher", 00131 00132 00133 // Bibsonomy.org BIBTEX extension 00134 "biburl" => "bkn:url", "keywords" => "dcterms:subject", "abstract" => "bibo:abstract", "asin" => "bibo:asin", 00135 "ean" => "bibo:eanucc13", "doi" => "bibo:doi", "issn" => "bibo:issn", "description" => "dcterms:description"); 00136 00137 // Sometimes a bibtex property introduce a new resource. In such a case, we have to specify what is the type 00138 // of the resource, and the property where the value of the bibtex property will be converted. 00139 // 00140 // For example, the property "author" suggest that a bibtex item refers to a person resource. 00141 // This property is clearly introducing a new resource. This new resource will be of type "foaf:Person" and the 00142 // value of this bibtex property will be described using the "foaf:name" property. 00143 00144 00146 private $bibPropertiesAdditionalObjects = array ( // Standard BIBTEX 00147 "author" => array ("foaf:Agent", "foaf:name"), "publisher" => array ("foaf:Organization", "foaf:name"), 00148 "editor" => array ("foaf:Person", "foaf:name"), "institution" => array ("foaf:Organization", "foaf:name"), 00149 "series" => array ("bibo:Series", "dcterms:title"), 00150 // "school" => array("foaf:Organization", "foaf:name"), 00151 "organization" => array ("foaf:Organization", "foaf:name"), "journal" => array ("bibo:Journal", "dcterms:title"), 00152 // "eprint" => array("bibo:Document", "dcterms:title"), 00153 "homepage" => array ("bkn:Homepage", "bkn:url"), "honor" => array ("bkn:Honor", "bkn:url"), 00154 "image" => array ("bkn:PhotoGallery", "bkn:url"), "memorial" => array ("bkn:Memorial", "bkn:url"), 00155 "biography" => array ("bkn:Biography", "bkn:url"), "bibliography" => array ("bkn:Bibliography", "bkn:url"), 00156 "death_date" => array ("bio:Death", "bio:date"),); 00157 00175 function __construct($document = "", $docmime = "application/x-bibtex", 00176 $base_uri = "http://www.baseuri.com/resource/", $registered_ip, $requester_ip) 00177 { 00178 parent::__construct(); 00179 00180 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host); 00181 00182 $this->docmime = $docmime; 00183 $this->text = $document; 00184 $this->baseURI = $base_uri; 00185 00186 $this->requester_ip = $requester_ip; 00187 00188 if($registered_ip == "") 00189 { 00190 $this->registered_ip = $requester_ip; 00191 } 00192 else 00193 { 00194 $this->registered_ip = $registered_ip; 00195 } 00196 00197 if(strtolower(substr($this->registered_ip, 0, 4)) == "self") 00198 { 00199 $pos = strpos($this->registered_ip, "::"); 00200 00201 if($pos !== FALSE) 00202 { 00203 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2)); 00204 00205 $this->registered_ip = $requester_ip . "::" . $account; 00206 } 00207 else 00208 { 00209 $this->registered_ip = $requester_ip; 00210 } 00211 } 00212 00213 $this->bibItems = array(); 00214 00215 $this->uri = $this->wsf_base_url . "/wsf/ws/converter/bibtex/"; 00216 $this->title = "Bibtex Converter Web Service"; 00217 $this->crud_usage = new CrudUsage(FALSE, TRUE, FALSE, FALSE); 00218 $this->endpoint = $this->wsf_base_url . "/ws/converter/bibtex/"; 00219 00220 $this->dtdURL = "converter/bibtex.dtd"; 00221 } 00222 00223 function __destruct() 00224 { 00225 parent::__destruct(); 00226 00227 if(isset($this->db)) 00228 { 00229 $this->db->close(); 00230 } 00231 } 00232 00243 protected function validateQuery() { return; } 00244 00245 00258 private function uriEncode($uri) 00259 { 00260 $uri = preg_replace("|[^a-zA-z0-9]|", " ", $uri); 00261 $uri = preg_replace("/\s+/", " ", $uri); 00262 $uri = str_replace(" ", "_", $uri); 00263 00264 return ($uri); 00265 } 00266 00267 // Communication structure 00268 /* 00269 00270 <!DOCTYPE resultset PUBLIC "-//BKN //Bibtex Converter DTD 0.1//EN" "http://bknetwork.org:8890/ws/dtd/converter/bibtex.dtd"> 00271 <resultset> 00272 <subject type="bibo:Book" uri="http://baseuri.com/companion"> 00273 <predicate type="dcterms:title"> 00274 <object type="rdfs:Literal">The {{\LaTeX}} {C}ompanion</object> 00275 </predicate> 00276 <predicate type="dcterms:creator"> 00277 <object type="rdfs:Literal">Goossens, Michel and Mittelbach, Franck and Samarin, Alexander</object> 00278 </predicate> 00279 <predicate type="dcterms:date"> 00280 <object type="rdfs:Literal">December 1993</object> 00281 </predicate> 00282 <predicate type="bibo:isbn"> 00283 <object type="rdfs:Literal">0-201-54199-8</object> 00284 </predicate> 00285 <predicate type="dcterms:publisher"> 00286 <object type="foaf:Organization" uri="http://baseuri.com/md5_hash_123456" label="AW"/> 00287 </predicate> 00288 </subject> 00289 <subject type="foaf:Organization" uri="http://baseuri.com/md5_hash_123456"> 00290 <predicate type="foaf:name"> 00291 <object type="rdfs:Literal">AW</object> 00292 </predicate> 00293 </subject> 00294 </resultset> 00295 00296 */ 00297 00308 public function pipeline_getResultset() 00309 { 00310 if($this->docmime == "text/xml") 00311 { 00312 return ($this->text); 00313 } 00314 else 00315 { 00316 $xml = new ProcessorXML(); 00317 00318 // Creation of the RESULTSET 00319 $resultset = $xml->createResultset(); 00320 00321 // Creation of the prefixes elements. 00322 $void = $xml->createPrefix("owl", "http://www.w3.org/2002/07/owl#"); 00323 $resultset->appendChild($void); 00324 $rdf = $xml->createPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); 00325 $resultset->appendChild($rdf); 00326 $dcterms = $xml->createPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); 00327 $resultset->appendChild($dcterms); 00328 $dcterms = $xml->createPrefix("wsf", "http://purl.org/ontology/wsf#"); 00329 $resultset->appendChild($dcterms); 00330 00331 00332 // Check if we are handling a collection of documents compiled by someone. 00333 if($this->enhancedBibtex) 00334 { 00335 foreach($this->bibItems as $item) 00336 { 00337 if($item->itemType == "heading") 00338 { 00339 $this->processingCollection = $item->itemID; 00340 break; 00341 } 00342 } 00343 } 00344 00345 foreach($this->bibItems as $item) 00346 { 00347 // Creation of a SUBJECT of the RESULTSET 00348 00349 if(!isset($this->bibTypes[$item->itemType])) 00350 { 00351 $item->itemType = "misc"; 00352 } 00353 00354 $subject = 00355 $xml->createSubject($this->bibTypes[$item->itemType], $this->baseURI . $this->uriEncode($item->itemID)); 00356 00357 // If we are processing a collection, lets make the link between the item and that collection. 00358 if($this->processingCollection != "" && $this->processingCollection != $item->itemID 00359 && $item->itemType != "subject" && $item->itemType != "person") 00360 { 00361 $pred = $xml->createPredicate("dcterms:isPartOf"); 00362 $object = $xml->createObject("", $this->baseURI . $this->uriEncode($this->processingCollection)); 00363 00364 $pred->appendChild($object); 00365 $subject->appendChild($pred); 00366 } 00367 00368 // Lets add the additional properties that define this bibtex item type 00369 if(isset($this->bibTypesAdditionalProperties[$item->itemType])) 00370 { 00371 // Creation of the predicate 00372 $pred = $xml->createPredicate($this->bibTypesAdditionalProperties[$item->itemType][0]); 00373 00374 // Creation of the OBJECT of the predicate 00375 $object = $xml->createObject("", $this->bibTypesAdditionalProperties[$item->itemType][1]); 00376 00377 $pred->appendChild($object); 00378 $subject->appendChild($pred); 00379 } 00380 00381 // Now lets convert all the bibtex item properties 00382 foreach($item->properties as $property => $value) 00383 { 00384 if(isset($this->bibProperties[$property])) 00385 { 00386 // Check if we have a enhanced bibtex file 00387 $processed = FALSE; 00388 00389 if($this->enhancedBibtex) 00390 { 00391 if($property == "author" || $property == "subjects") 00392 { 00393 // Lets explode and create authors 00394 $authors = explode(",", $value); 00395 00396 foreach($authors as $author) 00397 { 00398 // Creation of the predicate 00399 $pred = $xml->createPredicate($this->bibProperties[$property]); 00400 $object = $xml->createObject("", $this->baseURI . $this->uriEncode($author)); 00401 $pred->appendChild($object); 00402 00403 $subject->appendChild($pred); 00404 } 00405 00406 $processed = TRUE; 00407 } 00408 } 00409 00410 if($processed === FALSE) 00411 { 00412 // Creation of the predicate 00413 $pred = $xml->createPredicate($this->bibProperties[$property]); 00414 00415 if(isset($this->bibPropertiesAdditionalObjects[$property])) 00416 { 00417 $object = $xml->createObject("", $this->baseURI . $this->uriEncode($value)); 00418 $pred->appendChild($object); 00419 00420 // Lets create the new subject 00421 $subSubject = $xml->createSubject($this->bibPropertiesAdditionalObjects[$property][0], 00422 $this->baseURI . $this->uriEncode($value)); 00423 $subPred = $xml->createPredicate($this->bibPropertiesAdditionalObjects[$property][1]); 00424 $subObject = $xml->createObjectContent(str_replace("\\", "%5C", $value)); 00425 00426 $subPred->appendChild($subObject); 00427 $subSubject->appendChild($subPred); 00428 $resultset->appendChild($subSubject); 00429 } 00430 else 00431 { 00432 // Creation of the OBJECT of the predicate 00433 $object = $xml->createObjectContent(str_replace("\\", "%5C", $value)); 00434 00435 $pred->appendChild($object); 00436 } 00437 00438 $subject->appendChild($pred); 00439 } 00440 } 00441 } 00442 00443 $resultset->appendChild($subject); 00444 } 00445 00446 return ($this->injectDoctype($xml->saveXML($resultset))); 00447 } 00448 } 00449 00462 public function injectDoctype($xmlDoc) 00463 { 00464 $posHeader = strpos($xmlDoc, '"?>') + 3; 00465 $xmlDoc = substr($xmlDoc, 0, $posHeader) 00466 . "\n<!DOCTYPE resultset PUBLIC \"-//Bibliographic Knowledge Network//Converter BibTeX DTD 0.1//EN\" \"" 00467 . $this->dtdBaseURL . $this->dtdURL . "\">" . substr($xmlDoc, $posHeader, strlen($xmlDoc) - $posHeader); 00468 00469 return ($xmlDoc); 00470 } 00471 00490 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00491 { 00492 $this->conneg = new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, 00493 ConverterBibtex::$supportedSerializations); 00494 00495 // No text to process? Throw an error. 00496 if($this->text == "") 00497 { 00498 $this->conneg->setStatus(400); 00499 $this->conneg->setStatusMsg("Bad Request"); 00500 $this->conneg->setStatusMsgExt("No data to convert"); 00501 } 00502 00503 if($this->docmime != "application/x-bibtex" && $this->docmime != "text/xml") 00504 { 00505 $this->conneg->setStatus(400); 00506 $this->conneg->setStatusMsg("Bad Request"); 00507 $this->conneg->setStatusMsgExt( 00508 "Document mime not supported (supported mimes: application/x-bibtex and text/xml)"); 00509 } 00510 } 00511 00530 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00531 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); } 00532 00543 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); } 00544 00555 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); } 00556 00569 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); } 00570 00588 private function get_uri_label($uri) 00589 { 00590 // Find the base URI of the ontology 00591 $pos = strripos($uri, "#"); 00592 00593 if($pos === FALSE) 00594 { 00595 $pos = strripos($uri, "/"); 00596 } 00597 00598 if($pos !== FALSE) 00599 { 00600 $pos++; 00601 } 00602 00603 // Save the URI of the ontology 00604 $onto = substr($uri, 0, $pos); 00605 00606 // Save the URI of the class or property passed in parameter 00607 $resource = substr($uri, $pos, strlen($uri) - $pos); 00608 00609 // This statement associate a base ontology URI to its prefix. 00610 switch($onto) 00611 { 00612 case "http://xmlns.com/foaf/0.1/": 00613 return "foaf:" . $resource; 00614 break; 00615 00616 case "http://purl.org/umbel/sc/": 00617 case "http://purl.org/umbel/ac/": 00618 case "http://umbel.org/ns/": 00619 case "http://umbel.org/ns/sc/": 00620 case "http://umbel.org/ns/ac/": 00621 case "http://umbel.org/umbel/": 00622 case "http://umbel.org/umbel#": 00623 case "http://umbel.org/umbel/sc/": 00624 case "http://umbel.org/umbel/ac/": 00625 return "umbel:" . $resource; 00626 break; 00627 00628 case "http://www.w3.org/2000/01/rdf-schema#": 00629 return "rdfs:" . $resource; 00630 break; 00631 00632 case "http://www.w3.org/1999/02/22-rdf-syntax-ns#": 00633 return "rdf:" . $resource; 00634 break; 00635 00636 case "http://www.w3.org/2002/07/owl#": 00637 return "owl:" . $resource; 00638 break; 00639 00640 case "http://purl.org/dc/terms/": 00641 return "dcterms:" . $resource; 00642 break; 00643 00644 case "http://www.w3.org/2004/02/skos/core#": 00645 case "http://www.w3.org/2008/05/skos#": 00646 return "skos:" . $resource; 00647 break; 00648 00649 case "http://purl.org/ontology/bibo/": 00650 return "bibo:" . $resource; 00651 break; 00652 00653 case "http://purl.org/ontology/bkn#": 00654 return "bkn:" . $resource; 00655 break; 00656 00657 case "http://purl.org/vocab/bio/0.1/": 00658 return "bio:" . $resource; 00659 break; 00660 00661 case "http://schemas.talis.com/2005/address/schema#": 00662 return "address:" . $resource; 00663 break; 00664 00665 // By default, we return the "un-prefixed" URI passed in parameter. 00666 default: 00667 return $uri; 00668 break; 00669 } 00670 } 00671 00682 public function pipeline_serialize() 00683 { 00684 $rdf_part = ""; 00685 00686 switch($this->conneg->getMime()) 00687 { 00688 case "application/x-bibtex": 00689 $bibtex = ""; 00690 00691 $xml = new ProcessorXML(); 00692 $xml->loadXML($this->pipeline_getResultset()); 00693 00694 $subjects = $xml->getSubjects(); 00695 00696 $nbConvertedItems = 0; 00697 00698 foreach($subjects as $subject) 00699 { 00700 $subjectURI = $xml->getURI($subject); 00701 $subjectType = $xml->getType($subject); 00702 00703 // Check if the type of this subject is mappable to BibTeX 00704 $subjectType = $this->get_uri_label($subjectType); 00705 00706 if(($bibType = array_search($subjectType, $this->bibTypes)) !== FALSE) 00707 { 00708 $bibtex .= "@" . $bibType . "{" . $subjectURI . " \n"; 00709 } 00710 else 00711 { 00712 // If the type is unknow as a bibtex type, then we continue and doesnt convert that subject. 00713 continue; 00714 } 00715 00716 // Check if the properties of this subject are mappable to BibTeX 00717 00718 $predicates = $xml->getPredicates($subject); 00719 00720 foreach($predicates as $predicate) 00721 { 00722 $objects = $xml->getObjects($predicate); 00723 $predicateType = $this->get_uri_label($xml->getType($predicate)); 00724 00725 $bibPropertyType; 00726 00727 if(($bibPropertyType = array_search($predicateType, $this->bibProperties)) === FALSE) 00728 { 00729 // If the predicate is unmappable, we skip it 00730 continue; 00731 } 00732 00733 $nbConvertedItems++; 00734 00735 foreach($objects as $object) 00736 { 00737 $objectType = $xml->getType($object); 00738 00739 if($objectType == "rdfs:Literal") 00740 { 00741 $objectValue = $xml->getContent($object); 00742 00743 $bibtex .= " $bibPropertyType = \"$objectValue\",\n"; 00744 } 00745 else 00746 { 00747 $objectLabel = $xml->getLabel($object); 00748 00749 if($objectLabel == "") 00750 { 00751 $objectURI = $xml->getURI($object); 00752 $bibtex .= " $bibPropertyType = \"$objectURI\",\n"; 00753 } 00754 else 00755 { 00756 $bibtex .= " $bibPropertyType = \"$objectLabel\",\n"; 00757 } 00758 } 00759 } 00760 } 00761 00762 $bibtex .= "}\n"; 00763 } 00764 00765 if($nbConvertedItems == 0) 00766 { 00767 $this->conneg->setStatus(400); 00768 $this->conneg->setStatusMsg("Bad Request"); 00769 $this->conneg->setStatusMsgExt("No BibTex data converted"); 00770 return; 00771 } 00772 00773 return ($bibtex); 00774 break; 00775 00776 case "application/rdf+n3": 00777 00778 $xml = new ProcessorXML(); 00779 $xml->loadXML($this->pipeline_getResultset()); 00780 00781 $subjects = $xml->getSubjects(); 00782 00783 foreach($subjects as $subject) 00784 { 00785 $subjectURI = $xml->getURI($subject); 00786 $subjectType = $xml->getType($subject); 00787 00788 $rdf_part .= "\n <$subjectURI> a $subjectType ;\n"; 00789 00790 $predicates = $xml->getPredicates($subject); 00791 00792 foreach($predicates as $predicate) 00793 { 00794 $objects = $xml->getObjects($predicate); 00795 00796 foreach($objects as $object) 00797 { 00798 $objectType = $xml->getType($object); 00799 $predicateType = $xml->getType($predicate); 00800 00801 if($objectType == "rdfs:Literal") 00802 { 00803 $objectValue = $xml->getContent($object); 00804 $rdf_part .= " $predicateType \"\"\"" . str_replace(array( "\\" ), "\\\\", $objectValue) 00805 . "\"\"\" ;\n"; 00806 } 00807 else 00808 { 00809 $objectURI = $xml->getURI($object); 00810 $rdf_part .= " $predicateType <$objectURI> ;\n"; 00811 } 00812 } 00813 } 00814 00815 if(strlen($rdf_part) > 0) 00816 { 00817 $rdf_part = substr($rdf_part, 0, strlen($rdf_part) - 2) . ".\n"; 00818 } 00819 } 00820 00821 return ($rdf_part); 00822 break; 00823 00824 case "application/rdf+xml": 00825 00826 $xml = new ProcessorXML(); 00827 $xml->loadXML($this->pipeline_getResultset()); 00828 00829 $subjects = $xml->getSubjects(); 00830 00831 foreach($subjects as $subject) 00832 { 00833 $subjectURI = $xml->getURI($subject); 00834 $subjectType = $xml->getType($subject); 00835 00836 $rdf_part .= "\n <$subjectType rdf:about=\"".$this->xmlEncode($subjectURI)."\">\n"; 00837 00838 $predicates = $xml->getPredicates($subject); 00839 00840 foreach($predicates as $predicate) 00841 { 00842 $objects = $xml->getObjects($predicate); 00843 00844 foreach($objects as $object) 00845 { 00846 $objectType = $xml->getType($object); 00847 $predicateType = $xml->getType($predicate); 00848 00849 if($objectType == "rdfs:Literal") 00850 { 00851 $objectValue = $xml->getContent($object); 00852 $rdf_part .= " <$predicateType>" . $this->xmlEncode($objectValue) . "</$predicateType>\n"; 00853 } 00854 else 00855 { 00856 $objectURI = $xml->getURI($object); 00857 $rdf_part .= " <$predicateType rdf:resource=\"".$this->xmlEncode($objectURI)."\" />\n"; 00858 } 00859 } 00860 } 00861 00862 $rdf_part .= " </$subjectType>\n"; 00863 } 00864 00865 return ($rdf_part); 00866 break; 00867 } 00868 } 00869 00878 public function pipeline_serialize_reification() { return ""; } 00879 00890 public function ws_serialize() 00891 { 00892 switch($this->conneg->getMime()) 00893 { 00894 case "application/x-bibtex": 00895 return $this->pipeline_serialize(); 00896 break; 00897 00898 case "application/rdf+n3": 00899 00900 $rdf_document = ""; 00901 $rdf_document .= "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"; 00902 $rdf_document .= "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"; 00903 $rdf_document .= "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"; 00904 $rdf_document .= "@prefix bibo: <http://purl.org/ontology/bibo/> .\n"; 00905 $rdf_document .= "@prefix skos: <http://www.w3.org/2008/05/skos#> .\n"; 00906 $rdf_document .= "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n"; 00907 $rdf_document .= "@prefix event: <http://purl.org/NET/c4dm/event.owl> .\n"; 00908 $rdf_document .= "@prefix dcterms: <http://purl.org/dc/terms/> .\n"; 00909 $rdf_document .= "@prefix address: <http://schemas.talis.com/2005/address/schema> .\n"; 00910 $rdf_document .= "@prefix bkn: <http://purl.org/ontology/bkn#> .\n"; 00911 $rdf_document .= "@prefix bio: <http://purl.org/vocab/bio/0.1/> .\n"; 00912 $rdf_document .= "@prefix umbel: <http://umbel.org/umbel#> .\n"; 00913 00914 $rdf_document .= $this->pipeline_serialize(); 00915 00916 return $rdf_document; 00917 00918 break; 00919 00920 case "application/rdf+xml": 00921 $rdf_document = ""; 00922 $rdf_document .= "<?xml version=\"1.0\"?>\n"; 00923 $rdf_document 00924 .= "<rdf:RDF xmlns:bibo=\"http://purl.org/ontology/bibo/\" xmlns:bibo_degrees=\"http://purl.org/ontology/bibo/degrees/\" xmlns:bibo_status=\"http://purl.org/ontology/bibo/status/\" xmlns:owl=\"http://www.w3.org/2002/07/owl#\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:event=\"http://purl.org/NET/c4dm/event.owl#\" xmlns:address=\"http://schemas.talis.com/2005/address/schema#\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" xmlns:skos=\"http://www.w3.org/2008/05/skos#\" xmlns:bkn=\"http://purl.org/ontology/bkn#\" xmlns:bio=\"http://purl.org/vocab/bio/0.1/\" xmlns:umbel=\"http://umbel.org/umbel#\">\n\n"; 00925 00926 $rdf_document .= $this->pipeline_serialize(); 00927 00928 $rdf_document .= "</rdf:RDF>\n"; 00929 00930 return $rdf_document; 00931 break; 00932 00933 case "text/xml": 00934 return $this->pipeline_getResultset(); 00935 break; 00936 } 00937 } 00938 00951 public function ws_respond($content) 00952 { 00953 // First send the header of the request 00954 $this->conneg->respond(); 00955 00956 // second, send the content of the request 00957 00958 // Make sure there is no error. 00959 if($this->conneg->getStatus() == 200) 00960 { 00961 echo $content; 00962 } 00963 00964 $this->__destruct(); 00965 } 00966 00975 public function process() 00976 { 00977 // Make sure there was no conneg error prior to this process call 00978 if($this->conneg->getStatus() == 200) 00979 { 00980 switch($this->docmime) 00981 { 00982 case "text/xml": break; 00983 00984 case "application/x-bibtex": 00985 default: 00986 // check if it is a real bibtex file; or a bibtex file serialized in TSV. 00987 preg_match_all("|@(.*){(.*)}|U", str_replace(array ("\r", "\n"), "", $this->text), $matches); 00988 00989 if(count($matches[0]) > 1) 00990 { 00991 $parser = new BibtexParser($this->text); 00992 00993 $this->bibItems = $parser->items; 00994 } 00995 else 00996 { 00997 $parser = new BibtexParserCsv($this->text); 00998 00999 $this->bibItems = $parser->items; 01000 01001 $this->enhancedBibtex = TRUE; 01002 } 01003 01004 if(count($this->bibItems) <= 0) 01005 { 01006 $this->conneg->setStatus(400); 01007 $this->conneg->setStatusMsg("Bad Request"); 01008 $this->conneg->setStatusMsgExt("No BibTex data converted"); 01009 } 01010 break; 01011 } 01012 } 01013 } 01014 } 01015 01017 01018 ?>
