Skip to content

Commit fdd5411

Browse files
committed
Update frame matching and add tests for requireAll to match both properties, @id, and @type.
Fixes #40.
1 parent 181b7e2 commit fdd5411

11 files changed

+159
-25
lines changed

index.html

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,6 @@ <h2>Syntax Tokens and Keywords</h2>
14591459
<dt><code>@omitDefault</code></dt>
14601460
<dd>Used in <a href="#framing">Framing</a> to override the
14611461
value of <a>omit default flag</a> within a specific frame.
1462-
<div class="issue" data-number="41">Is this flag really useful? Easier to simply not have a default value,
1463-
if it shouldn't match.</div>
14641462
</dd>
14651463
<dt class="changed"><code>@requireAll</code></dt>
14661464
<dd class="changed">Used in <a href="#framing">Framing</a> to override the
@@ -1734,9 +1732,10 @@ <h2>Frame Matching Algorithm</h2>
17341732
<p>The Frame Matching Algorithm is used as part of the <a href="#framing-algorithm">Framing algorithm</a>
17351733
to determine if a particular <a>node object</a> matches the criteria set in a <a>frame</a>.
17361734
In general, a node object matches a frame if it meets the matches on <code>@type</code>,
1737-
or <code>@id</code>,
1738-
or if it matches given one of several different properties (or all properties, if the
1739-
<a>require all flag</a> is present.).</p>
1735+
<code>@id</code>,
1736+
or if it matches given one of several different properties.
1737+
If the <a>require all flag</a> is <code>true</code>, all properties much has defaults
1738+
or match for the frame to match.</p>
17401739

17411740
<p class="note">As matching is performed on expanded node objects, all values will be in the form of an array.</p>
17421741

@@ -1764,36 +1763,39 @@ <h2>Frame Matching Algorithm</h2>
17641763
a <a>frame</a> to match against (<var>frame</var>), and the <var>requireAll</var> flag
17651764
and returns a list of matched subjects by filtering each <var>node</var> in <var>subjects</var> as follows:</p>
17661765

1767-
<p>Frame matching follows an order of precedence, first attempting to match on a particular <code>@id</code>, then
1768-
a particular <code>@type</code> (or lack of <code>@type</code>), then by matching on any or all
1769-
of a set of properties, if neither <code>@id</code>, nor <code>@type</code> are in the frame.</p>
1766+
<p>All properties, including <code>@id</code> and <code>@type</code>, but no other <a>keywords</a> are considered
1767+
whem matching a frame..</p>
17701768

