示例#1
0
 /**
  * Loads an ontology from configuration files using the DBpedia mapping language.
  *
  * @param $pages Array of PageNode instances containing the configuration files
  * @return Ontology The ontology
  */
 public function read(array $pages)
 {
     $ontology = new Ontology();
     $ontology->addClass(new OntologyClass("owl:Thing"));
     OntologyDataTypes::addDataTypes($ontology);
     // TODO: range should be rdfs:Class
     $ontology->addProperty(new OntologyProperty("rdf:type", $ontology->getClass("owl:Thing")));
     foreach ($pages as $pageNode) {
         OntologyReader::createClasses($ontology, $pageNode);
     }
     foreach ($pages as $pageNode) {
         OntologyReader::linkClasses($ontology, $pageNode);
     }
     return $ontology;
 }
示例#2
0
 /**
  * Loads the ontology
  */
 private function loadOntology()
 {
     if ($this->allowCaching && file_exists(self::ONTOLOGY_FILE)) {
         $this->logger->info('Loading ontology from file.');
         $this->ontology = unserialize(file_get_contents(self::ONTOLOGY_FILE));
     } else {
         //Parse ontology schema pages
         $this->logger->info('Reading ontology...');
         $ontologyPages = $this->loadAllPages($this->ontologySource);
         //Load ontology
         $ontologyReader = new OntologyReader();
         $this->ontology = $ontologyReader->read($ontologyPages);
         LabelExtractor::addProperties($this->ontology);
         AbstractExtractor::addProperties($this->ontology);
         $this->destroyAllPages($ontologyPages);
         file_put_contents(self::ONTOLOGY_FILE, serialize($this->ontology));
         //Show the extracted ontology
         $writer = new ontology\OWLOntologyWriter();
         echo $writer->toOWL($this->ontology);
     }
 }
示例#3
0
 private function processOntology()
 {
     $path = $this->ontologyPath();
     if ($path === false) {
         return false;
     }
     try {
         $name = OntologyReader::getName($path);
         // check that namespace is known
         OntologyNamespaces::getUri($name, 'http://example.com/');
     } catch (\Exception $e) {
         $this->response(400, 'Invalid ontology page title ' . $path);
         return true;
         // we're done, give up
     }
     // TODO: add the following two lines? or at least the first line?
     // if (! $this->parsePage()) return true; // we're done, give up
     // if (! $this->hasTemplate(self::$ontologyTemplates)) ignore data? send error response?
     // forward source to ultrapedia
     // Ontology pages don't exist @ Ultrapedia
     //if (! $this->sendWiki()) return true; // error response already sent
     try {
         $configHolder = $this->configHandler->updateOntology($path, $this->rawPage);
     } catch (\Exception $e) {
         $this->response(500, 'Internal server error', 'Failed to update ontology: ' . $e);
         return true;
         // give up
     }
     $writer = new OWLOntologyWriter();
     $owl = $writer->toOWL($configHolder->ontology);
     if (!$this->sendOwl($owl)) {
         return true;
     }
     // error response already sent
     return $this->response(200, 'Successfully updated ontology schema');
 }
示例#4
0
 /**
  * @param $abstracts should properties for AbstractExtractor be added to ontology?
  * TODO: Create an interface ExtractorBuilder with methods addProperties() and createExtractor().
  * Give this method an array of ExtractorBuilders.
  */
 public function loadOntology($abstracts = true)
 {
     $ontologyPages = $this->loadAllPages($this->ontologyDir);
     $ontologyReader = new OntologyReader();
     $ontology = $ontologyReader->read($ontologyPages);
     \dbpedia\mapping\LabelExtractor::addProperties($ontology);
     if ($abstracts) {
         \dbpedia\mapping\AbstractExtractor::addProperties($ontology);
     }
     $this->destroyAllPages($ontologyPages);
     return $ontology;
 }