r21811 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r21810‎ | r21811 | r21812 >
Date:18:46, 2 May 2007
Author:vrandezo
Status:old
Tags:
Comment:
Added export for subrelations and subattributes.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/ExportRDF/SMW_SpecialExportRDF.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/ExportRDF/SMW_SpecialExportRDF.php
@@ -104,6 +104,7 @@
105105 public $ext_nsid = false;
106106 public $ext_section = false;
107107 // relevant title values, mandatory
 108+ public $title;
108109 public $title_text;
109110 public $title_namespace;
110111 public $title_id;
@@ -127,6 +128,7 @@
128129 * provided DB handler.
129130 */
130131 public function SMWExportTitle($title, $export, $modifier = '') {
 132+ $this->title = $title;
131133 $this->title_text = $title->getText();
132134 $this->title_id = $title->getArticleID();
133135 $this->title_namespace = $title->getNamespace();
@@ -551,6 +553,9 @@
552554 "\t<owl:AnnotationProperty rdf:about=\"&smw;hasType\">\n" .
553555 "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" .
554556 "\t</owl:AnnotationProperty>\n" .
 557+ "\t<owl:AnnotationProperty rdf:about=\"&smw;subPropertyOf\">\n" .
 558+ "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" .
 559+ "\t</owl:AnnotationProperty>\n" .
555560 "\t<owl:Class rdf:about=\"&smw;Thing\">\n" .
556561 "\t\t<rdfs:isDefinedBy rdf:resource=\"http://smw.ontoware.org/2005/smw\"/>\n" .
557562 "\t</owl:Class>\n" .
@@ -565,12 +570,20 @@
566571 $datatype_rel = false;
567572 $category_rel = false;
568573 $equality_rel = false;
 574+ $subrel_rel = false;
 575+ $subatt_rel = false;
569576
570577 // Set parameters for export
571578 switch ($et->title_namespace) {
572579 case SMW_NS_RELATION:
573580 $type = 'owl:ObjectProperty';
574581 $equality_rel = "owl:equivalentProperty";
 582+ global $smwgExportSemanticRelationHierarchy;
 583+ if ($smwgExportSemanticRelationHierarchy) {
 584+ $subrel_rel = "rdfs:subPropertyOf";
 585+ } else {
 586+ $subrel_rel = "smw:subPropertyOf";
 587+ }
575588 break;
576589 case SMW_NS_ATTRIBUTE:
577590 if ( $et->has_type === false ) return; //attributes w/o type not exportable, TODO: is this what we want?
@@ -585,6 +598,12 @@
586599 }
587600 $equality_rel = "owl:equivalentProperty";
588601 }
 602+ global $smwgExportSemanticRelationHierarchy;
 603+ if ($smwgExportSemanticRelationHierarchy) {
 604+ $subatt_rel = "rdfs:subPropertyOf";
 605+ } else {
 606+ $subatt_rel = "smw:subPropertyOf";
 607+ }
589608 break;
590609 case NS_CATEGORY:
591610 $type = 'owl:Class';
@@ -641,29 +660,33 @@
642661 // }
643662
644663 // add rdfs:subPropertyOf statements
645 - // FIXME: temporarily disabled
646 -// if ($subrel_rel) {
647 -// $relations = smwfGetSpecialPropertyValues($title,SMW_SP_IS_SUBRELATION_OF);
648 -// foreach ($relations as $relation) {
649 -// $relURIs = $this->getURIs($relation,0);
650 -// //@TODO: do type checks here or on saving ...
651 -// $this->post_ns_buffer .= "\t\t<$subrel_rel rdf:resource=\"$relURIs[0]\"/>\n";
652 -// if (!array_key_exists($relURIs[2], $this->element_queue)) {
653 -// $this->element_queue[$relURIs[2]] = true;
654 -// }
655 -// }
656 -// }
657 -// if ($subatt_rel) {
658 -// $attributes = smwfGetSpecialPropertyValues($title,SMW_SP_IS_SUBRELATION_OF);
659 -// foreach ($attributes as $attribute) {
660 -// $attURIs = $this->getURIs($attribute[2]);
661 -// //@TODO: do type checks here or on saving ...
662 -// $this->post_ns_buffer .= "\t\t<$subatt_rel rdf:resource=\"$attURIs[0]\"/>\n";
663 -// if (!array_key_exists($attURIs[2], $this->element_queue)) {
664 -// $this->element_queue[$attURIs[2]] = true;
665 -// }
666 -// }
667 -// }
 664+ if ($subrel_rel) {
 665+ $relations = &smwfGetStore()->getSpecialValues($et->title, SMW_SP_IS_SUBRELATION_OF);
 666+ foreach ($relations as $relation) {
 667+ // TODO in future, check type safety relations <-> attributes
 668+ // TODO check also the type of what I am pointing to (is it a relation or sth else?)
 669+ $suprel = $this->getExportTitle($relation, SMW_NS_RELATION);
 670+ $this->post_ns_buffer .= "\t\t<$subrel_rel rdf:resource=\"" . $suprel->long_uri . "\"/>\n";
 671+ if (!array_key_exists($suprel->hashkey, $this->element_queue)) {
 672+ $this->element_queue[$suprel->hashkey] = $suprel;
 673+ }
 674+ }
 675+ }
 676+ if ($subatt_rel) {
 677+ $attributes = &smwfGetStore()->getSpecialValues($et->title, SMW_SP_IS_SUBATTRIBUTE_OF);
 678+ foreach ($attributes as $attribute) {
 679+ // TODO in future, check type safety relations <-> attributes
 680+ // TODO check also the type of what I am pointing to (is it an atrribute or sth else?)
 681+ // TODO check the type of the attribute pointed to, does it match?
 682+ // Could lead to inconsistencies in the output -- and in the wiki? But this will
 683+ // need to be dealt with as soon as people add subattribute semantics to the wiki
 684+ $supatt = $this->getExportTitle($attribute, SMW_NS_ATTRIBUTE);
 685+ $this->post_ns_buffer .= "\t\t<$subatt_rel rdf:resource=\"" . $supatt->long_uri . "\"/>\n";
 686+ if (!array_key_exists($supatt->hashkey, $this->element_queue)) {
 687+ $this->element_queue[$supatt->hashkey] = $supatt;
 688+ }
 689+ }
 690+ }
668691
669692 if ($et->is_individual) { // do not print relations for schema elements, stay in OWL DL
670693 // print all relations
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php
@@ -56,6 +56,9 @@
5757 ##
5858 $smwgAllowRecursiveExport = false; // can normal users request recursive export?
5959 $smwgExportBacklinks = true; // should backlinks be included by default?
 60+$smwgExportSemanticRelationHierarchy = false; // should subrelations be exported with or wo semantics?
 61+// as long as the underlying implementation does not support the semantics the export
 62+// should reflect the same.
6063 ##
6164
6265 ###

Status & tagging log