Пример #1
0
 public function setDestination($destinationId, $destination)
 {
     PhpUtil::assertString($destinationId, 'destination id');
     PhpUtil::assertType($destination, 'dbpedia\\destinations\\QuadDestination', 'destination');
     if (isset($this->destinations[$destinationId])) {
         throw new \InvalidArgumentException('destination for id [' . $destinationId . '] already set');
     }
     $this->destinations[$destinationId] = $destination;
 }
Пример #2
0
 public function addUnit($unit)
 {
     PhpUtil::assertType($unit, 'dbpedia\\ontology\\dataTypes\\UnitDataType', 'unit');
     $unit->setDimension($this);
     foreach ($unit->getLabels() as $label) {
         if (isset($this->units[$label])) {
             throw new \InvalidArgumentException($this . ' already has unit label ' . $label);
         }
         $this->units[$label] = $unit;
     }
 }
Пример #3
0
 /**
  * Loads all classes and properties but does not link them.
  *
  * @param $ontology The ontology instance
  * @param $pageNode The page node of the configuration page
  */
 private function createClasses($ontology, $pageNode)
 {
     // PHP keeps going if param type is wrong, but we want an exception
     PhpUtil::assertType($ontology, 'dbpedia\\ontology\\Ontology', 'ontology');
     PhpUtil::assertType($pageNode, 'dbpedia\\wikiparser\\PageNode', 'page node');
     $name = self::getPageName($pageNode);
     foreach ($pageNode->getChildren('TemplateNode') as $node) {
         $templateName = $node->getTitle()->encoded();
         if ($templateName == OntologyClass::TEMPLATE_NAME) {
             $ontClass = new OntologyClass($name);
             $labelProperty = $node->getProperty("rdfs:label");
             if ($labelProperty) {
                 $ontClass->setLabel($labelProperty->getText());
             } else {
                 $this->logger->warn("Class " . $ontClass->getUri() . " does not define any label.");
             }
             $ontology->addClass($ontClass);
         } else {
             if ($templateName == OntologyObjectProperty::TEMPLATE_NAME || $templateName == OntologyDataTypeProperty::TEMPLATE_NAME) {
                 if ($templateName == OntologyObjectProperty::TEMPLATE_NAME) {
                     $ontProperty = new OntologyObjectProperty($name);
                 } else {
                     $ontProperty = new OntologyDataTypeProperty($name);
                 }
                 $labelProperty = $node->getProperty("rdfs:label");
                 if ($labelProperty) {
                     $ontProperty->setLabel($labelProperty->getText());
                 } else {
                     $this->logger->warn("Property without any label found on page " . $pageName);
                 }
                 $typeProperty = $node->getProperty("rdf:type");
                 if ($typeProperty) {
                     if ($typeProperty->getText() == 'owl:FunctionalProperty') {
                         $ontProperty->setFunctional(true);
                     } else {
                         $this->logger->warn("Property with an invalid type found on page " . $pageName);
                     }
                 }
                 $ontology->addProperty($ontProperty);
             }
         }
     }
 }
Пример #4
0
 public function __construct($destination)
 {
     PhpUtil::assertType($destination, 'dbpedia\\destinations\\QuadDestination', 'destination');
     $this->destination = $destination;
 }