private function assertRdfOutputForCase($case) { if (isset($case['exportcontroller']['syntax']) && $case['exportcontroller']['syntax'] === 'turtle') { $serializer = new TurtleSerializer(); } else { $serializer = new RDFXMLSerializer(); } $exportController = new ExportController($serializer); $exportController->enableBacklinks($case['exportcontroller']['parameters']['backlinks']); ob_start(); if (isset($case['exportcontroller']['print-pages'])) { $exportController->printPages($case['exportcontroller']['print-pages'], (int) $case['exportcontroller']['parameters']['recursion'], $case['exportcontroller']['parameters']['revisiondate']); } if (isset($case['exportcontroller']['wiki-info'])) { $exportController->printWikiInfo(); } $output = ob_get_clean(); if ($this->debug) { print_r($output); } if (isset($case['assert-output']['to-contain'])) { $this->stringValidator->assertThatStringContains($case['assert-output']['to-contain'], $output, $case['about']); } if (isset($case['assert-output']['not-contain'])) { $this->stringValidator->assertThatStringNotContains($case['assert-output']['not-contain'], $output, $case['about']); } }
private function fetchSerializedRdfOutputFor(array $pages) { $this->subjects = $pages; $instance = new ExportController(new RDFXMLSerializer()); ob_start(); $instance->printPages($pages); return ob_get_clean(); }
public function testFileUploadForDummyTextFile() { $subject = new DIWikiPage('RdfLinkedFile.txt', NS_FILE); $fileNS = Localizer::getInstance()->getNamespaceTextById(NS_FILE); $dummyTextFile = $this->fixturesFileProvider->newUploadForDummyTextFile('RdfLinkedFile.txt'); $dummyTextFile->doUpload('[[HasFile::File:RdfLinkedFile.txt]]'); $exportController = new ExportController(new RDFXMLSerializer()); $exportController->enableBacklinks(false); ob_start(); $exportController->printPages(array($subject->getTitle()->getPrefixedDBKey())); $output = ob_get_clean(); $expected = array("<rdfs:label>{$fileNS}:RdfLinkedFile.txt</rdfs:label>", '<swivt:file rdf:resource="' . $dummyTextFile->getLocalFile()->getFullURL() . '"/>', '<property:Media_type-23aux rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TEXT</property:Media_type-23aux>', '<property:MIME_type-23aux rdf:datatype="http://www.w3.org/2001/XMLSchema#string">text/plain</property:MIME_type-23aux>'); $this->stringValidator->assertThatStringContains($expected, $output); }
private function assertRdfOutputForCase($case, $debug) { $exportController = new ExportController(new RDFXMLSerializer()); $exportController->enableBacklinks($case['exportcontroller']['parameters']['backlinks']); ob_start(); if (isset($case['exportcontroller']['print-pages'])) { $exportController->printPages($case['exportcontroller']['print-pages'], (int) $case['exportcontroller']['parameters']['recursion'], $case['exportcontroller']['parameters']['revisiondate']); } if (isset($case['exportcontroller']['wiki-info'])) { $exportController->printWikiInfo(); } $output = ob_get_clean(); if ($debug) { print_r($output); } $this->stringValidator->assertThatStringContains($case['expected-output']['to-contain'], $output, $case['about']); }
/** * @since 2.0 made protected; use printAllToFile or printAllToOutput */ protected function printAll($ns_restriction = false, $delay, $delayeach) { $linkCache = LinkCache::singleton(); $db = wfGetDB(DB_SLAVE); $this->delay_flush = 10; $this->serializer->startSerialization(); $this->serializer->serializeExpData(SMWExporter::getOntologyExpData('')); $end = $db->selectField('page', 'max(page_id)', false, __METHOD__); $a_count = 0; $d_count = 0; // DEBUG $delaycount = $delayeach; for ($id = 1; $id <= $end; $id += 1) { $title = Title::newFromID($id); if (is_null($title) || !smwfIsSemanticsProcessed($title->getNamespace())) { continue; } if (!SMWExportController::fitsNsRestriction($ns_restriction, $title->getNamespace())) { continue; } $a_count += 1; // DEBUG $diPage = SMWDIWikiPage::newFromTitle($title); $this->queuePage($diPage, 1); while (count($this->element_queue) > 0) { $diPage = reset($this->element_queue); $this->serializePage($diPage, $diPage->recdepth); // resolve dependencies that will otherwise not be printed foreach ($this->element_queue as $key => $diaux) { if (!smwfIsSemanticsProcessed($diaux->getNamespace()) || !SMWExportController::fitsNsRestriction($ns_restriction, $diaux->getNamespace())) { // Note: we do not need to check the cache to guess if an element was already // printed. If so, it would not be included in the queue in the first place. $d_count += 1; // DEBUG } else { // don't carry values that you do not want to export (yet) unset($this->element_queue[$key]); } } // sleep each $delaycount for $delay µs to be nice to the server if ($delaycount-- < 0 && $delayeach != 0) { usleep($delay); $delaycount = $delayeach; } } $this->flush(); $linkCache->clear(); } $this->serializer->finishSerialization(); $this->flush(true); }
private function exportRdfToOutputChannel() { $exportController = new ExportController(new RDFXMLSerializer()); if ($this->pages !== array()) { return $exportController->printPages($this->pages); } if ($this->hasOption('file')) { return $exportController->printAllToFile($this->getOption('file'), $this->restrictNamespaceTo, $this->delay, $this->delayeach); } $exportController->printAllToOutput($this->restrictNamespaceTo, $this->delay, $this->delayeach); }
} else { $delay = 0; } if (!empty($options['e'])) { $delayeach = intval($options['e']); } else { $delayeach = $delay === 0 ? 0 : 1; } if (array_key_exists('categories', $options)) { $export_ns = NS_CATEGORY; } elseif (array_key_exists('concepts', $options)) { $export_ns = SMW_NS_CONCEPT; } elseif (array_key_exists('classes', $options)) { $export_ns = array(NS_CATEGORY, SMW_NS_CONCEPT); } elseif (array_key_exists('properties', $options)) { $export_ns = SMW_NS_PROPERTY; } elseif (array_key_exists('types', $options)) { $export_ns = SMW_NS_TYPE; } elseif (array_key_exists('individuals', $options)) { $export_ns = -1; } else { $export_ns = false; } if (isset($options['server'])) { $wgServer = $options['server']; } if ($outfile && empty($options['q'])) { print "\nWriting OWL/RDF dump to file \"{$outfile}\" ...\n"; } $exRDF = new SMWExportController(new SMWRDFXMLSerializer()); $exRDF->printAll($outfile, $export_ns, $delay, $delayeach);