/** * @param $name string, unit name used in ontology and mapping configuration * @param $labels list of strings, unit labels used in template property values */ public function __construct($name, $labels) { parent::__construct($name, OntologyNamespaces::getUri($name, OntologyNamespaces::DBPEDIA_ONTOLOGY_NAMESPACE)); if (!is_array($labels)) { throw new \InvalidArgumentException('labels must be an array'); } $this->labels = $labels; }
public function parse(Node $node) { if ($node instanceof PropertyNode) { $children = $node->getChildren('LinkNode'); foreach ($children as $child) { if (!$child->isExternalLink()) { $link = $child->getDestination(); if ($link) { return OntologyNamespaces::getUri($link->encoded(), OntologyNamespaces::DBPEDIA_INSTANCE_NAMESPACE); } } } } return null; }
private function writeGeoQuad($node, $subjectUri, $lat, $long) { if ($lat != '' && $long != '') { try { if (isset($this->ontologyProperty)) { // TODO: replace label with local part w/o class $ontologyPropertyLabel = $this->ontologyProperty->getLabel(); $originalSubjectUri = $subjectUri; $subjectUri = $this->pageContext->generateUri(OntologyNamespaces::getUri($node->getRoot()->getTitle()->encoded(), OntologyNamespaces::DBPEDIA_INSTANCE_NAMESPACE) . '__' . $ontologyPropertyLabel, null); $quad = new RdfQuad($subjectUri, $this->ontology->getProperty("rdf:type"), $this->ontology->getClass("gml:_Feature")->getUri(), $node->getSourceUri()); $this->destination->addQuad($quad); $quad = new RdfQuad($originalSubjectUri, $this->ontologyProperty, $subjectUri, $node->getSourceUri()); $this->destination->addQuad($quad); } $geoLat = $this->ontology->getProperty("geo:lat"); $geoLong = $this->ontology->getProperty("geo:long"); $georssPoint = $this->ontology->getProperty("georss:point"); $quad = new RdfQuad($subjectUri, $geoLat, $lat, $node->getSourceUri()); $this->destination->addQuad($quad); $quad = new RdfQuad($subjectUri, $geoLong, $long, $node->getSourceUri()); $this->destination->addQuad($quad); $quad = new RdfQuad($subjectUri, $georssPoint, $lat . " " . $long, $node->getSourceUri()); $this->destination->addQuad($quad); return true; } catch (\InvalidArgumentException $e) { $this->logger->warn($e->getMessage() . ' (Page: ' . $node->getRoot()->getTitle() . ')'); } } }
/** * Extracts all pages in the source directory according to the mappings */ private function extract() { $this->logger->info('Extracting...'); $extractor = $this->extractor; $pageCount = 0; $startTime = microtime(true); $logger = $this->logger; $callback = function ($page) use($extractor, &$pageCount, $startTime, $logger) { $pageUri = OntologyNamespaces::getUri($page->getTitle()->encoded(), OntologyNamespaces::DBPEDIA_INSTANCE_NAMESPACE); $pageContext = new mapping\PageContext($pageUri); $extractor->extract($page, $pageUri, $pageContext); $pageCount++; if ($pageCount % 10 == 0) { $timePerPage = round((microtime(true) - $startTime) * 1000.0 / $pageCount, 0); $logger->info('Extracted pages: ' . $pageCount . ' (' . $timePerPage . ' ms per page)'); } }; $this->pageSource->processPages($callback); $this->logger->info('Extraction finished (' . $pageCount . ' pages)'); }
/** * @param $name string, dimension name used in ontology and mapping configuration */ public function __construct($name) { parent::__construct($name, OntologyNamespaces::getUri($name, OntologyNamespaces::DBPEDIA_ONTOLOGY_NAMESPACE)); }
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'); }
/** * The uri of this property. * * @return string The uri of this property e.g. http://xmlns.com/foaf/0.1/name */ public function getUri() { return OntologyNamespaces::getUri($this->name, OntologyNamespaces::DBPEDIA_PROPERTY_NAMESPACE); }