Semanticmediawiki: Parser function #set_error for custom error messages

Created on 2 Apr 2019  路  8Comments  路  Source: SemanticMediaWiki/SemanticMediaWiki

Feature request for a parser function to set user-defined error messages

SMW already has a great set of features for defining properties, eg.

However, the properties used to define processing errors cannot be set manually, as described in 914

Use Case

Sometimes rules for properties cannot generally be defined, but have a certain meaning regarding their occurence. Imagine the following simple example. In our wiki, users will be able to input an area of an estate ("Property:has estate area" in m虏) and a size of a house ("Property:has building size" also in m虏). With features of SMW you can now generally define that both properties use m虏 as measurement, have a allowed values from 10 to 5000 (if you don't expect properties be greater than 5000m虏) and even define a "display precision" of 0, meaning that kommas entered will be rounded to full square meters.

But my rule is now that "Property:has building area" must be smaller or equal "Property:has estate area". (No building can be bigger than the estate it is built on.). This cannot be done when defining the properties, because the values on page X are different than on page Y.

Another simple use-case ist having a user annotate percentages for Property:A, Property:B and Property:C that must total to 100%.
Property:A can be set to hold values of 1...100, but sometimes it will be 100% A and 0%B or 50%A and 50%B...

Suggested solution

Introduction of a new parser function #set_error (or #input_error or something else) that takes in some strings (e.g. {{#set_error: ... error text ...|for=Foo }}) with that it builds an error record together with a type (such as user, #3792) and is later attached to the entity.

When you use page forms and tempaltes for your pages, you can easily compare values with the parser function extension and if the requirement is not met, could use the to be implmemented parser function #set_error to set user-defined values for "has processing error", "has improper value for" and "has processing error text" that currently cannot be set manually.

question

Most helpful comment

I believe that a possible way to deal with this in a way was shown here and
that solutions requiring programming effort will not happen in the sort and
medium range future. Thus closing.

The constraint schema (#3746) is most likely to be used in future for
custom ranges or boundaries by adding a Lua/Scribunto script that can
be used to hook into the constraint validation.

Aside the support for Lua, you can build your own custom_constraint
[0] to validate some user input.

PS: I somewhere have a prototype for this but it won't make the SMW 3.1 cut.

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/examples/register.custom.constraint.md

Cheers

On 8/21/19, Karsten Hoffmeyer notifications@github.com wrote:

I believe that a possible way to deal with this in a way was shown here and
that solutions requiring programming effort will not happen in the sort and
medium range future. Thus closing.

--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/3882#issuecomment-523462869

All 8 comments

Won't work because {{#if: condition | {{#set_error: ... }} }} will always evaluate the set_error regardless of the condition.

Won't work because {{#if: condition | {{#set_error: ... }} }} will always
evaluate the set_error regardless of the condition.

Correct.

So, what can you do?

You could define a custom error record much like Custom error record
with something like [[Has type::Record]] [[Has fields::Has processing error text;Has improper value for]] and use it in combination with
the in-text annotation syntax such as:

{{#if: condition | [[Custom error record::Failed with 123;Has text]] |
[[Custom error record::Failed with abc;Has text]] }}

Those errors would not appear in the Special:ProcessingErrorList, so
for that to happen you are required to change the initial query to
something like '[[Has processing error text::+]] || [[Has improper value for::+]]'

Cheers

On 4/3/19, Stephan Gambke notifications@github.com wrote:

Won't work because {{#if: condition | {{#set_error: ... }} }} will always
evaluate the set_error regardless of the condition.

--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/3882#issuecomment-479045119

or you simply could use
{{#set_error:{{#if: condition | error text | }} }}

or you simply could use
{{#set_error:{{#if: condition | error text | }} }}

Yes, with the only caveat that you can only set an error text and not
the property to which the error belongs.

On 4/3/19, Bernhard Krabina notifications@github.com wrote:

or you simply could use
{{#set_error:{{#if: condition | error text | }} }}

--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/3882#issuecomment-479061708

I am not sure how to deal with this from here. It appears to me that an ideal solution to this has not yet been determined.

I believe that a possible way to deal with this in a way was shown here and that solutions requiring programming effort will not happen in the sort and medium range future. Thus closing.

I believe that a possible way to deal with this in a way was shown here and
that solutions requiring programming effort will not happen in the sort and
medium range future. Thus closing.

The constraint schema (#3746) is most likely to be used in future for
custom ranges or boundaries by adding a Lua/Scribunto script that can
be used to hook into the constraint validation.

Aside the support for Lua, you can build your own custom_constraint
[0] to validate some user input.

PS: I somewhere have a prototype for this but it won't make the SMW 3.1 cut.

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/examples/register.custom.constraint.md

Cheers

On 8/21/19, Karsten Hoffmeyer notifications@github.com wrote:

I believe that a possible way to deal with this in a way was shown here and
that solutions requiring programming effort will not happen in the sort and
medium range future. Thus closing.

--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/3882#issuecomment-523462869

Thanks for the update on this.

Was this page helpful?
0 / 5 - 0 ratings