/** * tests if the manual set namespaceprefix 'foo' overwrites the prefix 'rdf' defined in * the default_prefixes array. */ function testOverwritingDefaultManual() { $_SESSION['test'] = 'Overwriting default manual test'; $model = new MemModel(); $pars = new N3Parser(); $model = $pars->parse2model($this->_generateModelString()); $ser = new RdfSerializer(); $string = $ser->serialize($model); $model2 = new MemModel(); $model2->load($string); $this->assertEqual($model2->parsedNamespaces[RDF_NAMESPACE_URI], 'rdf'); $model2->addNamespace('foo', RDF_NAMESPACE_URI); $this->assertEqual($model2->parsedNamespaces[RDF_NAMESPACE_URI], 'foo'); $model2->removeNamespace(RDF_NAMESPACE_URI); //$this->assertEqual($model2->parsedNamespaces[RDF_NAMESPACE_URI] , null); }
<?php //change the RDFAPI_INCLUDE_DIR to your local settings define("RDFAPI_INCLUDE_DIR", "C:/!htdocs/rdfapi-php/api/"); include RDFAPI_INCLUDE_DIR . "RdfAPI.php"; include_once RDFAPI_INCLUDE_DIR . PACKAGE_INFMODEL; include_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_N3; //uncomment the model you'd like to use $inf2 = new RDFSBModel('http://mytest.com'); $inf = new RDFSFModel('http://mytest.com'); $parser = new N3Parser(); $inf->addModel($parser->parse2model(' <http://example.org/baz1> <http://example.org/bat> <http://example.org/baz2> . <http://example.org/bat> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://example.org/bas> . ')); $inf2->addModel($parser->parse2model(' <http://example.org/baz1> <http://example.org/bat> <http://example.org/baz2> . <http://example.org/bat> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://example.org/bas> . ')); echo '<B>Added the following Triples:</B><BR>' . htmlentities(' <http://example.org/baz1> <http://example.org/bat> <http://example.org/baz2> .') . '<BR>' . htmlentities(' <http://example.org/bat> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://example.org/bas> . ') . '<BR>'; $inf->writeAsHtmlTable(); $inf2->writeAsHtmlTable(); #$sub=$inf2->subtract($inf); #$sub->writeAsHtmlTable(); #echo '<BR><hr><BR>'; echo '<BR><hr><BR>'; $inf->add(new Statement(new Resource('http://example.org/bat'), new Resource('http://www.w3.org/2000/01/rdf-schema#domain'), new Resource('http://example.org/Domain1'))); $inf->add(new Statement(new Resource('http://example.org/bat'), new Resource('http://www.w3.org/2000/01/rdf-schema#range'), new Resource('http://example.org/Range1')));
function testNestBlankAtEnd() { $mod = new MemModel(); $b3 = new BlankNode($mod); $mod->add(new Statement(new Resource('http://example.org/foo'), new Resource("http://example.org/bar2"), $b3)); $ser = new N3Serializer(); $ser->setCompress(true); $ser->setNest(true); $str = $ser->serialize($mod); //test if it can be loaded $par = new N3Parser(); $mod2 = $par->parse2model($str, false); //var_dump($str, $mod2->triples); $this->compareModelsIgnoringBlankNodes($mod, $mod2); }
*/ if ($argc <= 1) { echo <<<EOT Parses an N3 ("turtle") file Usage: php parseN3.php [--debug] /path/to/file.n3 EOT; exit(1); } if ($argc == 3 && $argv[1] == '--debug') { $bDebug = true; array_shift($argv); } else { $bDebug = false; } $file = $argv[1]; if (!file_exists($file)) { echo <<<EOT File does not exist. Usage: php parseN3.php [--debug] /path/to/file.n3 EOT; exit(2); } require_once 'config.php'; require_once RDFAPI_INCLUDE_DIR . 'syntax/N3Parser.php'; $parser = new N3Parser(); if ($bDebug) { $parser->debug = true; } $parser->parse(file_get_contents($file));
/** * */ function test1() { $inf = new RDFSBModel('http://myRDFSFModel.com'); $result = new MemModel(); $parser = new N3Parser(); $inf->addModel($parser->parse2model(' <http://example.org/baz1> <http://example.org/bat> <http://example.org/baz2> . <http://example.org/bat> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://example.org/bas> . ')); $result->addModel($parser->parse2model(' @prefix ns0: <http://example.org/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . ns0:baz1 ns0:bas ns0:baz2 ; ns0:bat ns0:baz2 . ns0:bat rdfs:subPropertyOf ns0:bas . ')); $this->assertTrue($inf->equals($result)); //next test $inf->add(new Statement(new Resource('http://example.org/bat'), new Resource('http://www.w3.org/2000/01/rdf-schema#domain'), new Resource('http://example.org/Domain1'))); $inf->add(new Statement(new Resource('http://example.org/bat'), new Resource('http://www.w3.org/2000/01/rdf-schema#range'), new Resource('http://example.org/Range1'))); $result = new MemModel(); $result->addModel($parser->parse2model(' @prefix ns0: <http://example.org/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . ns0:baz1 ns0:bas ns0:baz2 ; ns0:bat ns0:baz2 ; a ns0:Domain1 . ns0:bat rdfs:domain ns0:Domain1 ; rdfs:range ns0:Range1 ; rdfs:subPropertyOf ns0:bas . ns0:baz2 a ns0:Range1 . ')); $this->assertTrue($inf->equals($result)); // next test $inf->add(new Statement(new Resource('http://example.org/bas'), new Resource('http://www.w3.org/2000/01/rdf-schema#domain'), new Resource('http://example.org/Domain2'))); $inf->add(new Statement(new Resource('http://example.org/bas'), new Resource('http://www.w3.org/2000/01/rdf-schema#range'), new Resource('http://example.org/Range2'))); $result = new MemModel(); $result->addModel($parser->parse2model(' @prefix ns0: <http://example.org/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . ns0:baz1 ns0:bas ns0:baz2 ; ns0:bat ns0:baz2 ; a ns0:Domain1 , ns0:Domain2 . ns0:bat rdfs:domain ns0:Domain1 ; rdfs:range ns0:Range1 ; rdfs:subPropertyOf ns0:bas . ns0:bas rdfs:domain ns0:Domain2 ; rdfs:range ns0:Range2 . ns0:baz2 a ns0:Range1 , ns0:Range2 . ')); $this->assertTrue($inf->equals($result)); //next test $inf->add(new Statement(new Resource('http://example.org/Domain2'), new Resource('http://www.w3.org/2000/01/rdf-schema#subClassOf'), new Resource('http://example.org/Domain3'))); $inf->add(new Statement(new Resource('http://example.org/Domain3'), new Resource('http://www.w3.org/2000/01/rdf-schema#subClassOf'), new Resource('http://example.org/Domain2'))); $result = new MemModel(); $result->addModel($parser->parse2model(' @prefix ns0: <http://example.org/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . ns0:baz1 ns0:bas ns0:baz2 ; ns0:bat ns0:baz2 ; a ns0:Domain1 , ns0:Domain2 , ns0:Domain3 . ns0:bat rdfs:domain ns0:Domain1 ; rdfs:range ns0:Range1 ; rdfs:subPropertyOf ns0:bas . ns0:bas rdfs:domain ns0:Domain2 ; rdfs:range ns0:Range2 . ns0:baz2 a ns0:Range1 , ns0:Range2 . ns0:Domain3 rdfs:subClassOf ns0:Domain2 . ns0:Domain2 rdfs:subClassOf ns0:Domain3 . ')); $this->assertTrue($inf->equals($result)); //next test $inf->add(new Statement(new Resource('http://example.org/Range3'), new Resource('http://www.w3.org/2002/07/owl#sameAs'), new Resource('http://example.org/Range2'))); $result = new MemModel(); $result->addModel($parser->parse2model(' @prefix ns0: <http://example.org/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . ns0:baz1 ns0:bas ns0:baz2 ; ns0:bat ns0:baz2 ; a ns0:Domain1 , ns0:Domain2 , ns0:Domain3 . ns0:baz2 a ns0:Range1 , ns0:Range2 , ns0:Range3 . ns0:bat rdfs:domain ns0:Domain1 ; rdfs:range ns0:Range1 ; rdfs:subPropertyOf ns0:bas . ns0:bas rdfs:domain ns0:Domain2 ; rdfs:range ns0:Range2 . ns0:Range3 owl:sameAs ns0:Range2 . ns0:Domain3 rdfs:subClassOf ns0:Domain2 . ns0:Domain2 rdfs:subClassOf ns0:Domain3 . ')); $this->assertTrue($inf->equals($result)); //next test $findResult = $inf->find(new Resource('http://example.org/baz2'), null, null); $result = new MemModel(); $result->addModel($parser->parse2model(' @prefix ns0: <http://example.org/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . ns0:baz2 a ns0:Range1 , ns0:Range2 , ns0:Range3 . ')); $this->assertTrue($findResult->equals($result)); //text test $inf->remove(new Statement(new Resource('http://example.org/bat'), new Resource('http://www.w3.org/2000/01/rdf-schema#subPropertyOf'), new Resource('http://example.org/bas'))); $result = new MemModel(); $result->addModel($parser->parse2model(' @prefix ns0: <http://example.org/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . ns0:baz1 ns0:bat ns0:baz2 ; a ns0:Domain1 . ns0:bas rdfs:domain ns0:Domain2 ; rdfs:range ns0:Range2 . ns0:bat rdfs:domain ns0:Domain1 ; rdfs:range ns0:Range1 . ns0:baz2 a ns0:Range1 . ns0:Range3 owl:sameAs ns0:Range2 . ns0:Domain2 rdfs:subClassOf ns0:Domain3 . ns0:Domain3 rdfs:subClassOf ns0:Domain2 . ')); $this->assertTrue($inf->equals($result)); }
function MwRdfNTriplesToModel($ntrip) { require_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_N3; $parser = new N3Parser(); $model = $parser->parse2model($ntrip); return $model; }
function testPrefixNotDeclared() { $rdfInput = ' @prefix m: <http://www.example.org/meeting_organization#>. <http://www.example.org/people#fred> p:GivenName "Fred"; p:hasEmail <mailto:fred@example.com>; m:attending <http://meetings.example.com/cal#m1> . '; $n3pars = new N3Parser(); $model = $n3pars->parse2model($rdfInput, false); //var_dump($model); $this->assertErrorPattern('[Prefix not declared: p:]'); }
$needModel = true; include "config.inc.php"; include "utils.php"; include "setup.php"; $title = "RAP DB » Add"; include "header.php"; include "menu.php"; if ($db->modelExists($muri)) { $m = $db->getModel($muri); if (isset($_FILES["rdffile"])) { print "<h1>Uploading file to {$muri}</h1>\n"; print "<p>Got " . $_FILES["rdffile"]["name"] . "<br/>\n"; if (preg_match("/n3\$/", $_FILES["rdffile"]["name"])) { // N3 print "<p>Detected format N3.</p>\n"; $n3p = new N3Parser(); $m2 = $n3p->generateModel($_FILES["rdffile"]["tmp_name"]); } else { // default to XML $r = new RdfParser(); $m2 = $r->generateModel($_FILES["rdffile"]["tmp_name"]); } $m->addModel($m2); print "Read " . $_FILES["rdffile"]["size"] . " bytes and " . count($m2->triples) . " triples.<br/></p>\n"; } if (isset($_REQUEST["rdfuri"])) { $u = $_REQUEST["rdfuri"]; print "<h1>Downloading {$u}</h1>\n"; if (isset($PROXYHOST)) { $a = getthroughproxy($u, $PROXYHOST, $PROXYPORT); $f = tempnam();