Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php |
— | — | @@ -43,8 +43,11 @@ |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Create exportable data from a given semantic data record. |
| 47 | + * |
| 48 | + * @param $semdata SMWSemanticData |
| 49 | + * @return SMWExpData |
47 | 50 | */ |
48 | | - static public function makeExportData( /*SMWSemanticData*/ $semdata ) { |
| 51 | + static public function makeExportData( SMWSemanticData $semdata ) { |
49 | 52 | SMWExporter::initBaseURIs(); |
50 | 53 | $subject = $semdata->getSubject(); |
51 | 54 | if ( $subject->getNamespace() == SMW_NS_PROPERTY ) { |
— | — | @@ -71,7 +74,7 @@ |
72 | 75 | */ |
73 | 76 | static public function makeExportDataForSubject( SMWDIWikiPage $subject, $typesvalueforproperty = null ) { |
74 | 77 | global $wgContLang; |
75 | | - $result = new SMWExpData( self::getDataItemExpData( $subject ) ); |
| 78 | + $result = new SMWExpData( self::getDataItemExpElement( $subject ) ); |
76 | 79 | $subjectTitle = str_replace( '_', ' ', $subject->getDBkey() ); |
77 | 80 | if ( $subject->getNamespace() !== 0 ) { |
78 | 81 | $prefixedSubjectTitle = $wgContLang->getNsText( $subject->getNamespace()) . ":" . $subjectTitle; |
— | — | @@ -121,7 +124,7 @@ |
122 | 125 | if ( $property->isUserDefined() ) { |
123 | 126 | $pe = SMWExporter::getResourceElement( $property ); |
124 | 127 | foreach ( $dataItems as $dataItem ) { |
125 | | - $ed = self::getDataItemExpData( $dataItem ); |
| 128 | + $ed = self::getDataItemExpElement( $dataItem ); |
126 | 129 | if ( $ed !== null ) { |
127 | 130 | $expData->addPropertyObjectValue( $pe, $ed ); |
128 | 131 | } |
— | — | @@ -131,50 +134,60 @@ |
132 | 135 | if ( ( $diSubject == null ) || ( $diSubject->getDIType() != SMWDataItem::TYPE_WIKIPAGE ) ) { |
133 | 136 | return; // subject datavalue (wikipage) required for treating special properties properly |
134 | 137 | } |
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' ); |
140 | 143 | 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' ); |
145 | 146 | 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' ); |
161 | 149 | 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': |
163 | 165 | 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' ); |
165 | 167 | } else { |
166 | | - $pe = $equality_pe; |
167 | | - $cat_only = ( $diSubject->getNamespace() == NS_CATEGORY ); |
| 168 | + $pe = null; |
168 | 169 | } |
169 | 170 | 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; |
170 | 181 | } |
| 182 | + |
171 | 183 | if ( $pe === null ) return; // unknown special property, not exported |
| 184 | + |
172 | 185 | 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; |
177 | 190 | } |
178 | | - $ed = self::getDataItemExpData( $dataItem ); |
| 191 | + $ed = self::getDataItemExpElement( $dataItem ); |
179 | 192 | if ( $ed !== null ) { |
180 | 193 | if ( ( $property->getKey() == '_CONC' ) && ( $ed->getSubject()->getUri() == '' ) ) { |
181 | 194 | // equivalent to anonymous class -> simplify description |
— | — | @@ -340,13 +353,13 @@ |
341 | 354 | } |
342 | 355 | |
343 | 356 | /** |
344 | | - * Create an SWMExpData container that encodes the data of the given |
| 357 | + * Create an SWMExpElement that encodes the data of the given |
345 | 358 | * dataitem object. |
346 | 359 | * |
347 | 360 | * @param $dataItem SMWDataItem |
348 | | - * @return SMWExpData |
| 361 | + * @return SMWExpElement |
349 | 362 | */ |
350 | | - static public function getDataItemExpData( SMWDataItem $dataItem ) { |
| 363 | + static public function getDataItemExpElement( SMWDataItem $dataItem ) { |
351 | 364 | switch ( $dataItem->getDIType() ) { |
352 | 365 | case SMWDataItem::TYPE_NUMBER: |
353 | 366 | $lit = new SMWExpLiteral( $dataItem->getNumber(), 'http://www.w3.org/2001/XMLSchema#double', $dataItem ); |
— | — | @@ -416,6 +429,7 @@ |
417 | 430 | break; |
418 | 431 | case SMWDataItem::TYPE_CONCEPT: |
419 | 432 | /// TODO |
| 433 | + return null; |
420 | 434 | break; |
421 | 435 | case SMWDataItem::TYPE_PROPERTY: |
422 | 436 | return SMWExporter::getResourceElement( $dataItem->getDiWikiPage() ); |