Inheritance: IRdfWriter
Ejemplo n.º 1
0
        public static JToken JsonFromGraph2(IGraph graph, string rootType, JToken context)
        {
            System.IO.StringWriter stringWriter = new System.IO.StringWriter();
            IRdfWriter rdfWriter = new JsonLdWriter();
            rdfWriter.Save(graph, stringWriter);
            stringWriter.Flush();

            JToken flattened = JToken.Parse(stringWriter.ToString());

            return flattened;
        }
Ejemplo n.º 2
0
        public static JObject JsonFromGraph(IGraph graph, string rootType, JToken context)
        {
            System.IO.StringWriter stringWriter = new System.IO.StringWriter();
            IRdfWriter rdfWriter = new JsonLdWriter();
            rdfWriter.Save(graph, stringWriter);
            stringWriter.Flush();

            JObject frame = new JObject();
            frame.Add("@context", context);
            frame.Add("@type", rootType);
            //frame.Add("@embed", false);

            JToken flattened = JToken.Parse(stringWriter.ToString());
            JObject framed = JsonLdProcessor.Frame(flattened, frame, new JsonLdOptions());
            JObject compacted = JsonLdProcessor.Compact(framed, context, new JsonLdOptions());

            return compacted;
        }
Ejemplo n.º 3
0
        async Task<JObject> MakeCatalogEntry(string nuspecLocation)
        {
            Uri baseAddress = new Uri("http://tempuri.org/test");

            HttpClient client = new HttpClient();

            XDocument original = XDocument.Load(await client.GetStreamAsync(nuspecLocation));

            XDocument nuspec = NormalizeNuspecNamespace(original, GetXslt("XSLT.normalizeNuspecNamespace.xslt"));
            IGraph graph = CreateNuspecGraph(nuspec, baseAddress, GetXslt("XSLT.nuspec.xslt"));

            //  Compact JSON-LD projection of RDF

            JToken frame = GetJson("Context.package.json");

            using (var writer = new StringWriter())
            {
                IRdfWriter jsonLdWriter = new JsonLdWriter();
                jsonLdWriter.Save(graph, writer);
                writer.Flush();

                JToken flattened = JToken.Parse(writer.ToString());
                JObject framed = JsonLdProcessor.Frame(flattened, frame, new JsonLdOptions());
                JObject compacted = JsonLdProcessor.Compact(framed, frame["@context"], new JsonLdOptions());

                compacted.Remove("@context");

                return compacted;
            }
        }