public function testMinus() { $graph1 = new Graph(); $graph1->add('http://www.example.com/jdoe#jdoe', 'foaf:name', 'John Doe'); $graph2 = new Graph(); $graph2->add('http://www.example.com/jdoe#jdoe', 'foaf:name', 'Foo Bar'); $uow = new UnitOfWork($this->manager, 'fooUrl'); $this->assertEquals(1, 1); }
/** * Transforms the statements of a StatementIterator instance into a stream, a file for instance. * * @param StatementIterator $statements The StatementIterator containing all the Statements which * should be serialized by the serializer. * @param string|resource $outputStream filename or file pointer to the stream to where the serialization * should be written. * @param string $serialization The serialization which should be used. If null is given the * serializer will either apply some default serialization, or * the only one it is supporting, or will throw an Exception. * @throws \Exception If unknown serilaization was given. */ public function serializeIteratorToStream(StatementIterator $statements, $outputStream, $serialization = null) { /* * check parameter $outputStream */ if (is_resource($outputStream)) { // use it as it is } elseif (is_string($outputStream)) { $outputStream = fopen($outputStream, 'w'); } else { throw new \Exception('Parameter $outputStream is neither a string nor resource.'); } // if no format was given, serialize to turtle. if (null == $serialization) { $format = 'turtle'; } if (false === isset($this->serializationMap[$serialization])) { throw new \Exception('Unknown serialization given: ' . $serialization); } $graph = new Graph(); // go through all statements foreach ($statements as $statement) { /* * Handle subject */ $stmtSubject = $statement->getSubject(); if ($stmtSubject->isNamed()) { $s = $stmtSubject->getUri(); } elseif ($stmtSubject->isBlank()) { $s = $stmtSubject->getBlankId(); } else { throw new \Exception('Subject can either be a blank node or an URI.'); } /* * Handle predicate */ $stmtPredicate = $statement->getPredicate(); if ($stmtPredicate->isNamed()) { $p = $stmtPredicate->getUri(); } else { throw new \Exception('Predicate can only be an URI.'); } /* * Handle object */ $stmtObject = $statement->getObject(); if ($stmtObject->isNamed()) { $o = array('type' => 'uri', 'value' => $stmtObject->getUri()); } elseif ($stmtObject->isBlank()) { $o = array('type' => 'bnode', 'value' => $stmtObject->getBlankId()); } elseif ($stmtObject->isLiteral()) { $o = array('type' => 'literal', 'value' => $stmtObject->getValue()); } else { throw new \Exception('Object can either be a blank node, an URI or literal.'); } $graph->add($s, $p, $o); } fwrite($outputStream, $graph->serialise($this->serializationMap[$serialization]) . PHP_EOL); }
/** * temp function : converting a result to a graph. * * @param Result $result * * @return Graph */ private function resultToGraph($result) { if ($result instanceof Graph) { return $result; } $graph = new Graph(null); foreach ($result as $row) { $graph->add($row->subject, $row->predicate, $row->object); } return $graph; }