Ejemplo n.º 1
0
 /**
  * @dataProvider somePropertyProvider
  */
 public function testCommonMethods($property, $description, $expected)
 {
     $instance = new SomeProperty($property, $description);
     $this->assertEquals($expected['property'], $instance->getProperty());
     $this->assertEquals($expected['description'], $instance->getDescription());
     $this->assertEquals($expected['queryString'], $instance->getQueryString());
     $this->assertEquals($expected['queryStringAsValue'], $instance->getQueryString(true));
     $this->assertEquals($expected['isSingleton'], $instance->isSingleton());
     $this->assertEquals(array(), $instance->getPrintRequests());
     $this->assertEquals($expected['size'], $instance->getSize());
     $this->assertEquals($expected['depth'], $instance->getDepth());
     $this->assertEquals($expected['queryFeatures'], $instance->getQueryFeatures());
 }
 private function doMapSomeProperty(SomeProperty $description, &$exact)
 {
     $result = new ExpData(new ExpResource(''));
     $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('rdf', 'type'), new ExpData($this->exporter->getSpecialNsResource('owl', 'Restriction')));
     $property = $description->getProperty();
     if ($property->isInverse()) {
         $property = new DIProperty($property->getKey());
     }
     $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'onProperty'), new ExpData($this->exporter->getResourceElementForProperty($property)));
     $subdata = $this->getExpDataFromDescription($description->getDescription(), $exact);
     if ($description->getDescription() instanceof ValueDescription && $description->getDescription()->getComparator() === SMW_CMP_EQ) {
         $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'hasValue'), $subdata);
     } else {
         if ($subdata === false) {
             $owltype = $this->exporter->getOWLPropertyType($description->getProperty()->findPropertyTypeID());
             if ($owltype == 'ObjectProperty') {
                 $subdata = new ExpData($this->exporter->getSpecialNsResource('owl', 'Thing'));
             } elseif ($owltype == 'DatatypeProperty') {
                 $subdata = new ExpData($this->exporter->getSpecialNsResource('rdfs', 'Literal'));
             } else {
                 // no restrictions at all with annotation properties ...
                 return new ExpData($this->exporter->getSpecialNsResource('owl', 'Thing'));
             }
         }
         $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'someValuesFrom'), $subdata);
     }
     return $result;
 }
 /**
  * Modify the given query object to account for some property condition for
  * the given property. If it is not possible to generate a query for the
  * given data, the query type is changed to QueryContainer::Q_NOQUERY. Callers need
  * to check for this and discard the query in this case.
  *
  * @note This method does not support sortkey (_SKEY) property queries,
  * since they do not have a normal property table. This should not be a
  * problem since comparators on sortkeys are supported indirectly when
  * using comparators on wikipages. There is no reason to create any
  * query with _SKEY ad users cannot do so either (no user label).
  *
  * @since 1.8
  */
 private function interpretPropertyConditionForDescription(QuerySegment $query, SomeProperty $description)
 {
     $db = $this->queryBuilder->getStore()->getConnection('mw.db');
     $property = $description->getProperty();
     $tableid = $this->queryBuilder->getStore()->findPropertyTableID($property);
     if ($tableid === '') {
         // Give up
         $query->type = QuerySegment::Q_NOQUERY;
         return;
     }
     $proptables = $this->queryBuilder->getStore()->getPropertyTables();
     $proptable = $proptables[$tableid];
     if (!$proptable->usesIdSubject()) {
         // no queries with such tables
         // (only redirects are affected in practice)
         $query->type = QuerySegment::Q_NOQUERY;
         return;
     }
     $typeid = $property->findPropertyTypeID();
     $diType = DataTypeRegistry::getInstance()->getDataItemId($typeid);
     if ($property->isInverse() && $diType !== DataItem::TYPE_WIKIPAGE) {
         // can only invert properties that point to pages
         $query->type = QuerySegment::Q_NOQUERY;
         return;
     }
     $diHandler = $this->queryBuilder->getStore()->getDataItemHandlerForDIType($diType);
     $indexField = $diHandler->getIndexField();
     // TODO: strictly speaking, the DB key is not what we want here,
     // since sortkey is based on a "wiki value"
     $sortkey = $property->getKey();
     // *** Now construct the query ... ***//
     $query->joinTable = $proptable->getName();
     // *** Add conditions for selecting rows for this property ***//
     if (!$proptable->isFixedPropertyTable()) {
         $pid = $this->queryBuilder->getStore()->getObjectIds()->getSMWPropertyID($property);
         // Construct property hierarchy:
         $pqid = QuerySegment::$qnum;
         $pquery = new QuerySegment();
         $pquery->type = QuerySegment::Q_PROP_HIERARCHY;
         $pquery->joinfield = array($pid);
         $query->components[$pqid] = "{$query->alias}.p_id";
         $this->queryBuilder->addQuerySegmentForId($pqid, $pquery);
         // Alternative code without property hierarchies:
         // $query->where = "{$query->alias}.p_id=" . $this->m_dbs->addQuotes( $pid );
     }
     // else: no property column, no hierarchy queries
     // *** Add conditions on the value of the property ***//
     if ($diType === DataItem::TYPE_WIKIPAGE) {
         $o_id = $indexField;
         if ($property->isInverse()) {
             $s_id = $o_id;
             $o_id = 's_id';
         } else {
             $s_id = 's_id';
         }
         $query->joinfield = "{$query->alias}.{$s_id}";
         // process page description like main query
         $sub = $this->queryBuilder->buildQuerySegmentFor($description->getDescription());
         if ($sub >= 0) {
             $query->components[$sub] = "{$query->alias}.{$o_id}";
         }
         if (array_key_exists($sortkey, $this->queryBuilder->getSortKeys())) {
             // TODO: This SMW IDs table is possibly duplicated in the query.
             // Example: [[has capital::!Berlin]] with sort=has capital
             // Can we prevent that? (PERFORMANCE)
             $query->from = ' INNER JOIN ' . $db->tableName(SMWSql3SmwIds::tableName) . " AS ids{$query->alias} ON ids{$query->alias}.smw_id={$query->alias}.{$o_id}";
             $query->sortfields[$sortkey] = "ids{$query->alias}.smw_sortkey";
         }
     } else {
         // non-page value description
         $query->joinfield = "{$query->alias}.s_id";
         $this->interpretInnerValueDescription($query, $description->getDescription(), $proptable, $diHandler, 'AND');
         if (array_key_exists($sortkey, $this->queryBuilder->getSortKeys())) {
             $query->sortfields[$sortkey] = "{$query->alias}.{$indexField}";
         }
     }
 }