Skip to content

Commit

Permalink
Merge pull request #23 from vemonet/master
Browse files Browse the repository at this point in the history
Add support to access functions parameters using their predicate
  • Loading branch information
ThibaultGerrier authored Aug 11, 2021
2 parents 4677547 + d68eaca commit c0679d8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/function/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ const findParameters = (data, predicateObjectMap, prefixes) => {
if (param.constant) {
type = 'constant';
}
if (param[type].length === 1) {
if (param[type] && param[type].length === 1) {
param[type] = param[type][0];
}
result.push({
type,
data: param[type],
predicate: predicate
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/input-parser/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const calculateParams = (Parser, parameters, index, options) => {
if (temp && temp.length === 1) {
temp = temp[0];
}
result.push(temp);
result[p.predicate] = temp;
result.push(temp)
});
return result;
};
Expand Down
53 changes: 29 additions & 24 deletions tests/language/out.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,38 @@
{
"@id": "http://example.com/John",
"http://schema.org/name": "John",
"http://schema.org/familyName": "Doe",
"@type": "http://schema.org/Person"
},
{
"@id": "http://example.com/",
"http://schema.org/name": "",
"http://schema.org/familyName": "",
"@type": "http://schema.org/Person"
},
{
"@id": "http://example.com/Jason",
"http://schema.org/name": "Jason",
"http://schema.org/familyName": "",
"@type": "http://schema.org/Person"
},
{
"@id": "http://example.com/",
"http://schema.org/name": "",
"http://schema.org/familyName": "Jarvis",
"http://schema.org/language": [
{
"@value": "John",
"@language": "en"
},
{
"@value": "John",
"@language": "de"
},
{
"@value": "John",
"@language": "de-DE"
}
],
"@type": "http://schema.org/Person"
},
{
"@id": "http://example.com/Jimathy",
"http://schema.org/name": "Jimathy",
"http://schema.org/additionalName": [
"Jarvis",
""
"@id": "http://example.com/Jane",
"http://schema.org/name": "Jane",
"http://schema.org/language": [
{
"@value": "Jane",
"@language": "en"
},
{
"@value": "Jane",
"@language": "de"
},
{
"@value": "Jane",
"@language": "de-DE"
}
],
"@type": "http://schema.org/Person"
}
Expand Down

0 comments on commit c0679d8

Please sign in to comment.