Skip to content

Update frame matching and add tests for requireAll #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,6 @@ <h2>Syntax Tokens and Keywords</h2>
<dt><code>@omitDefault</code></dt>
<dd>Used in <a href="#framing">Framing</a> to override the
value of <a>omit default flag</a> within a specific frame.
<div class="issue" data-number="41">Is this flag really useful? Easier to simply not have a default value,
if it shouldn't match.</div>
</dd>
<dt class="changed"><code>@requireAll</code></dt>
<dd class="changed">Used in <a href="#framing">Framing</a> to override the
Expand Down Expand Up @@ -1678,9 +1676,10 @@ <h2>Frame Matching Algorithm</h2>
<p>The Frame Matching Algorithm is used as part of the <a href="#framing-algorithm">Framing algorithm</a>
to determine if a particular <a>node object</a> matches the criteria set in a <a>frame</a>.
In general, a node object matches a frame if it meets the matches on <code>@type</code>,
or <code>@id</code>,
or if it matches given one of several different properties (or all properties, if the
<a>require all flag</a> is present.).</p>
<code>@id</code>,
or if it matches given one of several different properties.
If the <a>require all flag</a> is <code>true</code>, all properties must have defaults
or match for the frame to match.</p>

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

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

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

<ol>
<li><var>node</var> matches if it has an <code>@id</code> property value
which is also a value of the <code>@id</code> property in <var>frame</var>.
Otherwise, <var>node</var> does not match if <var>frame</var> has a non-empty
<code>@id</code> property, other than an empty <a>dictionary</a>.
Otherwise, frame must not have a <code>@id</code> property; continue to the next step.
<div class="note">Framing works on <a>map of flattened subjects</a>,
and the act of flattening ensures that all subjects have an
<code>@id</code> property; thus the <code>"@id": []</code> pattern would
never match any <a>node object</a>. The <code>"@id": [{}]</code> pattern would
match any <a>node object</a> and is equivalent to not specifying a
<code>@id</code> property in <var>frame</var> at all</div>
</li>
<li><var>node</var> matches if frame has no non-<code>keyword</code> properties.</li>
<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.
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.
<li><var>node</var> matches if frame has no properties.</li>
<li>If <var>requireAll</var> is <strong>true</strong>, <var>node</var> matches if all properties (<var>property</var>)
in <var>frame</var> match any of the following conditions.
Or, if <var>requireAll</var> is <strong>false</strong>, if any of the properties (<var>property</var>)
in <var>frame</var> match any of the following conditions.
For the <var>values</var> of each <var>property</var> from <var>frame</var> in <var>node</var>:
<ol>
<li>If <var>property</var> is <code>@type</code>:
<li>If <var>property</var> is <code>@id</code>:
<ol>
<li><var>property</var> matches if the <code>@id</code> property in frame includes any <a>IRI</a> in <var>values</var>.</li>
<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>
</ol>
<div class="note">Framing works on <a>map of flattened subjects</a>,
and the act of flattening ensures that all subjects have an
<code>@id</code> property; thus the <code>"@id": []</code> pattern would
never match any <a>node object</a>. The <code>"@id": [{}]</code> pattern would
match any <a>node object</a> and is equivalent to not specifying a
<code>@id</code> property in <var>frame</var> at all</div>
</li>
<li>Otherwise, if <var>property</var> is <code>@type</code>:
<ol>
<li><var>property</var> matches if the <code>@type</code> property in frame includes any <a>IRI</a> in <var>values</var>.</li>
<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>
<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>
<li>Otherwise, <var>property</var> does not match.</li>
</ol>
</li>
<li>If <var>property</var> is <code>@id</code> or <code>@type</code> and does not match,
<var>node</var> does not match, and processing is terminated.</li>
<li>Otherwise, the value of <var>property</var> in <var>frame</var> MUST be empty, or an array
containing a valid <a>frame</a>.</li>
<li><var>property</var> matches if <var>values</var> is empty, or non existent,
Expand Down Expand Up @@ -2194,6 +2196,8 @@ <h2>Changes since JSON-LD Community Group Final Report</h2>
evaluating test results have been updated accordingly.</li>
<li>The IANA registration is changed from <code>application/ld-frame+json</code> to
<code>application/ld+json</code> with a required <code>profile</code> parameter.</li>
<li>The <a>require all flag</a> now needs all properties to be present, including
<code>@id</code> and <code>@type</code>.</li>
<li>Removed <code>@first</code> and <code>@last</code> values for the
<a>object embed flag</a> in favor of <code>@once</code>.</li>
</ul>
Expand Down
29 changes: 28 additions & 1 deletion tests/frame-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
}, {
"@id": "#t0024",
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
"name": "match on any common properties if @requireAll: true",
"name": "match on any common properties if @requireAll: false",
"purpose": "Match if @requireAll is false and both node and frame contain common non-keyword properties of any value.",
"option": {"specVersion": "json-ld-1.1"},
"input": "frame/0024-in.jsonld",
Expand Down Expand Up @@ -670,6 +670,33 @@
"frame": "frame/p050-frame.jsonld",
"expect": "frame/p050-out.jsonld",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"}
}, {
"@id": "#tra01",
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
"name": "@requireAll only matches if @type and other properties are present",
"purpose": "If @requireAll is true, then all listed properties, including @type, must be present to match.",
"input": "frame/ra01-in.jsonld",
"frame": "frame/ra01-frame.jsonld",
"expect": "frame/ra01-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tra02",
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
"name": "@requireAll only matches if @id and @type match",
"purpose": "If @requireAll is true, then all listed properties, including @id and @type, must be present to match.",
"input": "frame/ra02-in.jsonld",
"frame": "frame/ra02-frame.jsonld",
"expect": "frame/ra02-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tra03",
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
"name": "@requireAll with type and properties",
"purpose": "If @requireAll is true, then all listed properties, including @type, must be present to match.",
"input": "frame/ra03-in.jsonld",
"frame": "frame/ra03-frame.jsonld",
"expect": "frame/ra03-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}
]
}
6 changes: 6 additions & 0 deletions tests/frame/ra01-frame.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {"ex": "http://example.org/"},
"@requireAll": true,
"@type": "ex:Type",
"ex:p": {}
}
16 changes: 16 additions & 0 deletions tests/frame/ra01-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"@context": {"ex": "http://example.org/"},
"@id": "ex:Sub1",
"@type": "ex:Type",
"ex:p": "foo"
}, {
"@context": { "ex":"http://example.org/"},
"@id": "ex:Sub2",
"@type": "ex:Type"
}, {
"@context": { "ex":"http://example.org/"},
"@id": "ex:Sub3",
"ex:p": "foo"
}
]
8 changes: 8 additions & 0 deletions tests/frame/ra01-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {"ex": "http://example.org/"},
"@graph": [{
"@id": "ex:Sub1",
"@type": "ex:Type",
"ex:p": "foo"
}]
}
6 changes: 6 additions & 0 deletions tests/frame/ra02-frame.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {"ex": "http://example.org/"},
"@requireAll": true,
"@id": ["ex:Sub1", "ex:Sub2"],
"@type": "ex:Type"
}
17 changes: 17 additions & 0 deletions tests/frame/ra02-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"@context": {"ex": "http://example.org/"},
"@id": "ex:Sub1",
"@type": "ex:Type",
"ex:p": "foo"
}, {
"@context": { "ex":"http://example.org/"},
"@id": "ex:Sub2",
"@type": "ex:OtherType"
}, {
"@context": { "ex":"http://example.org/"},
"@id": "ex:Sub3",
"@type": "ex:Type",
"ex:p": "foo"
}
]
8 changes: 8 additions & 0 deletions tests/frame/ra02-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {"ex": "http://example.org/"},
"@graph": [{
"@id": "ex:Sub1",
"@type": "ex:Type",
"ex:p": "foo"
}]
}
10 changes: 10 additions & 0 deletions tests/frame/ra03-frame.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"@context": {
"@version": 1.1,
"@vocab": "https://schema.org/"
},
"@type": "Person",
"@requireAll": true,
"givenName": "John",
"familyName": "Doe"
}
21 changes: 21 additions & 0 deletions tests/frame/ra03-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"@context": {
"@version": 1.1,
"@vocab": "https://schema.org/"
},
"@graph": [
{
"@id": "1",
"@type": "Person",
"name": "John Doe",
"givenName": "John",
"familyName": "Doe"
},
{
"@id": "2",
"@type": "Person",
"name": "Jane Doe",
"givenName": "Jane"
}
]
}
11 changes: 11 additions & 0 deletions tests/frame/ra03-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"@context": {
"@version": 1.1,
"@vocab": "https://schema.org/"
},
"@id": "1",
"@type": "Person",
"familyName": "Doe",
"givenName": "John",
"name": "John Doe"
}