Beispiel #1
0
        public static RDFSharp.Model.RDFGraph DeserializeGraphFromJsonLd(string data)
        {
            var result = new RDFSharp.Model.RDFGraph();

            result.SetContext(new Uri("http://example.com/context/JsonLd"));

            var token = (JsonLD.Core.RDFDataset)JsonLD.Core.JsonLdProcessor.ToRDF(JsonLD.Util.JSONUtils.FromString(data));

            foreach (var quad in token.GetQuads("@default"))
            {
                var subject   = ToRDFSharpObject(quad["subject"]);
                var predicate = ToRDFSharpObject(quad["predicate"]);
                var @object   = ToRDFSharpObject(quad["object"]);
                var triple    = CreateTriple(subject, predicate, @object);
                result.AddTriple(triple);
            }

            return(result);
        }
Beispiel #2
0
        private static RDFSharp.Model.RDFGraph ConstructGraph()
        {
            var result = new RDFSharp.Model.RDFGraph();

            result.SetContext(new Uri("http://example.com/context/Local"));

            var exampleNamespace = new RDFSharp.Model.RDFNamespace("ex", "http://example.com/");

            RDFSharp.Model.RDFNamespaceRegister.AddNamespace(exampleNamespace);

            result.AddTriple(new RDFSharp.Model.RDFTriple(
                                 new RDFSharp.Model.RDFResource("ex:subject/001"),
                                 RDFSharp.Model.RDFVocabulary.FOAF.FIRSTNAME, // Equivalent to RDFResource("foaf:firstName") which is equivalent to RDFResource("http://xmlns.com/foaf/0.1/firstName")
                                 new RDFSharp.Model.RDFPlainLiteral("John")));
            result.AddTriple(new RDFSharp.Model.RDFTriple(
                                 new RDFSharp.Model.RDFResource("ex:subject/001"),
                                 RDFSharp.Model.RDFVocabulary.FOAF.FAMILY_NAME,
                                 new RDFSharp.Model.RDFPlainLiteral("Doe")));
            return(result);
        }