zoranbosnjak / asterix-specs

EUROCONTROL asterix specifications in structured format.
https://zoranbosnjak.github.io/asterix-specs/
BSD 3-Clause "New" or "Revised" License
23 stars 14 forks source link

JSON structure broken #29

Closed dedrone-fb closed 1 week ago

dedrone-fb commented 3 weeks ago

We are currently trying to write a Java datamodel based on the JSON you provide. We used to have that for the old JSON structure but now we fail because the ContextFree tag seems to be able to contain both Variations and Contents.

We also tried to use the python script to convert to the old format, but could not get it to produce the same JSON structure (verified with JSON structure compare, not text compare). We tinkered a bit but gave up.

This is just a random part of the JSON specs, showing that ContextFree also wraps Content elements - I think it should only wrap Variations and its subclasses

                                                                                },
                                                                                "tag": "ContentInteger"
                                                                            },
                                                                            "tag": "ContextFree"
                                                                        }
                                                                    },
                                                                    "tag": "Element"
                                                                },
                                                                "tag": "ContextFree"
zoranbosnjak commented 3 weeks ago

There are some unfortunate situations in asterix specs, where the structure of some subpart depends on the value of some other part. In such rare cases, there is a tag "Dependent" (in contrast to "ContextFree").

Additional problem is that this exceptional situation is possible with Variation and Content which are 2 different structural constructs. So your observation is correct. The latest specs structure is addressing both problems. Think of the Rule (ContextFree or Dependent) being generic to wrap any substructure.

The migration script only works one structural change back. It looks like you want to go way back with the conversion. This might be the reason for your problem. Now (depending on the category/item you work with), you may want to ignore the corner cases and eliminate this layer of complexity:

The process to eliminate this layer is simple: whenever you find rule:tag = ContextFree, you just take rule:content and when you find rule:tag = Dependent you take rule:content:default. The default will give you some simplified shape compatible structure which you can work with normally. For example... instead of complicated Dependent content, you will just get Raw content. Every Dependent structure has a default. In other words: it will at least parse the data, but you won't get the details from this generic structure.

With the latest commit bfcc7329027fc840fc6d513e42b96a9dabc7eab3, there is an updated example in the main project page which does exactly that: https://zoranbosnjak.github.io/asterix-specs/, scroll down to "Example: simplify specification with python script", see handle_rule function. You could filter each json through this script (adjusted to your needs) and work with the simplified version with less pain.

I hope it helps.

fbeister commented 1 week ago

Thanks for the explanation. We wrote an AST parser directly which seems to be working fine.

dedrone-fb commented 1 week ago

/