/** 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); }