Skip to content

Commit c4bbc2c

Browse files
committed
Add LINQPad samples to NuGet package
1 parent 4556362 commit c4bbc2c

18 files changed

+375
-1
lines changed

doc/linqpad-samples/Compact.linq

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Query Kind="Statements">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
10+
var opts = new JsonLdOptions();
11+
var compacted = JsonLdProcessor.Compact(Resources.Doc, Resources.Context, opts);
12+
13+
compacted.ToString().Dump("string");
14+
compacted.Dump("JSON DOM");
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Query Kind="Program">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
10+
void Main()
11+
{
12+
var opts = new JsonLdOptions();
13+
14+
var rdf = (RDFDataset)JsonLdProcessor.ToRDF(Resources.Doc, opts);
15+
var serialized = RDFDatasetUtils.ToNQuads(rdf); // serialize RDF to string
16+
17+
var parser = new CustomRDFParser();
18+
var jsonld = JsonLdProcessor.FromRDF(serialized, parser);
19+
jsonld.ToString().Dump("string");
20+
jsonld.Dump("JSON DOM");
21+
}
22+
23+
public class CustomRDFParser : IRDFParser
24+
{
25+
public RDFDataset Parse(JToken input)
26+
{
27+
// by public decree, references to example.org are normalized to https going forward...
28+
var converted = ((string)input).Replace("http://example.org/", "https://example.org/");
29+
return RDFDatasetUtils.ParseNQuads(converted);
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Query Kind="Program">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
10+
void Main()
11+
{
12+
var opts = new JsonLdOptions();
13+
14+
var callback = new JSONLDTripleCallback();
15+
var serialized = JsonLdProcessor.ToRDF(Resources.Doc, callback);
16+
serialized.Dump("RDF");
17+
}
18+
19+
public class JSONLDTripleCallback : IJSONLDTripleCallback
20+
{
21+
public object Call(RDFDataset dataset) =>
22+
RDFDatasetUtils.ToNQuads(dataset); // serialize the RDF dataset as NQuads
23+
}

doc/linqpad-samples/Expand.linq

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Query Kind="Statements">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
10+
var opts = new JsonLdOptions();
11+
var compacted = JsonLdProcessor.Compact(Resources.Doc, Resources.Context, opts);
12+
13+
var expanded = JsonLdProcessor.Expand(compacted);
14+
15+
expanded.ToString().Dump("string");
16+
expanded.Dump("JSON DOM");

doc/linqpad-samples/FileOrder.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Installation.linq
2+
Compact.linq
3+
Expand.linq
4+
Flatten.linq
5+
Frame.linq
6+
Normalize.linq
7+
ToRDF.linq
8+
FromRDF.linq
9+
CustomRDFRender.linq
10+
CustomRDFParser.linq
11+
RemoteDocumentLoader.linq

doc/linqpad-samples/Flatten.linq

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Query Kind="Statements">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
10+
var opts = new JsonLdOptions();
11+
var flattened = JsonLdProcessor.Flatten(Resources.Doc, Resources.Context, opts);
12+
13+
flattened.ToString().Dump("string");
14+
flattened.Dump("JSON DOM");

doc/linqpad-samples/Frame.linq

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Query Kind="Statements">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
10+
var opts = new JsonLdOptions();
11+
var framed = JsonLdProcessor.Frame(Resources.Doc, Resources.Frame, opts);
12+
13+
framed.ToString().Dump("string");
14+
framed.Dump("JSON DOM");

doc/linqpad-samples/FromRDF.linq

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Query Kind="Statements">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
10+
var opts = new JsonLdOptions();
11+
var rdf = (RDFDataset)JsonLdProcessor.ToRDF(Resources.Doc, opts);
12+
var serialized = RDFDatasetUtils.ToNQuads(rdf); // serialize RDF to string
13+
14+
var jsonld = JsonLdProcessor.FromRDF(serialized, opts);
15+
16+
jsonld.ToString().Dump("string");
17+
jsonld.Dump("JSON DOM");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Query Kind="Statements">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>Newtonsoft.Json.Linq</Namespace>
5+
<Namespace>JsonLD.Core</Namespace>
6+
</Query>
7+
8+
var json = "{'@context':{'test':'http://www.example.org/'},'test:hello':'world'}";
9+
var document = JObject.Parse(json);
10+
var expanded = JsonLdProcessor.Expand(document);
11+
12+
expanded.ToString().Dump("string");
13+
expanded.Dump("JSON DOM");

doc/linqpad-samples/Normalize.linq

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Query Kind="Statements">
2+
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
3+
<NuGetReference>Newtonsoft.Json</NuGetReference>
4+
<Namespace>JsonLD.Core</Namespace>
5+
<Namespace>Newtonsoft.Json.Linq</Namespace>
6+
</Query>
7+
8+
#load "Utils/Resources"
9+
#load "Utils/ObjectDumper"
10+
11+
var opts = new JsonLdOptions();
12+
var normalized = (RDFDataset)JsonLdProcessor.Normalize(Resources.Doc, opts);
13+
14+
normalized.JsonLDDump().Dump("string");
15+
normalized.Dump("JSON DOM");

0 commit comments

Comments
 (0)