17711769
<ol>
1772-
<li><var>node</var> matches if it has an <code>@id</code> property value
1773-
which is also a value of the <code>@id</code> property in <var>frame</var>.
1774-
Otherwise, <var>node</var> does not match if <var>frame</var> has a non-empty
1775-
<code>@id</code> property, other than an empty <a>dictionary</a>.
1776-
Otherwise, frame must not have a <code>@id</code> property; continue to the next step.
1777-
<div class="note">Framing works on <a>map of flattened subjects</a>,
1778-
and the act of flattening ensures that all subjects have an
1779-
<code>@id</code> property; thus the <code>"@id": []</code> pattern would
1780-
never match any <a>node object</a>. The <code>"@id": [{}]</code> pattern would
1781-
match any <a>node object</a> and is equivalent to not specifying a
1782-
<code>@id</code> property in <var>frame</var> at all</div>
1783-
</li>
1784-
<li><var>node</var> matches if frame has no non-<code>keyword</code> properties.</li>
1785-
<li>If <var>requireAll</var> is <strong>true</strong>, <var>node</var> matches if all non-<a>keyword</a> properties (<var>property</var>) in <var>frame</var> match any of the following conditions.
1786-
Or, if <var>requireAll</var> is <strong>false</strong>, if any of the non-<a>keyword</a> properties (<var>property</var>) in <var>frame</var> match any of the following conditions.
1770+
<li><var>node</var> matches if frame has no properties.</li>
1771+
<li>If <var>requireAll</var> is <strong>true</strong>, <var>node</var> matches if all properties (<var>property</var>)
1772+
in <var>frame</var> match any of the following conditions.
1773+
Or, if <var>requireAll</var> is <strong>false</strong>, if any of the properties (<var>property</var>)
1774+
in <var>frame</var> match any of the following conditions.
17871775
For the <var>values</var> of each <var>property</var> from <var>frame</var> in <var>node</var>:
17881776
<ol>
1789-
<li>If <var>property</var> is <code>@type</code>:
1777+
<li>If <var>property</var> is <code>@id</code>:
1778+
<ol>
1779+
<li><var>property</var> matches if the <code>@id</code> property in frame includes any <a>IRI</a> in <var>values</var>.</li>
1780+
<li>Otherwise, <var>property</var> matches if the <code>@type</code> property in <var>frame</var> is <code><a>wildcard</a></code> or <code><a>match none</a></code>.</li>
1781+
</ol>
1782+
<div class="note">Framing works on <a>map of flattened subjects</a>,
1783+
and the act of flattening ensures that all subjects have an
1784+
<code>@id</code> property; thus the <code>"@id": []</code> pattern would
1785+
never match any <a>node object</a>. The <code>"@id": [{}]</code> pattern would
1786+
match any <a>node object</a> and is equivalent to not specifying a
1787+
<code>@id</code> property in <var>frame</var> at all</div>
1788+
</li>
1789+
<li>Otherwise, if <var>property</var> is <code>@type</code>:
17901790
<ol>
17911791
<li><var>property</var> matches if the <code>@type</code> property in frame includes any <a>IRI</a> in <var>values</var>.</li>
17921792
<li>Otherwise, <var>property</var> matches if <var>values</var> is not empty and the <code>@type</code> property in <var>frame</var> is <code><a>wildcard</a></code>.</li>
17931793
<li>Otherwise, <var>property</var> matches if <var>values</var> is empty and the <code>@type</code> property in <var>frame</var> is <code><a>match none</a></code>.</li>
17941794
<li>Otherwise, <var>property</var> does not match.</li>
17951795
</ol>
17961796
</li>
1797+
<li>If <var>property</var> is <code>@id</code> or <code>@type</code> and does not match,
1798+
<var>node</var> does not match, and processing is terminated.</li>
17971799
<li>Otherwise, the value of <var>property</var> in <var>frame</var> MUST be empty, or an array
17981800
containing a valid <a>frame</a>.</li>
17991801
<li><var>property</var> matches if <var>values</var> is empty, or non existent,
@@ -2238,6 +2240,8 @@ <h2>Changes since JSON-LD Community Group Final Report</h2>
22382240
evaluating test results have been updated accordingly.</li>
22392241
<li>The IANA registration is changed from <code>application/ld-frame+json</code> to
22402242
<code>application/ld+json</code> with a required <code>profile</code> parameter.</li>
2243+
<li>The <a>require all flag</a> now needs all properties to be present, including
2244+
<code>@id</code> and <code>@type</code>.</li>
22412245
</ul>
22422246
</section>
22432247

