Hi Michael,

The data model of SMW never considered "insertion order" as a piece of information that should be recorded. In fact, a normal SQL RDBMs like MariaDB has no obligation to return tuples in a specific order unless there is an ordering clause in the query. Same for SPARQL. Relying on result orders to be the same "as in the table" is generally not robust.

To store and retrieve ordered lists in SMW, there are several options:

(1) Use sub-objects instead of plain values and store the index of each entry with the value. Then sort by this value when retrieving data. (2) Store the unordered values as you do now, and in addition store a string of the ordered values (comma-separated) in another property. You can use page variables to build such a string and #arraymap to decompose it (if you want to do more than just display this string).

I have worked with both solutions in practice. For things like lecture dates, we use (1) (though we use the date rather than the insertion order as an ordering criterion there). For things like author lists (where order matters), we use (2).

Best regards,

Markus


On 24/09/2020 12:37, Michael Erdmann wrote:
Dear Community,

is there a way to maintain the order of attribute values, e.g. in ASK queries. By "maintain" I mean to keep the order of the values as they had been added in the wiki page's annotations.

Currently I get this:

Test_Page contains:

    [[MyProperty::Page1]]
    [[MyProperty::Page2]]
    [[MyProperty::Page3]]

Another_Page contains this query:

    {{#ask: [[Test_Page]] | ?MyProperty | format = ul }}

and shows this result

    Test_Page (MyProperty: Page1, Page2, Page3)

Changing the order in Test_Page to:

    [[MyProperty::Page2]]
    [[MyProperty::Page3]]
    [[MyProperty::Page1]]

still results in exactly the same query result, i.e. Page1 at the beginnig of the list.

Is there a way to accomplish what I want in Wiki text?

If there is a way to accomplish this in PHP that is also fine for me. I investigated a bit already and found, that

    $data = StoreFactory::getStore()->getSemanticData( $myPage );
    $values = $data->getPropertyValues( $myProperty );

already returns the values in a constant order (page-IDs?). Is the DB maybe not prepared to maintain this information?

BTW. I am using MW1.31 and SMW3.0.2.

THX,
   michael


--

Dr. Michael Erdmann         |erdm...@diqa-pm.com    | +49 151 6140 1790
DIQA Projektmanagement GmbH | An der RaumFabrik 33c |   76227 Karlsruhe
Handelsregister: Amtsgericht Mannheim HRB 715454 USt-IdNr.: DE283037270
Geschäftsführer: Dr. Michael Erdmann, Dipl.-Wirtsch.-Inf. Daniel Hansch

This email may contain confidential information. If you are not the intended recipient please notify the sender immediately and delete this email. Any unauthorized copying, disclosure or distribution of this email is strictly forbidden.


_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel




_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

Reply via email to