zazuko / xrm

A friendly language for mappings to RDF
MIT License
1 stars 0 forks source link

Validate that templates are satisfied #57

Closed mchlrch closed 4 years ago

mchlrch commented 4 years ago

Add validation that checks if the correct amount of referenceables is declared.

subject template "http://city.example.com/{0}/{1}/{2}" with continent; should lead to validation WARNING

mchlrch commented 4 years ago

Maybe using https://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html#getFormats()

nnamtug commented 4 years ago

Using MessageFormat is not really straight forward, since there is no access to the internal data structure of a MessageFormat. Anyhow, using it is probably a good idea in order not to re-implement the logic of parsing the format (which probably would be wrong).

So i piggybacked MessageFormat.format and send faked arguments. Each argument is a sensor checking whether MessageFormat would read its content:

https://github.com/zazuko/rdf-mapping-dsl/blob/84a8561a66369a4b720ac9e188692e3a166d47cb/com.zazuko.rdfmapping.dsl.parent/com.zazuko.rdfmapping.dsl/src/com/zazuko/rdfmapping/dsl/validation/IriFormatAnalyzer.java#L39

Based on this sniffed data it is possible to do the proper validation. The sniffing part is hacky, but I think reusing MessageFormat is more important than not being hacky. Nonetheless, if we run into trouble with it, we still can change the implementation of IriFormatAnalyzer without braking the validation.

mchlrch commented 4 years ago

Tested and works well.

The template is not always an IRI, it can also just be whatever String. Right now the analyzer classes are named IriFormatAnalyz*. How about renaming them to TemplateFormatAnalyz*?