public function testSerializerSimple() { $g = new MongoGraph(); $g->add_literal_triple("http://example.com/1", $g->qname_to_uri("dct:title"), "some literal title"); $g->add_resource_triple("http://example.com/1", $g->qname_to_uri("dct:source"), "http://www.google.com"); $expected = "<http://example.com/1> <http://purl.org/dc/terms/title> \"some literal title\" <http://talisaspire.com/> .\n<http://example.com/1> <http://purl.org/dc/terms/source> <http://www.google.com> <http://talisaspire.com/> .\n"; $serializer = new NQuadSerializer(); $actual = $serializer->getSerializedIndex($g->_index, \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias()); $this->assertEquals($expected, $actual); }
/** * @param string $subject * @param array $triples * @param string $context * @return array */ public function getTArrayAbout($subject, array $triples, $context) { $graph = new MongoGraph(); foreach ($triples as $triple) { $triple = rtrim($triple); $parts = preg_split("/\\s/", $triple); $subject = trim($parts[0], '><'); $predicate = trim($parts[1], '><'); $object = $this->extract_object($parts); if ($this->isUri($object)) { $graph->add_resource_triple($subject, $predicate, $object); } else { $graph->add_literal_triple($subject, $predicate, $object); } } return $graph->to_tripod_array($subject, $context); }