Skip to content
Snippets Groups Projects
Commit fc8bcf4f authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Use the embedded json-ld context for expanding

parent b6167de3
No related branches found
No related tags found
No related merge requests found
...@@ -216,19 +216,19 @@ export default class JSONLD { ...@@ -216,19 +216,19 @@ export default class JSONLD {
* Expands a member of a list to a object with schema.org properties * Expands a member of a list to a object with schema.org properties
* *
* @param member * @param member
* @param [context]
*/ */
expandMember(member) { expandMember(member, context) {
const type = member["@type"]; if (context === undefined) {
context = member["@context"];
}
const entity = this.getEntityForIdentifier(type);
let result = {"@id": member["@id"]}; let result = {"@id": member["@id"]};
for (const key of Object.keys(context)) {
entity["hydra:supportedProperty"].forEach(function (property) { const value = context[key];
const id = property["hydra:property"]["@id"]; if (member[key] !== undefined)
const title = property["hydra:title"]; result[value] = member[key];
}
result[id] = member[title];
});
return result; return result;
} }
...@@ -239,7 +239,7 @@ export default class JSONLD { ...@@ -239,7 +239,7 @@ export default class JSONLD {
* @param member * @param member
* @param localContext * @param localContext
*/ */
static compactMember(member, localContext) { compactMember(member, localContext) {
let result = {}; let result = {};
for (const property in localContext) { for (const property in localContext) {
...@@ -267,11 +267,12 @@ export default class JSONLD { ...@@ -267,11 +267,12 @@ export default class JSONLD {
return []; return [];
} }
const otherContext = data['@context'];
let results = []; let results = [];
let that = this; let that = this;
members.forEach(function (member) { members.forEach(function (member) {
results.push(JSONLD.compactMember(that.expandMember(member), localContext)); results.push(that.compactMember(that.expandMember(member, otherContext), localContext));
}); });
return results; return results;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment