rdfWriter = $writer; } /** * Setup prefixes relevant for the dump */ public function setupPrefixes() { $this->rdfWriter->prefix( self::ONTOLOGY_PREFIX, self::ONTOLOGY_URL ); $this->rdfWriter->prefix( 'rdfs', 'http://www.w3.org/2000/01/rdf-schema#' ); $this->rdfWriter->prefix( 'owl', 'http://www.w3.org/2002/07/owl#' ); $this->rdfWriter->prefix( 'schema', 'http://schema.org/' ); $this->rdfWriter->prefix( 'cc', 'http://creativecommons.org/ns#' ); } /** * Write RDF data for link between categories. * @param string $fromName Child category name * @param string $toName Parent category name */ public function writeCategoryLinkData( $fromName, $toName ) { $titleFrom = Title::makeTitle( NS_CATEGORY, $fromName ); $titleTo = Title::makeTitle( NS_CATEGORY, $toName ); $this->rdfWriter->about( $this->titleToUrl( $titleFrom ) ) ->say( self::ONTOLOGY_PREFIX, 'isInCategory' ) ->is( $this->titleToUrl( $titleTo ) ); } /** * Write out the data for single category. * @param string $categoryName Category name */ public function writeCategoryData( $categoryName ) { $title = Title::makeTitle( NS_CATEGORY, $categoryName ); $this->rdfWriter->about( $this->titleToUrl( $title ) ) ->say( 'a' ) ->is( self::ONTOLOGY_PREFIX, 'Category' ); $titletext = $title->getText(); $this->rdfWriter->say( 'rdfs', 'label' )->value( $titletext ); } /** * Convert Title to link to target page. * @param Title $title * @return string */ private function titleToUrl( Title $title ) { return $title->getFullURL( '', false, PROTO_CANONICAL ); } }