-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
119 lines (99 loc) · 5.19 KB
/
Program.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// See https://aka.ms/new-console-template for more information
using VDS.RDF;
using VDS.RDF.Writing;
using System.Collections;
using VDS.RDF.JsonLd.Syntax;
using VDS.RDF.Parsing;
namespace RecordGenerator;
public class Program
{
public enum RDFFormat
{
NQuads,
Trig,
JsonLd,
CSV
}
public static RDFFormat parseRDFFormat(string formatString) =>
formatString switch
{
"n4" => RDFFormat.NQuads,
"jsonld" => RDFFormat.JsonLd,
"trig" => RDFFormat.Trig,
"csv" => RDFFormat.CSV,
_ => throw new Exception($"Invalid RDF Format {formatString}")
};
public static void Main(string[] args)
{
if (args.Length != 5)
throw new InvalidDataException("Usage: dotnet run <nobject> <nscopes> <nrecords> n4|trig|jsonld|csv <outfile>");
RDFFormat outFormat = parseRDFFormat(args.Reverse().Skip(1).First());
var outfile = args.Last();
var nObjects = int.Parse(args[0]);
var nRecords = int.Parse(args[1]);
var nScopes = int.Parse(args[2]);
var recordPrefix = "https://rdf.equinor.com/ontology/record/";
// var revisionPrefix = "https://rdf.equinor.com/ontology/revision/";
var melPrefix = "https://rdf.equinor.com/ontology/mel/";
// var xsdPrefix = "http://www.w3.org/2001/XMLSchema#";
var rdfPrefix = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
var pcaPrefix = "http://rds.posccaesar.org/ontology/plm/rdl/";
// var rdfsPrefix = "http://www.w3.org/2000/01/rdf-schema#";
// var provPrefix = "http://www.w3.org/ns/prov#";
// var isoPrefix = "http://standards.iso.org/8000#";
// var dcPrefix = "http://purl.org/dc/terms/";
var dataPrefix = "http://example.com/data/";
var store = new TripleStore();
var objects = Enumerable.Range(1, nObjects).Select(i => $"{dataPrefix}Object{i}");
var scopes = Enumerable.Range(0, (int)Math.Ceiling(Math.Log2(nScopes))).Select(i => (i, $"{dataPrefix}Scope{i}"));
for (int scopeNo = 1; scopeNo <= nScopes; scopeNo++)
{
var scopeMap = new BitArray(new int[] { scopeNo });
foreach (var obj in objects)
{
for (int i = 0; i < nRecords; i++)
{
var graph = new Graph(new UriNode(new Uri($"{obj}-{scopeNo}-Record{i}")));
graph.NamespaceMap.AddNamespace("data:", new Uri(dataPrefix));
graph.NamespaceMap.AddNamespace("rdl:", new Uri(pcaPrefix));
var recordType = graph.CreateUriNode(UriFactory.Create($"{recordPrefix}Record"));
var replacesRel = graph.CreateUriNode(UriFactory.Create($"{recordPrefix}replaces"));
var describesRel = graph.CreateUriNode(UriFactory.Create($"{recordPrefix}describes"));
var scopesRel = graph.CreateUriNode(UriFactory.Create($"{recordPrefix}isInScope"));
var subRecordRel = graph.CreateUriNode(UriFactory.Create($"{recordPrefix}isSubRecordOf"));
var rdfType = graph.CreateUriNode(UriFactory.Create($"{rdfPrefix}type"));
var melSystemType = graph.CreateUriNode(UriFactory.Create($"{melPrefix}System"));
var lengthType = graph.CreateUriNode(UriFactory.Create($"{pcaPrefix}Length"));
var weightType = graph.CreateUriNode(UriFactory.Create($"{pcaPrefix}Weight"));
var triples = new List<Triple>();
var objectNode = graph.CreateUriNode(UriFactory.Create(obj));
graph.BaseUri = new Uri($"{obj}-{scopeNo}-Record{i}");
var recordNode = graph.CreateUriNode(graph.BaseUri);
triples.Add(new Triple(recordNode, rdfType, recordType));
triples.Add(new Triple(recordNode, describesRel, objectNode));
triples.AddRange(scopes
.Where(i => scopeMap[i.Item1])
.Select(i => new Triple(recordNode, scopesRel, graph.CreateUriNode(UriFactory.Create(i.Item2))))
);
if (i > 0)
triples.Add(new Triple(recordNode, replacesRel, graph.CreateUriNode(UriFactory.Create($"{obj}-{scopeNo}-Record{i - 1}"))));
triples.Add(new Triple(objectNode, rdfType, melSystemType));
var iNode = graph.CreateLiteralNode($"{i}");
triples.Add(new Triple(objectNode, lengthType, iNode));
triples.Add(new Triple(objectNode, weightType, iNode));
graph.Assert(triples);
store.Add(graph);
}
}
IStoreWriter writer = outFormat switch
{
RDFFormat.JsonLd => new JsonLdWriter(),
RDFFormat.NQuads => new NQuadsWriter(VDS.RDF.Parsing.NQuadsSyntax.Rdf11),
RDFFormat.Trig => new TriGWriter() { Syntax = TriGSyntax.Rdf11 },
RDFFormat.CSV => new CsvStoreWriter(),
_ => throw new Exception("Invalid RDF Format")
};
writer.Save(store, outfile);
}
}
}