Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exp_Data.php |
— | — | @@ -12,36 +12,55 @@ |
13 | 13 | * SMWExpData is a data container for export-ready semantic content. It is |
14 | 14 | * organised as a tree-shaped data structure with one root subject and zero |
15 | 15 | * or more children connected with labelled edges to the root. Children are |
16 | | - * again SMWExpData objects, and edges are annotated with SMWExpElements |
| 16 | + * again SMWExpData objects, and edges are annotated with SMWExpNsElements |
17 | 17 | * specifying properties. |
| 18 | + * @note We do not allow property element without namespace abbreviation |
| 19 | + * here. Property aabbreviations are mandatory for some serialisations. |
18 | 20 | * |
19 | 21 | * @ingroup SMW |
20 | 22 | */ |
21 | | -class SMWExpData { |
| 23 | +class SMWExpData extends SMWExpElement { |
| 24 | + /** |
| 25 | + * The subject of the data that we store. |
| 26 | + * @var SMWExpResource |
| 27 | + */ |
22 | 28 | protected $m_subject; |
23 | | - protected $m_children = array(); // property text keys => array of children SMWExpData objects |
24 | | - protected $m_edges = array(); // property text keys => property SMWExpElements |
| 29 | + /** |
| 30 | + * Array mapping property URIs to arrays their values, given as |
| 31 | + * SMWExpElement objects. |
| 32 | + * @var array of array of SMWElement |
| 33 | + */ |
| 34 | + protected $m_children = array(); |
| 35 | + /** |
| 36 | + * Array mapping property URIs to arrays their SMWExpResource |
| 37 | + * @var array of SMWExpResource |
| 38 | + */ |
| 39 | + protected $m_edges = array(); |
25 | 40 | |
26 | 41 | /** |
27 | | - * Constructor. $subject is the SMWExpElement for the |
| 42 | + * Constructor. $subject is the SMWExpResource for the |
28 | 43 | * subject about which this SMWExpData is. |
29 | 44 | */ |
30 | | - public function __construct( SMWExpElement $subject ) { |
| 45 | + public function __construct( SMWExpResource $subject ) { |
| 46 | + parent::__construct( $subject->getDataItem() ); |
31 | 47 | $this->m_subject = $subject; |
32 | 48 | } |
33 | 49 | |
34 | 50 | /** |
35 | | - * Turn an array of SMWElements into an RDF collection. |
| 51 | + * Turn an array of SMWExpElements into an RDF collection. |
| 52 | + * |
| 53 | + * @param $elements array of SMWExpElement |
| 54 | + * @return SMWExpData |
36 | 55 | */ |
37 | | - public static function makeCollection( $elements ) { |
| 56 | + public static function makeCollection( array $elements ) { |
38 | 57 | if ( count( $elements ) == 0 ) { |
39 | | - return new SMWExpData( SMWExporter::getSpecialElement( 'rdf', 'nil' ) ); |
| 58 | + return new SMWExpData( SMWExporter::getSpecialNsResource( 'rdf', 'nil' ) ); |
40 | 59 | } else { |
41 | | - $rdftype = SMWExporter::getSpecialElement( 'rdf', 'type' ); |
42 | | - $rdffirst = SMWExporter::getSpecialElement( 'rdf', 'first' ); |
43 | | - $rdfrest = SMWExporter::getSpecialElement( 'rdf', 'rest' ); |
| 60 | + $rdftype = SMWExporter::getSpecialNsResource( 'rdf', 'type' ); |
| 61 | + $rdffirst = SMWExporter::getSpecialNsResource( 'rdf', 'first' ); |
| 62 | + $rdfrest = SMWExporter::getSpecialNsResource( 'rdf', 'rest' ); |
44 | 63 | $result = new SMWExpData( new SMWExpResource( '' ) ); // bnode |
45 | | - $result->addPropertyObjectValue( $rdftype, new SMWExpData( SMWExporter::getSpecialElement( 'rdf', 'List' ) ) ); |
| 64 | + $result->addPropertyObjectValue( $rdftype, new SMWExpData( SMWExporter::getSpecialNsResource( 'rdf', 'List' ) ) ); |
46 | 65 | $result->addPropertyObjectValue( $rdffirst, array_shift( $elements ) ); |
47 | 66 | $result->addPropertyObjectValue( $rdfrest, SMWExpData::makeCollection( $elements ) ); |
48 | 67 | return $result; |
— | — | @@ -51,53 +70,47 @@ |
52 | 71 | /** |
53 | 72 | * Return subject to which the stored semantic annotation refer to. |
54 | 73 | * |
55 | | - * @return SMWExpElement |
| 74 | + * @return SMWExpResource |
56 | 75 | */ |
57 | 76 | public function getSubject() { |
58 | 77 | return $this->m_subject; |
59 | 78 | } |
60 | 79 | |
61 | 80 | /** |
62 | | - * Set the subject element. |
63 | | - * |
64 | | - * @param SMWExpResource $subject |
65 | | - */ |
66 | | - public function setSubject( SMWExpResource $subject ) { |
67 | | - $this->m_subject = $subject; |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Store a value for a property identified by its title object. No duplicate elimination as this |
72 | | - * is usually done in SMWSemanticData already (which is typically used to generate this object). |
73 | | - * |
74 | | - * @param SMWExpResource $property |
| 81 | + * Store a value for a property identified by its title object. No |
| 82 | + * duplicate elimination as this is usually done in SMWSemanticData |
| 83 | + * already (which is typically used to generate this object). |
| 84 | + * |
| 85 | + * @param SMWExpNsResource $property |
75 | 86 | * @param SMWExpData $child |
76 | 87 | */ |
77 | | - public function addPropertyObjectValue( SMWExpResource $property, SMWExpData $child ) { |
78 | | - if ( !array_key_exists( $property->getName(), $this->m_edges ) ) { |
79 | | - $this->m_children[$property->getName()] = array(); |
80 | | - $this->m_edges[$property->getName()] = $property; |
| 88 | + public function addPropertyObjectValue( SMWExpNsResource $property, SMWExpElement $child ) { |
| 89 | + if ( !array_key_exists( $property->getUri(), $this->m_edges ) ) { |
| 90 | + $this->m_children[$property->getUri()] = array(); |
| 91 | + $this->m_edges[$property->getUri()] = $property; |
81 | 92 | } |
82 | | - $this->m_children[$property->getName()][] = $child; |
| 93 | + $this->m_children[$property->getUri()][] = $child; |
83 | 94 | } |
84 | 95 | |
85 | 96 | /** |
86 | | - * Return the list of SMWExpElements for all properties for which some values exist. |
| 97 | + * Return the list of SMWExpResource objects for all properties for |
| 98 | + * which some values have been given. |
87 | 99 | * |
88 | | - * @return array of SMWExpElements |
| 100 | + * @return array of SMWExpResource |
89 | 101 | */ |
90 | 102 | public function getProperties() { |
91 | 103 | return $this->m_edges; |
92 | 104 | } |
93 | 105 | |
94 | 106 | /** |
95 | | - * Return the list of SMWExpData values associated to some property (element). |
| 107 | + * Return the list of SMWExpElement values associated to some property |
| 108 | + * (element). |
96 | 109 | * |
97 | | - * @return array of SMWExpData |
| 110 | + * @return array of SMWExpElement |
98 | 111 | */ |
99 | 112 | public function getValues( SMWExpResource $property ) { |
100 | | - if ( array_key_exists( $property->getName(), $this->m_children ) ) { |
101 | | - return $this->m_children[$property->getName()]; |
| 113 | + if ( array_key_exists( $property->getUri(), $this->m_children ) ) { |
| 114 | + return $this->m_children[$property->getUri()]; |
102 | 115 | } else { |
103 | 116 | return array(); |
104 | 117 | } |
— | — | @@ -106,76 +119,91 @@ |
107 | 120 | /** |
108 | 121 | * Return the list of SMWExpData values associated to some property that is |
109 | 122 | * specifed by a standard namespace id and local name. |
110 | | - * |
| 123 | + * |
| 124 | + * @param $namespaceId string idetifying a known special namespace (e.g. "rdf") |
| 125 | + * @param $localName string of local name (e.g. "type") |
111 | 126 | * @return array of SMWExpData |
112 | 127 | */ |
113 | | - public function getSpecialValues( $namespace, $localname ) { |
114 | | - $pe = SMWExporter::getSpecialElement( $namespace, $localname ); |
115 | | - if ( $pe !== null ) { |
116 | | - return $this->getValues( $pe ); |
117 | | - } else { |
118 | | - return array(); |
119 | | - } |
| 128 | + public function getSpecialValues( $namespaceId, $localName ) { |
| 129 | + $pe = SMWExporter::getSpecialNsResource( $namespaceId, $localName ); |
| 130 | + return $this->getValues( $pe ); |
120 | 131 | } |
121 | 132 | |
122 | 133 | /** |
123 | | - * This function finds the main type (class) element of the subject based on the |
124 | | - * current property assignments. It returns this type element (SMWExpElement) and |
125 | | - * removes the according type assignement from the data. |
| 134 | + * This function finds the main type (class) element of the subject |
| 135 | + * based on the current property assignments. It returns this type |
| 136 | + * element (SMWExpElement) and removes the according type assignement |
| 137 | + * from the data. If no type is assigned, the element for rdf:Resource |
| 138 | + * is returned. |
| 139 | + * |
| 140 | + * @note Under all normal conditions, the result will be an |
| 141 | + * SMWExpResource. |
| 142 | + * |
| 143 | + * @return SMWExpElement |
126 | 144 | */ |
127 | 145 | public function extractMainType() { |
128 | | - $pe = SMWExporter::getSpecialElement( 'rdf', 'type' ); |
129 | | - if ( array_key_exists( $pe->getName(), $this->m_children ) ) { |
130 | | - $result = array_shift( $this->m_children[$pe->getName()] ); |
131 | | - if ( count( $this->m_children[$pe->getName()] ) == 0 ) { |
132 | | - unset( $this->m_edges[$pe->getName()] ); |
133 | | - unset( $this->m_children[$pe->getName()] ); |
| 146 | + $pe = SMWExporter::getSpecialNsResource( 'rdf', 'type' ); |
| 147 | + if ( array_key_exists( $pe->getUri(), $this->m_children ) ) { |
| 148 | + $result = array_shift( $this->m_children[$pe->getUri()] ); |
| 149 | + if ( count( $this->m_children[$pe->getUri()] ) == 0 ) { |
| 150 | + unset( $this->m_edges[$pe->getUri()] ); |
| 151 | + unset( $this->m_children[$pe->getUri()] ); |
134 | 152 | } |
135 | | - return $result->getSubject(); |
| 153 | + return ( $result instanceof SMWExpData ) ? $result->getSubject() : $result; |
136 | 154 | } else { |
137 | | - return SMWExporter::getSpecialElement( 'rdf', 'Resource' ); |
| 155 | + return SMWExporter::getSpecialNsResource( 'rdf', 'Resource' ); |
138 | 156 | } |
139 | 157 | } |
140 | 158 | |
141 | 159 | /** |
142 | | - * Check if this element can be serialised using parseType="Collection" and |
143 | | - * if yes return an array of SMWExpElements corresponding to the collection |
144 | | - * elements in the specified order. Otherwise return false. |
| 160 | + * Check if this element encodes an RDF list, and if yes return an |
| 161 | + * array of SMWExpElements corresponding to the collection elements in |
| 162 | + * the specified order. Otherwise return false. |
| 163 | + * The method only returns lists that can be encoded using |
| 164 | + * parseType="Collection" in RDF/XML, i.e. only lists of non-literal |
| 165 | + * resources. |
| 166 | + * |
| 167 | + * @return mixed array of SMWExpElement (but not SMWExpLiteral) or false |
145 | 168 | */ |
146 | 169 | public function getCollection() { |
147 | | - $rdftype = SMWExporter::getSpecialElement( 'rdf', 'type' ); |
148 | | - $rdffirst = SMWExporter::getSpecialElement( 'rdf', 'first' ); |
149 | | - $rdfrest = SMWExporter::getSpecialElement( 'rdf', 'rest' ); |
150 | | - $rdfnil = SMWExporter::getSpecialElement( 'rdf', 'nil' ); |
151 | | - $name = $this->getSubject()->getName(); |
| 170 | + $rdftypeUri = SMWExporter::getSpecialNsResource( 'rdf', 'type' )->getUri(); |
| 171 | + $rdffirstUri = SMWExporter::getSpecialNsResource( 'rdf', 'first' )->getUri(); |
| 172 | + $rdfrestUri = SMWExporter::getSpecialNsResource( 'rdf', 'rest' )->getUri(); |
| 173 | + $rdfnilUri = SMWExporter::getSpecialNsResource( 'rdf', 'nil' )->getUri(); |
152 | 174 | // first check if we are basically an RDF List: |
153 | | - if ( ( ( $name == '' ) || ( $name { 0 } == '_' ) ) && // bnode |
154 | | - ( array_key_exists( $rdftype->getName(), $this->m_children ) ) && |
155 | | - ( count( $this->m_children[$rdftype->getName()] ) == 1 ) && |
156 | | - ( array_key_exists( $rdffirst->getName(), $this->m_children ) ) && |
157 | | - ( count( $this->m_children[$rdffirst->getName()] ) == 1 ) && |
158 | | - ( array_key_exists( $rdfrest->getName(), $this->m_children ) ) && |
159 | | - !( end( $this->m_children[$rdffirst->getName()] ) instanceof SMWExpLiteral ) && |
| 175 | + if ( ( $this->m_subject->isBlankNode() ) && |
| 176 | + ( count( $this->m_children ) == 3 ) && |
| 177 | + ( array_key_exists( $rdftypeUri, $this->m_children ) ) && |
| 178 | + ( count( $this->m_children[$rdftypeUri] ) == 1 ) && |
| 179 | + ( array_key_exists( $rdffirstUri, $this->m_children ) ) && |
| 180 | + ( count( $this->m_children[$rdffirstUri] ) == 1 ) && |
| 181 | + !( end( $this->m_children[$rdffirstUri] ) instanceof SMWExpLiteral ) && |
160 | 182 | // (parseType collection in RDF not possible with literals :-/) |
161 | | - ( count( $this->m_children[$rdfrest->getName()] ) == 1 ) && |
162 | | - ( count( $this->m_children ) == 3 ) ) { |
163 | | - $typedata = end( $this->m_children[$rdftype->getName()] ); |
164 | | - $rdflist = SMWExporter::getSpecialElement( 'rdf', 'List' ); |
165 | | - if ( $typedata->getSubject()->getName() == $rdflist->getName() ) { |
166 | | - $first = end( $this->m_children[$rdffirst->getName()] ); |
167 | | - $rest = end( $this->m_children[$rdfrest->getName()] ); |
168 | | - $restlist = $rest->getCollection(); |
169 | | - if ( $restlist === false ) { |
| 183 | + ( array_key_exists( $rdfrestUri, $this->m_children ) ) && |
| 184 | + ( count( $this->m_children[$rdfrestUri] ) == 1 ) ) { |
| 185 | + $typedata = end( $this->m_children[$rdftypeUri] ); |
| 186 | + $rdflistUri = SMWExporter::getSpecialNsResource( 'rdf', 'List' )->getUri(); |
| 187 | + if ( $typedata->getSubject()->getUri() == $rdflistUri ) { |
| 188 | + $first = end( $this->m_children[$rdffirstUri] ); |
| 189 | + $rest = end( $this->m_children[$rdfrestUri] ); |
| 190 | + if ( $rest instanceof SMWExpData ) { |
| 191 | + $restlist = $rest->getCollection(); |
| 192 | + if ( $restlist === false ) { |
| 193 | + return false; |
| 194 | + } else { |
| 195 | + array_unshift( $restlist, $first ); |
| 196 | + return $restlist; |
| 197 | + } |
| 198 | + } elseif ( ( $rest instanceof SMWExpResource ) && |
| 199 | + ( $rest->getUri() == $rdfnilUri ) ) { |
| 200 | + return array( $first ); |
| 201 | + } else { |
170 | 202 | return false; |
171 | | - } else { |
172 | | - array_unshift( $restlist, $first ); |
173 | | - return $restlist; |
174 | 203 | } |
175 | 204 | } else { |
176 | 205 | return false; |
177 | 206 | } |
178 | | - } elseif ( ( !array_key_exists( $rdftype->getName(), $this->m_children ) ) && |
179 | | - ( $name == $rdfnil->getName() ) ) { |
| 207 | + } elseif ( ( count( $this->m_children ) == 0 ) && ( $this->m_subject->getUri() == $rdfnilUri ) ) { |
180 | 208 | return array(); |
181 | 209 | } else { |
182 | 210 | return false; |
— | — | @@ -183,34 +211,44 @@ |
184 | 212 | } |
185 | 213 | |
186 | 214 | /** |
187 | | - * Return an array of ternary arrays (subject predicate object) of SMWExpElements |
188 | | - * that represents the flattened version of the given data. |
| 215 | + * Return an array of ternary arrays (subject predicate object) of |
| 216 | + * SMWExpElements that represents the flattened version of this data. |
| 217 | + * |
| 218 | + * @return array of array of SMWExpElement |
189 | 219 | */ |
190 | | - public function getTripleList() { |
| 220 | + public function getTripleList( SMWExpElement $subject = null ) { |
191 | 221 | global $smwgBnodeCount; |
192 | | - |
193 | 222 | if ( !isset( $smwgBnodeCount ) ) { |
194 | 223 | $smwgBnodeCount = 0; |
195 | 224 | } |
196 | | - |
| 225 | + |
| 226 | + if ( $subject == null ) { |
| 227 | + $subject = $this->m_subject; |
| 228 | + } |
| 229 | + |
197 | 230 | $result = array(); |
198 | | - |
| 231 | + |
199 | 232 | foreach ( $this->m_edges as $key => $edge ) { |
200 | | - foreach ( $this->m_children[$key] as $child ) { |
201 | | - $name = $child->getSubject()->getName(); |
202 | | - |
203 | | - if ( $name === '' || $name[0] === '_' ) { // bnode, rename ID to avoid unifying bnodes of different contexts |
| 233 | + foreach ( $this->m_children[$key] as $childElement ) { |
| 234 | + if ( $childElement instanceof SMWExpData ) { |
| 235 | + $childSubject = $childElement->getSubject(); |
| 236 | + } else { |
| 237 | + $childSubject = $childElement; |
| 238 | + } |
| 239 | + |
| 240 | + if ( ( $childSubject instanceof SMWExpResource ) && |
| 241 | + ( $childSubject->isBlankNode() ) ) { // bnode, rename ID to avoid unifying bnodes of different contexts |
204 | 242 | // TODO: should we really rename bnodes of the form "_id" here? |
205 | | - $child = clone $child; |
206 | | - $subject = new SMWExpResource( '_' . $smwgBnodeCount++, $child->getSubject()->getDataValue() ); |
207 | | - $child->setSubject( $subject ); |
| 243 | + $childSubject = new SMWExpResource( '_' . $smwgBnodeCount++, $childSubject()->getDataItem() ); |
208 | 244 | } |
209 | | - |
210 | | - $result[] = array( $this->m_subject, $edge, $child->getSubject() ); |
211 | | - $result = array_merge( $result, $child->getTripleList() ); // recursively generate all children's triples |
| 245 | + |
| 246 | + $result[] = array( $subject, $edge, $childSubject ); |
| 247 | + if ( $childElement instanceof SMWExpData ) { // recursively add child's triples |
| 248 | + $result = array_merge( $result, $child->getTripleList( $childSubject ) ); |
| 249 | + } |
212 | 250 | } |
213 | 251 | } |
214 | | - |
| 252 | + |
215 | 253 | return $result; |
216 | 254 | } |
217 | 255 | |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exp_Element.php |
— | — | @@ -16,140 +16,215 @@ |
17 | 17 | * |
18 | 18 | * @ingroup SMW |
19 | 19 | */ |
20 | | -class SMWExpElement { |
21 | | - protected $m_dv; |
22 | | - protected $m_name; |
| 20 | +abstract class SMWExpElement { |
23 | 21 | |
24 | 22 | /** |
25 | | - * Constructor. $dv is the SMWDataValue from which this object was created, |
26 | | - * if any. |
| 23 | + * The SMWDataItem that this export element is associated with, if |
| 24 | + * any. Might be unset if not given yet. |
| 25 | + * @var SMWDataItem |
27 | 26 | */ |
28 | | - public function __construct( $name, $dv = null ) { |
29 | | - $this->m_name = $name; |
30 | | - $this->m_dv = $dv; |
31 | | - } |
| 27 | + protected $m_dataItem; |
32 | 28 | |
33 | 29 | /** |
34 | | - * Return a string for denoting contents of the element, e.g. the URI or the literal |
35 | | - * values. |
| 30 | + * Constructor. |
| 31 | + * |
| 32 | + * @param $dataItem SMWDataItem or null |
36 | 33 | */ |
37 | | - public function getName() { |
38 | | - return $this->m_name; |
| 34 | + public function __construct( $dataItem = null ) { |
| 35 | + if ( $dataItem !== null ) { |
| 36 | + $this->m_dataItem = $dataItem; |
| 37 | + } |
39 | 38 | } |
40 | 39 | |
41 | 40 | /** |
42 | | - * If available, return the SMWDataValue object from which this SMWExpElement was built. |
43 | | - * NULL if unset. |
| 41 | + * Get a SMWDataItem object that represents the contents of this export |
| 42 | + * element in SMW, or null if no such data item could be found. |
| 43 | + * |
| 44 | + * @return SMWDataItem or null |
44 | 45 | */ |
45 | | - public function getDataValue() { |
46 | | - return $this->m_dv; |
| 46 | + public function getDataItem() { |
| 47 | + return isset( $this->m_dataItem ) ? $this->m_dataItem : null; |
47 | 48 | } |
48 | 49 | } |
49 | 50 | |
50 | 51 | /** |
51 | | - * A single resource (individual) for export. Defined by a URI, and possibly |
52 | | - * also providing abbreviated forms (QNames). |
| 52 | + * A single resource (individual) for export, as defined by a URI. |
53 | 53 | * This class can also be used to represent blank nodes: It is assumed that all |
54 | | - * objects of class SMWExpElement or any of its subclasses do represent blank |
| 54 | + * objects of class SMWExpElement or any of its subclasses represent a blank |
55 | 55 | * node if their name is empty or of the form "_id" where "id" is any |
56 | 56 | * identifier string. IDs are local to the current context, such as a list of |
57 | 57 | * triples or an SMWExpData container. |
58 | | - * |
59 | | - * @todo This class should be split into two: one general resource class, and |
60 | | - * one that only supports resources with namespace/qname form, because the |
61 | | - * latter is strictly necessary in some places where resources are used. |
| 58 | + * |
62 | 59 | * @ingroup SMW |
63 | 60 | */ |
64 | 61 | class SMWExpResource extends SMWExpElement { |
65 | 62 | |
66 | | - protected $m_namespace = false; |
67 | | - protected $m_namespaceid = false; |
68 | | - protected $m_localname = false; |
69 | | - |
70 | 63 | /** |
71 | | - * Constructor. $dv is the SMWDataValue from which this object was created, |
72 | | - * if any. If $namespace and $namespaceid are given, then $name is assumed to |
73 | | - * be the local name and they are used to build a QName. Otherwise $name is |
74 | | - * assumed to be the full URI. |
| 64 | + * Constructor. The given URI must not contain serialization-specific |
| 65 | + * abbreviations or escapings, such as XML entities. |
| 66 | + * |
| 67 | + * @param $uri string of the full URI |
| 68 | + * @param $dataItem SMWDataItem or null |
75 | 69 | */ |
76 | | - public function __construct( $name, $dv = null, $namespace = false, $namespaceid = false ) { |
77 | | - if ( $namespace !== false ) { |
78 | | - $this->m_namespace = $namespace; |
79 | | - $this->m_namespaceid = $namespaceid; |
80 | | - $this->m_localname = $name; |
81 | | - parent::__construct( $namespace . $name, $dv ); |
82 | | - } else { |
83 | | - parent::__construct( $name, $dv ); |
84 | | - } |
| 70 | + public function __construct( $uri, $dataItem = null ) { |
| 71 | + parent::__construct( $dataItem ); |
| 72 | + $this->m_uri = $uri; |
85 | 73 | } |
86 | 74 | |
87 | 75 | /** |
88 | | - * Return true of this resource represents a blank node. |
| 76 | + * Return true if this resource represents a blank node. |
| 77 | + * |
| 78 | + * @return boolean |
89 | 79 | */ |
90 | 80 | public function isBlankNode() { |
91 | | - return ( $this->m_name == '' ) || ( $this->m_name{0} == '_' ); |
| 81 | + return ( $this->m_uri == '' ) || ( $this->m_uri{0} == '_' ); |
92 | 82 | } |
93 | 83 | |
94 | 84 | /** |
95 | | - * Return a qualitifed name for the element, or false if no such name could be found. |
| 85 | + * Get the URI of this resource. The result is a UTF-8 encoded URI (or |
| 86 | + * IRI) without any escaping. |
| 87 | + * |
| 88 | + * @return string |
96 | 89 | */ |
| 90 | + public function getUri() { |
| 91 | + return $this->m_uri; |
| 92 | + } |
| 93 | + |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | +/** |
| 98 | + * A single resource (individual) for export, defined by a URI for which there |
| 99 | + * also is a namespace abbreviation. |
| 100 | + * |
| 101 | + * @ingroup SMW |
| 102 | + */ |
| 103 | +class SMWExpNsResource extends SMWExpResource { |
| 104 | + |
| 105 | + /** |
| 106 | + * Namespace URI prefix of the abbreviated URI |
| 107 | + * @var string |
| 108 | + */ |
| 109 | + protected $m_namespace; |
| 110 | + /** |
| 111 | + * Namespace abbreviation of the abbreviated URI |
| 112 | + * @var string |
| 113 | + */ |
| 114 | + protected $m_namespaceid; |
| 115 | + /** |
| 116 | + * Local part of the abbreviated URI |
| 117 | + * @var string |
| 118 | + */ |
| 119 | + protected $m_localname; |
| 120 | + |
| 121 | + /** |
| 122 | + * Constructor. The given URI must not contain serialization-specific |
| 123 | + * abbreviations or escapings, such as XML entities. |
| 124 | + * |
| 125 | + * @param $localname string local part of the abbreviated URI |
| 126 | + * @param $namespace string namespace URI prefix of the abbreviated URI |
| 127 | + * @param $namespaceid string namespace abbreviation of the abbreviated URI |
| 128 | + * @param $dataItem SMWDataItem or null |
| 129 | + */ |
| 130 | + public function __construct( $localname, $namespace, $namespaceid, $dataItem = null ) { |
| 131 | + parent::__construct( $namespace . $localname, $dataItem ); |
| 132 | + $this->m_namespace = $namespace; |
| 133 | + $this->m_namespaceid = $namespaceid; |
| 134 | + $this->m_localname = $localname; |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Return a qualitifed name for the element. |
| 139 | + * |
| 140 | + * @return string |
| 141 | + */ |
97 | 142 | public function getQName() { |
98 | | - if ( $this->m_namespace != false ) { |
99 | | - return $this->m_namespaceid . ':' . $this->m_localname; |
100 | | - } else { |
101 | | - return false; |
102 | | - } |
| 143 | + return $this->m_namespaceid . ':' . $this->m_localname; |
103 | 144 | } |
104 | 145 | |
105 | 146 | /** |
106 | | - * If a QName was given, this method returns the namespace identifier used (the part before :). |
| 147 | + * Get the namespace identifier used (the part before :). |
| 148 | + * |
| 149 | + * @return string |
107 | 150 | */ |
108 | | - public function getNamespaceID() { |
| 151 | + public function getNamespaceId() { |
109 | 152 | return $this->m_namespaceid; |
110 | 153 | } |
111 | 154 | |
112 | 155 | /** |
113 | | - * If a QName was given, this method returns the complete namespace URI that the |
114 | | - * namespace identifier abbreviates. |
| 156 | + * Get the namespace URI that is used in the abbreviation. |
| 157 | + * |
| 158 | + * @return string |
115 | 159 | */ |
116 | 160 | public function getNamespace() { |
117 | 161 | return $this->m_namespace; |
118 | 162 | } |
119 | 163 | |
120 | 164 | /** |
121 | | - * If a QName was given, this method returns its local name (the part after :). |
| 165 | + * Get the local name (the part after :). |
| 166 | + * |
| 167 | + * @return string |
122 | 168 | */ |
123 | 169 | public function getLocalName() { |
124 | 170 | return $this->m_localname; |
125 | 171 | } |
| 172 | + |
126 | 173 | } |
127 | 174 | |
128 | 175 | /** |
129 | | - * A single datatype literal for export. Defined by a literal value and a datatype URI. |
130 | | - * Currently no support for language tags. |
| 176 | + * A single datatype literal for export. Defined by a literal value and a |
| 177 | + * datatype URI. |
| 178 | + * |
| 179 | + * @todo Currently no support for language tags. |
| 180 | + * |
131 | 181 | * @ingroup SMW |
132 | 182 | */ |
133 | 183 | class SMWExpLiteral extends SMWExpElement { |
134 | 184 | |
135 | | - protected $m_datatype = false; |
| 185 | + /** |
| 186 | + * Datatype URI for the literal. |
| 187 | + * @var string |
| 188 | + */ |
| 189 | + protected $m_datatype; |
| 190 | + /** |
| 191 | + * Lexical form of the literal. |
| 192 | + * @var string |
| 193 | + */ |
| 194 | + protected $m_lexicalForm; |
136 | 195 | |
137 | 196 | /** |
138 | | - * Constructor. $dv is the SMWDataValue from which this object was created, |
139 | | - * if any. $name here should be the plain string for representing the literal |
140 | | - * without datatype or language information. The string $name is a plain UTF8-string |
141 | | - * witout any escape sequences whatsoever. Note that it may be required to escape |
142 | | - * some symbols in some contexts, especially <, >, & in XML and HTML. |
| 197 | + * Constructor. The given lexical form should be the plain string for |
| 198 | + * representing the literal without datatype or language information. |
| 199 | + * It must not use any escaping or abbrevition mechanisms. |
| 200 | + * |
| 201 | + * @param $lexicalForm string lexical form |
| 202 | + * @param $datatype string datatype URI or empty for untyped literals |
| 203 | + * @param $dataItem SMWDataItem or null |
143 | 204 | */ |
144 | | - public function __construct( $name, $dv = null, $datatype = false ) { |
| 205 | + public function __construct( $lexicalForm, $datatype = '', $dataItem = null ) { |
| 206 | + parent::__construct( $dataItem ); |
| 207 | + $this->m_lexicalForm = $lexicalForm; |
145 | 208 | $this->m_datatype = $datatype; |
146 | | - parent::__construct( $name, $dv ); |
147 | 209 | } |
148 | 210 | |
149 | 211 | /** |
150 | | - * Return the URI of the datatype used, or false if untyped. |
| 212 | + * Return the URI of the datatype used, or the empty string if untyped. |
| 213 | + * |
| 214 | + * @return string |
151 | 215 | */ |
152 | 216 | public function getDatatype() { |
153 | 217 | return $this->m_datatype; |
154 | 218 | } |
155 | 219 | |
| 220 | + /** |
| 221 | + * Return the lexical form of the literal. The result does not use |
| 222 | + * any escapings and might still need to be escaped in some contexts. |
| 223 | + * The lexical form is not validated or canonicalized. |
| 224 | + * |
| 225 | + * @return string |
| 226 | + */ |
| 227 | + public function getLexicalForm() { |
| 228 | + return $this->m_lexicalForm; |
| 229 | + } |
| 230 | + |
156 | 231 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_ExportController.php |
— | — | @@ -158,21 +158,22 @@ |
159 | 159 | } |
160 | 160 | |
161 | 161 | if ( $recursiondepth != 0 ) { |
162 | | - $subrecdepth = ($recursiondepth>0) ? ($recursiondepth-1) : ($recursiondepth==0 ? 0 : -1); |
| 162 | + $subrecdepth = $recursiondepth > 0 ? ( $recursiondepth - 1 ) : |
| 163 | + ( $recursiondepth == 0 ? 0 : -1 ); |
163 | 164 | |
164 | 165 | foreach ( $data->getProperties() as $property ) { |
165 | | - if ( $property->getDataValue() instanceof SMWWikiPageValue ) { |
166 | | - $this->queuePage( $property->getDataValue(), 0 ); // no real recursion along properties |
| 166 | + if ( $property->getDataItem() instanceof SMWWikiPageValue ) { |
| 167 | + $this->queuePage( $property->getDataItem(), 0 ); // no real recursion along properties |
167 | 168 | } |
168 | 169 | $wikipagevalues = false; |
169 | | - foreach ( $data->getValues( $property ) as $expdata ) { |
170 | | - $subject = $expdata->getSubject(); |
171 | | - if ( !$wikipagevalues && ( $subject->getDataValue() instanceof SMWWikiPageValue ) ) { |
| 170 | + foreach ( $data->getValues( $property ) as $valueExpElement ) { |
| 171 | + $valueResource = $valueExpElement instanceof SMWExpData ? $valueExpElement->getSubject() : $valueExpElement; |
| 172 | + if ( !$wikipagevalues && ( $valueResource->getDataItem() instanceof SMWWikiPageValue ) ) { |
172 | 173 | $wikipagevalues = true; |
173 | 174 | } elseif ( !$wikipagevalues ) { |
174 | 175 | break; |
175 | 176 | } |
176 | | - $this->queuePage( $subject->getDatavalue(), $subrecdepth ); |
| 177 | + $this->queuePage( $valueResource->getDataItem(), $subrecdepth ); |
177 | 178 | } |
178 | 179 | } |
179 | 180 | |
— | — | @@ -527,10 +528,10 @@ |
528 | 529 | } |
529 | 530 | |
530 | 531 | $data = new SMWExpData( new SMWExpResource( $nexturl ) ); |
531 | | - $ed = new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Thing' ) ); |
532 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), $ed ); |
| 532 | + $ed = new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) ); |
| 533 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
533 | 534 | $ed = new SMWExpData( new SMWExpResource( $nexturl ) ); |
534 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdfs', 'isDefinedBy' ), $ed ); |
| 535 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdfs', 'isDefinedBy' ), $ed ); |
535 | 536 | $this->serializer->serializeExpData( $data ); |
536 | 537 | } |
537 | 538 | |
— | — | @@ -556,39 +557,39 @@ |
557 | 558 | |
558 | 559 | // assemble export data: |
559 | 560 | $data = new SMWExpData( new SMWExpResource( '&wiki;#wiki' ) ); |
560 | | - $ed = new SMWExpData( SMWExporter::getSpecialElement( 'swivt', 'Wikisite' ) ); |
561 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), $ed ); |
| 561 | + $ed = new SMWExpData( SMWExporter::getSpecialNsResource( 'swivt', 'Wikisite' ) ); |
| 562 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
562 | 563 | // basic wiki information |
563 | 564 | $ed = new SMWExpData( new SMWExpLiteral( $wgSitename ) ); |
564 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdfs', 'label' ), $ed ); |
| 565 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdfs', 'label' ), $ed ); |
565 | 566 | $ed = new SMWExpData( new SMWExpLiteral( $wgSitename, null, 'http://www.w3.org/2001/XMLSchema#string' ) ); |
566 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'siteName' ), $ed ); |
| 567 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'siteName' ), $ed ); |
567 | 568 | $ed = new SMWExpData( new SMWExpLiteral( SMWExporter::expandURI( '&wikiurl;' ), null, 'http://www.w3.org/2001/XMLSchema#string' ) ); |
568 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'pagePrefix' ), $ed ); |
| 569 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'pagePrefix' ), $ed ); |
569 | 570 | $ed = new SMWExpData( new SMWExpLiteral( SMW_VERSION, null, 'http://www.w3.org/2001/XMLSchema#string' ) ); |
570 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'smwVersion' ), $ed ); |
| 571 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'smwVersion' ), $ed ); |
571 | 572 | $ed = new SMWExpData( new SMWExpLiteral( $wgLanguageCode, null, 'http://www.w3.org/2001/XMLSchema#string' ) ); |
572 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'langCode' ), $ed ); |
| 573 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'langCode' ), $ed ); |
573 | 574 | $mainpage = Title::newMainPage(); |
574 | 575 | if ( $mainpage !== null ) { |
575 | 576 | $ed = new SMWExpData( new SMWExpResource( $mainpage->getFullURL() ) ); |
576 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'mainPage' ), $ed ); |
| 577 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'mainPage' ), $ed ); |
577 | 578 | } |
578 | 579 | // statistical information |
579 | 580 | $ed = new SMWExpData( new SMWExpLiteral( SiteStats::pages(), null, 'http://www.w3.org/2001/XMLSchema#int' ) ); |
580 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'pageCount' ), $ed ); |
| 581 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'pageCount' ), $ed ); |
581 | 582 | $ed = new SMWExpData( new SMWExpLiteral( SiteStats::articles(), null, 'http://www.w3.org/2001/XMLSchema#int' ) ); |
582 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'contentPageCount' ), $ed ); |
| 583 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'contentPageCount' ), $ed ); |
583 | 584 | $ed = new SMWExpData( new SMWExpLiteral( SiteStats::images(), null, 'http://www.w3.org/2001/XMLSchema#int' ) ); |
584 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'mediaCount' ), $ed ); |
| 585 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'mediaCount' ), $ed ); |
585 | 586 | $ed = new SMWExpData( new SMWExpLiteral( SiteStats::edits(), null, 'http://www.w3.org/2001/XMLSchema#int' ) ); |
586 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'editCount' ), $ed ); |
| 587 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'editCount' ), $ed ); |
587 | 588 | $ed = new SMWExpData( new SMWExpLiteral( SiteStats::views(), null, 'http://www.w3.org/2001/XMLSchema#int' ) ); |
588 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'viewCount' ), $ed ); |
| 589 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'viewCount' ), $ed ); |
589 | 590 | $ed = new SMWExpData( new SMWExpLiteral( SiteStats::users(), null, 'http://www.w3.org/2001/XMLSchema#int' ) ); |
590 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'userCount' ), $ed ); |
| 591 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'userCount' ), $ed ); |
591 | 592 | $ed = new SMWExpData( new SMWExpLiteral( SiteStats::numberingroup( 'sysop' ), null, 'http://www.w3.org/2001/XMLSchema#int' ) ); |
592 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'adminCount' ), $ed ); |
| 593 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'adminCount' ), $ed ); |
593 | 594 | |
594 | 595 | $this->serializer->startSerialization(); |
595 | 596 | $this->serializer->serializeExpData( SMWExporter::getOntologyExpData( '' ) ); |
— | — | @@ -601,10 +602,10 @@ |
602 | 603 | $nexturl = SMWExporter::expandURI( '&export;&offset=0' ); |
603 | 604 | } |
604 | 605 | $data = new SMWExpData( new SMWExpResource( $nexturl ) ); |
605 | | - $ed = new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Thing' ) ); |
606 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), $ed ); |
| 606 | + $ed = new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) ); |
| 607 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
607 | 608 | $ed = new SMWExpData( new SMWExpResource( $nexturl ) ); |
608 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdfs', 'isDefinedBy' ), $ed ); |
| 609 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdfs', 'isDefinedBy' ), $ed ); |
609 | 610 | $this->serializer->serializeExpData( $data ); |
610 | 611 | |
611 | 612 | $this->serializer->finishSerialization(); |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Serializer_RDFXML.php |
— | — | @@ -75,8 +75,8 @@ |
76 | 76 | $this->post_ns_buffer .= "\t<$typename rdf:about=\"$uri\" />\n"; |
77 | 77 | } |
78 | 78 | |
79 | | - public function serializeExpData( SMWExpData $data ) { |
80 | | - $this->serializeNestedExpData( $data, '' ); |
| 79 | + public function serializeExpData( SMWExpData $expData ) { |
| 80 | + $this->serializeNestedExpData( $expData, '' ); |
81 | 81 | $this->serializeNamespaces(); |
82 | 82 | if ( !$this->namespaces_are_global ) { |
83 | 83 | $this->pre_ns_buffer .= $this->post_ns_buffer; |
— | — | @@ -106,13 +106,13 @@ |
107 | 107 | * Serialize the given SMWExpData object, possibly recursively with |
108 | 108 | * increased indentation. |
109 | 109 | * |
110 | | - * @param $data SMWExpData containing the data to be serialised. |
| 110 | + * @param $expData SMWExpData containing the data to be serialised. |
111 | 111 | * @param $indent string specifying a prefix for indentation (usually a sequence of tabs) |
112 | 112 | */ |
113 | | - protected function serializeNestedExpData( SMWExpData $data, $indent ) { |
114 | | - $this->recordDeclarationTypes( $data ); |
| 113 | + protected function serializeNestedExpData( SMWExpData $expData, $indent ) { |
| 114 | + $this->recordDeclarationTypes( $expData ); |
115 | 115 | |
116 | | - $type = $data->extractMainType()->getQName(); |
| 116 | + $type = $expData->extractMainType()->getQName(); |
117 | 117 | if ( !$this->namespace_block_started ) { // start new ns block |
118 | 118 | $this->pre_ns_buffer .= "\t$indent<$type"; |
119 | 119 | $this->namespace_block_started = true; |
— | — | @@ -120,61 +120,42 @@ |
121 | 121 | $this->post_ns_buffer .= "\t$indent<$type"; |
122 | 122 | } |
123 | 123 | |
124 | | - if ( ( $data->getSubject() instanceof SMWExpLiteral ) || |
125 | | - ( $data->getSubject() instanceof SMWExpResource ) ) { |
126 | | - $this->post_ns_buffer .= ' rdf:about="' . $data->getSubject()->getName() . '"'; |
| 124 | + if ( $expData->getSubject() instanceof SMWExpResource ) { |
| 125 | + $this->post_ns_buffer .= ' rdf:about="' . $expData->getSubject()->getUri() . '"'; |
127 | 126 | } // else: blank node, no "rdf:about" |
128 | 127 | |
129 | | - if ( count( $data->getProperties() ) == 0 ) { // nothing else to export |
| 128 | + if ( count( $expData->getProperties() ) == 0 ) { // nothing else to export |
130 | 129 | $this->post_ns_buffer .= " />\n"; |
131 | 130 | } else { // process data |
132 | 131 | $this->post_ns_buffer .= ">\n"; |
133 | 132 | |
134 | | - foreach ( $data->getProperties() as $property ) { |
| 133 | + foreach ( $expData->getProperties() as $property ) { |
135 | 134 | $prop_decl_queued = false; |
136 | | - $class_type_prop = $this->isOWLClassTypeProperty( $property ); |
| 135 | + $isClassTypeProp = $this->isOWLClassTypeProperty( $property ); |
137 | 136 | |
138 | | - foreach ( $data->getValues( $property ) as $value ) { |
139 | | - $this->post_ns_buffer .= "\t\t$indent<" . $property->getQName(); |
| 137 | + foreach ( $expData->getValues( $property ) as $valueElement ) { |
140 | 138 | $this->requireNamespace( $property->getNamespaceID(), $property->getNamespace() ); |
141 | | - $object = $value->getSubject(); |
142 | 139 | |
143 | | - if ( $object instanceof SMWExpLiteral ) { |
| 140 | + if ( $valueElement instanceof SMWExpLiteral ) { |
144 | 141 | $prop_decl_type = SMW_SERIALIZER_DECL_APROP; |
145 | | - if ( $object->getDatatype() != '' ) { |
146 | | - $this->post_ns_buffer .= ' rdf:datatype="' . $object->getDatatype() . '"'; |
147 | | - } |
148 | | - $this->post_ns_buffer .= '>' . |
149 | | - str_replace( array( '&', '>', '<' ), array( '&', '>', '<' ), $object->getName() ) . |
150 | | - '</' . $property->getQName() . ">\n"; |
151 | | - } else { // resource (maybe blank node), could have subdescriptions |
| 142 | + $this->serializeExpLiteral( $property, $valueElement, "\t\t$indent" ); |
| 143 | + } elseif ( $valueElement instanceof SMWExpResource ) { |
152 | 144 | $prop_decl_type = SMW_SERIALIZER_DECL_OPROP; |
153 | | - $collection = $value->getCollection(); |
| 145 | + $this->serializeExpResource( $property, $valueElement, "\t\t$indent", $isClassTypeProp ); |
| 146 | + } elseif ( $valueElement instanceof SMWExpData ) { |
| 147 | + $prop_decl_type = SMW_SERIALIZER_DECL_OPROP; |
| 148 | + |
| 149 | + $collection = $valueElement->getCollection(); |
154 | 150 | if ( $collection !== false ) { // RDF-style collection (list) |
155 | | - $this->post_ns_buffer .= " rdf:parseType=\"Collection\">\n"; |
156 | | - foreach ( $collection as $subvalue ) { |
157 | | - $this->serializeNestedExpData( $subvalue, $indent . "\t\t" ); |
158 | | - if ( $class_type_prop ) { |
159 | | - $this->requireDeclaration( $subvalue, SMW_SERIALIZER_DECL_CLASS ); |
160 | | - } |
161 | | - } |
| 151 | + $this->serializeExpCollection( $property, $collection, "\t\t$indent", $isClassTypeProp ); |
| 152 | + } elseif ( count( $valueElement->getProperties() ) > 0 ) { // resource with data |
| 153 | + $this->post_ns_buffer .= "\t\t$indent<" . $expResourceProperty->getQName() . ">\n"; |
| 154 | + $this->serializeNestedExpData( $valueElement, "\t\t$indent" ); |
162 | 155 | $this->post_ns_buffer .= "\t\t$indent</" . $property->getQName() . ">\n"; |
163 | | - } else { |
164 | | - if ( $class_type_prop ) { |
165 | | - $this->requireDeclaration( $object, SMW_SERIALIZER_DECL_CLASS ); |
166 | | - } |
167 | | - if ( count( $value->getProperties() ) > 0 ) { // resource with data: serialise |
168 | | - $this->post_ns_buffer .= ">\n"; |
169 | | - $this->serializeNestedExpData( $value, $indent . "\t\t" ); |
170 | | - $this->post_ns_buffer .= "\t\t$indent</" . $property->getQName() . ">\n"; |
171 | | - } else { // resource without data |
172 | | - if ( !$object->isBlankNode() ) { |
173 | | - $this->post_ns_buffer .= ' rdf:resource="' . $object->getName() . '"'; |
174 | | - } |
175 | | - $this->post_ns_buffer .= "/>\n"; |
176 | | - } |
| 156 | + } else { // resource without data |
| 157 | + $this->serializeExpResource( $property, $valueElement->getSubject(), "\t\t$indent", $isClassTypeProp ); |
177 | 158 | } |
178 | | - } |
| 159 | + } // else: no other types of export elements |
179 | 160 | |
180 | 161 | if ( !$prop_decl_queued ) { |
181 | 162 | $this->requireDeclaration( $property, $prop_decl_type ); |
— | — | @@ -185,6 +166,68 @@ |
186 | 167 | $this->post_ns_buffer .= "\t$indent</" . $type . ">\n"; |
187 | 168 | } |
188 | 169 | } |
| 170 | + |
| 171 | + /** |
| 172 | + * Add a serialization of the given SMWExpLiteral to the output, |
| 173 | + * assuming that an opening property tag is alerady there. |
| 174 | + * |
| 175 | + * @param $expResourceProperty SMWExpNsResource the property to use |
| 176 | + * @param $expLiteral SMWExpLiteral the data value to use |
| 177 | + * @param $indent string specifying a prefix for indentation (usually a sequence of tabs) |
| 178 | + */ |
| 179 | + protected function serializeExpLiteral( SMWExpNsResource $expResourceProperty, SMWExpLiteral $expLiteral, $indent ) { |
| 180 | + $this->post_ns_buffer .= $indent . '<' . $expResourceProperty->getQName(); |
| 181 | + if ( $expLiteral->getDatatype() != '' ) { |
| 182 | + $this->post_ns_buffer .= ' rdf:datatype="' . $expLiteral->getDatatype() . '"'; |
| 183 | + } |
| 184 | + $this->post_ns_buffer .= '>' . |
| 185 | + str_replace( array( '&', '>', '<' ), array( '&', '>', '<' ), $expLiteral->getLexicalForm() ) . |
| 186 | + '</' . $expResourceProperty->getQName() . ">\n"; |
| 187 | + } |
| 188 | + |
| 189 | + /** |
| 190 | + * Add a serialization of the given SMWExpResource to the output, |
| 191 | + * assuming that an opening property tag is alerady there. |
| 192 | + * |
| 193 | + * @param $expResourceProperty SMWExpNsResource the property to use |
| 194 | + * @param $expResource SMWExpResource the data value to use |
| 195 | + * @param $indent string specifying a prefix for indentation (usually a sequence of tabs) |
| 196 | + * @param $isClassTypeProp boolean whether the resource must be declared as a class |
| 197 | + */ |
| 198 | + protected function serializeExpResource( SMWExpNsResource $expResourceProperty, SMWExpResource $expResource, $indent, $isClassTypeProp ) { |
| 199 | + $this->post_ns_buffer .= $indent . '<' . $expResourceProperty->getQName(); |
| 200 | + if ( !$expResource->isBlankNode() ) { |
| 201 | + $this->post_ns_buffer .= ' rdf:resource="' . $expResource->getUri() . '"'; |
| 202 | + } |
| 203 | + $this->post_ns_buffer .= "/>\n"; |
| 204 | + if ( $isClassTypeProp ) { |
| 205 | + $this->requireDeclaration( $expResource, SMW_SERIALIZER_DECL_CLASS ); |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * Add a serialization of the given SMWExpResource to the output, |
| 211 | + * assuming that an opening property tag is alerady there. |
| 212 | + * |
| 213 | + * @param $expResourceProperty SMWExpNsResource the property to use |
| 214 | + * @param $expResource array of (SMWExpResource or SMWExpData) |
| 215 | + * @param $indent string specifying a prefix for indentation (usually a sequence of tabs) |
| 216 | + * @param $isClassTypeProp boolean whether the resource must be declared as a class |
| 217 | + */ |
| 218 | + protected function serializeExpCollection( SMWExpNsResource $expResourceProperty, array $collection, $indent, $isClassTypeProp ) { |
| 219 | + $this->post_ns_buffer .= $indent . '<' . $expResourceProperty->getQName() . " rdf:parseType=\"Collection\">\n"; |
| 220 | + foreach ( $collection as $expElement ) { |
| 221 | + if ( $expElement instanceof SMWExpData ) { |
| 222 | + $this->serializeNestedExpData( $expElement, $indent ); |
| 223 | + } else { |
| 224 | + $this->serializeExpResource( $expResourceProperty, $expElement, $indent ); |
| 225 | + } |
| 226 | + if ( $isClassTypeProp ) { |
| 227 | + $this->requireDeclaration( $expResource, SMW_SERIALIZER_DECL_CLASS ); |
| 228 | + } |
| 229 | + } |
| 230 | + $this->post_ns_buffer .= "$indent</" . $expResourceProperty->getQName() . ">\n"; |
| 231 | + } |
189 | 232 | |
190 | 233 | /** |
191 | 234 | * Escape a string in the special form that is required for values in |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php |
— | — | @@ -70,11 +70,11 @@ |
71 | 71 | * @param mixed $typesvalueforproperty either an SMWTypesValue or null |
72 | 72 | */ |
73 | 73 | static public function makeExportDataForSubject( SMWDIWikiPage $subject, $typesvalueforproperty = null ) { |
74 | | - $result = self::getDataItemExpData( $subject ); |
| 74 | + $result = new SMWExpData( self::getDataItemExpData( $subject ) ); |
75 | 75 | $subj_title = Title::makeTitle( $subject->getNamespace(), $subject->getDBkey() ); |
76 | 76 | switch ( $subject->getNamespace() ) { |
77 | 77 | case NS_CATEGORY: case SMW_NS_CONCEPT: |
78 | | - $maintype_pe = SMWExporter::getSpecialElement( 'owl', 'Class' ); |
| 78 | + $maintype_pe = SMWExporter::getSpecialNsResource( 'owl', 'Class' ); |
79 | 79 | $label = $subj_title->getText(); |
80 | 80 | break; |
81 | 81 | case SMW_NS_PROPERTY: |
— | — | @@ -82,22 +82,22 @@ |
83 | 83 | $types = smwfGetStore()->getPropertyValues( $subject, new SMWDIProperty( '_TYPE' ) ); |
84 | 84 | $typesvalueforproperty = end( $types ); |
85 | 85 | } |
86 | | - $maintype_pe = SMWExporter::getSpecialElement( 'owl', SMWExporter::getOWLPropertyType( $typesvalueforproperty ) ); |
| 86 | + $maintype_pe = SMWExporter::getSpecialNsResource( 'owl', SMWExporter::getOWLPropertyType( $typesvalueforproperty ) ); |
87 | 87 | $label = $subj_title->getText(); |
88 | 88 | break; |
89 | 89 | default: |
90 | 90 | $label = $subj_title->getPrefixedText(); |
91 | | - $maintype_pe = SMWExporter::getSpecialElement( 'swivt', 'Subject' ); |
| 91 | + $maintype_pe = SMWExporter::getSpecialNsResource( 'swivt', 'Subject' ); |
92 | 92 | } |
93 | | - $ed = new SMWExpData( new SMWExpLiteral( $label ) ); |
94 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdfs', 'label' ), $ed ); |
95 | | - $ed = new SMWExpData( new SMWExpResource( '&wikiurl;' . $subj_title->getPrefixedURL() ) ); |
96 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'page' ), $ed ); |
97 | | - $ed = new SMWExpData( new SMWExpResource( SMWExporter::$m_exporturl . '/' . $subj_title->getPrefixedURL() ) ); |
98 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdfs', 'isDefinedBy' ), $ed ); |
99 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), new SMWExpData( $maintype_pe ) ); |
100 | | - $ed = new SMWExpData( new SMWExpLiteral( $subject->getNamespace(), null, 'http://www.w3.org/2001/XMLSchema#integer' ) ); |
101 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'wikiNamespace' ), $ed ); |
| 93 | + $ed = new SMWExpLiteral( $label ); |
| 94 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdfs', 'label' ), $ed ); |
| 95 | + $ed = new SMWExpResource( '&wikiurl;' . $subj_title->getPrefixedURL() ); |
| 96 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'page' ), $ed ); |
| 97 | + $ed = new SMWExpResource( SMWExporter::$m_exporturl . '/' . $subj_title->getPrefixedURL() ); |
| 98 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdfs', 'isDefinedBy' ), $ed ); |
| 99 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $maintype_pe ); |
| 100 | + $ed = new SMWExpLiteral( $subject->getNamespace(), 'http://www.w3.org/2001/XMLSchema#integer' ); |
| 101 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'wikiNamespace' ), $ed ); |
102 | 102 | return $result; |
103 | 103 | } |
104 | 104 | |
— | — | @@ -120,23 +120,25 @@ |
121 | 121 | } |
122 | 122 | } |
123 | 123 | } else { // pre-defined property, only exported if known |
124 | | - $subject = $expData->getSubject()->getDatavalue(); |
125 | | - if ( $subject == null ) return; // subject datavalue (wikipage) required for treating special properties properly |
126 | | - switch ( $subject->getNamespace() ) { |
| 124 | + $diSubject = $expData->getSubject()->getDataItem(); |
| 125 | + if ( ( $diSubject == null ) || ( $diSubject->getDIType() != SMWDataItem::TYPE_WIKIPAGE ) ) { |
| 126 | + return; // subject datavalue (wikipage) required for treating special properties properly |
| 127 | + } |
| 128 | + switch ( $diSubject->getNamespace() ) { |
127 | 129 | case NS_CATEGORY: case SMW_NS_CONCEPT: |
128 | | - $category_pe = SMWExporter::getSpecialElement( 'rdfs', 'subClassOf' ); |
| 130 | + $category_pe = SMWExporter::getSpecialNsResource( 'rdfs', 'subClassOf' ); |
129 | 131 | $subprop_pe = null; |
130 | | - $equality_pe = SMWExporter::getSpecialElement( 'owl', 'equivalentClass' ); |
| 132 | + $equality_pe = SMWExporter::getSpecialNsResource( 'owl', 'equivalentClass' ); |
131 | 133 | break; |
132 | 134 | case SMW_NS_PROPERTY: |
133 | | - $category_pe = SMWExporter::getSpecialElement( 'rdf', 'type' ); |
134 | | - $subprop_pe = SMWExporter::getSpecialElement( 'rdfs', 'subPropertyOf' ); |
135 | | - $equality_pe = SMWExporter::getSpecialElement( 'owl', 'equivalentProperty' ); |
| 135 | + $category_pe = SMWExporter::getSpecialNsResource( 'rdf', 'type' ); |
| 136 | + $subprop_pe = SMWExporter::getSpecialNsResource( 'rdfs', 'subPropertyOf' ); |
| 137 | + $equality_pe = SMWExporter::getSpecialNsResource( 'owl', 'equivalentProperty' ); |
136 | 138 | break; |
137 | 139 | default: |
138 | | - $category_pe = SMWExporter::getSpecialElement( 'rdf', 'type' ); |
| 140 | + $category_pe = SMWExporter::getSpecialNsResource( 'rdf', 'type' ); |
139 | 141 | $subprop_pe = null; |
140 | | - $equality_pe = SMWExporter::getSpecialElement( 'owl', 'sameAs' ); |
| 142 | + $equality_pe = SMWExporter::getSpecialNsResource( 'owl', 'sameAs' ); |
141 | 143 | } |
142 | 144 | $pe = null; |
143 | 145 | $cat_only = false; // basic namespace checking for equivalent categories |
— | — | @@ -147,14 +149,14 @@ |
148 | 150 | case '_URI': $pe = $equality_pe; break; |
149 | 151 | case '_SUBP': $pe = $subprop_pe; break; |
150 | 152 | case '_MDAT': |
151 | | - $pe = SMWExporter::getSpecialElement( 'swivt', 'wikiPageModificationDate' ); |
| 153 | + $pe = SMWExporter::getSpecialNsResource( 'swivt', 'wikiPageModificationDate' ); |
152 | 154 | break; |
153 | 155 | case '_REDI': /// TODO: currently no check for avoiding OWL DL illegal redirects is done |
154 | | - if ( $subject->getNamespace() == SMW_NS_PROPERTY ) { |
| 156 | + if ( $diSubject->getNamespace() == SMW_NS_PROPERTY ) { |
155 | 157 | $pe = null; // checking the typing here is too cumbersome, smart stores will smush the properties anyway, and the others will not handle them equivalently |
156 | 158 | } else { |
157 | 159 | $pe = $equality_pe; |
158 | | - $cat_only = ( $subject->getNamespace() == NS_CATEGORY ); |
| 160 | + $cat_only = ( $diSubject->getNamespace() == NS_CATEGORY ); |
159 | 161 | } |
160 | 162 | break; |
161 | 163 | } |
— | — | @@ -167,10 +169,10 @@ |
168 | 170 | } |
169 | 171 | $ed = self::getDataItemExpData( $dataItem ); |
170 | 172 | if ( $ed !== null ) { |
171 | | - if ( ( $property->getKey() == '_CONC' ) && ( $ed->getSubject()->getName() == '' ) ) { |
| 173 | + if ( ( $property->getKey() == '_CONC' ) && ( $ed->getSubject()->getUri() == '' ) ) { |
172 | 174 | // equivalent to anonymous class -> simplify description |
173 | 175 | foreach ( $ed->getProperties() as $subp ) { |
174 | | - if ( $subp->getName() != SMWExporter::getSpecialElement( 'rdf', 'type' )->getName() ) { |
| 176 | + if ( $subp->getUri() != SMWExporter::getSpecialNsResource( 'rdf', 'type' )->getUri() ) { |
175 | 177 | foreach ( $ed->getValues( $subp ) as $subval ) { |
176 | 178 | $expData->addPropertyObjectValue( $subp, $subval ); |
177 | 179 | } |
— | — | @@ -226,7 +228,7 @@ |
227 | 229 | } |
228 | 230 | } |
229 | 231 | |
230 | | - return new SMWExpResource( $localname, $diWikiPage, $namespace, $namespaceid ); |
| 232 | + return new SMWExpNsResource( $localname, $namespace, $namespaceid, $diWikiPage ); |
231 | 233 | } |
232 | 234 | |
233 | 235 | /** |
— | — | @@ -251,21 +253,25 @@ |
252 | 254 | } |
253 | 255 | |
254 | 256 | /** |
255 | | - * Create an SMWExportElement for some special element that belongs to a known vocabulary. |
256 | | - * The parameter given must be a supported namespace id (e.g. "rdfs") and a local name (e.g. "label"). |
257 | | - * Returns NULL if $namespace is not known. |
| 257 | + * Create an SMWExpNsResource for some special element that belongs to |
| 258 | + * a known vocabulary. An exception is generated when given parameters |
| 259 | + * that do not fit any known vocabulary. |
| 260 | + * |
| 261 | + * @param $namespaceId string (e.g. "rdf") |
| 262 | + * @param $localName string (e.g. "type") |
| 263 | + * @return SMWExpNsResource |
258 | 264 | */ |
259 | | - static public function getSpecialElement( $namespace, $localname ) { |
| 265 | + static public function getSpecialNsResource( $namespaceId, $localName ) { |
260 | 266 | $namespaces = array( |
261 | 267 | 'swivt' => '&swivt;', |
262 | 268 | 'rdfs' => '&rdfs;', |
263 | 269 | 'rdf' => '&rdf;', |
264 | 270 | 'owl' => '&owl;', |
265 | 271 | ); |
266 | | - if ( array_key_exists( $namespace, $namespaces ) ) { |
267 | | - return new SMWExpResource( $localname, null, $namespaces[$namespace], $namespace ); |
| 272 | + if ( array_key_exists( $namespaceId, $namespaces ) ) { |
| 273 | + return new SMWExpNsResource( $localName, $namespaces[$namespaceId], $namespaceId ); |
268 | 274 | } else { |
269 | | - return null; |
| 275 | + throw new InvalidArgumentException( "The vocabulary '$namespaceId' is not a known special vocabulary." ); |
270 | 276 | } |
271 | 277 | } |
272 | 278 | |
— | — | @@ -317,12 +323,12 @@ |
318 | 324 | */ |
319 | 325 | static public function getOntologyExpData( $ontologyuri ) { |
320 | 326 | $data = new SMWExpData( new SMWExpResource( $ontologyuri ) ); |
321 | | - $ed = new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Ontology' ) ); |
322 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), $ed ); |
323 | | - $ed = new SMWExpData( new SMWExpLiteral( date( DATE_W3C ), null, 'http://www.w3.org/2001/XMLSchema#dateTime' ) ); |
324 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'creationDate' ), $ed ); |
325 | | - $ed = new SMWExpData( new SMWExpResource( 'http://semantic-mediawiki.org/swivt/1.0' ) ); |
326 | | - $data->addPropertyObjectValue( SMWExporter::getSpecialElement( 'owl', 'imports' ), $ed ); |
| 327 | + $ed = SMWExporter::getSpecialNsResource( 'owl', 'Ontology' ); |
| 328 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
| 329 | + $ed = new SMWExpLiteral( date( DATE_W3C ), 'http://www.w3.org/2001/XMLSchema#dateTime' ); |
| 330 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'swivt', 'creationDate' ), $ed ); |
| 331 | + $ed = new SMWExpResource( 'http://semantic-mediawiki.org/swivt/1.0' ); |
| 332 | + $data->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'imports' ), $ed ); |
327 | 333 | return $data; |
328 | 334 | } |
329 | 335 | |
— | — | @@ -336,22 +342,22 @@ |
337 | 343 | static public function getDataItemExpData( SMWDataItem $dataItem ) { |
338 | 344 | switch ( $dataItem->getDIType() ) { |
339 | 345 | case SMWDataItem::TYPE_NUMBER: |
340 | | - $lit = new SMWExpLiteral( $dataItem->getNumber(), $dataItem, 'http://www.w3.org/2001/XMLSchema#double' ); |
341 | | - return new SMWExpData( $lit ); |
| 346 | + $lit = new SMWExpLiteral( $dataItem->getNumber(), 'http://www.w3.org/2001/XMLSchema#double', $dataItem ); |
| 347 | + return $lit; |
342 | 348 | break; |
343 | 349 | case SMWDataItem::TYPE_STRING: case SMWDataItem::TYPE_BLOB: |
344 | | - $lit = new SMWExpLiteral( smwfHTMLtoUTF8( $dataItem->getString() ), $dataItem, 'http://www.w3.org/2001/XMLSchema#string' ); |
345 | | - return new SMWExpData( $lit ); |
| 350 | + $lit = new SMWExpLiteral( smwfHTMLtoUTF8( $dataItem->getString() ), 'http://www.w3.org/2001/XMLSchema#string', $dataItem ); |
| 351 | + return $lit; |
346 | 352 | break; |
347 | 353 | case SMWDataItem::TYPE_BOOLEAN: |
348 | 354 | $xsdvalue = $dataItem->getBoolean() ? 'true' : 'false'; |
349 | | - $lit = new SMWExpLiteral( $xsdvalue, $dataItem, 'http://www.w3.org/2001/XMLSchema#boolean' ); |
350 | | - return new SMWExpData( $lit ); |
| 355 | + $lit = new SMWExpLiteral( $xsdvalue, 'http://www.w3.org/2001/XMLSchema#boolean', $dataItem ); |
| 356 | + return $lit; |
351 | 357 | break; |
352 | 358 | case SMWDataItem::TYPE_URI: |
353 | 359 | /// TODO This escaping seems very odd. The serialisation should handle such things. |
354 | 360 | $res = new SMWExpResource( str_replace( '&', '&', $dataItem->getURI() ), $dataItem ); |
355 | | - return new SMWExpData( $res ); |
| 361 | + return $res; |
356 | 362 | break; |
357 | 363 | case SMWDataItem::TYPE_TIME: |
358 | 364 | $gregorianTime = $dataItem->getForCalendarModel( SMWDITime::CM_GREGORIAN ); |
— | — | @@ -377,8 +383,8 @@ |
378 | 384 | } |
379 | 385 | } |
380 | 386 | $xsdvalue .= 'Z'; |
381 | | - $lit = new SMWExpLiteral( $xsdvalue, $gregorianTime, $xsdtype ); |
382 | | - return new SMWExpData( $lit ); |
| 387 | + $lit = new SMWExpLiteral( $xsdvalue, $xsdtype, $gregorianTime ); |
| 388 | + return $lit; |
383 | 389 | break; |
384 | 390 | case SMWDataItem::TYPE_GEO: |
385 | 391 | /// TODO |
— | — | @@ -393,19 +399,19 @@ |
394 | 400 | $title = Title::makeTitle( $dataItem->getNamespace(), $dataItem->getDBkey() ) ; |
395 | 401 | $file = wfFindFile( $title ); |
396 | 402 | if ( $file !== false ) { |
397 | | - return new SMWExpData( new SMWExpResource( $file->getFullURL() ) ); |
| 403 | + return new SMWExpResource( $file->getFullURL() ); |
398 | 404 | } else { // Medialink to non-existing file :-/ |
399 | | - return new SMWExpData( SMWExporter::getResourceElement( $dataItem ) ); |
| 405 | + return SMWExporter::getResourceElement( $dataItem ); |
400 | 406 | } |
401 | 407 | } else { |
402 | | - return new SMWExpData( SMWExporter::getResourceElement( $dataItem ) ); |
| 408 | + return SMWExporter::getResourceElement( $dataItem ); |
403 | 409 | } |
404 | 410 | break; |
405 | 411 | case SMWDataItem::TYPE_CONCEPT: |
406 | 412 | /// TODO |
407 | 413 | break; |
408 | 414 | case SMWDataItem::TYPE_PROPERTY: |
409 | | - return new SMWExpData( SMWExporter::getResourceElement( $dataItem->getDiWikiPage() ) ); |
| 415 | + return SMWExporter::getResourceElement( $dataItem->getDiWikiPage() ); |
410 | 416 | break; |
411 | 417 | } |
412 | 418 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Serializer_Turtle.php |
— | — | @@ -107,13 +107,15 @@ |
108 | 108 | $firstvalue = false; |
109 | 109 | |
110 | 110 | $this->requireNamespace( $property->getNamespaceID(), $property->getNamespace() ); |
111 | | - $object = $value->getSubject(); |
112 | 111 | |
113 | | - if ( $object instanceof SMWExpLiteral ) { |
| 112 | + if ( $value instanceof SMWExpLiteral ) { |
114 | 113 | $prop_decl_type = SMW_SERIALIZER_DECL_APROP; |
115 | | - $this->serializeExpLiteral( $object ); |
116 | | - } else { // resource (maybe blank node), could have subdescriptions |
| 114 | + $this->serializeExpLiteral( $value ); |
| 115 | + } elseif ( $value instanceof SMWExpResource ) { |
117 | 116 | $prop_decl_type = SMW_SERIALIZER_DECL_OPROP; |
| 117 | + $this->serializeExpResource( $value ); |
| 118 | + } elseif ( $value instanceof SMWExpData ) { // resource (maybe blank node), could have subdescriptions |
| 119 | + $prop_decl_type = SMW_SERIALIZER_DECL_OPROP; |
118 | 120 | $collection = $value->getCollection(); |
119 | 121 | if ( $collection !== false ) { // RDF-style collection (list) |
120 | 122 | $this->post_ns_buffer .= "( "; |
— | — | @@ -132,7 +134,7 @@ |
133 | 135 | $this->post_ns_buffer .= "\n"; |
134 | 136 | $this->serializeNestedExpData( $value, $indent . "\t\t" ); |
135 | 137 | } else { // resource without data: may need to be queued |
136 | | - $this->serializeExpResource( $object ); |
| 138 | + $this->serializeExpResource( $value->getSubject() ); |
137 | 139 | } |
138 | 140 | } |
139 | 141 | } |
— | — | @@ -147,7 +149,7 @@ |
148 | 150 | } |
149 | 151 | |
150 | 152 | protected function serializeExpLiteral( SMWExpLiteral $element ) { |
151 | | - $this->post_ns_buffer .= '"' . str_replace( array( '\\', "\n", '"' ), array( '\\\\', "\\n", '\"' ), $element->getName() ) . '"'; |
| 153 | + $this->post_ns_buffer .= '"' . str_replace( array( '\\', "\n", '"' ), array( '\\\\', "\\n", '\"' ), $element->getLexicalForm() ) . '"'; |
152 | 154 | $dt = $element->getDatatype(); |
153 | 155 | if ( ( $dt != '' ) && ( $dt != 'http://www.w3.org/2001/XMLSchema#string' ) ) { |
154 | 156 | $count = 0; |
— | — | @@ -164,10 +166,10 @@ |
165 | 167 | if ( $element->isBlankNode() ) { |
166 | 168 | $this->post_ns_buffer .= '[]'; |
167 | 169 | } else { |
168 | | - if ( $element->getQName() !== false ) { |
| 170 | + if ( $element instanceof SMWExpNsResource ) { |
169 | 171 | $this->post_ns_buffer .= $element->getQName(); |
170 | 172 | } else { |
171 | | - $this->post_ns_buffer .= '<' . str_replace( '>', '\>', SMWExporter::expandURI( $element->getName() ) ) . '>'; |
| 173 | + $this->post_ns_buffer .= '<' . str_replace( '>', '\>', SMWExporter::expandURI( $element->getUri() ) ) . '>'; |
172 | 174 | } |
173 | 175 | } |
174 | 176 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Serializer.php |
— | — | @@ -216,13 +216,17 @@ |
217 | 217 | * declaration is already available, and records a todo otherwise. |
218 | 218 | */ |
219 | 219 | protected function requireDeclaration( SMWExpResource $resource, $decltype ) { |
220 | | - $namespaceid = $resource->getNamespaceID(); |
221 | 220 | // Do not declare predefined OWL language constructs: |
222 | | - if ( ( $namespaceid == 'owl' ) || ( $namespaceid == 'rdf' ) || ( $namespaceid == 'rdfs' ) ) return; |
| 221 | + if ( $resource instanceof SMWExpNsResource ) { |
| 222 | + $nsId = $resource->getNamespaceId(); |
| 223 | + if ( ( $nsId == 'owl' ) || ( $nsId == 'rdf' ) || ( $nsId == 'rdfs' ) ) { |
| 224 | + return; |
| 225 | + } |
| 226 | + } |
223 | 227 | // Do not declare blank nodes: |
224 | 228 | if ( $resource->isBlankNode() ) return; |
225 | 229 | |
226 | | - $name = $resource->getName(); |
| 230 | + $name = $resource->getUri(); |
227 | 231 | if ( array_key_exists( $name, $this->decl_done ) && ( $this->decl_done[$name] & $decltype ) ) { |
228 | 232 | return; |
229 | 233 | } |
— | — | @@ -237,12 +241,11 @@ |
238 | 242 | * Update the declaration "todo" and "done" lists for the case that the |
239 | 243 | * given data has been serialized with the type information it provides. |
240 | 244 | * |
241 | | - * @param $data specifying the type data upon which declarations are based |
| 245 | + * @param $expData specifying the type data upon which declarations are based |
242 | 246 | */ |
243 | | - protected function recordDeclarationTypes( SMWExpData $data ) { |
244 | | - foreach ( $data->getSpecialValues( 'rdf', 'type') as $typedata ) { |
245 | | - $typeresource = $typedata->getSubject(); |
246 | | - if ( $typeresource instanceof SMWExpResource ) { |
| 247 | + protected function recordDeclarationTypes( SMWExpData $expData ) { |
| 248 | + foreach ( $expData->getSpecialValues( 'rdf', 'type') as $typeresource ) { |
| 249 | + if ( $typeresource instanceof SMWExpNsResource ) { |
247 | 250 | switch ( $typeresource->getQName() ) { |
248 | 251 | case 'owl:Class': $typeflag = SMW_SERIALIZER_DECL_CLASS; break; |
249 | 252 | case 'owl:ObjectProperty': $typeflag = SMW_SERIALIZER_DECL_OPROP; break; |
— | — | @@ -250,7 +253,7 @@ |
251 | 254 | default: $typeflag = 0; |
252 | 255 | } |
253 | 256 | if ( $typeflag != 0 ) { |
254 | | - $this->declarationDone( $data->getSubject(), $typeflag ); |
| 257 | + $this->declarationDone( $expData->getSubject(), $typeflag ); |
255 | 258 | } |
256 | 259 | } |
257 | 260 | } |
— | — | @@ -264,7 +267,7 @@ |
265 | 268 | * @param $typeflag integer specifying the type (e.g. SMW_SERIALIZER_DECL_CLASS) |
266 | 269 | */ |
267 | 270 | protected function declarationDone( SMWExpResource $element, $typeflag ) { |
268 | | - $name = $element->getName(); |
| 271 | + $name = $element->getUri(); |
269 | 272 | $curdone = array_key_exists( $name, $this->decl_done ) ? $this->decl_done[$name] : 0; |
270 | 273 | $this->decl_done[$name] = $curdone | $typeflag; |
271 | 274 | if ( array_key_exists( $name, $this->decl_todo ) ) { |
— | — | @@ -288,9 +291,9 @@ |
289 | 292 | * used as such, hence it is enough to check the property. Moreover, we do |
290 | 293 | * not use OWL Datatypes in SMW, so rdf:type, rdfs:domain, etc. always |
291 | 294 | * refer to classes. |
292 | | - * @param SMWExpResource $property |
| 295 | + * @param SMWExpNsResource $property |
293 | 296 | */ |
294 | | - protected function isOWLClassTypeProperty( SMWExpResource $property ) { |
| 297 | + protected function isOWLClassTypeProperty( SMWExpNsResource $property ) { |
295 | 298 | $locname = $property->getLocalName(); |
296 | 299 | if ( $property->getNamespaceID() == 'rdf' ) { |
297 | 300 | return ( $locname == 'type' ); |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php |
— | — | @@ -152,8 +152,8 @@ |
153 | 153 | if ( !$this->isValid() ) return null; |
154 | 154 | |
155 | 155 | $result = new SMWExpData( new SMWExpResource( '', $this ) ); // bnode |
156 | | - $ed = new SMWExpData( SMWExporter::getSpecialElement( 'swivt', 'Container' ) ); |
157 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), $ed ); |
| 156 | + $ed = new SMWExpData( SMWExporter::getSpecialNsResource( 'swivt', 'Container' ) ); |
| 157 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
158 | 158 | $count = 0; |
159 | 159 | foreach ( $this->getDVs() as $value ) { |
160 | 160 | $count++; |
— | — | @@ -162,11 +162,11 @@ |
163 | 163 | } |
164 | 164 | if ( ( $value->getTypeID() == '_wpg' ) || ( $value->getTypeID() == '_uri' ) || ( $value->getTypeID() == '_ema' ) ) { |
165 | 165 | $result->addPropertyObjectValue( |
166 | | - SMWExporter::getSpecialElement( 'swivt', 'object' . $count ), |
| 166 | + SMWExporter::getSpecialNsResource( 'swivt', 'object' . $count ), |
167 | 167 | $value->getExportData() ); |
168 | 168 | } else { |
169 | 169 | $result->addPropertyObjectValue( |
170 | | - SMWExporter::getSpecialElement( 'swivt', 'value' . $count ), |
| 170 | + SMWExporter::getSpecialNsResource( 'swivt', 'value' . $count ), |
171 | 171 | $value->getExportData() ); |
172 | 172 | } |
173 | 173 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php |
— | — | @@ -102,13 +102,13 @@ |
103 | 103 | $exact = true; |
104 | 104 | $owldesc = $this->descriptionToExpData( $desc, $exact ); |
105 | 105 | if ( $owldesc === false ) { |
106 | | - $element = new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Thing' ) ); |
| 106 | + $element = new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) ); |
107 | 107 | } |
108 | 108 | if ( !$exact ) { |
109 | 109 | $result = new SMWExpData( new SMWExpResource( '' ) ); |
110 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), |
111 | | - new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Class' ) ) ); |
112 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdfs', 'subClassOf' ), $owldesc ); |
| 110 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), |
| 111 | + new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Class' ) ) ); |
| 112 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdfs', 'subClassOf' ), $owldesc ); |
113 | 113 | return $result; |
114 | 114 | } else { |
115 | 115 | return $owldesc; |
— | — | @@ -121,18 +121,18 @@ |
122 | 122 | public function descriptionToExpData( $desc, &$exact ) { |
123 | 123 | if ( ( $desc instanceof SMWConjunction ) || ( $desc instanceof SMWDisjunction ) ) { |
124 | 124 | $result = new SMWExpData( new SMWExpResource( '' ) ); |
125 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), |
126 | | - new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Class' ) ) ); |
| 125 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), |
| 126 | + new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Class' ) ) ); |
127 | 127 | $elements = array(); |
128 | 128 | foreach ( $desc->getDescriptions() as $subdesc ) { |
129 | 129 | $element = $this->descriptionToExpData( $subdesc, $exact ); |
130 | 130 | if ( $element === false ) { |
131 | | - $element = new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Thing' ) ); |
| 131 | + $element = new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) ); |
132 | 132 | } |
133 | 133 | $elements[] = $element; |
134 | 134 | } |
135 | 135 | $prop = ( $desc instanceof SMWConjunction ) ? 'intersectionOf':'unionOf'; |
136 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'owl', $prop ), |
| 136 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', $prop ), |
137 | 137 | SMWExpData::makeCollection( $elements ) ); |
138 | 138 | } elseif ( $desc instanceof SMWClassDescription ) { |
139 | 139 | if ( count( $desc->getCategories() ) == 1 ) { // single category |
— | — | @@ -143,35 +143,35 @@ |
144 | 144 | foreach ( $desc->getCategories() as $cat ) { |
145 | 145 | $elements[] = new SMWExpData( SMWExporter::getResourceElement( $cat ) ); ; |
146 | 146 | } |
147 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'owl', 'unionOf' ), |
| 147 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'unionOf' ), |
148 | 148 | SMWExpData::makeCollection( $elements ) ); |
149 | 149 | } |
150 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), |
151 | | - new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Class' ) ) ); |
| 150 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), |
| 151 | + new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Class' ) ) ); |
152 | 152 | } elseif ( $desc instanceof SMWConceptDescription ) { |
153 | 153 | $result = new SMWExpData( SMWExporter::getResourceElement( $desc->getConcept() ) ); |
154 | 154 | } elseif ( $desc instanceof SMWSomeProperty ) { |
155 | 155 | $result = new SMWExpData( new SMWExpResource( '' ) ); |
156 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdf', 'type' ), |
157 | | - new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Restriction' ) ) ); |
158 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'owl', 'onProperty' ), |
| 156 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), |
| 157 | + new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Restriction' ) ) ); |
| 158 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'onProperty' ), |
159 | 159 | new SMWExpData( SMWExporter::getResourceElement( $desc->getProperty() ) ) ); |
160 | 160 | $subdata = $this->descriptionToExpData( $desc->getDescription(), $exact ); |
161 | 161 | if ( ( $desc->getDescription() instanceof SMWValueDescription ) && |
162 | 162 | ( $desc->getDescription()->getComparator() == SMW_CMP_EQ ) ) { |
163 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'owl', 'hasValue' ), $subdata ); |
| 163 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'hasValue' ), $subdata ); |
164 | 164 | } else { |
165 | 165 | if ( $subdata === false ) { |
166 | 166 | $owltype = SMWExporter::getOWLPropertyType( $desc->getProperty()->getPropertyTypeID() ); |
167 | 167 | if ( $owltype == 'ObjectProperty' ) { |
168 | | - $subdata = new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Thing' ) ); |
| 168 | + $subdata = new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) ); |
169 | 169 | } elseif ( $owltype == 'DatatypeProperty' ) { |
170 | | - $subdata = new SMWExpData( SMWExporter::getSpecialElement( 'rdfs', 'Literal' ) ); |
| 170 | + $subdata = new SMWExpData( SMWExporter::getSpecialNsResource( 'rdfs', 'Literal' ) ); |
171 | 171 | } else { // no restrictions at all with annotation properties ... |
172 | | - return new SMWExpData( SMWExporter::getSpecialElement( 'owl', 'Thing' ) ); |
| 172 | + return new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) ); |
173 | 173 | } |
174 | 174 | } |
175 | | - $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'owl', 'someValuesFrom' ), $subdata ); |
| 175 | + $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'someValuesFrom' ), $subdata ); |
176 | 176 | } |
177 | 177 | } elseif ( $desc instanceof SMWValueDescription ) { |
178 | 178 | if ( $desc->getComparator() == SMW_CMP_EQ ) { |