MediaWiki  1.34.0
CategoriesRdf.php
Go to the documentation of this file.
1 <?php
19 use Wikimedia\Purtle\RdfWriter;
20 
28  const ONTOLOGY_PREFIX = 'mediawiki';
32  const ONTOLOGY_URL = 'https://www.mediawiki.org/ontology#';
36  const OWL_URL = 'https://www.mediawiki.org/ontology/ontology.owl';
40  const FORMAT_VERSION = "1.1";
46  const SPECIAL_DUMP = 'Special:CategoryDump';
50  private $rdfWriter;
51 
52  public function __construct( RdfWriter $writer ) {
53  $this->rdfWriter = $writer;
54  }
55 
59  public function setupPrefixes() {
60  $this->rdfWriter->prefix( self::ONTOLOGY_PREFIX, self::ONTOLOGY_URL );
61  $this->rdfWriter->prefix( 'rdfs', 'http://www.w3.org/2000/01/rdf-schema#' );
62  $this->rdfWriter->prefix( 'owl', 'http://www.w3.org/2002/07/owl#' );
63  $this->rdfWriter->prefix( 'schema', 'http://schema.org/' );
64  $this->rdfWriter->prefix( 'cc', 'http://creativecommons.org/ns#' );
65  }
66 
72  public function writeCategoryLinkData( $fromName, $toName ) {
73  $titleFrom = Title::makeTitle( NS_CATEGORY, $fromName );
74  $titleTo = Title::makeTitle( NS_CATEGORY, $toName );
75  $this->rdfWriter->about( $this->titleToUrl( $titleFrom ) )
76  ->say( self::ONTOLOGY_PREFIX, 'isInCategory' )
77  ->is( $this->titleToUrl( $titleTo ) );
78  }
79 
87  public function writeCategoryData( $categoryName, $isHidden, $pages, $subcategories ) {
88  if ( $pages < 0 ) {
89  // Bugfix for T201119
90  $pages = 0;
91  }
92  $title = Title::makeTitle( NS_CATEGORY, $categoryName );
93  $this->rdfWriter->about( $this->titleToUrl( $title ) )
94  ->say( 'a' )
95  ->is( self::ONTOLOGY_PREFIX, 'Category' );
96  if ( $isHidden ) {
97  $this->rdfWriter->is( self::ONTOLOGY_PREFIX, 'HiddenCategory' );
98  }
99  $titletext = $title->getText();
100  $this->rdfWriter->say( 'rdfs', 'label' )->value( $titletext );
101  $this->rdfWriter->say( self::ONTOLOGY_PREFIX, 'pages' )->value( $pages );
102  $this->rdfWriter->say( self::ONTOLOGY_PREFIX, 'subcategories' )->value( $subcategories );
103  // TODO: do we want files too here? Easy to add, but don't have use case so far.
104  }
105 
111  public function labelToUrl( $titleLabel ) {
112  return $this->titleToUrl( Title::makeTitle( NS_CATEGORY, $titleLabel ) );
113  }
114 
120  private function titleToUrl( Title $title ) {
121  return $title->getFullURL( '', false, PROTO_CANONICAL );
122  }
123 
128  public function getDumpURI() {
129  return $this->titleToUrl( Title::makeTitle( NS_MAIN, self::SPECIAL_DUMP ) );
130  }
131 
132 }
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:203
CategoriesRdf
Helper class to produce RDF representation of categories.
Definition: CategoriesRdf.php:24
CategoriesRdf\OWL_URL
const OWL_URL
OWL description of the ontology.
Definition: CategoriesRdf.php:36
CategoriesRdf\ONTOLOGY_URL
const ONTOLOGY_URL
Base URL for Mediawiki ontology.
Definition: CategoriesRdf.php:32
CategoriesRdf\labelToUrl
labelToUrl( $titleLabel)
Make URL from title label.
Definition: CategoriesRdf.php:111
CategoriesRdf\$rdfWriter
RdfWriter $rdfWriter
Definition: CategoriesRdf.php:50
NS_MAIN
const NS_MAIN
Definition: Defines.php:60
CategoriesRdf\FORMAT_VERSION
const FORMAT_VERSION
Current version of the dump format.
Definition: CategoriesRdf.php:40
CategoriesRdf\writeCategoryLinkData
writeCategoryLinkData( $fromName, $toName)
Write RDF data for link between categories.
Definition: CategoriesRdf.php:72
$title
$title
Definition: testCompression.php:34
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:74
CategoriesRdf\titleToUrl
titleToUrl(Title $title)
Convert Title to link to target page.
Definition: CategoriesRdf.php:120
CategoriesRdf\SPECIAL_DUMP
const SPECIAL_DUMP
Special page for Dump identification.
Definition: CategoriesRdf.php:46
CategoriesRdf\writeCategoryData
writeCategoryData( $categoryName, $isHidden, $pages, $subcategories)
Write out the data for single category.
Definition: CategoriesRdf.php:87
CategoriesRdf\setupPrefixes
setupPrefixes()
Setup prefixes relevant for the dump.
Definition: CategoriesRdf.php:59
Title
Represents a title within MediaWiki.
Definition: Title.php:42
CategoriesRdf\__construct
__construct(RdfWriter $writer)
Definition: CategoriesRdf.php:52
CategoriesRdf\ONTOLOGY_PREFIX
const ONTOLOGY_PREFIX
Prefix used for Mediawiki ontology in the dump.
Definition: CategoriesRdf.php:28
CategoriesRdf\getDumpURI
getDumpURI()
Get URI of the dump for this particular wiki.
Definition: CategoriesRdf.php:128