Пример #1
0
        public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
        {
            IServiceProvider serviceProvider = context.HttpContext.RequestServices;

            var response = context.HttpContext.Response;

            var graph = context.Object as IGraph;

            var ldApi      = new JsonLD.Core.JsonLdApi();
            var rdfDataset = new JsonLD.Core.RDFDataset();

            foreach (var triple in graph.Triples)
            {
                var ntf = new VDS.RDF.Writing.Formatting.NTriplesFormatter();
                if (triple.Object.NodeType == NodeType.Literal)
                {
                    var objNode = (ILiteralNode)triple.Object;
                    rdfDataset.AddTriple(triple.Subject.ToString(ntf).Trim('<', '>'), triple.Predicate.ToString(ntf).Trim('<', '>'), objNode.Value, objNode.DataType?.OriginalString, string.IsNullOrEmpty(objNode.Language) ? null : objNode.Language);
                }
                else
                {
                    rdfDataset.AddTriple(triple.Subject.ToString(ntf).Trim('<', '>'), triple.Predicate.ToString(ntf).Trim('<', '>'), triple.Object.ToString(ntf).Trim('<', '>'));
                }
            }

            var ld = ldApi.FromRDF(rdfDataset);

            return(response.WriteAsync(ld.ToString()));
        }
Пример #2
0
 public static void WriteDataset(JsonLD.Core.RDFDataset dataset)
 {
     foreach (var quad in dataset.GetQuads("@default"))
     {
         var nodes = quad.Keys
                     .Select(key => quad[key])
                     .OfType <JsonLD.Core.RDFDataset.Node>();
         WriteLine(string.Join(" ", nodes.Select(FormatString)));
     }
 }
Пример #3
0
 public static void WriteDataset(JsonLD.Core.RDFDataset dataset)
 {
     foreach (var quad in dataset.GetQuads("@default"))
     {
         var values = quad.Keys
                      .Select(key => quad[key])
                      .OfType <JsonLD.Core.RDFDataset.Node>()
                      .SelectMany(node => node.Keys.Intersect(RelevantNodeKeys).Select(k => node[k]));
         Util.WriteLine(string.Join(" ", values));
     }
 }