Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/90052
Change subject: Simplify SemanticData subobject serializer/deserializer
......................................................................
Simplify SemanticData subobject serializer/deserializer
Change-Id: Ia007ed92ef938d277179c56f7f903995c3561795
---
M includes/serializer/Deserializers/SemanticDataDeserializer.php
M includes/serializer/README.md
M includes/serializer/Serializers/SemanticDataSerializer.php
3 files changed, 105 insertions(+), 93 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/52/90052/1
diff --git a/includes/serializer/Deserializers/SemanticDataDeserializer.php
b/includes/serializer/Deserializers/SemanticDataDeserializer.php
index 6a58d27..0cec0f4 100644
--- a/includes/serializer/Deserializers/SemanticDataDeserializer.php
+++ b/includes/serializer/Deserializers/SemanticDataDeserializer.php
@@ -143,7 +143,7 @@
}
// Check whether the current dataItem has a subobject reference
- if ( isset( $value['sobj'] ) && $value['sobj'] !== null ) {
+ if ( $dataItem->getDIType() === DataItem::TYPE_WIKIPAGE &&
$dataItem->getSubobjectName() !== '' ) {
$dataItem = $this->unserializeSubobject(
$data,
diff --git a/includes/serializer/README.md b/includes/serializer/README.md
index da36536..e82b156 100644
--- a/includes/serializer/README.md
+++ b/includes/serializer/README.md
@@ -11,7 +11,7 @@
```php
$foo = new Foo( ... );
$serialized = SerializerFactory::serialize( $foo );
-$unserialized = SerializerFactory::unserialize( $serialized );
+$unserialized = SerializerFactory::deserialize( $serialized );
```
### SemanticDataSerializer
@@ -19,93 +19,112 @@
#### Data model
```php
-[subject] -> Subject serialization
-[data] -> array container
- [property] -> Property serialization
- [dataitem] -> DataItem serialization
- ...
-[sobj] -> array container
- [subject] -> Subobject subject serialization
- [data] -> array container
- [property] -> Property serialization
- [dataitem] -> DataItem serialization
- ...
-[serializer] -> Class of the generator and entry point for the un-serializer
-[version] -> Number to compare structural integrity between serialization and
un-serialization
+"subject": -> Subject serialization,
+"data": [
+ {
+ "property": -> Property serialization,
+ "dataitem": [
+ {
+ "type": -> DataItemType,
+ "item": -> DataItem serialization
+ }
+ ]
+ }
+]
+"sobj": [
+ {
+ "subject": ...,
+ "data": [
+ {
+ "property": ...,
+ "dataitem": [
+ {
+ "type": ...,
+ "item": ...
+ }
+ ]
+ },
+ },
+],
+"serializer": -> Class of the generator and entry point for the un-serializer,
+"version": -> Number to compare structural integrity between serialization and
un-serialization
```
#### Example
-For a page called "Foo" that contains <code>[[Has property::Bar]]</code>,
<code>{{#subobject:|Has subobjects=Bam}}</code>, <code>{{#ask:Has
subobjects::Bam}}</code>, the Serializer will output:
+For a page called "Foo" that contains <code>[[Has property::Bar]]</code>,
<code>{{#subobject:|Has subobjects=Bam}}</code>, <code>{{#ask:[[Has
subobjects::Bam]]}}</code>, the Serializer will output:
```php
-[subject] => Foo#0#
-[data] => Array (
- [0] => Array (
- [property] => Has_property
- [dataitem] => Array (
- [0] => Array (
- [type] => 9
- [item] => Bar#0#
- )
- )
- )
- [1] => Array (
- [property] => _ASK
- [dataitem] => Array (
- [0] => Array (
- [type] => 9
- [item] =>
Foo#0##_QUERYc8606da8f325fc05aa8e8b958821c3b4
- [sobj] => _QUERYc8606da8f325fc05aa8e8b958821c3b4
- )
- )
- )
- [2] => Array (
- [property] => _MDAT
- [dataitem] => Array (
- [0] => Array (
- [type] => 6
- [item] => 1/2013/10/10/14/55/40
- )
- )
- )
- [3] => Array (
- [property] => _SKEY
- [dataitem] => Array (
- [0] => Array (
- [type] => 2
- [item] => Foo
- )
- )
- )
- [4] => Array (
- [property] => _SOBJ
- [dataitem] => Array (
- [0] => Array (
- [type] => 9
- [item] =>
Foo#0##_fc4b104aabf80eb06429e946aa8f7070
- [sobj] => _fc4b104aabf80eb06429e946aa8f7070
- )
- )
- )
-)
-[sobj] => Array (
- [0] => Array (
- [subject] => Foo#0##_fc4b104aabf80eb06429e946aa8f7070
- [data] => Array (
- [0] => Array (
- [property] => Has_subobjects
- [dataitem] => Array (
- [0] => Array (
- [type] => 9
- [item] => Bam#0#
- )
- )
- )
- )
- )
+"subject": "Foo#0#",
+"data": [
+ {
+ "property": "Has_property",
+ "dataitem": [
+ {
+ "type": 9,
+ "item": "Bar#0#"
+ }
+ ]
+ },
+ {
+ "property": "_ASK",
+ "dataitem": [
+ {
+ "type": 9,
+ "item":
"Foo#0##_QUERYc8606da8f325fc05aa8e8b958821c3b4"
+ }
+ ]
+ },
...
-)
-[serializer] => SMW\Serializers\SemanticDataSerializer
-[version] => 0.1
+ {
+ "property": "_SOBJ",
+ "dataitem": [
+ {
+ "type": 9,
+ "item":
"Foo#0##_fc4b104aabf80eb06429e946aa8f7070"
+ }
+ ]
+ }
+],
+"sobj": [
+ {
+ "subject": "Foo#0##_QUERYc8606da8f325fc05aa8e8b958821c3b4",
+ "data": [
+ {
+ "property": "_ASKDE",
+ "dataitem": [
+ {
+ "type": 1,
+ "item": "1"
+ }
+ ]
+ },
+ },
+ ...
+ {
+ "subject": "Foo#0##_fc4b104aabf80eb06429e946aa8f7070",
+ "data": [
+ {
+ "property": "Has_subobjects",
+ "dataitem": [
+ {
+ "type": 9,
+ "item": "Bam#0#"
+ }
+ ]
+ },
+ {
+ "property": "_SKEY",
+ "dataitem": [
+ {
+ "type": 2,
+ "item": "Foo"
+ }
+ ]
+ }
+ ]
+ }
+],
+"serializer": "SMW\\Serializers\\SemanticDataSerializer",
+"version": 0.1
```
### QueryResultSerializer
diff --git a/includes/serializer/Serializers/SemanticDataSerializer.php
b/includes/serializer/Serializers/SemanticDataSerializer.php
index 75ef2bf..23bb21a 100644
--- a/includes/serializer/Serializers/SemanticDataSerializer.php
+++ b/includes/serializer/Serializers/SemanticDataSerializer.php
@@ -52,7 +52,7 @@
/**
* Build property and dataItem serialization record
*/
- foreach ( $semanticData->getProperties() as $key => $property )
{
+ foreach ( $semanticData->getProperties() as $property ) {
$prop = array();
@@ -95,22 +95,15 @@
* in the system (type changes that can occur during the time between
* serialization and unserialization)
*
- * @note 'sobj' is only added for when a subobject is present
- *
* @return array
*/
protected function serializeDataItem( DataItem $dataItem ) {
- $di = array(
+ return array(
'type' => $dataItem->getDIType(),
'item' => $dataItem->getSerialization()
);
- if ( $dataItem->getDIType() === DataItem::TYPE_WIKIPAGE &&
$dataItem->getSubobjectName() ) {
- $di += array( 'sobj' => $dataItem->getSubobjectName() );
- }
-
- return $di;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/90052
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia007ed92ef938d277179c56f7f903995c3561795
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits