Exemplo n.º 1
0
 public function equals(Statement $toTest)
 {
     if ($toTest instanceof Statement && $this->getSubject()->equals($toTest->getSubject()) && $this->getPredicate()->equals($toTest->getPredicate()) && $this->getObject()->equals($toTest->getObject())) {
         if ($this->isQuad() && $toTest->isQuad() && $this->getGraph()->equals($toTest->getGraph())) {
             return true;
         } elseif ($this->isTriple() && $toTest->isTriple()) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Returns the object.
  *
  * @return Resource
  * @access	public
  */
 function getObject()
 {
     return $this->statement->getObject();
 }
 public function mapFreebaseStatement(Statement $statement)
 {
     $subject = $this->mapFreebaseUri($statement->getSubject());
     $this->statistics['triple-mapped-subject']++;
     $isValueCvt = $this->cvtProvider->isCVTProperty($statement->getPredicate());
     $predicate = $this->mapFreebaseProperty($statement->getPredicate());
     $this->statistics['triple-mapped-subject-property']++;
     $objects = [];
     $qualifiers = [];
     $source = [];
     $isReviewed = $this->reviewedFacts->isReviewedFact($statement->getSubject(), $statement->getPredicate());
     if ($isValueCvt && !$this->propertyExpectCvt($predicate)) {
         $this->statistics['triple-value-cvt']++;
         //CVT management
         $cvt = $this->cvtProvider->getCVT($statement->getObject());
         //Special cases
         $specialMapping = [];
         if ($predicate instanceof SpouseProperty) {
             if (array_key_exists('<http://rdf.freebase.com/ns/people.marriage.type_of_union>', $cvt)) {
                 switch ($cvt['<http://rdf.freebase.com/ns/people.marriage.type_of_union>'][0]) {
                     case '<http://rdf.freebase.com/ns/m.04ztj>':
                     case '<http://rdf.freebase.com/ns/m.0jgjn>':
                     case '<http://rdf.freebase.com/ns/m.0dl5ys>':
                     case '<http://rdf.freebase.com/ns/m.03m4r>':
                     case '<http://rdf.freebase.com/ns/m.01bl8s>':
                     case '<http://rdf.freebase.com/ns/m.075xk9>':
                         $predicate = new WikidataProperty('P26', false, 'wikibase-item');
                         break;
                     case '<http://rdf.freebase.com/ns/m.01g63y>':
                         throw new Mappingfailure();
                         //TODO: What to do with https://www.freebase.com/m/01g63y Domestic partnership
                         /*$predicate = new WikidataProperty('P451', false, 'wikibase-item');
                         		break;*/
                     //TODO: What to do with https://www.freebase.com/m/01g63y Domestic partnership
                     /*$predicate = new WikidataProperty('P451', false, 'wikibase-item');
                     		break;*/
                     default:
                         throw new Exception('Unknown mariage type: ' . $cvt['<http://rdf.freebase.com/ns/people.marriage.type_of_union>'][0]);
                 }
                 $this->statistics['triple-used']++;
             } else {
                 //By default we concider that it is a union
                 $predicate = new WikidataProperty('P26', false, 'wikibase-item');
             }
             $specialMapping['/ns/people.marriage.spouse'] = $predicate;
         }
         foreach ($cvt as $cvtPredicate => $values) {
             foreach ($values as $value) {
                 try {
                     $property = $this->mapFreebaseProperty($cvtPredicate, $specialMapping);
                     if ($property instanceof ValueProperty) {
                         $objects[] = $this->mapValue($value, $property);
                         $this->statistics['triple-used']++;
                     } elseif ($property instanceof WikidataProperty) {
                         list($pred, $value) = $this->mapQualifierValue($cvtPredicate, $property, $value);
                         if ($value !== $subject) {
                             //Filter qualifiers that have as value the subject. Useful when the relation is used in both directions in Wikidata
                             if ($property->isSource()) {
                                 $source[str_replace('P', 'S', $pred)][] = $value;
                             } else {
                                 $qualifiers[$pred][] = $value;
                             }
                             $this->statistics['triple-used']++;
                         }
                     } else {
                         throw new Exception('Invalid property as qualifier');
                     }
                     if ($this->reviewedFacts->isReviewedFact($statement->getObject(), $cvtPredicate)) {
                         $isReviewed = true;
                         //We should maybe be harder and ask for everything reviewed
                     }
                 } catch (Mappingfailure $e) {
                     //don't fail for qualifiers
                 }
             }
         }
         if (empty($objects) && $predicate instanceof WikidataProperty) {
             if (!array_key_exists($predicate->getPid(), $qualifiers)) {
                 //Find main property
                 throw new Mappingfailure();
             }
             $objects = $qualifiers[$predicate->getPid()];
             unset($qualifiers[$predicate->getPid()]);
         }
     } else {
         $objects[] = $this->mapValue($statement->getObject(), $predicate);
     }
     if (!$predicate instanceof WikidataProperty) {
         throw new Mappingfailure();
     }
     $statements = [];
     foreach ($objects as $object) {
         //Special formatting
         if ($predicate->getPid() === 'P774') {
             if (preg_match('/^(\\d{2})(\\d{5})$/', $object, $m)) {
                 $object = $m[1] . '-' . $m[2];
             }
         } elseif ($predicate->getPid() === 'P274') {
             $object = str_replace(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], ['₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉', '₀'], $object);
         } elseif (in_array($predicate->getPid(), ['P1953', 'P1954', 'P1955']) && !is_numeric($object)) {
             throw new Mappingfailure();
         } elseif (strpos($statement->getPredicate(), '/key/') !== false) {
             $object = $this->unescapeFreebaseKey($object);
         }
         $statements[] = new Statement($subject, $predicate->getPid(), $object, $qualifiers, $source, $isReviewed);
     }
     $this->statistics['triple-used']++;
     $this->statistics['claim-created'] += count($statements);
     return $statements;
 }