Ejemplo n.º 1
0
 /**
  * Loop trough the jena infmodel tests
  */
 function testRdfsFModel()
 {
     $testURI = 'http://www.hpl.hp.com/semweb/2003/query_tester#';
     $testmodel = new MemModel($testURI);
     $testmodel->load(RDFS_INF_TESTFILES . 'rdfs/manifest-standard.rdf');
     $i = 1;
     do {
         $inf = new RDFSBModel();
         #$inf->addModel($rdfsAxioms);
         $res1 = $testmodel->find(new Resource(RDFS_INF_TESTFILES . 'rdfs/test' . $i++), null, null);
         if ($res1->isEmpty()) {
             break;
         }
         $findTBOX = $res1->find(null, new Resource($testURI . 'tbox'), null);
         $inf->load(RDFS_INF_TESTFILES . $findTBOX->triples[0]->getLabelObject());
         $findDATA = $res1->find(null, new Resource($testURI . 'data'), null);
         $inf->load(RDFS_INF_TESTFILES . $findDATA->triples[0]->getLabelObject());
         $findQUERY = $res1->find(null, new Resource($testURI . 'query'), null);
         $query = $this->_doFindFromFile(RDFS_INF_TESTFILES . $findQUERY->triples[0]->getLabelObject(), $inf);
         $result = new MemModel();
         $findRESULT = $res1->find(null, new Resource($testURI . 'result'), null);
         $result->load(RDFS_INF_TESTFILES . $findRESULT->triples[0]->getLabelObject());
         $isEqual = $query->containsAll($result);
         if (!$isEqual) {
             $query->writeAsHtmlTable();
             $result->writeAsHtmlTable();
             $subtract = $result->subtract($query);
             echo '<BR><BR>subtracted<BR>';
             $subtract->writeAsHtmlTable();
         }
         $findDATA = $res1->find(null, new Resource($testURI . 'description'), null);
         echo '<b>' . $findDATA->triples[0]->getLabelObject() . ' (RDFSFModel)</b><BR>';
         $this->assertTrue($isEqual);
     } while (true);
 }
Ejemplo n.º 2
0
 /**
  * generates a test model containing given number of statements
  * and given indextype.
  *
  * @return Object MemModel $model
  * @param  int $num 
  * @param  int $des
  * @param  int $ind
  * @param  Object MemModel $needle
  */
 function _generateModel($num, $des, $ind, $needle)
 {
     $model = new RDFSBModel();
     // generate Subjects
     for ($i = 0; $i < $num; $i++) {
         $subs[$i] = new Resource('http://www.example.org/Subject' . $i % 6);
     }
     // generate Predicates
     for ($i = 0; $i < $num; $i++) {
         $preds[$i] = new Resource('http://www.example.org/Predicate' . $i % 7);
     }
     // generate Objects
     for ($i = 0; $i < $num; $i++) {
         $objs[$i] = new Resource('http://www.example.org/Object' . $i % 5);
     }
     for ($i = 0; $i < $num; $i++) {
         $model->add(new Statement($subs[$i], $preds[$i], $objs[$i]));
     }
     $model->index($ind);
     return $model;
 }
Ejemplo n.º 3
0
<?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')));
Ejemplo n.º 4
0
    /**
     * 
     */
    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));
    }
 /**
  * generates a test model containing given number of statements
  * and given indextype.
  *
  * @return Object MemModel $model
  * @param  int $num 
  * @param  int $des
  * @param  int $ind
  * @param  Object MemModel $needle
  */
 function _generateModel($stats, $ind)
 {
     $model = new RDFSBModel();
     $model->index($ind);
     for ($i = 0; $i < $stats; $i++) {
         $subs[$i] = new Resource('http://www.example.org/sub' . $i % 3);
         $preds[$i] = new Resource('http://www.example.org/pred' . $i % 5);
         $objs[$i] = new Resource('http://www.example.org/obj' . $i % 9);
     }
     for ($i = 0; $i < $stats; $i++) {
         $model->add(new Statement($subs[$i], $preds[$i], $objs[$i]));
     }
     return $model;
 }