Skip to content
Snippets Groups Projects
Commit c96671f7 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Merge branch 'dev' into 'main'

Release: Sprint/2022 12 :robot:

See merge request !8
parents 32bc81eb 868940b1
No related branches found
No related tags found
1 merge request!8Release: Sprint/2022 12 :robot:
Pipeline #761874 passed
...@@ -6,10 +6,67 @@ namespace SQL2Linked.Implementations ...@@ -6,10 +6,67 @@ namespace SQL2Linked.Implementations
{ {
public class ResourceTypeStructuralData : StructuralData<ResourceType, ResourceTypeModel> public class ResourceTypeStructuralData : StructuralData<ResourceType, ResourceTypeModel>
{ {
public readonly string ResourceTypeUrlPrefix = "https://purl.org/coscine/resourcetype";
public readonly Uri RdfType = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
public readonly Uri DcatDataService = new ("http://www.w3.org/ns/dcat#DataService");
public readonly Uri dctermsTitle = new("http://purl.org/dc/terms/title");
public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<ResourceType> entries) public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<ResourceType> entries)
{ {
// ToDo: Implement
throw new NotImplementedException(); var graphs = new List<IGraph>();
foreach (var entry in entries)
{
var resourceTypeGraphName = $"{ResourceTypeUrlPrefix}/{entry.Id}";
var graph = RdfStoreConnector.GetGraph(resourceTypeGraphName);
// check if a triple with a dcat:DataService already exists in the resourcetype graph
var getTriplesDcatDataService = graph.GetTriplesWithObject(DcatDataService);
if (!getTriplesDcatDataService.Any())
{
graph.Assert(
new Triple(
graph.CreateUriNode(new Uri(resourceTypeGraphName)),
graph.CreateUriNode(RdfType),
graph.CreateUriNode(DcatDataService)
)
);
Console.WriteLine($"For resource type '{entry.DisplayName}' will migrate triple '{graph.BaseUri}' a dcat:DataService. ");
}
else
{
Console.WriteLine($"For resource type '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri}' a dcat:DataService. ");
}
// check if a triple with dcterms:title '{entry.DisplayName}' already exists in the role graph
var getTriplesDctermsTitle = graph.GetTriplesWithPredicate(dctermsTitle);
if (!getTriplesDctermsTitle.Any())
{
graph.Assert(
new Triple(
graph.CreateUriNode(new Uri(resourceTypeGraphName)),
graph.CreateUriNode(dctermsTitle),
graph.CreateLiteralNode(entry.DisplayName)
)
);
Console.WriteLine($"For resource type '{entry.DisplayName}' will migrate triple '{graph.BaseUri}' dcterms:title '{entry.DisplayName}'. ");
} }
else
{
Console.WriteLine($"For resource type '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri}' dcterms:title '{entry.DisplayName}'. ");
} }
if (!getTriplesDcatDataService.Any() || !getTriplesDctermsTitle.Any())
{
graphs.Add(graph);
}
}
return graphs;
}
}
} }
\ No newline at end of file
...@@ -6,10 +6,65 @@ namespace SQL2Linked.Implementations ...@@ -6,10 +6,65 @@ namespace SQL2Linked.Implementations
{ {
public class RoleStructuralData : StructuralData<Role, RoleModel> public class RoleStructuralData : StructuralData<Role, RoleModel>
{ {
public readonly string RoleUrlPrefix = "https://purl.org/coscine/roles";
public readonly Uri RdfType = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
public readonly Uri orgRole = new("http://www.w3.org/ns/org#Role");
public readonly Uri dctermsTitle = new("http://purl.org/dc/terms/title");
public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Role> entries) public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Role> entries)
{ {
// ToDo: Implement var graphs = new List<IGraph>();
throw new NotImplementedException();
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(orgRole);
if (!getTriplesOrgRole.Any())
{
graph.Assert(
new Triple(
graph.CreateUriNode(new Uri(roleGraphName)),
graph.CreateUriNode(RdfType),
graph.CreateUriNode(orgRole)
)
);
Console.WriteLine($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri}' a org:Role. ");
}
else
{
Console.WriteLine($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri}' a org:Role. ");
}
// check if a triple with dcterms:title '{entry.DisplayName}' already exists in the role graph
var getTriplesDctermsTitle = graph.GetTriplesWithPredicate(dctermsTitle);
if (!getTriplesDctermsTitle.Any())
{
graph.Assert(
new Triple(
graph.CreateUriNode(new Uri(roleGraphName)),
graph.CreateUriNode(dctermsTitle),
graph.CreateLiteralNode(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;
} }
} }
} }
\ No newline at end of file
...@@ -25,17 +25,9 @@ namespace SQL2Linked.Implementations ...@@ -25,17 +25,9 @@ namespace SQL2Linked.Implementations
if (!getTriples.Any()) if (!getTriples.Any())
{ {
// check if a user graph already exists
var exists = RdfStoreConnector.HasGraph(userGraphName);
if (!exists)
{
RdfStoreConnector.CreateNamedGraph(userGraphName);
}
graph.Assert( graph.Assert(
new Triple( new Triple(
graph.CreateBlankNode(), graph.CreateUriNode(new Uri(userGraphName)),
graph.CreateUriNode(RdfType), graph.CreateUriNode(RdfType),
graph.CreateUriNode(FoafPerson) graph.CreateUriNode(FoafPerson)
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment