Skip to content

Commit

Permalink
Fix how datetime is generated
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldelaparra committed Oct 25, 2020
1 parent 8ed6b5a commit 0d605c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions ModelToRdf.Extensions/RdfExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using VDS.RDF;
using VDS.RDF.Nodes;

namespace ModelToRdf.Extensions
{
Expand Down
44 changes: 32 additions & 12 deletions ModelToRdf/ModelToRdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,25 +49,44 @@ internal static void ToRDFGraph(this IDictionary<string, JToken> 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;
}

}
}

Expand Down

0 comments on commit 0d605c4

Please sign in to comment.