Skip to content
Snippets Groups Projects

Hotfix/921-correctImportFile

Merged Marcel Nellesen requested to merge Hotfix/774-fixAnalyticsLogs into Hotfix/921-correctImportFile
4 files
+ 41
60
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -9,6 +9,7 @@ using NDesk.Options;
using Coscine.Configuration;
using System.Net;
using System.IO;
using VDS.RDF.Parsing.Contexts;
namespace DfgStructureParser
{
@@ -97,15 +98,19 @@ namespace DfgStructureParser
var subClassNode = g.CreateUriNode(new Uri("http://www.w3.org/2000/01/rdf-schema#subClassOf"));
ReplacePredicate(g, broaderTriples, subClassNode);
//remove notation count
var inpcompleteSuperClassTriples = g.GetTriplesWithPredicateObject(subClassNode, g.CreateUriNode(new Uri("http://www.dfg.de/dfg_profil/gremien/fachkollegien/faecher"))).ToList();
var dfgParentNode = g.CreateUriNode(new Uri("http://www.dfg.de/dfg_profil/gremien/fachkollegien/faecher/"));
ReplaceObject(g, inpcompleteSuperClassTriples, dfgParentNode);
// remove notation count
var notationTriples = g.GetTriples(new Uri("http://www.w3.org/2004/02/skos/core#notation")).ToList();
RemoveTriples(g, notationTriples);
//remove concept scheme
// remove concept scheme
var conceptSchemeTriples = g.GetTriples(new Uri("http://www.w3.org/2004/02/skos/core#ConceptScheme")).ToList();
RemoveTriples(g, conceptSchemeTriples);
//remove top concept
// remove top concept
var topConceptTriples = g.GetTriples(new Uri("http://www.w3.org/2004/02/skos/core#hasTopConcept")).ToList();
RemoveTriples(g, topConceptTriples);
@@ -151,6 +156,16 @@ namespace DfgStructureParser
}
}
public static void ReplaceObject(IGraph graph, List<Triple> triples, INode replacement)
{
foreach (var triple in triples)
{
var newTriple = new Triple(triple.Subject, triple.Predicate, replacement);
graph.Retract(triple);
graph.Assert(newTriple);
}
}
public static void RemoveTriples(IGraph graph, List<Triple> triples)
{
foreach (var triple in triples)
@@ -173,11 +188,25 @@ namespace DfgStructureParser
{
var parentNodeTriples = graph.GetTriplesWithSubject(new Uri("http://www.dfg.de/dfg_profil/gremien/fachkollegien/faecher")).ToList();
var properParentNode = graph.GetUriNode(new Uri("http://www.dfg.de/dfg_profil/gremien/fachkollegien/faecher/"));
// rebind triples to correct parent node
ReplaceSubject(graph, parentNodeTriples, properParentNode);
graph.Assert(properParentNode, graph.CreateUriNode(new Uri("http://purl.org/dc/elements/1.1/publisher")), graph.CreateUriNode(new Uri("http://www.dfg.de/")));
// remove unnecessary ascribing to schema
List<Triple> parentTypeTriples = graph.GetTriplesWithSubjectPredicate(graph.CreateUriNode(new Uri("http://www.dfg.de/dfg_profil/gremien/fachkollegien/faecher/")), graph.CreateUriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"))).ToList();
RemoveTriples(graph, parentTypeTriples);
// add parent node specific label and copyright notice
graph.Assert(properParentNode, graph.CreateUriNode(new Uri("http://purl.org/dc/terms/publisher")), graph.CreateUriNode(new Uri("http://www.dfg.de/")));
graph.Assert(properParentNode, graph.CreateUriNode(new Uri("http://purl.org/dc/terms/rights")), graph.CreateLiteralNode("Copyright © 2020 Deutsche Forschungsgemeinschaft"));
// add "@en" suffix to the title of the parent node
var titleTripleList = graph.GetTriplesWithSubjectPredicate(graph.CreateUriNode(new Uri("http://www.dfg.de/dfg_profil/gremien/fachkollegien/faecher/")), graph.CreateUriNode(new Uri("http://purl.org/dc/terms/title"))).ToList();
var titleTriple = titleTripleList[0];
LiteralNode titleNode = (LiteralNode)titleTriple.Object;
ILiteralNode newTitleNode = graph.CreateLiteralNode(titleNode.Value, "en");
ReplaceObject(graph, titleTripleList, newTitleNode);
var schemeNodeTriples = graph.GetTriples(new Uri("http://www.w3.org/2004/02/skos/core#inScheme")).ToList();
RemoveTriples(graph, schemeNodeTriples);
}
Loading