コード例 #1
0
ファイル: OntologyReader.php プロジェクト: ljarray/dbpedia
 /**
  * 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);
             }
         }
     }
 }
コード例 #2
0
ファイル: OWLOntologyWriter.php プロジェクト: ljarray/dbpedia
 private function writeClass(OntologyClass $class, &$output)
 {
     $output .= "\t<owl:Class rdf:about=\"" . $class->getUri() . "\">\n";
     if ($class->getLabel()) {
         $output .= "\t\t<rdfs:label xml:lang=\"en\">" . $class->getLabel() . "</rdfs:label>\n";
     }
     if ($class->getSubClassOf()) {
         $output .= "\t\t<rdfs:subClassOf rdf:resource=\"" . $class->getSubClassOf()->getUri() . "\"/>\n";
     }
     if ($class->getEquivalentClass()) {
         $output .= "\t\t<owl:equivalentClass rdf:resource=\"" . $class->getEquivalentClass()->getUri() . "\"/>\n";
     }
     $output .= "\t</owl:Class>\n\n";
 }