public static function addProperties(Ontology $ontology) { $ontology->addProperty(new OntologyDataTypeProperty(self::PROPERTY, $ontology->getClass("owl:Thing"), $ontology->getDataType("xsd:string"))); }
/** * Links all classes and properties according to the configuration. * * TODO: It would be cleaner to use a two-stage process: Copy the data (class and property * names etc.) from the page nodes to intermediary data structures (probably simple maps * or simple data objects), then build the final ontology objects from these data * structures. No need to go through the page nodes twice, no need to modify or remove * classes after they were added to the ontology. Would also enable checks for cyclic * dependencies etc. * * @param $ontology The ontology instance * @param $pageNode The page node of the configuration page */ private function linkClasses(Ontology $ontology, PageNode $pageNode) { $name = self::getPageName($pageNode); foreach ($pageNode->getChildren('TemplateNode') as $node) { //Class $templateName = $node->getTitle()->encoded(); if ($templateName == OntologyClass::TEMPLATE_NAME) { $ontologyClass = $ontology->getClass($name); //Sub class $subClassNode = $node->getProperty("rdfs:subClassOf"); if ($subClassNode) { try { $parentClass = $ontology->getClass($subClassNode->getText()); $ontologyClass->setSubClassOf($parentClass); } catch (\InvalidArgumentException $e) { $this->logger->warn("subClassOf " . $name . " (" . $subClassNode->getText() . ") not found"); } } //Equivalent Class $equivalentClassNode = $node->getProperty("owl:equivalentClass"); if ($equivalentClassNode) { try { $equivalentClass = $ontology->getClass($equivalentClassNode->getText()); $ontologyClass . setEquivalentClass($equivalentClass); } catch (\InvalidArgumentException $e) { $this->logger->warn("equivalentClass " . $name . " (" . $equivalentClassNode->getText() . ") not found"); } } } else { if ($templateName == OntologyObjectProperty::TEMPLATE_NAME || $templateName == OntologyDataTypeProperty::TEMPLATE_NAME) { $ontologyProperty = $ontology->getProperty($name); //Domain $domainUriNode = $node->getProperty("rdfs:domain"); if ($domainUriNode) { try { $domainClass = $ontology->getClass($domainUriNode->getText()); } catch (\InvalidArgumentException $e) { $this->logger->warn("Domain of " . $name . " (" . $domainUriNode->getText() . ") not found. Assuming owl:Thing"); $domainClass = $ontology->getClass("owl:Thing"); } $ontologyProperty->setDomain($domainClass); } else { $ontologyProperty->setDomain($ontology->getClass("owl:Thing")); } //Range $rangeUriNode = $node->getProperty("rdfs:range"); if ($rangeUriNode) { if ($ontologyProperty instanceof OntologyObjectProperty) { try { $rangeClass = $ontology->getClass($rangeUriNode->getText()); } catch (\InvalidArgumentException $e) { $this->logger->warn("Range of " . $name . " (" . $rangeUriNode->getText() . ") not found. Assuming owl:Thing"); $rangeClass = $ontology->getClass("owl:Thing"); } $ontologyProperty->setRange($rangeClass); } else { try { $dataType = $ontology->getDataType($rangeUriNode->getText()); $ontologyProperty->setRange($dataType); } catch (\InvalidArgumentException $e) { $this->logger->warn("Range of " . $name . " (" . $rangeUriNode->getText() . ") not found. Removing property."); $ontology->removeProperty($ontologyProperty); } } } else { if ($ontologyProperty instanceof OntologyObjectProperty) { $ontologyProperty->setRange($ontology->getClass("owl:Thing")); } else { $this->logger->warn("Range of " . $name . " not defined. Removing property."); $ontology->removeProperty($ontologyProperty); } } } } } }