Example #1
0
 /**
  * @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;
 }
Example #2
0
 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() . ')');
         }
     }
 }
Example #4
0
 /**
  * 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)');
 }
Example #5
0
 /**
  * @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));
 }
Example #6
0
 private function processData()
 {
     if ($this->parsedTitle->nsCode() !== WikiTitle::NS_MAIN) {
         return false;
     }
     if (!$this->parsePage()) {
         return true;
     }
     // we're done, give up
     try {
         $configHolder = $this->configHandler->loadConfigFile();
     } catch (\Exception $e) {
         return $this->response(500, 'Internal server error', 'Failed to load config: ' . $e);
     }
     // forward source to ultrapedia
     if (!$this->sendWiki()) {
         return true;
     }
     // error response already sent
     $secs = microtime(true);
     $extractor = $configHolder->extractor;
     // destinations must be SingletonQuadDestinations, so key doesn't matter
     // destination must be a StringQuadDestination
     // TODO: check types
     $destination = $configHolder->destinations->getDestination('');
     $pageUri = OntologyNamespaces::appendUri(OntologyNamespaces::DBPEDIA_INSTANCE_NAMESPACE, $this->parsedTitle->encoded());
     $pageContext = new mapping\PageContext($pageUri);
     $extractor->extract($this->parsedPage, $pageUri, $pageContext);
     $delete = $this->delete($this->parsedPage->getSourceUriPrefix());
     $insert = $this->insert((string) $destination);
     $sparul = $this->sparul(array($delete, $insert));
     $this->log->info('Successfully extracted data (' . (microtime(true) - $secs) * 1000 . ' millis)');
     // send triples to triple store
     if (!$this->sendSparul($sparul)) {
         return true;
     }
     // error response already sent
     return $this->response(200, 'Successfully extracted data', $this->reply ? "Successfully extracted data.\n\n" . $sparul : null);
 }
Example #7
0
 /**
  * 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);
 }