-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample8_CustomRDFRender.cs
38 lines (32 loc) · 1.26 KB
/
Sample8_CustomRDFRender.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Res = JsonLD.Demo.Resources.Resources;
using System;
using JsonLD.Core;
using Newtonsoft.Json.Linq;
namespace JsonLD.Demo
{
public static class Sample8_CustomRDFRender
{
private static readonly string _docJson = Res.ReadString("doc.json");
private class JSONLDTripleCallback : IJSONLDTripleCallback
{
public object Call(RDFDataset dataset) =>
RDFDatasetUtils.ToNQuads(dataset); // serialize the RDF dataset as NQuads
}
internal static void Run()
{
var doc = JObject.Parse(_docJson);
var callback = new JSONLDTripleCallback();
var serialized = JsonLdProcessor.ToRDF(doc, callback);
Console.WriteLine(serialized);
/*
Output:
<http://example.org/ld-experts> <http://schema.org/member> _:b0 .
<http://example.org/ld-experts> <http://schema.org/name> "LD Experts" .
_:b0 <http://schema.org/image> <http://manu.sporny.org/images/manu.png> .
_:b0 <http://schema.org/name> "Manu Sporny" .
_:b0 <http://schema.org/url> <http://manu.sporny.org/> .
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
*/
}
}
}