usnistgov / metaschema

Documentation for and implementations of the metaschema modeling language
https://pages.nist.gov/metaschema/
Other
35 stars 17 forks source link

Documenting Metapath Syntax #311

Open aj-stein-nist opened 1 year ago

aj-stein-nist commented 1 year ago

User Story:

As a Metaschema developer, to ensure I can implement a Metaschema-enabled library and/or tools that must completely implement Metapath for use in constraint targets and index targets, I want a specification document regarding the syntax of Metapath, supported axes for queries, and required functions.

Goals:

Dependencies:

None.

Acceptance Criteria

{The items above are general acceptance criteria for all User Stories. Please describe anything else that must be completed for this issue to be considered resolved.}

david-waltermire commented 7 months ago

Looking at the [XPath syntax](), Metapath is expected to support:

2 Basics

3 Expressions

david-waltermire commented 7 months ago

We need to figure out where to organize Metapath specification details in the Metaschema specification website. Any ideas?

wendellpiez commented 7 months ago

Having the outline is super useful.

Separately I am going to have to document a current limitation on the InspectorXSLT, namely that paths only work that conform additionally to these requirements: https://qt4cg.org/specifications/xslt-40/Overview.html#node-patterns

And this does relate to a semantic question, namely what does it mean for a constraint @target expression returns not nodes to which a constraint can apply, but something else?

For example, do these work or are they errors (if so what), no-ops or something else?

<has-cardinality target="/*/name()" max-occurs="2"/>

<expect target="42" test=". gt 40"/>

<index name="numbers" target="1 to 100">
  <key-field select="@value"/>
</index>

Of these, I'd call the first an innocuous mistake (why count the names instead of the things), the second meaningless (42 is always greater than 40) and the third an error (because numeric values don't have 'value' flags to index them by).

These problems and more could be avoided by restricting Metapath in @target to paths returning sequences of nodes.

Bringing it all the way to current functionality in the InspectorXSLT - which handles @target by producing templates to match the implicated nodes - would require an even stricter limit, namely to the XSLT pattern syntax linked above.

This would offer other significant advantages as well. For example, the XPath axes following-sibling:: and preceding-sibling:: are somewhat curious in a language for addressing JSON - and pattern syntax includes only XPath axes that look down to branches the tree, not up or over.

expect/@test does not pose at all the same problems in implementation as @target does - mainly since more or less anything can be reduced into a Boolean value for @test, but @target has to have nodes to serve as context for evaluation.

aj-stein-nist commented 7 months ago

We need to figure out where to organize Metapath specification details in the Metaschema specification website. Any ideas?

I am fine with putting Metapath under the syntax section, as it came up during discussion. It could be both considered as something separate of Metaschema syntax or something separate embedded within certain Metaschema elements, but I am not picky and will wait from more feedback from this group and the larger community.

Are we going to spell out every section of the XPath 3.0 specification and copy it more or less, have a page on the site specifically call out this outline and define the scope with links to relevant page (so cross out items are a not-supported list and not crossouts), and third more complex section is custom written sections where the content is different?

aj-stein-nist commented 7 months ago

These problems and more could be avoided by restricting Metapath in @target to paths returning sequences of nodes.

How do we know what a path is when we have a evaluation focus context? Is target="." referring to a path unconditionally or does it depend on the content? If it is a constraint for a flag or field that could be but how do we know that in a way a Metaschema processor could know?

wendellpiez commented 7 months ago

These are excellent questions and I can walk you through how it works in my implementation, with the (XML/XPath-based) assumptions that implies. (I.e. 'how it could/would work in XPath' not 'how it should work (definitively) in Metaschema'. This is because it hinges crucially on the notion of relative paths evaluated in context.

The question is a little different for the different constraints, as well - what happens with matches or expect is a bit different from has-cardinality, etc. (Whether @target names something that is counted, or serves as a context for further evaluation.)

But to jump past a longer explanation, keep in mind that where a constraint (rule) is defined in a metaschema does provide context in the form of this rule's location within a definition (local or global). Outside such placement (i.e., written as a 'standoff rule') the @target will implicitly be reaching always from the root. (While nothing I say means anything without demo samples, shared across implementations.)