NASA-PDS / pds4-information-model

The software tools and data necessary for generating the Information Model including PDS4 ontology, data, and information model.
https://nasa-pds.github.io/pds4-information-model/
Other
9 stars 6 forks source link

LDDTool: Use sch:value-of to display a variable in Schematron validation #167

Closed jshughes closed 3 years ago

jshughes commented 4 years ago

On Jan 18, 2019, at 7:59 AM, Mark Bentley (HE SPACE OPERATIONS BV)

jordanpadams commented 4 years ago

@msbentley it is in the plan for Build 11.0 (October 2020). We can also try to get a point build out if you need it for a previous version of the IM

msbentley commented 4 years ago

Thanks @jordanpadams and @jshughes! Indeed whether we can use it immediately depends on if the next version(s) of LDDTool will support dictionaries built against other IMs. If not, we may have to wait until next year when some of the PSA missions probably update their IM versions (currently we're all on 1B00).

jordanpadams commented 4 years ago

@msbentley we are also going to work that into this next delivery as well, so hopefully we will be able to work that out.

msbentley commented 4 years ago

Fantastic! I'm stuck on 0.2.1.5b plus a workaround script, so it will be great to upgrade and "cleanly" generate dictionaries!

jordanpadams commented 3 years ago

@jshughes can you provide a status on this?

jshughes commented 3 years ago

Next in queue to be addressed.

jordanpadams commented 3 years ago

June schedule status: delayed due to other bug fix taking precedent. still on schedule for delivery by end of build cycle.

jordanpadams commented 3 years ago

July schedule status: delayed due to other IM and DDWG work pulling staff away from task. Slack built into schedule should allow for this to be completed in this build.

jordanpadams commented 3 years ago

August schedule status: delayed due to other IM and DDWG work pulling staff away from task. Slack built into schedule should allow for this to be completed in this build.

jshughes commented 3 years ago

After further review of the request, it seems that the request can be accommodated under the current implementation. A test case and the results follow.

SCH_ValueOf_Display msn:mission_phase_name name="num_colons" value="string-length(.) - string-length(translate(., ':', ''))" name="required_colons" value="4" Assert $num_colons eq $required_colons In Product_Collection, the number of colons found: (<sch:value-of select="$num_colons"/>) is inconsistent with the number expected: (<sch:value-of select="$required_colons"/>). In Product_Collection, the number of colons found: () is inconsistent with the number expected: ().
jshughes commented 3 years ago

This resolution of this issue will now be further tested under SI&T

msbentley commented 3 years ago

Well, that's even easier - thanks @jshughes I'll give it a test also on my current version of lddtool!

msbentley commented 3 years ago

Hi @jshughes I tested this and it indeed works, but my Ingest file no longer validates:

The prefix "sch" for element "sch:value-of" is not bound.

I guess I would have to define the sch prefix in my Ingest file?

jordanpadams commented 3 years ago

@jshughes the nested XML is kind of a cludge here. should we use XML entity escaping here instead?

e.g.

<sch:rule context="msn:mission_phase_name">
<sch:let name="num_colons" value="string-length(.) - string-length(translate(., ':', ''))"/>
<sch:let name="required_colons" value="4"/>
<sch:assert test="$num_colons eq $required_colons">
In Product_Collection, the number of colons found: (<sch:value-of select="$num_colons"/>) is inconsistent with the number expected: (&lt;sch:value-of select="$required_colons"/&gt;).</sch:assert>
</sch:rule>
</sch:pattern>

Note: &lt;sch:value-of select="$required_colons"/&gt; instead of <sch:value-of select="$required_colons"/>

jordanpadams commented 3 years ago

LDDTool can then just recognize that and "convert" in the output to schematron

jshughes commented 3 years ago

Sorry, I should have cleared that up. When entering the rule into DD_Rule, the escape sequence "\<" must be used for "<" and likewise "\>" for ">". Otherwise, the Ingest_LDD XML document will not validate correctly. LDDTool then converts as necessary.

msbentley commented 3 years ago

Ahh, that did the trick - fantastic, many thanks - time to go and add more descriptive messages to my dictionaries using this trick!

jordanpadams commented 3 years ago

@jshughes before we close this out, can we briefly document this somewhere either in the LDDTool docs or on the SBN wiki just so we don't forget about it when we put some more effort into refining the documentation for LDDTool.

jordanpadams commented 3 years ago

@jshughes @msbentley this has been documented here: https://pds-data-dictionaries.github.io/development/ldd-how-to.html#using-schematron-value-of-functionality

gxtchen commented 3 years ago

@msbentley @jshughes Can you provide a test file for me to finish verifying the latest release build? Thx,

msbentley commented 3 years ago

I can send an LDD ingest file if you need it, but an example snippet from my current development PSA dictionary is:


    <DD_Rule>    
        <local_identifier>logical_identifier_filename</local_identifier>
        <rule_context>pds:Product_Observational/pds:Identification_Area</rule_context>
        <rule_assign>name="file-name" value="replace(tokenize(document-uri(/), '/')[last()],'\.[^.]+$','')"</rule_assign>
        <rule_assign>name="lid" value="tokenize(pds:logical_identifier, ':')[last()]"</rule_assign>

        <DD_Rule_Statement>
            <rule_type>Assert</rule_type>
            <rule_test>
                lower-case($file-name) = $lid
            </rule_test>
            <rule_message>
                Label filename (&lt;sch:value-of select="$file-name"/&gt;) and last component of the LID (product ID) (&lt;sch:value-of select="$lid"/&gt;) must match for observational products
            </rule_message>
            <rule_description>Filename (minus extension) and the product ID (last part of the LID) must match for observational products (case can be different)</rule_description>
        </DD_Rule_Statement>
    </DD_Rule>