/** Generate the converted TSV items using the internal XML representation
 
     @return a XML document
     
     @author Frederick Giasson, Structured Dynamics LLC.
 */
 public function pipeline_getResultset()
 {
     if ($this->docmime == "text/xml") {
         return $this->text;
     } else {
         $xml = new ProcessorXML();
         // Creation of the RESULTSET
         $resultset = $xml->createResultset();
         // Creation of the prefixes elements.
         $void = $xml->createPrefix("owl", "http://www.w3.org/2002/07/owl#");
         $resultset->appendChild($void);
         $rdf = $xml->createPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
         $resultset->appendChild($rdf);
         $dcterms = $xml->createPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
         $resultset->appendChild($dcterms);
         $dcterms = $xml->createPrefix("wsf", "http://purl.org/ontology/wsf#");
         $resultset->appendChild($dcterms);
         // Check if we are handling a collection of documents compiled by someone.
         if ($this->enhancedBibtex) {
             foreach ($this->bibItems as $item) {
                 if ($item->itemType == "heading") {
                     $this->processingCollection = $item->itemID;
                     break;
                 }
             }
         }
         foreach ($this->bibItems as $item) {
             // Creation of a SUBJECT of the RESULTSET
             if (!isset($this->bibTypes[$item->itemType])) {
                 $item->itemType = "misc";
             }
             $subject = $xml->createSubject($this->bibTypes[$item->itemType], $this->baseURI . $this->uriEncode($item->itemID));
             // If we are processing a collection, lets make the link between the item and that collection.
             if ($this->processingCollection != "" && $this->processingCollection != $item->itemID && $item->itemType != "subject" && $item->itemType != "person") {
                 $pred = $xml->createPredicate("dcterms:isPartOf");
                 $object = $xml->createObject("", $this->baseURI . $this->uriEncode($this->processingCollection));
                 $pred->appendChild($object);
                 $subject->appendChild($pred);
             }
             // Lets add the additional properties that define this bibtex item type
             if (isset($this->bibTypesAdditionalProperties[$item->itemType])) {
                 // Creation of the predicate
                 $pred = $xml->createPredicate($this->bibTypesAdditionalProperties[$item->itemType][0]);
                 // Creation of the OBJECT of the predicate
                 $object = $xml->createObject("", $this->bibTypesAdditionalProperties[$item->itemType][1]);
                 $pred->appendChild($object);
                 $subject->appendChild($pred);
             }
             // Now lets convert all the bibtex item properties
             foreach ($item->properties as $property => $value) {
                 if (isset($this->bibProperties[$property])) {
                     // Check if we have a enhanced bibtex file
                     $processed = FALSE;
                     if ($this->enhancedBibtex) {
                         if ($property == "author" || $property == "subjects") {
                             // Lets explode and create authors
                             $authors = explode(",", $value);
                             foreach ($authors as $author) {
                                 // Creation of the predicate
                                 $pred = $xml->createPredicate($this->bibProperties[$property]);
                                 $object = $xml->createObject("", $this->baseURI . $this->uriEncode($author));
                                 $pred->appendChild($object);
                                 $subject->appendChild($pred);
                             }
                             $processed = TRUE;
                         }
                     }
                     if ($processed === FALSE) {
                         // Creation of the predicate
                         $pred = $xml->createPredicate($this->bibProperties[$property]);
                         if (isset($this->bibPropertiesAdditionalObjects[$property])) {
                             $object = $xml->createObject("", $this->baseURI . $this->uriEncode($value));
                             $pred->appendChild($object);
                             // Lets create the new subject
                             $subSubject = $xml->createSubject($this->bibPropertiesAdditionalObjects[$property][0], $this->baseURI . $this->uriEncode($value));
                             $subPred = $xml->createPredicate($this->bibPropertiesAdditionalObjects[$property][1]);
                             $subObject = $xml->createObjectContent(str_replace("\\", "%5C", $value));
                             $subPred->appendChild($subObject);
                             $subSubject->appendChild($subPred);
                             $resultset->appendChild($subSubject);
                         } else {
                             // Creation of the OBJECT of the predicate
                             $object = $xml->createObjectContent(str_replace("\\", "%5C", $value));
                             $pred->appendChild($object);
                         }
                         $subject->appendChild($pred);
                     }
                 }
             }
             $resultset->appendChild($subject);
         }
         return $this->injectDoctype($xml->saveXML($resultset));
     }
 }
 /** Generate the converted irJSON items using the internal XML representation
 
       @return a XML document
       
       @author Frederick Giasson, Structured Dynamics LLC.
   */
 public function pipeline_getResultset()
 {
     if ($this->docmime == "text/xml") {
         return $this->text;
     }
     if ($this->docmime == "application/iron+json") {
         // Check if a linkage file of kind RDF has been defined for this irJSON file.
         foreach ($this->parser->linkageSchemas as $linkageSchema) {
             if (strtolower($linkageSchema->linkedType) == "application/rdf+xml") {
                 $xml = new ProcessorXML();
                 $resultset = $xml->createResultset();
                 // Creation of the prefixes elements.
                 $void = $xml->createPrefix("owl", "http://www.w3.org/2002/07/owl#");
                 $resultset->appendChild($void);
                 $rdf = $xml->createPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
                 $resultset->appendChild($rdf);
                 $dcterms = $xml->createPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
                 $resultset->appendChild($dcterms);
                 $dcterms = $xml->createPrefix("iron", "http://purl.org/ontology/iron#");
                 $resultset->appendChild($dcterms);
                 //
                 // Map dataset
                 //
                 $datasetSubject = $xml->createSubject("http://rdfs.org/ns/void#Dataset", $this->parser->dataset->id[0]);
                 // Map other attributes
                 if (isset($this->parser->dataset->attributes)) {
                     foreach ($this->parser->dataset->attributes as $property => $obj) {
                         if (stripos($this->parser->dataset->attributes[$property]["valueType"], "primitive:string") !== FALSE) {
                             foreach ($this->parser->dataset->attributes[$property] as $key => $value) {
                                 if (gettype($key) == "integer") {
                                     // Get the linked property.
                                     $prop = $this->getLinkedProperty($property, $linkageSchema);
                                     $pred = $xml->createPredicate($prop);
                                     $object = $xml->createObjectContent($value);
                                     $pred->appendChild($object);
                                     $datasetSubject->appendChild($pred);
                                 }
                             }
                         }
                         if (stripos($this->parser->dataset->attributes[$property]["valueType"], "type:object") !== FALSE) {
                             foreach ($this->parser->dataset->attributes[$property] as $key => $value) {
                                 if (gettype($key) == "integer") {
                                     // Check for the reference
                                     if (isset($this->parser->dataset->attributes[$property][$key]["ref"])) {
                                         // Reference to an external record
                                         if (substr($this->parser->dataset->attributes[$property][$key]["ref"], 0, 2) == "@@") {
                                             $this->parser->dataset->attributes[$property][$key]["ref"] = substr($this->parser->dataset->attributes[$property][$key]["ref"], 2, strlen($this->parser->dataset->attributes[$property][$key]["ref"]) - 2);
                                         } elseif (substr($this->parser->dataset->attributes[$property][$key]["ref"], 0, 1) == "@") {
                                             $this->parser->dataset->attributes[$property][$key]["ref"] = $this->parser->dataset->id[0] . substr($this->parser->dataset->attributes[$property][$key]["ref"], 1, strlen($this->parser->dataset->attributes[$property][$key]["ref"]) - 1);
                                         }
                                     } else {
                                         /*
                                           If no reference has been specified, we have to create a BNode for it even if the
                                           object (instance record) is not defined anywhere.
                                           This object will then be used
                                         */
                                         $this->parser->dataset->attributes[$property][$key]["ref"] = $this->wsf_graph . "irs/" . md5(microtime());
                                     }
                                     // Check if metaData has been added to this relationship
                                     if (isset($this->parser->dataset->attributes[$property][$key]["metaData"])) {
                                         // Get the linked property.
                                         $prop = $this->getLinkedProperty($property, $linkageSchema);
                                         $pred = $xml->createPredicate($prop);
                                         $object = $xml->createObject("", $this->parser->dataset->attributes[$property][$key]["ref"]);
                                         foreach ($this->parser->dataset->attributes[$property][$key]["metaData"] as $metaKey => $metaObject) {
                                             foreach ($metaObject as $metaAttribute => $metaValue) {
                                                 // Reify all metaData attributes/values
                                                 $metaProp = $this->getLinkedProperty($metaAttribute, $linkageSchema);
                                                 $reify = $xml->createReificationStatement($metaProp, $metaValue);
                                                 $object->appendChild($reify);
                                             }
                                         }
                                         $pred->appendChild($object);
                                         $datasetSubject->appendChild($pred);
                                     } else {
                                         // No metaData exists for this relationship. We simply create the s-p-o triple
                                         $prop = $this->getLinkedProperty($property, $linkageSchema);
                                         $pred = $xml->createPredicate($prop);
                                         $object = $xml->createObject("", $this->parser->dataset->attributes[$property][$key]["ref"]);
                                         $pred->appendChild($object);
                                         $datasetSubject->appendChild($pred);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $resultset->appendChild($datasetSubject);
                 //
                 // Map instance records
                 //
                 foreach ($this->parser->instanceRecords as $instanceRecord) {
                     $uri = $this->parser->dataset->id[0] . $instanceRecord->id[0];
                     $subject;
                     // Map types
                     if (isset($instanceRecord->attributes["type"])) {
                         foreach ($instanceRecord->attributes["type"] as $key => $type) {
                             if (gettype($key) != "string") {
                                 if (isset($linkageSchema->typeX[$type][0]["mapTo"])) {
                                     $type = $linkageSchema->typeX[$type][0]["mapTo"];
                                 } else {
                                     // If the type is not linked, we create one in the temporary ontology of the node.
                                     /** @todo Add this new type in the internal ontology of the node. */
                                     if (strpos($type, "http://") === FALSE) {
                                         $type = $this->wsf_graph . "ontology/types/" . $type;
                                     }
                                 }
                             }
                             if ($key == "0") {
                                 $subject = $xml->createSubject($type, $uri);
                             } elseif (gettype($key) != "string") {
                                 $pred = $xml->createPredicate("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
                                 $object = $xml->createObject("", $type);
                                 $pred->appendChild($object);
                                 $subject->appendChild($pred);
                             }
                         }
                     } else {
                         $subject = $xml->createSubject("http://www.w3.org/2002/07/owl#Thing", $uri);
                     }
                     // Map other attributes
                     if (isset($instanceRecord->attributes)) {
                         foreach ($instanceRecord->attributes as $property => $obj) {
                             if (stripos($instanceRecord->attributes[$property]["valueType"], "primitive:string") !== FALSE) {
                                 foreach ($instanceRecord->attributes[$property] as $key => $value) {
                                     if (gettype($key) == "integer") {
                                         // Get the linked property.
                                         $prop = $this->getLinkedProperty($property, $linkageSchema);
                                         $pred = $xml->createPredicate($prop);
                                         $object = $xml->createObjectContent($value);
                                         $pred->appendChild($object);
                                         $subject->appendChild($pred);
                                     }
                                 }
                             }
                             if (stripos($instanceRecord->attributes[$property]["valueType"], "type:object") !== FALSE) {
                                 foreach ($instanceRecord->attributes[$property] as $key => $value) {
                                     if (gettype($key) == "integer" && $property != "type") {
                                         // Check for the reference
                                         if (isset($instanceRecord->attributes[$property][$key]["ref"])) {
                                             // Reference to an external record
                                             if (substr($instanceRecord->attributes[$property][$key]["ref"], 0, 2) == "@@") {
                                                 $instanceRecord->attributes[$property][$key]["ref"] = substr($instanceRecord->attributes[$property][$key]["ref"], 2, strlen($instanceRecord->attributes[$property][$key]["ref"]) - 2);
                                             } elseif (substr($instanceRecord->attributes[$property][$key]["ref"], 0, 1) == "@") {
                                                 $instanceRecord->attributes[$property][$key]["ref"] = $this->parser->dataset->id[0] . substr($instanceRecord->attributes[$property][$key]["ref"], 1, strlen($instanceRecord->attributes[$property][$key]["ref"]) - 1);
                                             }
                                         } else {
                                             /*
                                               If no reference has been specified, we have to create a BNode for it even if the
                                               object (instance record) is not defined anywhere.
                                               This object will then be used
                                             */
                                             $instanceRecord->attributes[$property][$key]["ref"] = $this->wsf_graph . "irs/" . md5(microtime());
                                         }
                                         // Check if metaData has been added to this relationship
                                         if (isset($instanceRecord->attributes[$property][$key]["metaData"])) {
                                             // Get the linked property.
                                             $prop = $this->getLinkedProperty($property, $linkageSchema);
                                             $pred = $xml->createPredicate($prop);
                                             $object = $xml->createObject("", $instanceRecord->attributes[$property][$key]["ref"]);
                                             foreach ($instanceRecord->attributes[$property][$key]["metaData"] as $metaKey => $metaObject) {
                                                 foreach ($metaObject as $metaAttribute => $metaValue) {
                                                     // Reify all metaData attributes/values
                                                     $metaProp = $this->getLinkedProperty($metaAttribute, $linkageSchema);
                                                     $reify = $xml->createReificationStatement($metaProp, $metaValue);
                                                     $object->appendChild($reify);
                                                 }
                                             }
                                             $pred->appendChild($object);
                                             $subject->appendChild($pred);
                                         } else {
                                             // No metaData exists for this relationship. We simply create the s-p-o triple
                                             $prop = $this->getLinkedProperty($property, $linkageSchema);
                                             $pred = $xml->createPredicate($prop);
                                             $object = $xml->createObject("", $instanceRecord->attributes[$property][$key]["ref"]);
                                             $pred->appendChild($object);
                                             $subject->appendChild($pred);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $resultset->appendChild($subject);
                 }
                 return $this->injectDoctype($xml->saveXML($resultset));
             }
         }
         // No RDF linkage file exists for this irJSON file, then we throw an error
         $this->conneg->setStatus(400);
         $this->conneg->setStatusMsg("Bad Request");
         $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name);
         $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws, $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "No linkage file of type 'RDF' has been defined for this Instance Record Vocabulary file. Cant convert this file in '" . $this->conneg->getMime() . "'", $this->errorMessenger->_200->level);
         return;
     }
     // Unsupported docmime type
     $this->conneg->setStatus(400);
     $this->conneg->setStatusMsg("Bad Request");
     $this->conneg->setStatusMsgExt($this->errorMessenger->_302->name);
     $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws, $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, "Mime type you requested: " . $this->docmime, $this->errorMessenger->_302->level);
 }
Пример #3
0
 /** Generate the converted TSV items using the internal XML representation
 
       @return a XML document
       
       @author Frederick Giasson, Structured Dynamics LLC.
   */
 public function pipeline_getResultset()
 {
     if ($this->docmime == "text/xml") {
         return $this->text;
     } else {
         $xml = new ProcessorXML();
         $resultset = $xml->createResultset();
         foreach ($this->tsvResources as $uri => $properties) {
             $subject = $xml->createSubject("http://www.w3.org/2002/07/owl#Thing", $this->baseURI . $this->uriEncode($uri));
             foreach ($properties as $propertyValue) {
                 $propertyValue[1] = trim($propertyValue[1]);
                 // check if the object of the TSV is a reference to another subject of the same document
                 if (substr($propertyValue[0], 0, 1) == "{" && substr($propertyValue[0], strlen($propertyValue[0]) - 1, 1) == "}") {
                     $property = $this->get_domain($this->baseURI) . "/ontology#" . $this->uriEncode($propertyValue[0]);
                     $value = $this->baseURI . $this->uriEncode($propertyValue[1]);
                     $pred = $xml->createPredicate($property);
                     $object = $xml->createObject("http://www.w3.org/2002/07/owl#Thing", $value);
                     $pred->appendChild($object);
                     $subject->appendChild($pred);
                 } else {
                     $property = $this->get_domain($this->baseURI) . "/ontology#" . $this->uriEncode($propertyValue[0]);
                     $value = $propertyValue[1];
                     $pred = $xml->createPredicate($property);
                     $object = $xml->createObjectContent($value);
                     $pred->appendChild($object);
                     $subject->appendChild($pred);
                 }
             }
             $resultset->appendChild($subject);
         }
         return $this->injectDoctype($xml->saveXML($resultset));
     }
 }