Index: trunk/extensions/SemanticMediaWiki/specials/ExportRDF/SMW_SpecialExportRDF.php |
— | — | @@ -68,8 +68,11 @@ |
69 | 69 | } elseif ( ($bl == '0') || ( '' == $bl && $postform) ) { |
70 | 70 | $backlinks = false; //everybody can explicitly switch off backlinks |
71 | 71 | } |
| 72 | + $date = $wgRequest->getText( 'date' ); |
| 73 | + if ('' == $date) $date = $wgRequest->getVal( 'date' ); |
72 | 74 | |
73 | 75 | $exRDF = new ExportRDF(); |
| 76 | + if ('' !== $date) $exRDF->setDate($date); |
74 | 77 | $exRDF->printPages($pages,$recursive,$backlinks); |
75 | 78 | return; |
76 | 79 | } |
— | — | @@ -142,7 +145,7 @@ |
143 | 146 | $this->modifier = $modifier; |
144 | 147 | if ($modifier != '') $modifier = '#' . $modifier; |
145 | 148 | |
146 | | - $this->is_individual = ( ($this->title_namespace !== SMW_NS_RELATION) && ($this->title_namespace !== SMW_NS_ATTRIBUTE) && ($this->title_namespace !== NS_CATEGORY) ); |
| 149 | + $this->is_individual = ( ($this->title_namespace !== SMW_NS_PROPERTY) && ($this->title_namespace !== NS_CATEGORY) ); |
147 | 150 | $this->exists = $title->exists(); |
148 | 151 | |
149 | 152 | if ($this->exists) { |
— | — | @@ -169,14 +172,10 @@ |
170 | 173 | $this->ns_uri = ExportRDF::makeXMLExportId(urlencode(str_replace(' ', '_', $ns_text))); |
171 | 174 | $baseXML = ExportRDF::makeXMLExportId(urlencode(str_replace(' ', '_', $this->title_text . $modifier))); |
172 | 175 | switch ($this->title_namespace) { |
173 | | - case SMW_NS_RELATION: |
174 | | - $xmlprefix = 'relation:'; |
175 | | - $xmlent = '&relation;'; |
| 176 | + case SMW_NS_PROPERTY: |
| 177 | + $xmlprefix = 'property:'; |
| 178 | + $xmlent = '&property;'; |
176 | 179 | break; |
177 | | - case SMW_NS_ATTRIBUTE: |
178 | | - $xmlprefix = 'attribute:'; |
179 | | - $xmlent = '&attribute;'; |
180 | | - break; |
181 | 180 | default: |
182 | 181 | $xmlprefix = 'wiki:'; |
183 | 182 | $xmlent = '&wiki;'; |
— | — | @@ -194,7 +193,11 @@ |
195 | 194 | $this->long_uri = $this->ns_uri . $this->ext_section; |
196 | 195 | $this->short_uri = $this->ext_nsid . ':' . $this->ext_section; |
197 | 196 | } |
198 | | - $this->label = $ns_text . $this->title_text; |
| 197 | + if ($this->is_individual) { |
| 198 | + $this->label = $ns_text . $this->title_text; |
| 199 | + } else { |
| 200 | + $this->label = $this->title_text; |
| 201 | + } |
199 | 202 | //$this->label = $this->title_text; // we show the namespace prefixes in most specials in our wiki, so this should also be done by external (re)users (mak) |
200 | 203 | //TODO: should we make an exception for schema elements (Category, Attriubte, ...) where the prefix is clear from the context? At least namespaces like User: seem to be essential for understanding. |
201 | 204 | if ($this->modifier != '') $this->label .= " ($this->modifier)"; |
— | — | @@ -248,6 +251,12 @@ |
249 | 252 | var $store; |
250 | 253 | |
251 | 254 | /** |
| 255 | + * Date used to filter the export. If a page has not been changed since that |
| 256 | + * date it will not be exported |
| 257 | + */ |
| 258 | + var $date; |
| 259 | + |
| 260 | + /** |
252 | 261 | * Array of additional namespaces (abbreviation => URI), flushed on |
253 | 262 | * closing the current namespace tag. Since we export RDF in a streamed |
254 | 263 | * way, it is not always possible to embed additional namespaces into |
— | — | @@ -318,9 +327,20 @@ |
319 | 328 | |
320 | 329 | $this->element_queue = array(); |
321 | 330 | $this->element_done = array(); |
| 331 | + $this->date = ''; |
322 | 332 | } |
323 | 333 | |
324 | 334 | /** |
| 335 | + * Sets a date as a filter. Any page that has not been changed since that date |
| 336 | + * will not be exported. The date has to be a string in XSD format. |
| 337 | + */ |
| 338 | + public function setDate($date) { |
| 339 | + $timeint = strtotime($date); |
| 340 | + $stamp = date("YmdHis", $timeint); |
| 341 | + $this->date = $stamp; |
| 342 | + } |
| 343 | + |
| 344 | + /** |
325 | 345 | * This function prints all selected pages. The parameter $recursion determines |
326 | 346 | * how referenced ressources are treated: |
327 | 347 | * '0' : add brief declarations for each |
— | — | @@ -390,13 +410,14 @@ |
391 | 411 | } |
392 | 412 | |
393 | 413 | // if pages are not processed recursively, print mentioned declarations |
394 | | - if (count($this->element_queue) > 0) { |
| 414 | + if (!empty($this->element_queue)) { |
395 | 415 | if ( '' != $this->pre_ns_buffer ) { |
396 | 416 | $this->post_ns_buffer .= "\t<!-- auxilliary definitions -->\n"; |
397 | 417 | } else { |
398 | 418 | print "\t<!-- auxilliary definitions -->\n"; // just print this comment, so that later outputs still find the empty pre_ns_buffer! |
399 | 419 | } |
400 | | - foreach ( $this->element_queue as $et ) { |
| 420 | + while (!empty($this->element_queue)) { |
| 421 | + $et = array_pop($this->element_queue); |
401 | 422 | $this->printTriples($et,false); |
402 | 423 | } |
403 | 424 | } |
— | — | @@ -513,10 +534,8 @@ |
514 | 535 | "\t<!ENTITY smwdt 'http://smw.ontoware.org/2005/smw-datatype#'>\n" . |
515 | 536 | // A note on "wiki": this namespace is crucial as a fallback when it would be illegal to start e.g. with a number. In this case, one can always use wiki:... followed by "_" and possibly some namespace, since _ is legal as a first character. |
516 | 537 | "\t<!ENTITY wiki '" . $this->wiki_xmlns_xml . "'>\n" . |
517 | | - "\t<!ENTITY relation '" . $this->wiki_xmlns_xml . |
518 | | - $this->makeXMLExportId(urlencode(str_replace(' ', '_', $wgContLang->getNsText(SMW_NS_RELATION) . ':'))) . "'>\n" . |
519 | | - "\t<!ENTITY attribute '" . $this->wiki_xmlns_xml . |
520 | | - $this->makeXMLExportId(urlencode(str_replace(' ', '_', $wgContLang->getNsText(SMW_NS_ATTRIBUTE) . ':'))) . "'>\n" . |
| 538 | + "\t<!ENTITY property '" . $this->wiki_xmlns_xml . |
| 539 | + $this->makeXMLExportId(urlencode(str_replace(' ', '_', $wgContLang->getNsText(SMW_NS_PROPERTY) . ':'))) . "'>\n" . |
521 | 540 | "\t<!ENTITY wikiurl '" . $this->wiki_xmlns_url . "'>\n" . |
522 | 541 | "]>\n\n" . |
523 | 542 | "<rdf:RDF\n" . |
— | — | @@ -525,9 +544,8 @@ |
526 | 545 | "\txmlns:owl =\"&owl;\"\n" . |
527 | 546 | "\txmlns:smw=\"&smw;\"\n" . |
528 | 547 | "\txmlns:wiki=\"&wiki;\"\n" . |
529 | | - "\txmlns:relation=\"&relation;\"\n" . |
530 | | - "\txmlns:attribute=\"&attribute;\""; |
531 | | - $this->global_namespaces = array('rdf'=>true, 'rdfs'=>true, 'owl'=>true, 'smw'=>true, 'wiki'=>true, 'relation'=>true, 'attribute'=>true); |
| 548 | + "\txmlns:property=\"&property;\""; |
| 549 | + $this->global_namespaces = array('rdf'=>true, 'rdfs'=>true, 'owl'=>true, 'smw'=>true, 'wiki'=>true, 'property'=>true); |
532 | 550 | |
533 | 551 | $this->post_ns_buffer .= |
534 | 552 | ">\n\t<!-- reference to the Semantic MediaWiki schema -->\n" . |
— | — | @@ -540,9 +558,21 @@ |
541 | 559 | "\t<owl:AnnotationProperty rdf:about=\"&smw;subPropertyOf\">\n" . |
542 | 560 | "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" . |
543 | 561 | "\t</owl:AnnotationProperty>\n" . |
| 562 | + "\t<owl:AnnotationProperty rdf:about=\"&smw;exportDate\">\n" . |
| 563 | + "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" . |
| 564 | + "\t</owl:AnnotationProperty>\n" . |
| 565 | + "\t<owl:AnnotationProperty rdf:about=\"&smw;hasModifier\">\n" . |
| 566 | + "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" . |
| 567 | + "\t</owl:AnnotationProperty>\n" . |
| 568 | + "\t<owl:AnnotationProperty rdf:about=\"&smw;baseProperty\">\n" . |
| 569 | + "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" . |
| 570 | + "\t</owl:AnnotationProperty>\n" . |
544 | 571 | "\t<owl:Class rdf:about=\"&smw;Thing\">\n" . |
545 | 572 | "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" . |
546 | 573 | "\t</owl:Class>\n" . |
| 574 | + "\t<owl:Ontology rdf:about=\"\">\n" . |
| 575 | + "\t\t<smw:exportDate rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">" . date(DATE_W3C) . "</smw:exportDate>\n" . |
| 576 | + "\t</owl:Ontology>" . |
547 | 577 | "\t<!-- exported page data -->\n"; |
548 | 578 | } |
549 | 579 | |
— | — | @@ -551,16 +581,37 @@ |
552 | 582 | } |
553 | 583 | |
554 | 584 | function printTriples($et, $fullexport=true) { |
| 585 | + // return if younger than the filtered date |
| 586 | + if ($et->exists && ($this->date !== '')) { |
| 587 | + $rev = Revision::getTimeStampFromID($et->title->getLatestRevID()); |
| 588 | + if ($rev < $this->date) return; |
| 589 | + } |
| 590 | + |
555 | 591 | $datatype_rel = false; |
556 | 592 | $category_rel = false; |
557 | 593 | $equality_rel = false; |
558 | 594 | $subrel_rel = false; |
559 | 595 | $subatt_rel = false; |
| 596 | + |
| 597 | + // if this was already exported, don't do it again |
| 598 | + if (array_key_exists($et->hashkey, $this->element_done)) return; |
560 | 599 | |
561 | 600 | // Set parameters for export |
562 | 601 | switch ($et->title_namespace) { |
563 | | - case SMW_NS_RELATION: |
564 | | - $type = 'owl:ObjectProperty'; |
| 602 | + case SMW_NS_PROPERTY: |
| 603 | + if ( $et->has_type ) { |
| 604 | + if ( ('annouri' == $et->has_type->getTypeID()) || ('annostring' == $et->has_type->getTypeID()) ) { |
| 605 | + $type = 'owl:AnnotationProperty'; |
| 606 | + //$subrel_rel = "smw:subPropertyOf"; |
| 607 | + //TODO can it be equivalent? cannot be a subproperty |
| 608 | + } elseif ('_wpg' == $et->has_type->getTypeID()) { |
| 609 | + $type = 'owl:ObjectProperty'; |
| 610 | + } else { |
| 611 | + $type = 'owl:DatatypeProperty'; |
| 612 | + } |
| 613 | + } else { |
| 614 | + $type = 'owl:ObjectProperty'; |
| 615 | + } |
565 | 616 | $equality_rel = "owl:equivalentProperty"; |
566 | 617 | global $smwgExportSemanticRelationHierarchy; |
567 | 618 | if ($smwgExportSemanticRelationHierarchy) { |
— | — | @@ -569,25 +620,6 @@ |
570 | 621 | $subrel_rel = "smw:subPropertyOf"; |
571 | 622 | } |
572 | 623 | break; |
573 | | - case SMW_NS_ATTRIBUTE: |
574 | | - if ( $et->has_type === false ) return; //attributes w/o type not exportable, TODO: is this what we want? |
575 | | - if ( ('annouri' == $et->has_type->getTypeID()) || ('annostring' == $et->has_type->getTypeID()) ) { |
576 | | - $type = 'owl:AnnotationProperty'; // cannot be a subproperty, etc. |
577 | | - } else { |
578 | | - if ('' != SMWTypeHandlerFactory::getXSDTypeByID($et->has_type->getTypeID())) { |
579 | | - $type = 'owl:DatatypeProperty'; |
580 | | - } else { // no xsd-type -> treat as object property |
581 | | - $type = 'owl:ObjectProperty'; |
582 | | - } |
583 | | - $equality_rel = "owl:equivalentProperty"; |
584 | | - } |
585 | | - global $smwgExportSemanticRelationHierarchy; |
586 | | - if ($smwgExportSemanticRelationHierarchy) { |
587 | | - $subatt_rel = "rdfs:subPropertyOf"; |
588 | | - } else { |
589 | | - $subatt_rel = "smw:subPropertyOf"; |
590 | | - } |
591 | | - break; |
592 | 624 | case NS_CATEGORY: |
593 | 625 | $type = 'owl:Class'; |
594 | 626 | $category_rel = "rdfs:subClassOf"; |
— | — | @@ -612,6 +644,18 @@ |
613 | 645 | $et->title_prefurl . "\"/>\n" . |
614 | 646 | "\t\t<rdfs:isDefinedBy rdf:resource=\"" . |
615 | 647 | $this->special_url . '/' . $et->title_prefurl . "\"/>\n"; |
| 648 | + // If the property is modified by a unit, export the modifier |
| 649 | + // and the base relation explicitly |
| 650 | + if ( $et->has_type && $et->modifier ) { |
| 651 | + $this->post_ns_buffer .= "\t\t<smw:hasModifier rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">" . |
| 652 | + $et->modifier . |
| 653 | + "</smw:hasModifier>\n"; |
| 654 | + $baseprop = $this->getExportTitle($et->title_text, SMW_NS_PROPERTY); |
| 655 | + $this->post_ns_buffer .= "\t\t<smw:baseProperty rdf:resource=\"" . $baseprop->long_uri . "\"/>\n"; |
| 656 | + if (!array_key_exists($baseprop->hashkey, $this->element_queue)) { |
| 657 | + $this->element_queue[$baseprop->hashkey] = $baseprop; |
| 658 | + } |
| 659 | + } |
616 | 660 | |
617 | 661 | if ( ($fullexport) && ($et->exists) ) { |
618 | 662 | // add statements about categories |
— | — | @@ -647,7 +691,7 @@ |
648 | 692 | foreach ($relations as $relation) { |
649 | 693 | // TODO in future, check type safety relations <-> attributes |
650 | 694 | // TODO check also the type of what I am pointing to (is it a relation or sth else?) |
651 | | - $suprel = $this->getExportTitle($relation, SMW_NS_RELATION); |
| 695 | + $suprel = $this->getExportTitle($relation, SMW_NS_PROPERTY); |
652 | 696 | $this->post_ns_buffer .= "\t\t<$subrel_rel rdf:resource=\"" . $suprel->long_uri . "\"/>\n"; |
653 | 697 | if (!array_key_exists($suprel->hashkey, $this->element_queue)) { |
654 | 698 | $this->element_queue[$suprel->hashkey] = $suprel; |
— | — | @@ -662,7 +706,7 @@ |
663 | 707 | // TODO check the type of the attribute pointed to, does it match? |
664 | 708 | // Could lead to inconsistencies in the output -- and in the wiki? But this will |
665 | 709 | // need to be dealt with as soon as people add subattribute semantics to the wiki |
666 | | - $supatt = $this->getExportTitle($attribute, SMW_NS_ATTRIBUTE); |
| 710 | + $supatt = $this->getExportTitle($attribute, SMW_NS_PROPERTY); |
667 | 711 | $this->post_ns_buffer .= "\t\t<$subatt_rel rdf:resource=\"" . $supatt->long_uri . "\"/>\n"; |
668 | 712 | if (!array_key_exists($supatt->hashkey, $this->element_queue)) { |
669 | 713 | $this->element_queue[$supatt->hashkey] = $supatt; |
— | — | @@ -678,30 +722,10 @@ |
679 | 723 | foreach ( $values as $value ) { |
680 | 724 | $pt = $this->getExportTitleFromTitle( $prop, $value->getUnit() ); |
681 | 725 | $this-> post_ns_buffer .= $value->exportToRDF( $pt->short_uri, $this ); |
682 | | -// $ot = $this->getExportTitleFromTitle( $obj ); |
683 | | -// if ($ot->is_individual) { // check OWL Fullness |
684 | | -// $this->post_ns_buffer .= "\t\t<" . $pt->short_uri . ' rdf:resource="' . $ot->long_uri . "\"/>\n"; |
685 | | -// } |
| 726 | + // TODO check OWL Fullness in Wikipage |
686 | 727 | } |
687 | 728 | } |
688 | | - // print all attributes |
689 | | -/* $atts = $this->store->getAttributes( $et->title ); |
690 | | - foreach ( $atts as $att ) { |
691 | | - $dvs = $this->store->getAttributeValues( $et->title, $att ); |
692 | | - foreach ( $dvs as $dv ) { |
693 | | - $pt = $this->getExportTitleFromTitle( $att, $dv->getUnit() ); |
694 | | - $xsdtype = SMWTypeHandlerFactory::getXSDTypeByID( $dv->getTypeID() ); |
695 | | - $xsdvalue = $dv->getXSDValue(); |
696 | | - if ( ($xsdtype !== '') && ($xsdtype !== NULL) && ($xsdvalue != '') ) { |
697 | | - $this->post_ns_buffer .= "\t\t<" . $pt->short_uri . ' rdf:datatype="' . $xsdtype . '">' . $xsdvalue . '</' . $pt->short_uri . ">\n"; |
698 | | - } elseif ($xsdtype === '') { // no xsd-type -> export as object property |
699 | | - $this->post_ns_buffer .= "\t\t<" . $pt->short_uri . ' rdf:resource="' . $xsdvalue . "\"/>\n"; |
700 | | - } else { |
701 | | - $this->post_ns_buffer .= "\t\t<!-- Sorry, type '$xsdtype' of attribute '$pt->label' could not be resolved to XSD. Probably an upgrade issue. Try saving the respective article again. -->\n"; |
702 | | - } |
703 | | - } |
704 | | - } |
705 | | -*/ } |
| 729 | + } |
706 | 730 | } |
707 | 731 | |
708 | 732 | $this->post_ns_buffer .= "\t</" . $type . ">\n"; |
— | — | @@ -762,7 +786,7 @@ |
763 | 787 | */ |
764 | 788 | public function getURI(Title $title, $unit = '') { |
765 | 789 | $et = $this->getExportTitleFromTitle( $title, $unit ); |
766 | | - return $et->short_uri; |
| 790 | + return $et->long_uri; |
767 | 791 | } |
768 | 792 | |
769 | 793 | /** Fetch SMWExportTitle for a given article. The inputs are |
— | — | @@ -842,8 +866,7 @@ |
843 | 867 | static function fitsNsRestriction($res, $ns) { |
844 | 868 | if ($res === false) return true; |
845 | 869 | if ($res >= 0) return ( $res == $ns ); |
846 | | - return ( ($res != NS_CATEGORY) && ($res != SMW_NS_RELATION) |
847 | | - && ($res != SMW_NS_ATTRIBUTE) && ($res != SMW_NS_TYPE) ); |
| 870 | + return ( ($res != NS_CATEGORY) && ($res != SMW_NS_PROPERTY) && ($res != SMW_NS_TYPE) ); |
848 | 871 | } |
849 | 872 | |
850 | 873 | /** This function transforms a valid url-encoded URI into a string |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_OldDataValue.php |
— | — | @@ -542,6 +542,18 @@ |
543 | 543 | } else { return false; } |
544 | 544 | } |
545 | 545 | |
| 546 | + /** |
| 547 | + * Creates the export line for the RDF export |
| 548 | + * |
| 549 | + * @param string $QName The element name of this datavalue |
| 550 | + * @param ExportRDF $exporter the exporter calling this function |
| 551 | + * @return the line to be exported |
| 552 | + */ |
| 553 | + public function exportToRDF($QName, ExportRDF $exporter) { |
| 554 | + $type = $this->type_handler->getXSDType(); |
| 555 | + $value = $this->getXSDValue(); |
| 556 | + return "\t\t<$QName rdf:datatype=\"$type\">$value</$QName>\n"; |
| 557 | + } |
546 | 558 | } |
547 | 559 | |
548 | 560 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php |
— | — | @@ -128,9 +128,16 @@ |
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
| 132 | + /** |
| 133 | + * Creates the export line for the RDF export |
| 134 | + * |
| 135 | + * @param string $QName The element name of this datavalue |
| 136 | + * @param ExportRDF $exporter the exporter calling this function |
| 137 | + * @return the line to be exported |
| 138 | + */ |
132 | 139 | public function exportToRDF($QName, ExportRDF $exporter) { |
133 | 140 | $obj = $exporter->getURI( $this->getTitle() ); |
134 | | - return "\t\t<$QName rdf:resource=\"$obj\" />\n"; |
| 141 | + return "\t\t<$QName rdf:resource=\"$obj\"/>\n"; |
135 | 142 | } |
136 | 143 | |
137 | 144 | ///// special interface for wiki page values |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php |
— | — | @@ -92,6 +92,13 @@ |
93 | 93 | return $this->m_infolinks; |
94 | 94 | } |
95 | 95 | |
| 96 | + /** |
| 97 | + * Creates the export line for the RDF export |
| 98 | + * |
| 99 | + * @param string $QName The element name of this datavalue |
| 100 | + * @param ExportRDF $exporter the exporter calling this function |
| 101 | + * @return the line to be exported |
| 102 | + */ |
96 | 103 | public function exportToRDF($QName, ExportRDF $exporter) { |
97 | 104 | return "\t\t<$QName rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">$this->m_xsdvalue</$QName>\n"; |
98 | 105 | } |