bwanders / dokuwiki-strata

Strata - a Semi-Structured Data plugin for Dokuwiki
https://www.dokuwiki.org/plugin:strata
17 stars 8 forks source link

Missing field values on query output #21

Closed ghost closed 8 years ago

ghost commented 8 years ago

Missing values in query results.

strata plugin version : 2016-02-03 PHP version on server : 5.3.3 (Redhat 6)

Entry 1 (expurged)

<data ct>
libellé:blabla
id:CT-097
R*:
A:DO
C*:
I*:
</data>

Entry 2 (on another wiki page)

<data ct>
libellé:blabla
id:CT-058
R*:
A:DE
C*:
I*:
</data>

Entry 3 (on another wiki page)

<data ct>
libellé:blabla
id:CT-001
R*:
A:
C*:
I*:
</data>

query

<table ?c "Chantier" ?l "Libellé" ?r "Responsable">
?c is a: ct
?c libellé:?l

optional {
  ?c A:?r
}

sort {
  ?c (desc)
}
</table>

Output shows the "A" field of first record (DO) but an empty value for the second one (which should read DE)

Doing a sql query on the sqlite database shows that both records contain values for the "A" field (as well as the corresponding wiki pages)

The wiki page which contains the query codes embed the NOCACHE directive.

Deleting the wiki page for the second record, and recreating it afterwards with the same record descriptions does not solve the problem

Regards,

MB

PS : records entries have been sanitized for the issue report.

ghost commented 8 years ago

Hum....

If i remove the optional block like this :

<table ?c "Chantier" ?l "Libellé" ?r "Responsable">
?c is a: ct
?c libellé:?l
?c A:?r

sort {
  ?c (desc)
}
</table>

All records values are displayed, none is missing.

Maybe I've not understood how optional is supposed to work.

bwanders commented 8 years ago

I'm reopening this because I want to investigate the specific situation. If this is correct behaviour, it should be documented why this is happening, if it is not, this is a bug. Will triage in the coming weeks.

ghost commented 8 years ago

I think I found out when it happens .

Let's says you have two optional fields and you use one optional block in the query :

<table ?c "Chantier" ?l "Libellé" ?r "Responsable" ?s "Statut">
?c is a: ct
?c libellé:?l

optional {
  ?c A:?r
   ?c status:?s
}

sort {
  ?c (desc)
}
</table>

Then some records are not correctly displayed , that is, existing values are missing as explained above.

Writing the query with separate optional blocks get the expected results, all existing values are showing up :

<table ?c "Chantier" ?l "Libellé" ?r "Responsable" ?s "Statut">
?c is a: ct
?c libellé:?l

optional {
  ?c A:?r
}
optional {
   ?c status:?s
}

sort {
  ?c (desc)
}
</table>
bwanders commented 8 years ago

What you describe about multiple fields in an optional block is correct behaviour. The idea is that

optional {
   ?c A: ?r
   ?c status: ?s
}

Does not mean "two optional fields" but actually means "Optionally match everything in this block". So, the variables in the optional field are only filled if the whole pattern inside the optional block matches. In this case that means that any given ?c must have values for both the A and a status field. If the pattern does not match, no variables inside the optional field will be bound. So both ?r and ?s will be empty in this case.

The earlier problem is something else. And I do not yet understand why that is not working.

ghost commented 8 years ago

As a matter of fact, I have "sanitzed" too much my first code examples.

The real code samples illustrating the behaviour I described are the later ones with two fields in one optional block.

By the way, do you the Phd Thesis "A framework for creating semantic wikis for biomedical research laboratories" by Daniel Davison (Univeristy of Twente) ? the thesis describes a dokuwiki plugin that provides a UI for end users and enables them entering data in a strata dabase.

It would be nice if the plugin could be published on dokuwiki.org ( I emailed Mr Davison about that matter)

bwanders commented 8 years ago

Yes, I know that master's thesis (I supervised it). I agree that the plugin described there would be nice.

If you are in a hurry, a similar effect can be created using the bureaucracy plugin to build forms and the pagemod plugin to create new pages. Good luck!