Skip to content
Snippets Groups Projects

Release: Sprint/2022 12 :robot:

Merged Petar Hristov requested to merge dev into main
2 files
+ 45
4
Compare changes
  • Side-by-side
  • Inline
Files
2
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Metadata;
using VDS.RDF;
namespace SQL2Linked.Implementations
{
public class UserStructuralData : StructuralData<User, UserModel>
{
public readonly string UserUrlPrefix = "https://purl.org/coscine/users";
public readonly Uri RdfType = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
public readonly Uri FoafPerson = new("http://xmlns.com/foaf/0.1/Person");
public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<User> entries)
{
// ToDo: Implement
throw new NotImplementedException();
var graphs = new List<IGraph>();
foreach (var entry in entries)
{
var userGraphName = $"{UserUrlPrefix}/{entry.Id}";
var graph = RdfStoreConnector.GetGraph(userGraphName);
// check if a triple with a foaf:Person already exists in the user graph
var getTriples = graph.GetTriplesWithObject(FoafPerson);
if (!getTriples.Any())
{
// check if a user graph already exists
var exists = RdfStoreConnector.HasGraph(userGraphName);
if (!exists)
{
RdfStoreConnector.CreateNamedGraph(userGraphName);
}
graph.Assert(
new Triple(
graph.CreateBlankNode(),
graph.CreateUriNode(RdfType),
graph.CreateUriNode(FoafPerson)
)
);
graphs.Add(graph);
Console.WriteLine($"Will migrate user '{entry.DisplayName}' with id '{entry.Id}'.");
}
else
{
Console.WriteLine($"Will NOT migrate user '{entry.DisplayName}' with id '{entry.Id}'.");
}
}
return graphs;
}
}
}
\ No newline at end of file
}
Loading