Example #1
0
 public function __construct(Erfurt_Sparql_Query2_IriRef $iri, $withChilds = false)
 {
     $this->iri = $iri;
     if ($withChilds) {
         // TODO what the heck???
         $owApp = OntoWiki::getInstance();
         $store = $owApp->erfurt->getStore();
         $graph = $owApp->selectedModel;
         $types = array_keys($store->getTransitiveClosure($graph->getModelIri(), EF_RDFS_SUBCLASSOF, array($iri->getIri()), true));
         foreach ($types as $type) {
             $this->subclasses[] = new Erfurt_Sparql_Query2_IriRef($type);
         }
     }
 }
Example #2
0
 /**
  *
  * @param string $type the uri of the class
  * @param string $id
  * @param array  $options
  *
  * @return int id
  */
 public function addTypeFilter($type, $id = null, $option = array())
 {
     if ($id == null) {
         $id = 'type' . count($this->_filter);
     } else {
         if (isset($this->_filter[$id])) {
             $this->removeFilter($id);
         }
     }
     //shortcut navigation - only a rdfs class given
     $options['mode'] = 'instances';
     $options['type'] = $type;
     $options['memberPredicate'] = EF_RDF_TYPE;
     $options['withChilds'] = isset($option['withChilds']) ? $option['withChilds'] : true;
     $options['hierarchyUp'] = EF_RDFS_SUBCLASSOF;
     $options['hierarchyIsInverse'] = true;
     //$options['hierarchyDown'] = null;
     $options['direction'] = 1;
     // down the tree
     $memberPredicate = $options['memberPredicate'];
     if (is_string($memberPredicate)) {
         $memberPredicate = new Erfurt_Sparql_Query2_IriRef($memberPredicate);
     }
     if (!$memberPredicate instanceof Erfurt_Sparql_Query2_Verb) {
         throw new RuntimeException('Option "member_predicate" passed to Ontowiki_Model_Instances ' . 'must be an instance of Erfurt_Sparql_Query2_IriRef ' . 'or string instance of ' . typeHelper($memberPredicate) . ' given');
     }
     $type = new Erfurt_Sparql_Query2_IriRef($options['type']);
     $subClasses = array();
     if ($options['withChilds']) {
         $subClasses = array_keys($this->_store->getTransitiveClosure($this->_graph, $options['hierarchyUp'], array($type->getIri()), $options['hierarchyIsInverse']));
     } else {
         if (isset($options['subtypes'])) {
             //dont query, take the given. maybe the new navigation can use this
             $subClasses = $options['subtypes'];
         } else {
             $subClasses = array();
         }
     }
     if (count($subClasses) > 1) {
         // there are subclasses. "1" because the class itself is somehow included in the subclasses...
         $typeVar = new Erfurt_Sparql_Query2_Var($type);
         $triple = $this->_resourceQuery->addTriple($this->_resourceVar, $memberPredicate, $typeVar);
         $or = new Erfurt_Sparql_Query2_ConditionalOrExpression();
         foreach ($subClasses as $subclass) {
             $or->addElement(new Erfurt_Sparql_Query2_Equals($typeVar, new Erfurt_Sparql_Query2_IriRef($subclass)));
         }
         $filterObj = $this->_resourceQuery->addFilter($or);
     } else {
         // no subclasses
         $triple = $this->_resourceQuery->addTriple($this->_resourceVar, $memberPredicate, new Erfurt_Sparql_Query2_IriRef($type->getIri()));
     }
     //save
     $this->_filter[$id] = array('id' => $id, 'mode' => 'rdfsclass', 'rdfsclass' => $options['type'], 'withChilds' => $options['withChilds'], 'objects' => array($triple, isset($filterObj) ? $filterObj : null));
     //these filters bring there own triple
     $this->removeAllTriple();
     $this->invalidate();
     return $id;
 }
Example #3
0
 /**
  * setBase
  * @param Erfurt_Sparql_Query2_IriRef $base
  * @return Erfurt_Sparql_Query2 $this
  */
 public function setBase(Erfurt_Sparql_Query2_IriRef $base)
 {
     if ($base->isPrefixed()) {
         throw new RuntimeException('Trying to add base with a prefix');
     }
     $this->base = $base;
     return $this;
     //for chaining
 }