Exemplo n.º 1
0
        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));
        }