diff --git a/ModelToRdf.Extensions/RdfExtensions.cs b/ModelToRdf.Extensions/RdfExtensions.cs index 96f6cc6..40d8606 100644 --- a/ModelToRdf.Extensions/RdfExtensions.cs +++ b/ModelToRdf.Extensions/RdfExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using VDS.RDF; +using VDS.RDF.Nodes; namespace ModelToRdf.Extensions { diff --git a/ModelToRdf/ModelToRdf.cs b/ModelToRdf/ModelToRdf.cs index 32ec943..502414a 100644 --- a/ModelToRdf/ModelToRdf.cs +++ b/ModelToRdf/ModelToRdf.cs @@ -4,6 +4,7 @@ using ModelToRdf.Extensions; using Newtonsoft.Json.Linq; using VDS.RDF; +using VDS.RDF.Query.Expressions.Functions.XPath.String; using VDS.RDF.Writing.Formatting; namespace ModelToRdf @@ -48,25 +49,44 @@ internal static void ToRDFGraph(this IDictionary jDictionary, Gr internal static void ToRDFGraph(this JToken jToken, string key, IUriNode entityNode, Graph graph) { //TODO: This is very specific to E3 (==0) - if (string.IsNullOrWhiteSpace(jToken.ToString()) || jToken.ToString().Equals("0")) - return; - + //if (string.IsNullOrWhiteSpace(jToken.ToString()) || jToken.ToString().Equals("0")) + // return; + //TODO: Implement: If has attribute "Id"; if (key.ToLower().Equals("id") || key.ToLower().Equals("@id")) { - //TODO: This is very specific to E3 (==0). - if (jToken.ToString().Equals("0")) - return; - graph.Assert(entityNode, key.ToUriNode(DefaultIri), jToken.ToString().ToLiteralNode()); } else if (key.ToLower().EndsWith("id") || key.ToLower().EndsWith("ids")) { - //TODO: This is very specific to E3 (==0). - if (jToken.ToString().Equals("0")) - return; - graph.Assert(entityNode, key.ToUriNode(DefaultIri), jToken.ToString().ToUriNode(DefaultIri)); } else { - graph.Assert(entityNode, key.ToUriNode(DefaultIri), jToken.ToString().ToLiteralNode()); + //TODO: Create a node for each type: + switch (jToken.Type) { + case JTokenType.Date: + var dateTime = DateTime.Parse(jToken.ToString()); + graph.Assert(entityNode, key.ToUriNode(DefaultIri), dateTime.ToString("yyyy-MM-dd HH:mm:ss").ToLiteralNode()); + break; + case JTokenType.None: + case JTokenType.Object: + case JTokenType.Array: + case JTokenType.Constructor: + case JTokenType.Property: + case JTokenType.Comment: + case JTokenType.Integer: + case JTokenType.Float: + case JTokenType.String: + case JTokenType.Boolean: + case JTokenType.Null: + case JTokenType.Undefined: + case JTokenType.Raw: + case JTokenType.Bytes: + case JTokenType.Guid: + case JTokenType.Uri: + case JTokenType.TimeSpan: + default: + graph.Assert(entityNode, key.ToUriNode(DefaultIri), jToken.ToString().ToLiteralNode()); + break; + } + } }