private static async Task <JArray> ExpandAsync(RemoteDocument doc, Uri documentLocation, JsonLdProcessorOptions options = null) { var activeContext = new JsonLdContext { Base = documentLocation }; if (options.Base != null) { activeContext.Base = options.Base; } var processor = new JsonLdProcessor(options); if (options.ExpandContext != null) { var expandObject = options.ExpandContext as JObject; if (expandObject != null) { var contextProperty = expandObject.Property("@context"); if (contextProperty != null) { activeContext = processor.ProcessContext(activeContext, contextProperty.Value); } else { activeContext = processor.ProcessContext(activeContext, expandObject); } } else { activeContext = processor.ProcessContext(activeContext, options.ExpandContext); } } if (doc.ContextUrl != null) { var contextDoc = await LoadJsonAsync(doc.ContextUrl, options); if (contextDoc.Document is string) { contextDoc.Document = JToken.Parse(contextDoc.Document as string); } activeContext = processor.ProcessContext(activeContext, contextDoc.Document as JToken); } if (doc.Document is string) { doc.Document = JToken.Parse(doc.Document as string); } return(processor.Expand(activeContext, null, doc.Document as JToken)); }
/// <summary> /// Create a deep clone of this context /// </summary> /// <returns>A new JsonLdContext that is a clone of this context</returns> public JsonLdContext Clone() { var clone = new JsonLdContext { Base = Base, HasBase = HasBase, Language = Language, Version = Version, Vocab = Vocab, }; foreach (var termDefEntry in _termDefinitions) { clone.AddTerm(termDefEntry.Key, termDefEntry.Value.Clone()); } return(clone); }