r86266 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86265‎ | r86266 | r86267 >
Date:17:20, 17 April 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
improved RDF export code structure, enable equivalence-inducing redirects for properties
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php
@@ -43,8 +43,11 @@
4444
4545 /**
4646 * Create exportable data from a given semantic data record.
 47+ *
 48+ * @param $semdata SMWSemanticData
 49+ * @return SMWExpData
4750 */
48 - static public function makeExportData( /*SMWSemanticData*/ $semdata ) {
 51+ static public function makeExportData( SMWSemanticData $semdata ) {
4952 SMWExporter::initBaseURIs();
5053 $subject = $semdata->getSubject();
5154 if ( $subject->getNamespace() == SMW_NS_PROPERTY ) {
@@ -71,7 +74,7 @@
7275 */
7376 static public function makeExportDataForSubject( SMWDIWikiPage $subject, $typesvalueforproperty = null ) {
7477 global $wgContLang;
75 - $result = new SMWExpData( self::getDataItemExpData( $subject ) );
 78+ $result = new SMWExpData( self::getDataItemExpElement( $subject ) );
7679 $subjectTitle = str_replace( '_', ' ', $subject->getDBkey() );
7780 if ( $subject->getNamespace() !== 0 ) {
7881 $prefixedSubjectTitle = $wgContLang->getNsText( $subject->getNamespace()) . ":" . $subjectTitle;
@@ -121,7 +124,7 @@
122125 if ( $property->isUserDefined() ) {
123126 $pe = SMWExporter::getResourceElement( $property );
124127 foreach ( $dataItems as $dataItem ) {
125 - $ed = self::getDataItemExpData( $dataItem );
 128+ $ed = self::getDataItemExpElement( $dataItem );
126129 if ( $ed !== null ) {
127130 $expData->addPropertyObjectValue( $pe, $ed );
128131 }
@@ -131,50 +134,60 @@
132135 if ( ( $diSubject == null ) || ( $diSubject->getDIType() != SMWDataItem::TYPE_WIKIPAGE ) ) {
133136 return; // subject datavalue (wikipage) required for treating special properties properly
134137 }
135 - switch ( $diSubject->getNamespace() ) {
136 - case NS_CATEGORY: case SMW_NS_CONCEPT:
137 - $category_pe = SMWExporter::getSpecialNsResource( 'rdfs', 'subClassOf' );
138 - $subprop_pe = null;
139 - $equality_pe = SMWExporter::getSpecialNsResource( 'owl', 'equivalentClass' );
 138+
 139+ $filterNamespace = 0; // if not 0 then limit exported values to pages in this namespace
 140+ switch ( $property->getKey() ) {
 141+ case '_INST':
 142+ $pe = SMWExporter::getSpecialNsResource( 'rdf', 'type' );
140143 break;
141 - case SMW_NS_PROPERTY:
142 - $category_pe = SMWExporter::getSpecialNsResource( 'rdf', 'type' );
143 - $subprop_pe = SMWExporter::getSpecialNsResource( 'rdfs', 'subPropertyOf' );
144 - $equality_pe = SMWExporter::getSpecialNsResource( 'owl', 'equivalentProperty' );
 144+ case '_SUBC':
 145+ $pe = SMWExporter::getSpecialNsResource( 'rdfs', 'subClassOf' );
145146 break;
146 - default:
147 - $category_pe = SMWExporter::getSpecialNsResource( 'rdf', 'type' );
148 - $subprop_pe = null;
149 - $equality_pe = SMWExporter::getSpecialNsResource( 'owl', 'sameAs' );
150 - }
151 - $pe = null;
152 - $cat_only = false; // basic namespace checking for equivalent categories
153 - switch ( $property->getKey() ) {
154 - ///TODO: distinguish instanceof and subclassof in the _INST case
155 - case '_INST': $pe = $category_pe; break;
156 - case '_CONC': $pe = $equality_pe; break;
157 - case '_URI': $pe = $equality_pe; break;
158 - case '_SUBP': $pe = $subprop_pe; break;
159 - case '_MDAT':
160 - $pe = SMWExporter::getSpecialNsResource( 'swivt', 'wikiPageModificationDate' );
 147+ case '_CONC': // we actually simplify this below, but need a non-null value now
 148+ $pe = SMWExporter::getSpecialNsResource( 'owl', 'equivalentClass' );
161149 break;
162 - case '_REDI': /// TODO: currently no check for avoiding OWL DL illegal redirects is done
 150+ case '_URI': case '_REDI':
 151+ /// TODO: currently no full check for avoiding OWL DL illegal redirects is done
 152+ $cat_only = ( $diSubject->getNamespace() == NS_CATEGORY );
 153+ if ( ( $diSubject->getNamespace() == NS_CATEGORY ) ||
 154+ ( $diSubject->getNamespace() == SMW_NS_CONCEPT ) ) {
 155+ $pe = SMWExporter::getSpecialNsResource( 'owl', 'equivalentClass' );
 156+ $filterNamespace = $diSubject->getNamespace();
 157+ } elseif ( $diSubject->getNamespace() == SMW_NS_PROPERTY ) {
 158+ $pe = SMWExporter::getSpecialNsResource( 'owl', 'equivalentProperty' );
 159+ $filterNamespace = SMW_NS_PROPERTY;
 160+ } else {
 161+ $pe = SMWExporter::getSpecialNsResource( 'owl', 'sameAs' );
 162+ }
 163+ break;
 164+ case '_SUBP':
163165 if ( $diSubject->getNamespace() == SMW_NS_PROPERTY ) {
164 - $pe = null; // checking the typing here is too cumbersome, smart stores will smush the properties anyway, and the others will not handle them equivalently
 166+ $pe = SMWExporter::getSpecialNsResource( 'rdfs', 'subPropertyOf' );
165167 } else {
166 - $pe = $equality_pe;
167 - $cat_only = ( $diSubject->getNamespace() == NS_CATEGORY );
 168+ $pe = null;
168169 }
169170 break;
 171+ case '_MDAT':
 172+ $pe = SMWExporter::getSpecialNsResource( 'swivt', 'wikiPageModificationDate' );
 173+ break;
 174+ case '_SKEY':
 175+ $pe = SMWExporter::getSpecialNsResource( 'swivt', 'wikiPageSortKey' );
 176+ break;
 177+ case '_TYPE': /// TODO: property type currently not exported
 178+ $pe = null;
 179+ break;
 180+ default: $pe = null;
170181 }
 182+
171183 if ( $pe === null ) return; // unknown special property, not exported
 184+
172185 foreach ( $dataItems as $dataItem ) {
173 - if ( $cat_only ) {
174 - if ( !( $dataItem instanceof SMWDIWikiPage ) || ( $dataItem->getNamespace() != NS_CATEGORY ) ) {
175 - continue;
176 - }
 186+ if ( ( $filterNamespace !== 0 ) && !( $dataItem instanceof SMWDIUri ) &&
 187+ ( !( $dataItem instanceof SMWDIWikiPage ) ||
 188+ ( $dataItem->getNamespace() != $filterNamespace ) ) ) {
 189+ continue;
177190 }
178 - $ed = self::getDataItemExpData( $dataItem );
 191+ $ed = self::getDataItemExpElement( $dataItem );
179192 if ( $ed !== null ) {
180193 if ( ( $property->getKey() == '_CONC' ) && ( $ed->getSubject()->getUri() == '' ) ) {
181194 // equivalent to anonymous class -> simplify description
@@ -340,13 +353,13 @@
341354 }
342355
343356 /**
344 - * Create an SWMExpData container that encodes the data of the given
 357+ * Create an SWMExpElement that encodes the data of the given
345358 * dataitem object.
346359 *
347360 * @param $dataItem SMWDataItem
348 - * @return SMWExpData
 361+ * @return SMWExpElement
349362 */
350 - static public function getDataItemExpData( SMWDataItem $dataItem ) {
 363+ static public function getDataItemExpElement( SMWDataItem $dataItem ) {
351364 switch ( $dataItem->getDIType() ) {
352365 case SMWDataItem::TYPE_NUMBER:
353366 $lit = new SMWExpLiteral( $dataItem->getNumber(), 'http://www.w3.org/2001/XMLSchema#double', $dataItem );
@@ -416,6 +429,7 @@
417430 break;
418431 case SMWDataItem::TYPE_CONCEPT:
419432 /// TODO
 433+ return null;
420434 break;
421435 case SMWDataItem::TYPE_PROPERTY:
422436 return SMWExporter::getResourceElement( $dataItem->getDiWikiPage() );

Status & tagging log