The #subobject parser function apparently cannot be nested, which can be desirable.
Syntax suggestion:
{{#subobject:
|Has property 1=value
|Has property 2=values
|{{#subobject:
|Has property 1=value
|Has property 2=values
}}
}}
{{#subobject:
|Has property 1=value
|Has property 2=values
|{{#subobject:
|Has property 1=value
|Has property 2=values
}}
}}
This won't work as each entity (meaning a subobject) needs a context of the embedding instance but you run into the same problems as described in (#3654) about how parser functions work in MW. The second #subobject is unable to determine that its context object is the first #subobject and not the embedding subject (== wiki page).
There are other issues but (without having delved into it) I would guess above is a general show stopper for the proposed syntax .
I guess a good alternative would be a return identifier = yes parameter for #subobject, which would allow for:
{{#subobject:
|Has property 1=value
|Has property 2=values
|Has subthing={{#subobject:
|Has property 1=value
|Has property 2=values
|return identifier=yes
}}
}}
I guess a good alternative would be a return identifier = yes parameter for
It doesn't work like this, the second #subobject needs the reference of the first. In your example the first gets the reference of the second while semantics for the subtree are subject -> #subobject (first) -> #subobject (second), so the second has to "know" that it belongs to the first (which it cannot as outlined above).
Note that I wrote Has subthing not Has subobject. While these two subobjects would be siblings in the subtree, return identifier = yes would still facilitate the construction of a hierarchy between subobjects outside of the subtree.
Besides the technical aspect, what is the use case here? What sort of data would require such construct?
Articles that mention books with multiple editions.
The following is a quick hack (untested == contains caveats yet to be found, no guarantees) but it should provide an idea of what is required to make the semi tree structure available (for example the change fails for SG [0]).
For those who want (it ain't me) to implement this:
Whether this is a functionality we want to support or not (maintenance cost, hidden technical debt, errors that may arise due to hierarchy dependencies etc.) is a different discussion.
@@ -46,10 +46,12 @@ class SubobjectParserFunction {
* Fixed identifier that describes a property that can auto-linked the
* embeddedding subject
*/
const PARAM_LINKWITH = '@linkWith';
+ const PARAM_EMBEDDED = '@embedded';
+
/**
* @var ParserData
*/
protected $parserData;
@@ -81,10 +83,12 @@ class SubobjectParserFunction {
/**
* @var boolean
*/
private $isComparableContent = false;
+ private $embedded = false;
+
/**
* @since 1.9
*
* @param ParserData $parserData
* @param Subobject $subobject
@@ -167,11 +171,11 @@ class SubobjectParserFunction {
// An empty output in MW forces an extra <br> element.
//if ( $html == '' ) {
// $html = '<p></p>';
//}
- return $html;
+ return $html . $this->embedded;
}
protected function addDataValuesToSubobject( ParserParameterProcessor $parserParameterProcessor ) {
// Named subobjects containing a "." in the first five characters are
@@ -190,10 +194,11 @@ class SubobjectParserFunction {
$this->subobject->setEmptyContainerForId(
$id
);
+ $this->embedded = $this->embedded ? $id : '';
$subject = $this->subobject->getSubject();
foreach ( $parameters as $property => $values ) {
if ( $property === self::PARAM_SORTKEY ) {
@@ -202,10 +207,19 @@ class SubobjectParserFunction {
if ( $property === self::PARAM_CATEGORY ) {
$property = DIProperty::TYPE_CATEGORY;
}
+ if ( $property === 'Has subobject' ) {
+ $subSemanticData = $this->parserData->getSemanticData()->findSubSemanticData( end( $values ) );
+ $this->subobject->getSemanticData()->addPropertyObjectValue(
+ new DIProperty( '_SOBJ' ),
+ new \SMWDIContainer( $subSemanticData )
+ );
+ continue;
+ }
+
foreach ( $values as $value ) {
$dataValue = DataValueFactory::getInstance()->newDataValueByText(
$property,
$value,
@@ -251,10 +265,15 @@ class SubobjectParserFunction {
return [ $parameters, $id ];
}
private function preprocess( ParserParameterProcessor $parserParameterProcessor, $useFirst ) {
+ if ( $parserParameterProcessor->hasParameter( self::PARAM_EMBEDDED ) ) {
+ $this->embedded = true;
+ $parserParameterProcessor->removeParameterByKey( self::PARAM_EMBEDDED );
+ }
{{#subobject:
|Has text=test
|Has subobject={{#subobject:
|Has page=123
|@embedded=true
|Has subobject={{#subobject:
|Has page=123,1234|+sep=,
|@embedded=true
}}
}}
}}
{{#ask: [[Has text::test]]
|?Has text
|?Has subobject
|?Has subobject.Has page
|?Has subobject.Has subobject.Has page
}}
{{#ask: [[Has page::123]]
|?Has page
|?Has subobject
|?-Has subobject.Has text
|?-Has subobject.Has subobject.Has text
}}

[0] as it returns "[39e98b4cffe23e9ab6c97a72] /mw-master-pg2/index.php?title=Subsubobject&action=submit TypeError from line 81 of ...\extensions\SemanticGlossary\src\Cache\CacheInvalidator.php: Argument 2 passed to SG\Cache\CacheInvalidator::invalidateCacheOnStoreUpdate() must be an instance of SMW\SemanticData, null given, called in ...\extensions\SemanticGlossary\src\Cache\CacheInvalidator.php on line 135")
We need a developer for implementation. Thus I added this enhancement to the "Enhancements and features" project as "open". Closing here.
Most helpful comment
The following is a quick hack (untested == contains caveats yet to be found, no guarantees) but it should provide an idea of what is required to make the semi tree structure available (for example the change fails for SG [0]).
For those who want (it ain't me) to implement this:
Whether this is a functionality we want to support or not (maintenance cost, hidden technical debt, errors that may arise due to hierarchy dependencies etc.) is a different discussion.
Changes
Usage
Notes
[0]
as it returns "[39e98b4cffe23e9ab6c97a72] /mw-master-pg2/index.php?title=Subsubobject&action=submit TypeError from line 81 of ...\extensions\SemanticGlossary\src\Cache\CacheInvalidator.php: Argument 2 passed to SG\Cache\CacheInvalidator::invalidateCacheOnStoreUpdate() must be an instance of SMW\SemanticData, null given, called in ...\extensions\SemanticGlossary\src\Cache\CacheInvalidator.php on line 135")