Description
Given the current specification, I don't see a way to deal with self-contained matching rules -- i.e. matching rules for an object which contains itself as an attribute --, where the depth of the recursion is unknown.
For instance,
[
{
"id": "1",
"elements": [
{
"id": "1.1"
}
]
},
{
"id": "2",
"elements": [
{
"id": "2.1",
"elements": [
{
"id": "2.1.1"
},
{
"id": "2.1.2"
},
]
}
]
}
]
A pseudo-definition for such data structure,
element: { id: string, elements: []element }
This could be solved by enabling nth-level path expressions, so one could specify the matching rules for any "elements" attribute (1). Another solution could be implementing named matching rules and being able to reference them, so that the first-level "elements" would just reference back to a general named matching rule (2).
(1)
"matchingRules": {
"$.body": {
"match": "type",
"min": "1"
},
"$.body[*].id": {
"match": "type"
},
"*.elements": { // matches any "elements" attribute in the tree
"match": "type",
"min": "1"
},
"*.elements[*].id": {
"match": "type"
}
}
(2)
"matchingRules": {
"rules": {
"elements": {
"$": {
"match": "type",
"min": "1"
},
"$[*].id": {
"match": "type"
},
"$[*].elements": {
"match": "rules.elements" // reference to named rule
}
}
},
"$.body": "rules.elements" // reference to named rule
}
The problem with (2) is it generates an infinite number of possible rules, so I'm not sure of it's compatibility with your rule-weighting algorithm.
I am not sure if this could be pactified via regexp capturing groups, but in any case, I don't think that's a sustainable option.