function _doFindFromFile($file, &$model)
 {
     $nullVarURIs = array('var:x', 'var:y', 'var:z');
     $mod = new MemModel();
     $mod->load($file);
     $return = new MemModel();
     foreach ($mod->triples as $statement) {
         if (in_array($statement->getLabelSubject(), $nullVarURIs)) {
             $findS = null;
         } else {
             $findS = $statement->getSubject();
         }
         if (in_array($statement->getLabelPredicate(), $nullVarURIs)) {
             $findP = null;
         } else {
             $findP = $statement->getPredicate();
         }
         if (in_array($statement->getLabelObject(), $nullVarURIs)) {
             $findO = null;
         } else {
             $findO = $statement->getObject();
         }
         $return->addModel($model->find($findS, $findP, $findO));
     }
     return $return;
 }
示例#2
0
 /**
  * Returns a model, containing all Statements, having a Predicate, that 
  * is supported by the inference. 
  * 
  * @return	object Model
  * @access	public
  */
 function getSchema()
 {
     $res = new MemModel();
     //Search the base-model for all statements, having a Predicate, that
     //is supported by the inference.
     foreach ($this->supportedInference as $inferencePredicateLabel) {
         $res->addModel($this->find(null, new Resource($inferencePredicateLabel), null));
     }
     return $res;
 }
示例#3
0
 function _generateRDF()
 {
     $model = new MemModel();
     $model->setBaseURI($this->doclink);
     $proc = new xsltprocessor();
     include_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_RDF;
     $pars = new RdfParser();
     foreach ($this->stylelink as $key => $value) {
         $xsl = new DomDocument();
         $xsl->load($value);
         $proc->importStyleSheet($xsl);
         $model->addModel($pars->generateModel($proc->transformToXML($this->domdoc), $this->doclink));
     }
     return $model;
 }
    /**
     * 
     */
    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));
    }