tests/frame-manifest.jsonld

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
}, {
198198
"@id": "#t0024",
199199
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
200-
"name": "match on any common properties if @requireAll: true",
200+
"name": "match on any common properties if @requireAll: false",
201201
"purpose": "Match if @requireAll is false and both node and frame contain common non-keyword properties of any value.",
202202
"option": {"specVersion": "json-ld-1.1"},
203203
"input": "frame/0024-in.jsonld",
@@ -658,6 +658,33 @@
658658
"frame": "frame/p050-frame.jsonld",
659659
"expect": "frame/p050-out.jsonld",
660660
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"}
661+
}, {
662+
"@id": "#tra01",
663+
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
664+
"name": "@requireAll only matches if @type and other properties are present",
665+
"purpose": "If @requireAll is true, then all listed properties, including @type, must be present to match.",
666+
"input": "frame/ra01-in.jsonld",
667+
"frame": "frame/ra01-frame.jsonld",
668+
"expect": "frame/ra01-out.jsonld",
669+
"option": {"specVersion": "json-ld-1.1"}
670+
}, {
671+
"@id": "#tra02",
672+
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
673+
"name": "@requireAll only matches if @id and @type match",
674+
"purpose": "If @requireAll is true, then all listed properties, including @id and @type, must be present to match.",
675+
"input": "frame/ra02-in.jsonld",
676+
"frame": "frame/ra02-frame.jsonld",
677+
"expect": "frame/ra02-out.jsonld",
678+
"option": {"specVersion": "json-ld-1.1"}
679+
}, {
680+
"@id": "#tra03",
681+
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
682+
"name": "@requireAll with type and properties",
683+
"purpose": "If @requireAll is true, then all listed properties, including @type, must be present to match.",
684+
"input": "frame/ra03-in.jsonld",
685+
"frame": "frame/ra03-frame.jsonld",
686+
"expect": "frame/ra03-out.jsonld",
687+
"option": {"specVersion": "json-ld-1.1"}
661688
}
662689
]
663690
}

tests/frame/ra01-frame.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {"ex": "http://example.org/"},
3+
"@requireAll": true,
4+
"@type": "ex:Type",
5+
"ex:p": {}
6+
}

tests/frame/ra01-in.jsonld

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"@context": {"ex": "http://example.org/"},
4+
"@id": "ex:Sub1",
5+
"@type": "ex:Type",
6+
"ex:p": "foo"
7+
}, {
8+
"@context": { "ex":"http://example.org/"},
9+
"@id": "ex:Sub2",
10+
"@type": "ex:Type"
11+
}, {
12+
"@context": { "ex":"http://example.org/"},
13+
"@id": "ex:Sub3",
14+
"ex:p": "foo"
15+
}
16+
]

tests/frame/ra01-out.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {"ex": "http://example.org/"},
3+
"@graph": [{
4+
"@id": "ex:Sub1",
5+
"@type": "ex:Type",
6+
"ex:p": "foo"
7+
}]
8+
}

tests/frame/ra02-frame.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {"ex": "http://example.org/"},
3+
"@requireAll": true,
4+
"@id": ["ex:Sub1", "ex:Sub2"],
5+
"@type": "ex:Type"
6+
}

tests/frame/ra02-in.jsonld

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"@context": {"ex": "http://example.org/"},
4+
"@id": "ex:Sub1",
5+
"@type": "ex:Type",
6+
"ex:p": "foo"
7+
}, {
8+
"@context": { "ex":"http://example.org/"},
9+
"@id": "ex:Sub2",
10+
"@type": "ex:OtherType"
11+
}, {
12+
"@context": { "ex":"http://example.org/"},
13+
"@id": "ex:Sub3",
14+
"@type": "ex:Type",
15+
"ex:p": "foo"
16+
}
17+
]

tests/frame/ra02-out.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {"ex": "http://example.org/"},
3+
"@graph": [{
4+
"@id": "ex:Sub1",
5+
"@type": "ex:Type",
6+
"ex:p": "foo"
7+
}]
8+
}

tests/frame/ra03-frame.jsonld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@vocab": "https://schema.org/"
5+
},
6+
"@type": "Person",
7+
"@requireAll": true,
8+
"givenName": "John",
9+
"familyName": "Doe"
10+
}

tests/frame/ra03-in.jsonld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@vocab": "https://schema.org/"
5+
},
6+
"@graph": [
7+
{
8+
"@id": "1",
9+
"@type": "Person",
10+
"name": "John Doe",
11+
"givenName": "John",
12+
"familyName": "Doe"
13+
},
14+
{
15+
"@id": "2",
16+
"@type": "Person",
17+
"name": "Jane Doe",
18+
"givenName": "Jane"
19+
}
20+
]
21+
}

tests/frame/ra03-out.jsonld

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@vocab": "https://schema.org/"
5+
},
6+
"@id": "1",
7+
"@type": "Person",
8+
"familyName": "Doe",
9+
"givenName": "John",
10+
"name": "John Doe"
11+
}

0 commit comments

Comments
 (0)