/** * 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); } }
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'); }