Skip to content
Snippets Groups Projects
Select Git revision
  • caae480fa3f9edfaa7bca169cf1492fd04784b86
  • main default protected
  • feature/add_assessment_repo
  • feature/documentation_flight_mechanic_assessment
  • feature/update_create_mission_docs
  • feature/update_mission_analysis_docs
  • documentation/initial_sizing_readonly
  • fix/missing-API-documentation-for-python-modules
  • fix/missing-api-documentation
  • feature/python_example_folder_update
  • beta_release protected
  • fix/revert-gitlab-config
  • fix/citationEcologicalAssessment
  • documentation/styleupdate
  • feature/lightMode
  • documentation/create_mission_xml
  • 28-empennage-design-update-documentation-according-to-workshop
  • documentation/fix-dot-equations
  • documentation/propulsion-design-module
  • documentation/gitlab-workflow
  • documentation/cost_estimation_update
  • 0.5.0
22 results

additional_software.md

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StructuralData.cs 3.87 KiB
    using Coscine.Configuration;
    using Coscine.Database.Models;
    using Coscine.Metadata;
    using VDS.RDF;
    using VDS.RDF.Query;
    
    namespace SQL2Linked
    {
        public abstract class StructuralData<S, T> where S : class where T : DatabaseModel<S>, new()
        {
            public T Model { get; init; }
            public ConsulConfiguration Configuration { get; init; }
            public RdfStoreConnector RdfStoreConnector { get; init; }
            public static string Prefix { get; set; }
            public readonly SparqlRemoteEndpoint QueryEndpoint;
    
            public StructuralData()
            {
                Configuration = new ConsulConfiguration();
                RdfStoreConnector = new RdfStoreConnector(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
                Model = new T();
                Prefix = Configuration.GetStringAndWait("coscine/global/epic/prefix");
                QueryEndpoint = new SparqlRemoteEndpoint(new Uri(string.Format("http://localhost:8890/sparql")));
            }
    
            public abstract IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<S> entries);
    
            public void Migrate(bool dummyMode)
            {
                var spacer = new string('-', 35);
                Console.WriteLine($"\n{spacer}\n{typeof(T).Name}\n{spacer}");
                var graphs = ConvertToLinkedData(Model.GetAll());
                if (!dummyMode)
                {
                    StoreGraphs(graphs);
                }
            }
    
            private void StoreGraphs(IEnumerable<IGraph> graphs)
            {
                foreach (var graph in graphs)
                {
                    Console.WriteLine($" ({graph.BaseUri})");
                    var exists = RdfStoreConnector.HasGraph(graph.BaseUri);
                    if (exists)
                    {
                        Console.WriteLine($" - Graph {graph.BaseUri} exists");
    
                        // Clear the existing graph from the store
                        RdfStoreConnector.ClearGraph(graph.BaseUri);
                        Console.WriteLine($" - Cleared Graph {graph.BaseUri}");
                    }
                    // Add the new graph to the store
                    RdfStoreConnector.AddGraph(graph);
                    Console.WriteLine($" - Graph {graph.BaseUri} added successfully");
                    Console.WriteLine();
                }
            }
            public void AssertToGraphUriNode(IGraph graph, string graphSubject, string graphPredicate, string graphObject)
            {
                graph.Assert(
                    new Triple(
                        graph.CreateUriNode(new Uri(graphSubject)),
                        graph.CreateUriNode(new Uri(graphPredicate)),
                        graph.CreateUriNode(new Uri(graphObject))
                    )
                );
            }
    
            public void AssertToGraphLiteralNode(IGraph graph, string graphSubject, string graphPredicate, string graphObject, Uri? objectType = null)
            {
                graph.Assert(
                    new Triple(
                        graph.CreateUriNode(new Uri(graphSubject)),
                        graph.CreateUriNode(new Uri(graphPredicate)),
                        graph.CreateLiteralNode(graphObject, objectType)
                    )
                );
            }
    
            public void AssertToGraphBlankAndUriNode(IGraph graph, string graphSubject, string graphPredicate, string graphObject)
            {
                graph.Assert(
                    new Triple(
                        graph.CreateBlankNode(graphSubject),
                        graph.CreateUriNode(new Uri(graphPredicate)),
                        graph.CreateUriNode(new Uri(graphObject))
                    )
                );
            }
    
            public void AssertToGraphBlankAndUriNode(IGraph graph, IBlankNode graphSubject, string graphPredicate, string graphObject)
            {
                graph.Assert(
                    new Triple(
                        graphSubject,
                        graph.CreateUriNode(new Uri(graphPredicate)),
                        graph.CreateUriNode(new Uri(graphObject))
                    )
                );
            }
    
        }
    }