コード例 #1
0
 /**
  * @since 2.0
  *
  * @param mixed $expected
  * @param ExpData $exportData
  */
 public function assertThatExportDataContainsProperty($expectedProperties, ExpData $exportData)
 {
     $expProperties = $exportData->getProperties();
     $this->assertNotEmpty($expProperties);
     $expectedProperties = is_array($expectedProperties) ? $expectedProperties : array($expectedProperties);
     $expectedToCount = count($expectedProperties);
     $actualComparedToCount = 0;
     $assertThatExportDataContainsProperty = false;
     foreach ($expProperties as $expProperty) {
         foreach ($expectedProperties as $expectedProperty) {
             if ($expectedProperty->getHash() === $expProperty->getHash()) {
                 $actualComparedToCount++;
                 $assertThatExportDataContainsProperty = true;
             }
         }
     }
     $this->assertTrue($assertThatExportDataContainsProperty);
     $this->assertEquals($expectedToCount, $actualComparedToCount);
 }
コード例 #2
0
 /**
  * Serialize the given SMWExpData object, possibly recursively with
  * increased indentation.
  *
  * @param $data SMWExpData containing the data to be serialised.
  * @param $indent string specifying a prefix for indentation (usually a sequence of tabs)
  */
 protected function serializeNestedExpData(SMWExpData $data, $indent)
 {
     if (count($data->getProperties()) == 0) {
         return;
         // nothing to export
     }
     // Avoid posting turtle property declarations already known for the
     // subject more than once
     if ($data->getSubject()->getDataItem() !== null && $data->getSubject()->getDataItem()->getNamespace() === SMW_NS_PROPERTY) {
         $hash = $data->getHash();
         $poolCache = InMemoryPoolCache::getInstance()->getPoolCacheFor('turtle.serializer');
         if ($poolCache->contains($hash) && $poolCache->fetch($hash)) {
             return;
         }
         $poolCache->save($hash, true);
     }
     $this->recordDeclarationTypes($data);
     $bnode = false;
     $this->post_ns_buffer .= $indent;
     if (!$data->getSubject()->isBlankNode()) {
         $this->serializeExpResource($data->getSubject());
     } else {
         // blank node
         $bnode = true;
         $this->post_ns_buffer .= "[";
     }
     if ($indent !== '' && !$bnode) {
         // called to generate a nested descripion; but Turtle cannot nest non-bnode descriptions, do this later
         $this->subexpdata[] = $data;
         return;
     } elseif (!$bnode) {
         $this->post_ns_buffer .= "\n ";
     }
     $firstproperty = true;
     foreach ($data->getProperties() as $property) {
         $this->post_ns_buffer .= $firstproperty ? "\t" : " ;\n {$indent}\t";
         $firstproperty = false;
         $prop_decl_queued = false;
         $class_type_prop = $this->isOWLClassTypeProperty($property);
         $this->serializeExpResource($property);
         $firstvalue = true;
         foreach ($data->getValues($property) as $value) {
             $this->post_ns_buffer .= $firstvalue ? '  ' : ' ,  ';
             $firstvalue = false;
             if ($value instanceof SMWExpLiteral) {
                 $prop_decl_type = SMW_SERIALIZER_DECL_APROP;
                 $this->serializeExpLiteral($value);
             } elseif ($value instanceof SMWExpResource) {
                 $prop_decl_type = SMW_SERIALIZER_DECL_OPROP;
                 $this->serializeExpResource($value);
             } elseif ($value instanceof SMWExpData) {
                 // resource (maybe blank node), could have subdescriptions
                 $prop_decl_type = SMW_SERIALIZER_DECL_OPROP;
                 $collection = $value->getCollection();
                 if ($collection !== false) {
                     // RDF-style collection (list)
                     $this->post_ns_buffer .= "( ";
                     foreach ($collection as $subvalue) {
                         $this->serializeNestedExpData($subvalue, $indent . "\t\t");
                         if ($class_type_prop) {
                             $this->requireDeclaration($subvalue->getSubject(), SMW_SERIALIZER_DECL_CLASS);
                         }
                     }
                     $this->post_ns_buffer .= " )";
                 } else {
                     if ($class_type_prop) {
                         $this->requireDeclaration($value->getSubject(), SMW_SERIALIZER_DECL_CLASS);
                     }
                     if (count($value->getProperties()) > 0) {
                         // resource with data: serialise
                         $this->post_ns_buffer .= "\n";
                         $this->serializeNestedExpData($value, $indent . "\t\t");
                     } else {
                         // resource without data: may need to be queued
                         $this->serializeExpResource($value->getSubject());
                     }
                 }
             }
             if (!$prop_decl_queued) {
                 $this->requireDeclaration($property, $prop_decl_type);
                 $prop_decl_queued = true;
             }
         }
     }
     $this->post_ns_buffer .= ($bnode ? " ]" : " .") . ($indent === '' ? "\n\n" : '');
 }
コード例 #3
0
ファイル: SMW_SparqlStore.php プロジェクト: Tjorriemorrie/app
 /**
  * Find a normalized representation of the given SMWExpData that can
  * be used in an update of the stored data. Normalization uses
  * redirects.
  * Moreover, the method records any auxiliary data that should be
  * written to the store when including this SMWExpElement into updates.
  * This auxiliary data is collected in a call-by-ref array.
  *
  * @since 1.6
  * @param $expData SMWExpData object containing the update data
  * @param $auxiliaryExpData array of SMWExpData
  * @param $expandSubject boolean controls if redirects/auxiliary data should also be sought for subject
  * @return SMWExpData
  */
 protected function expandUpdateExpData(SMWExpData $expData, array &$auxiliaryExpData, $expandSubject)
 {
     $subjectExpResource = $expData->getSubject();
     if ($expandSubject) {
         $expandedExpElement = $this->expandUpdateExpElement($subjectExpResource, $auxiliaryExpData);
         if ($expandedExpElement instanceof SMWExpData) {
             $newExpData = $expandedExpElement;
         } else {
             // instanceof SMWExpResource
             $newExpData = new SMWExpData($subjectExpResource);
         }
     } else {
         $newExpData = new SMWExpData($subjectExpResource);
     }
     foreach ($expData->getProperties() as $propertyResource) {
         $propertyTarget = $this->expandUpdateExpElement($propertyResource, $auxiliaryExpData);
         foreach ($expData->getValues($propertyResource) as $expElement) {
             $elementTarget = $this->expandUpdateExpElement($expElement, $auxiliaryExpData);
             $newExpData->addPropertyObjectValue($propertyTarget, $elementTarget);
         }
     }
     return $newExpData;
 }