Skip to content
Snippets Groups Projects
Commit abfaaef3 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Fix: Speedup listing of metadata

parent f5f77526
Branches
Tags
No related merge requests found
Pipeline #837305 passed
......@@ -20,6 +20,8 @@ namespace SQL2Linked.Implementations
private ProjectResourceModel ProjectResourceModel = new ProjectResourceModel();
private LicenseModel LicenseModel = new LicenseModel();
private readonly Dictionary<string, string> _targetClassMap = new Dictionary<string, string>();
// Override to also receive deleted resources
public override IEnumerable<Resource> GetAll()
{
......@@ -134,11 +136,13 @@ namespace SQL2Linked.Implementations
AssertToGraphLiteralNode(graph, resourceGraphName, cosc + "terms/resource#deleted", entry.Deleted.ToString().ToLower(), new Uri("http://www.w3.org/2001/XMLSchema#boolean"));
Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{resourceGraphName} {cosc}terms/resource#deleted {entry.Deleted}'. ");
var targetClass = GetTargetClass(entry);
SparqlParameterizedString cmdString = new SparqlParameterizedString
{
CommandText = "SELECT DISTINCT ?g " +
"WHERE {" +
"GRAPH ?g { ?s ?p ?o } . " +
"GRAPH ?g { ?s a <" + targetClass + "> } . " +
"FILTER(contains(STR(?g), \"" + resourceHandleName + "@\"))" +
"}"
};
......@@ -188,5 +192,36 @@ namespace SQL2Linked.Implementations
return graphs;
}
/// <summary>
/// Since Application Profile URL does not have to be the targetClass, resolve it first
/// </summary>
/// <param name="entry"></param>
/// <returns></returns>
private string GetTargetClass(Resource entry)
{
if (_targetClassMap.ContainsKey(entry.ApplicationProfile))
{
return _targetClassMap[entry.ApplicationProfile];
}
var targetClassCmdString = new SparqlParameterizedString
{
CommandText = "SELECT DISTINCT ?targetClass " +
"WHERE { @applicationProfile <http://www.w3.org/ns/shacl#targetClass> ?targetClass }"
};
targetClassCmdString.SetUri("applicationProfile", new Uri(entry.ApplicationProfile));
var targetClassResultSet = QueryEndpoint.QueryWithResultSet(targetClassCmdString.ToString());
var targetClass = entry.ApplicationProfile;
foreach (var result in targetClassResultSet)
{
targetClass = result[0].ToString();
}
_targetClassMap.Add(entry.ApplicationProfile, targetClass);
return targetClass;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment