Select Git revision
Ex2_Battery_Optimization_noSolutions.ipynb
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
RoleStructuralData.cs 2.52 KiB
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using VDS.RDF;
namespace SQL2Linked.Implementations
{
public class RoleStructuralData : StructuralData<Role, RoleModel>
{
public readonly string RoleUrlPrefix = "https://purl.org/coscine/roles";
public readonly Uri cosc = new("https://purl.org/coscine/");
public readonly Uri rdf = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
public readonly Uri org = new("http://www.w3.org/ns/org#");
public readonly Uri dcterms = new("http://purl.org/dc/terms/");
public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Role> entries)
{
var graphs = new List<IGraph>();
foreach (var entry in entries)
{
var roleGraphName = $"{RoleUrlPrefix}/{entry.Id}";
var graph = RdfStoreConnector.GetGraph(roleGraphName);
// check if a triple with a org:role already exists in the role graph
var getTriplesOrgRole = graph.GetTriplesWithObject(new Uri(org + "Role"));
if (!getTriplesOrgRole.Any())
{
AssertToGraphUriNode(graph, roleGraphName, rdf + "type", org + "Role");
Console.WriteLine($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {rdf}type {org}Role'. ");
}
else
{
Console.WriteLine($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri} {rdf}type {org}Role'. ");
}
// check if a triple with dcterms:title '{entry.DisplayName}' already exists in the role graph
var getTriplesDctermsTitle = graph.GetTriplesWithPredicate(new Uri(dcterms + "title"));
if (!getTriplesDctermsTitle.Any())
{
AssertToGraphLiteralNode(graph, roleGraphName, dcterms + "title", entry.DisplayName);
Console.WriteLine($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {dcterms}title {entry.DisplayName}'. ");
}
else
{
Console.WriteLine($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri} {dcterms}title {entry.DisplayName}'. ");
}
if (!getTriplesOrgRole.Any() || !getTriplesDctermsTitle.Any())
{
graphs.Add(graph);
}
}
return graphs;
}
}
}