Skip to content

Commit e825e96

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

11 files changed

+159
-25
lines changed

index.html

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,6 @@ <h2>Syntax Tokens and Keywords</h2>
14101410
<dt><code>@omitDefault</code></dt>
14111411
<dd>Used in <a href="#framing">Framing</a> to override the
14121412
value of <a>omit default flag</a> within a specific frame.
1413-
<div class="issue" data-number="41">Is this flag really useful? Easier to simply not have a default value,
1414-
if it shouldn't match.</div>
14151413
</dd>
14161414
<dt class="changed"><code>@requireAll</code></dt>
14171415
<dd class="changed">Used in <a href="#framing">Framing</a> to override the
@@ -1678,9 +1676,10 @@ <h2>Frame Matching Algorithm</h2>
16781676
<p>The Frame Matching Algorithm is used as part of the <a href="#framing-algorithm">Framing algorithm</a>
16791677
to determine if a particular <a>node object</a> matches the criteria set in a <a>frame</a>.
16801678
In general, a node object matches a frame if it meets the matches on <code>@type</code>,
1681-
or <code>@id</code>,
1682-
or if it matches given one of several different properties (or all properties, if the
1683-
<a>require all flag</a> is present.).</p>
1679+
<code>@id</code>,
1680+
or if it matches given one of several different properties.
1681+
If the <a>require all flag</a> is <code>true</code>, all properties much has defaults
1682+
or match for the frame to match.</p>
16841683

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

@@ -1708,36 +1707,39 @@ <h2>Frame Matching Algorithm</h2>
17081707
a <a>frame</a> to match against (<var>frame</var>), and the <var>requireAll</var> flag
17091708
and returns a list of matched subjects by filtering each <var>node</var> in <var>subjects</var> as follows:</p>
17101709

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

17151713
<ol>
1716-
<li><var>node</var> matches if it has an <code>@id</code> property value
1717-
which is also a value of the <code>@id</code> property in <var>frame</var>.
1718-
Otherwise, <var>node</var> does not match if <var>frame</var> has a non-empty
1719-
<code>@id</code> property, other than an empty <a>dictionary</a>.
1720-
Otherwise, frame must not have a <code>@id</code> property; continue to the next step.
1721-
<div class="note">Framing works on <a>map of flattened subjects</a>,
1722-
and the act of flattening ensures that all subjects have an
1723-
<code>@id</code> property; thus the <code>"@id": []</code> pattern would
1724-
never match any <a>node object</a>. The <code>"@id": [{}]</code> pattern would
1725-
match any <a>node object</a> and is equivalent to not specifying a
1726-
<code>@id</code> property in <var>frame</var> at all</div>
1727-
</li>
1728-
<li><var>node</var> matches if frame has no non-<code>keyword</code> properties.</li>
1729-
<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.
1730-
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.
1714+
<li><var>node</var> matches if frame has no properties.</li>
1715+
<li>If <var>requireAll</var> is <strong>true</strong>, <var>node</var> matches if all properties (<var>property</var>)
1716+
in <var>frame</var> match any of the following conditions.
1717+
Or, if <var>requireAll</var> is <strong>false</strong>, if any of the properties (<var>property</var>)
1718+
in <var>frame</var> match any of the following conditions.
17311719
For the <var>values</var> of each <var>property</var> from <var>frame</var> in <var>node</var>:
17321720
<ol>
1733-
<li>If <var>property</var> is <code>@type</code>:
1721+
<li>If <var>property</var> is <code>@id</code>:
1722+
<ol>
1723+
<li><var>property</var> matches if the <code>@id</code> property in frame includes any <a>IRI</a> in <var>values</var>.</li>
1724+
<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>
1725+
</ol>
1726+
<div class="note">Framing works on <a>map of flattened subjects</a>,
1727+
and the act of flattening ensures that all subjects have an
1728+
<code>@id</code> property; thus the <code>"@id": []</code> pattern would
1729+
never match any <a>node object</a>. The <code>"@id": [{}]</code> pattern would
1730+
match any <a>node object</a> and is equivalent to not specifying a
1731+
<code>@id</code> property in <var>frame</var> at all</div>
1732+
</li>
1733+
<li>Otherwise, if <var>property</var> is <code>@type</code>:
17341734
<ol>
17351735
<li><var>property</var> matches if the <code>@type</code> property in frame includes any <a>IRI</a> in <var>values</var>.</li>
17361736
<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>
17371737
<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>
17381738
<li>Otherwise, <var>property</var> does not match.</li>
17391739
</ol>
17401740
</li>
1741+
<li>If <var>property</var> is <code>@id</code> or <code>@type</code> and does not match,
1742+
<var>node</var> does not match, and processing is terminated.</li>
17411743
<li>Otherwise, the value of <var>property</var> in <var>frame</var> MUST be empty, or an array
17421744
containing a valid <a>frame</a>.</li>
17431745
<li><var>property</var> matches if <var>values</var> is empty, or non existent,
@@ -2194,6 +2196,8 @@ <h2>Changes since JSON-LD Community Group Final Report</h2>
21942196
evaluating test results have been updated accordingly.</li>
21952197
<li>The IANA registration is changed from <code>application/ld-frame+json</code> to
21962198
<code>application/ld+json</code> with a required <code>profile</code> parameter.</li>
2199+
<li>The <a>require all flag</a> now needs all properties to be present, including
2200+
<code>@id</code> and <code>@type</code>.</li>
21972201
<li>Removed <code>@first</code> and <code>@last</code> values for the
21982202
<a>object embed flag</a> in favor of <code>@once</code>.</li>
21992203
</ul>

tests/frame-manifest.jsonld

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
}, {
199199
"@id": "#t0024",
200200
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
201-
"name": "match on any common properties if @requireAll: true",
201+
"name": "match on any common properties if @requireAll: false",
202202
"purpose": "Match if @requireAll is false and both node and frame contain common non-keyword properties of any value.",
203203
"option": {"specVersion": "json-ld-1.1"},
204204
"input": "frame/0024-in.jsonld",
@@ -670,6 +670,33 @@
670670
"frame": "frame/p050-frame.jsonld",
671671
"expect": "frame/p050-out.jsonld",
672672
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"}
673+
}, {
674+
"@id": "#tra01",
675+
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
676+
"name": "@requireAll only matches if @type and other properties are present",
677+
"purpose": "If @requireAll is true, then all listed properties, including @type, must be present to match.",
678+
"input": "frame/ra01-in.jsonld",
679+
"frame": "frame/ra01-frame.jsonld",
680+
"expect": "frame/ra01-out.jsonld",
681+
"option": {"specVersion": "json-ld-1.1"}
682+
}, {
683+
"@id": "#tra02",
684+
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
685+
"name": "@requireAll only matches if @id and @type match",
686+
"purpose": "If @requireAll is true, then all listed properties, including @id and @type, must be present to match.",
687+
"input": "frame/ra02-in.jsonld",
688+
"frame": "frame/ra02-frame.jsonld",
689+
"expect": "frame/ra02-out.jsonld",
690+
"option": {"specVersion": "json-ld-1.1"}
691+
}, {
692+
"@id": "#tra03",
693+
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
694+
"name": "@requireAll with type and properties",
695+
"purpose": "If @requireAll is true, then all listed properties, including @type, must be present to match.",
696+
"input": "frame/ra03-in.jsonld",
697+
"frame": "frame/ra03-frame.jsonld",
698+
"expect": "frame/ra03-out.jsonld",
699+
"option": {"specVersion": "json-ld-1.1"}
673700
}
674701
]
675702
}

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)