Example #1
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);
 }