static private RemovePreserve ( Context ctx, JToken input, JsonLD.Core.JsonLdOptions opts ) : JToken | ||
ctx | Context | the active context used to compact the input. |
input | JToken | the framed, compacted output. |
opts | JsonLD.Core.JsonLdOptions | |
return | JToken |
/// <exception cref="JsonLD.Core.JsonLdError"></exception> public static JObject Frame(JToken input, JToken frame, JsonLdOptions options) { if (frame is JObject) { frame = JsonLdUtils.Clone((JObject)frame); } // TODO string/IO input JToken expandedInput = Expand(input, options); JArray expandedFrame = Expand(frame, options); JsonLdApi api = new JsonLdApi(expandedInput, options); JArray framed = api.Frame(expandedInput, expandedFrame); Context activeCtx = api.context.Parse(frame["@context" ]); JToken compacted = api.Compact(activeCtx, null, framed); if (!(compacted is JArray)) { JArray tmp = new JArray(); tmp.Add(compacted); compacted = tmp; } string alias = activeCtx.CompactIri("@graph"); JObject rval = activeCtx.Serialize(); rval[alias] = compacted; JsonLdUtils.RemovePreserve(activeCtx, rval, options); return(rval); }
/// <exception cref="JsonLdError"></exception> public static async Task <JObject> FrameAsync(JToken input, JToken frame, JsonLdOptions options) { if (frame is JObject) { frame = JsonLdUtils.Clone((JObject)frame); } // TODO string/IO input JToken expandedInput = await ExpandAsync(input, options); var expandedFrame = await ExpandAsync(frame, options); var api = await JsonLdApi.CreateAsync(expandedInput, options); var framed = api.Frame(expandedInput, expandedFrame); var activeCtx = await api.context.ParseAsync(frame["@context" ]); var compacted = api.Compact(activeCtx, null, framed); if (!(compacted is JArray)) { compacted = new JArray { compacted }; } var alias = activeCtx.CompactIri("@graph"); var rval = activeCtx.Serialize(); rval[alias] = compacted; JsonLdUtils.RemovePreserve(activeCtx, rval, options); return(rval); }