function testUnite() { $_SESSION['test'] = 'MemModel unite test'; $model1 = new MemModel(); $stat = new Statement(new Resource('http://www.example.org/sub1'), new Resource('http://www.example.org/pred1'), new Resource('http://www.example.org/obj1')); $stat2 = new Statement(new Resource('http://www.example.org/sub2'), new Resource('http://www.example.org/pred2'), new Resource('http://www.example.org/obj2')); $stat3 = new Statement(new Resource('http://www.example.org/sub3'), new Resource('http://www.example.org/pred3'), new Resource('http://www.example.org/obj3')); $model1->add($stat); $model1->add($stat2); $model2 = new MemModel(); $model2->add($stat); $model2->add($stat2); $model2->add($stat3); $res = new MemModel(); $res = $model1->unite($model2); $this->assertEqual(3, $res->size()); $this->assertTrue($res->contains($stat)); $this->assertTrue($res->contains($stat2)); $this->assertTrue($res->contains($stat3)); }
function MwRdfInPage($article) { $text = $article->getContent(true); $parser = new Parser(); $text = $parser->preprocess($text, $article->mTitle, new ParserOptions()); preg_match_all("@<rdf>(.*?)</rdf>@s", $text, $matches, PREG_PATTERN_ORDER); $content = $matches[1]; $rdf = implode(' ', array_values($content)); $model = null; if (strlen($rdf) > 0) { $parser->mOutputType = OT_HTML; $rdf = $parser->replaceVariables($rdf); global $default_prefixes, $wgRdfNamespaces; require_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_N3; $parser = new N3Parser(); $parser->baseURI = $article->mTitle->getFullURL(); $prefixes = array_merge($default_prefixes, $wgRdfNamespaces, MwRdfNamespacePrefixes()); $prelude = ""; foreach ($prefixes as $prefix => $uri) { $prelude .= "@prefix {$prefix}: <{$uri}> .\n"; } # XXX: set correct properties $model = $parser->parse2model($prelude . $rdf); if ($model === false) { global $RDFS_comment; $model = ModelFactory::getDefaultModel(); $model->add(new Statement(MwRdfArticleResource($article), $RDFS_comment, MwRdfLiteral("Error parsing in-page RDF: " . $parser->errors[0] . "\n code here: \n '" . $prelude . $rdf . "'", null, "en"))); } else { # To make it unique, we unite with an empty model $fake = new MemModel(); $model =& $fake->unite($model); } } return $model; }