Topic on Extension talk:Semantic MediaWiki

Records and Result format table

8
Summary by Dominik Maus

Use anonymous subobjects.

Dominik Maus (talkcontribs)

Greetings everyone,

I set multiple records of the same type on a single page, and try to #show them as format=table. The table is created just fine, but the #show does not create separate table rows. For each of the records, it appends as a newline in the first table row.


I did the following:

{{#set:NeedsResource=Travertine Slab;5}}
{{#set:NeedsResource=Marble Slab;1}}
{{#show: {{FULLPAGENAME}}
|?NeedsResource.Resource = Name
|?NeedsResource.NeedMin = Name
|format = table}}

I want the query to put each of the sets into a separate table row but can't seem to find a way to do so.

Any hints are very welcome!

Thanks

Dominik Maus (talkcontribs)

Installation details:

MW 1.35.0

SMW 3.2.1

SRF 3.2.0

Cavila (talkcontribs)

I keep getting Caught exception of type Flow\Exception\NoParserException when attempting to reply. Here's another try.

To store objects with their own property/value pairs, you should be using #subobject, not #set. See https://www.semantic-mediawiki.org/wiki/Help:Adding_subobjects. Or alternatively, place each set on its own page, if that works for you.

Dominik Maus (talkcontribs)

I've tried the subobject approach, but it enlists everything in one single table row aswell. Own page is a no-go. I want to set multiple properties of the same name for the same page, which works, just not the query results.

Cavila (talkcontribs)

When I add subobjects and query them, e.g.

{{#ask: [[-Has subobject::{{FULLPAGENAME}}]] |?NeedsResource }}

I do get two distinct rows.

Just for clarity, I'm asuming there's a semicolon because you've defined the property as being one of data type "Record", right?

Dominik Maus (talkcontribs)

Yes that is correct, I wanted it to be a record with a few subproperties.

If I do this one:

{{#subobject: test
|level=1
|test=b
}}
{{#subobject: test
|level=2
|test=a
}}

{{#ask: [[-Has subobject::{{FULLPAGENAME}}]] |?test}}

there is only a single row:

Cavila (talkcontribs)

I see, the problem is that you've given them identical names (test), which translates to a single subobject rather than two. You can either give them distinct names (e.g. test1 and test2) or leave that part blank, in which case SMW defaults to anonymous, hash-based identifiers.

Dominik Maus (talkcontribs)

Oh nice, the anonymous did the trick! Thanks!