예제 #1
0
        public void StorageStardogUpdateNamedGraphRemoveTriples()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/graph");
                stardog.SaveGraph(g);

                INode rdfType = g.CreateUriNode(new Uri(VDS.RDF.Parsing.RdfSpecsHelper.RdfType));

                stardog.UpdateGraph(g.BaseUri, null, g.GetTriplesWithPredicate(rdfType));
                g.Retract(g.GetTriplesWithPredicate(rdfType).ToList());

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/graph"));

                if (g.Triples.Count == h.Triples.Count)
                {
                    Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
                }
                else
                {
                    Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph");
                }
                Assert.IsFalse(h.GetTriplesWithPredicate(rdfType).Any(), "Retrieved Graph should not contain any rdf:type Triples");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #2
0
        public void StorageStardogDeleteNamedGraph()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/tempGraph");
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/tempGraph"));

                if (g.Triples.Count == h.Triples.Count)
                {
                    Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
                }
                else
                {
                    Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph");
                }

                stardog.DeleteGraph("http://example.org/tempGraph");
                Graph i = new Graph();
                stardog.LoadGraph(i, new Uri("http://example.org/tempGraph"));

                Assert.IsTrue(i.IsEmpty, "Retrieved Graph should be empty since it has been deleted");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #3
0
        public void StorageStardogSaveToNamedGraphOverwrite()
        {
            try
            {
                //Options.UseBomForUtf8 = false;
                Options.HttpDebugging = true;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/namedGraph");
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/namedGraph"));

                Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");

                Graph i = new Graph();
                i.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
                i.BaseUri = new Uri("http://example.org/namedGraph");
                stardog.SaveGraph(i);

                Graph j = new Graph();
                stardog.LoadGraph(j, "http://example.org/namedGraph");

                Assert.AreNotEqual(g, j, "Retrieved Graph should not be equal to overwritten Graph");
                Assert.AreEqual(i, j, "Retrieved Graph should be equal to Saved Graph");
            }
            finally
            {
                Options.HttpDebugging = false;
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #4
0
        public void StorageStardogReasoningByQuery1()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            Skip.If(stardog.Reasoning == StardogReasoningMode.DatabaseControlled,
                    "Version of Stardog being tested does not support configuring reasoning mode at connection level");

            Graph g = new Graph();

            g.LoadFromFile("resources\\stardog-reasoning-test.rdf");
            g.BaseUri = new Uri("http://www.reasoningtest.com/");
            stardog.SaveGraph(g);

            String query = "Select ?building where { ?building <http://www.reasoningtest.com#hasLocation> ?room.}";

            Console.WriteLine(query);
            Console.WriteLine();

            SparqlResultSet resultsWithReasoning = stardog.Query(query, true) as SparqlResultSet;

            Assert.NotNull(resultsWithReasoning);
            if (resultsWithReasoning != null)
            {
                Console.WriteLine("Results With Reasoning");
                TestTools.ShowResults(resultsWithReasoning);
                Assert.True(true, "Reasoning By Query OK !");
            }
            else
            {
                Assert.True(false, "Did not get a SPARQL Result Set as expected");
            }
        }
예제 #5
0
        public void StorageStardogSaveToDefaultGraph()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = null;
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, (Uri)null);
                Console.WriteLine("Retrieved " + h.Triples.Count + " Triple(s) from Stardog");

                if (g.Triples.Count == h.Triples.Count)
                {
                    Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
                }
                else
                {
                    Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph");
                }
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #6
0
        public void StorageStardogSaveToNamedGraphOverwrite()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            Graph g = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/namedGraph");
            stardog.SaveGraph(g);

            Graph h = new Graph();

            stardog.LoadGraph(h, new Uri("http://example.org/namedGraph"));

            Assert.Equal(g, h);

            Graph i = new Graph();

            i.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
            i.BaseUri = new Uri("http://example.org/namedGraph");
            stardog.SaveGraph(i);

            Graph j = new Graph();

            stardog.LoadGraph(j, "http://example.org/namedGraph");

            Assert.NotEqual(g, j);
            Assert.Equal(i, j);
        }
예제 #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strComunidade"></param>
        /// <param name="LearningObject"></param>
        /// <returns></returns>
        public static LearningObjectContextModel GetLearningObjectWithComunidade(String strComunidade, 
            String LearningObjectID)
        {
            LearningObjectContextModel modelToReturn = new LearningObjectContextModel();
            StardogConnector dog = new StardogConnector("http://*****:*****@"PREFIX onto: <http://www.owl-ontologies.com/OntoAdapt2.owl#>
                          SELECT *   WHERE { ");
            strb.AppendFormat(" onto:{0}  onto:LOLink ?t", LearningObjectID);
            //strb.AppendFormat(" onto:{0} onto:hasLOMediaType ?Media.", LearningObjectID);
            //strb.AppendFormat(" onto:{0} onto:LearningObjectFormat ?ObjFormat", LearningObjectID);
            strb.Append(".}");

            SparqlResultSet resultsNoReasoning = dog.Query(strb.ToString()) as SparqlResultSet;

            List<SparqlResult> lista = resultsNoReasoning.ToList();

            List<String> toReturn = new List<string>();

            foreach (SparqlResult rlt in lista)
            {
                //modelToReturn.LOLink = RemoveURLFromOntoloryResults(rlt[0].ToString());

            }
            return modelToReturn;
        }
예제 #8
0
        public void StorageStardogLoadNamedGraph()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            // Ensure graph exists
            Graph g = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/graph");
            stardog.SaveGraph(g);

            // Load it back from the store
            Graph h = new Graph();

            stardog.LoadGraph(h, new Uri("http://example.org/graph"));

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in h.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

            Assert.False(h.IsEmpty);
            Assert.Equal(g, h);
        }
예제 #9
0
        public void StorageStardogSparqlUpdate1()
        {
            StardogConnector stardog = StardogTests.GetConnection();
            IGraph           g;

            g = new Graph();
            stardog.LoadGraph(g, "http://example.org/stardog/update/1");
            if (!g.IsEmpty)
            {
                Console.WriteLine("Dropping graph");
                stardog.Update("DROP SILENT GRAPH <http://example.org/stardog/update/1>");
                Console.WriteLine("Dropped graph");
                Thread.Sleep(2500);
                g = new Graph();
                stardog.LoadGraph(g, "http://example.org/stardog/update/1");
                Assert.True(g.IsEmpty, "Graph should be empty after DROP command");
            }

            Console.WriteLine("Inserting data");
            stardog.Update(
                "INSERT DATA { GRAPH <http://example.org/stardog/update/1> { <http://x> <http://y> <http://z> } }");
            Console.WriteLine("Inserted data");
            g = new Graph();
            stardog.LoadGraph(g, "http://example.org/stardog/update/1");
            Assert.False(g.IsEmpty, "Graph should not be empty");
            Assert.Equal(1, g.Triples.Count);
        }
예제 #10
0
        public void StorageStardogReasoningByQuery2()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            if (stardog.Reasoning == StardogReasoningMode.DatabaseControlled)
            {
                throw new SkipTestException(
                          "Version of Stardog being tested does not support configuring reasoning mode at connection level");
            }

            Graph g = new Graph();

            g.LoadFromFile("resources\\stardog-reasoning-test.rdf");
            g.BaseUri = new Uri("http://www.reasoningtest.com/");
            stardog.SaveGraph(g);

            String query = "Select ?building where { ?building <http://www.reasoningtest.com#hasLocation> ?room.}";

            Console.WriteLine(query);
            Console.WriteLine();

            SparqlResultSet resultsWithNoReasoning = stardog.Query(query, false) as SparqlResultSet;

            Assert.Null(resultsWithNoReasoning);
            if (resultsWithNoReasoning != null)
            {
                Console.WriteLine("Results With No Reasoning");
                Assert.True(false, "There should not be any reasoning results !");
            }
            else
            {
                Assert.True(true, "No SPARQL Results returned ! Success.");
            }
        }
예제 #11
0
        public void StorageStardogSparqlUpdate3()
        {
            StardogConnector stardog = StardogTests.GetConnection();
            IGraph           g;

            Console.WriteLine("Dropping graph");
            stardog.Update("DROP SILENT GRAPH <http://example.org/stardog/update/3>");
            Console.WriteLine("Dropped graph");
            Thread.Sleep(2500);
            g = new Graph();
            stardog.LoadGraph(g, "http://example.org/stardog/update/3");
            Assert.True(g.IsEmpty, "Graph should be empty after DROP command");

            Console.WriteLine("Inserting data");
            IGraph newData = new Graph();

            newData.BaseUri = new Uri("http://example.org/stardog/update/3");
            newData.Assert(newData.CreateUriNode(new Uri("http://x")), newData.CreateUriNode(new Uri("http://y")),
                           newData.CreateUriNode(new Uri("http://z")));
            stardog.SaveGraph(newData);
            Console.WriteLine("Inserted data");
            g = new Graph();
            stardog.LoadGraph(g, "http://example.org/stardog/update/3");
            Assert.False(g.IsEmpty, "Graph should not be empty");
            Assert.Equal(1, g.Triples.Count);
        }
예제 #12
0
        public void StorageStardogIsReadyValidDb()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            Assert.True(stardog.IsReady);

            stardog.Dispose();
        }
예제 #13
0
        public void StorageStardogTransactionTest()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            stardog.Begin();
            stardog.Commit();
            stardog.Dispose();
        }
예제 #14
0
 /// <summary>
 /// Delete a graph by name from the database
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static bool DeleteGraph(Uri name)
 {
     using (StardogConnector dog = new StardogConnector(ConnectionString(), ConnectionDatabase(), ConnectionUser(), ConnectionPassword()))
     {
         dog.DeleteGraph(name);
     }
     return true;
 }
예제 #15
0
        public void StorageStardogIsReadyInvalidDb()
        {
            Skip.IfNot(TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseStardog), "Test Config marks Stardog as unavailable, test cannot be run");
            StardogConnector stardog = new StardogConnector(TestConfigManager.GetSetting(TestConfigManager.StardogServer),
                                                            "i_dont_exist",
                                                            TestConfigManager.GetSetting(TestConfigManager.StardogUser),
                                                            TestConfigManager.GetSetting(TestConfigManager.StardogPassword));

            Assert.False(stardog.IsReady);

            stardog.Dispose();
        }
예제 #16
0
        public void StorageStardogReasoningMode()
        {
            StardogConnector connector = StardogTests.GetConnection();

            if (connector.Reasoning != StardogReasoningMode.DatabaseControlled)
            {
                Assert.Pass();
            }
            else
            {
                connector.Reasoning = StardogReasoningMode.DL;
            }
        }
예제 #17
0
        public void StorageStardogReasoningQL()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            if (stardog.Reasoning == StardogReasoningMode.DatabaseControlled)
            {
                Assert.Inconclusive(
                    "Version of Stardog being tested does not support configuring reasoning mode at connection level");
            }

            Graph g = new Graph();

            g.LoadFromFile("resources\\InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/reasoning");
            stardog.SaveGraph(g);

            String query = "PREFIX rdfs: <" + NamespaceMapper.RDFS +
                           "> SELECT * WHERE { { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } UNION { GRAPH <http://example.org/reasoning> { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } } }";

            Console.WriteLine(query);
            Console.WriteLine();

            SparqlResultSet resultsNoReasoning = stardog.Query(query) as SparqlResultSet;

            if (resultsNoReasoning != null)
            {
                Console.WriteLine("Results without Reasoning");
                TestTools.ShowResults(resultsNoReasoning);
            }
            else
            {
                Assert.Fail("Did not get a SPARQL Result Set as expected");
            }

            stardog.Reasoning = StardogReasoningMode.QL;
            SparqlResultSet resultsWithReasoning = stardog.Query(query) as SparqlResultSet;

            if (resultsWithReasoning != null)
            {
                Console.WriteLine("Results with Reasoning");
                TestTools.ShowResults(resultsWithReasoning);
            }
            else
            {
                Assert.Fail("Did not get a SPARQL Result Set as expected");
            }

            Assert.IsTrue(resultsWithReasoning.Count >= resultsNoReasoning.Count,
                          "Reasoning should yield as many if not more results");
        }
예제 #18
0
        public void StorageStardogReasoningQL()
        {
            try
            {
                //Options.UseBomForUtf8 = false;
                Options.HttpDebugging = true;

                StardogConnector stardog = StardogTests.GetConnection();;

                Graph g = new Graph();
                g.LoadFromFile("InferenceTest.ttl");
                g.BaseUri = new Uri("http://example.org/reasoning");
                stardog.SaveGraph(g);

                String query = "PREFIX rdfs: <" + NamespaceMapper.RDFS + "> SELECT * WHERE { { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } UNION { GRAPH <http://example.org/reasoning> { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } } }";
                Console.WriteLine(query);
                Console.WriteLine();

                SparqlResultSet resultsNoReasoning = stardog.Query(query) as SparqlResultSet;
                if (resultsNoReasoning != null)
                {
                    Console.WriteLine("Results without Reasoning");
                    TestTools.ShowResults(resultsNoReasoning);
                }
                else
                {
                    Assert.Fail("Did not get a SPARQL Result Set as expected");
                }

                stardog.Reasoning = StardogReasoningMode.QL;
                SparqlResultSet resultsWithReasoning = stardog.Query(query) as SparqlResultSet;
                if (resultsWithReasoning != null)
                {
                    Console.WriteLine("Results with Reasoning");
                    TestTools.ShowResults(resultsWithReasoning);
                }
                else
                {
                    Assert.Fail("Did not get a SPARQL Result Set as expected");
                }

                Assert.IsTrue(resultsWithReasoning.Count >= resultsNoReasoning.Count, "Reasoning should yield as many if not more results");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
                Options.HttpDebugging = false;
            }
        }
예제 #19
0
        public void StorageStardogReasoningMode()
        {
            StardogConnector connector = StardogTests.GetConnection();

            if (connector.Reasoning != StardogReasoningMode.DatabaseControlled)
            {
                return;
            }
            else
            {
                Assert.Throws <RdfStorageException>(() =>
                                                    connector.Reasoning = StardogReasoningMode.DL
                                                    );
            }
        }
예제 #20
0
        public void StorageStardogLoadDefaultGraph()
        {
            StardogConnector stardog = StardogTests.GetConnection();;
            Graph            g       = new Graph();

            stardog.LoadGraph(g, (Uri)null);

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

            Assert.IsFalse(g.IsEmpty);
        }
예제 #21
0
        public void StorageStardogTransactionTest()
        {
            try
            {
                Options.HttpDebugging = true;

                StardogConnector stardog = StardogTests.GetConnection();;
                stardog.Begin();
                stardog.Commit();
                stardog.Dispose();
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
예제 #22
0
        public void StorageStardogLoadNamedGraph()
        {
            StardogConnector stardog = StardogTests.GetConnection();;
            Graph            g       = new Graph();

            stardog.LoadGraph(g, new Uri("http://example.org/graph"));

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

            Assert.IsFalse(g.IsEmpty);
        }
예제 #23
0
        public void StorageStardogAmpersandsInDataTest()
        {
            try
            {
                Options.HttpDebugging = true;

                StardogConnector stardog = StardogTests.GetConnection();;

                //Save the Graph
                Graph  g        = new Graph();
                String fragment = "@prefix : <http://example.org/> . [] :string \"This has & ampersands in it\" .";
                g.LoadFromString(fragment);
                g.BaseUri = new Uri("http://example.org/ampersandGraph");

                Console.WriteLine("Original Graph:");
                TestTools.ShowGraph(g);

                stardog.SaveGraph(g);

                //Retrieve and check it round trips
                Graph h = new Graph();
                stardog.LoadGraph(h, g.BaseUri);

                Console.WriteLine("Graph as retrieved from Stardog:");
                TestTools.ShowGraph(h);

                Assert.AreEqual(g, h, "Graphs should be equal");

                //Now try to delete the data from this Graph
                GenericUpdateProcessor processor = new GenericUpdateProcessor(stardog);
                SparqlUpdateParser     parser    = new SparqlUpdateParser();
                processor.ProcessCommandSet(parser.ParseFromString("WITH <http://example.org/ampersandGraph> DELETE WHERE { ?s ?p ?o }"));

                Graph i = new Graph();
                stardog.LoadGraph(i, g.BaseUri);

                Console.WriteLine("Graph as retrieved after the DELETE WHERE:");
                TestTools.ShowGraph(i);

                Assert.AreNotEqual(g, i, "Graphs should not be equal");
                Assert.AreNotEqual(h, i, "Graphs should not be equal");
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
예제 #24
0
        public void StorageStardogSaveToNamedGraph()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/graph");
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/graph"));

                Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #25
0
        public void StorageStardogSparqlUpdate5()
        {
            StardogConnector stardog = StardogTests.GetConnection();
            IGraph           g;

            // Begin a transaction
            stardog.Begin();

            // Try to make an update
            stardog.Update(
                "DROP SILENT GRAPH <http://example.org/stardog/update/5>; INSERT DATA { GRAPH <http://example.org/stardog/update/5> { <http://x> <http://y> <http://z> } }");

            // Rollback the transaction
            stardog.Rollback();

            g = new Graph();
            stardog.LoadGraph(g, "http://example.org/stardog/update/5");
            Assert.False(g.IsEmpty, "Graph should not be empty after update");
            Assert.Equal(1, g.Triples.Count);

            stardog.Dispose();
        }
예제 #26
0
        public void StorageStardogLoadDefaultGraph()
        {
            StardogConnector stardog = StardogTests.GetConnection();
            Graph            g       = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            stardog.SaveGraph(g);

            Graph h = new Graph();

            stardog.LoadGraph(h, (Uri)null);

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in h.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

            Assert.False(h.IsEmpty);
        }
예제 #27
0
        public void StorageStardogSaveToNamedGraph2()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();

                Graph g = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                Uri u = new Uri("http://example.org/graph/" + DateTime.Now.Ticks);
                g.BaseUri = u;
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, u);

                Assert.Equal(g, h);
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #28
0
        /// <summary>
        /// Tries to load a Generic IO Manager based on information from the Configuration Graph
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Output Object</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            IGenericIOManager manager = null;
            obj = null;

            String server, user, pwd, store;
            bool isAsync;

            Object temp;
            INode storeObj;

            //Create the URI Nodes we're going to use to search for things
            INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer),
                  propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase),
                  propStore = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore),
                  propAsync = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAsync);

            switch (targetType.FullName)
            {
                case AllegroGraph:
                    //Get the Server, Catalog and Store
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    String catalog = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog));
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;

                    //Get User Credentials
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                    if (user != null && pwd != null)
                    {
                        manager = new AllegroGraphConnector(server, catalog, store, user, pwd);
                    }
                    else
                    {
                        manager = new AllegroGraphConnector(server, catalog, store);
                    }
                    break;

                case DatasetFile:
                    //Get the Filename and whether the loading should be done asynchronously
                    String file = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile));
                    if (file == null) return false;
                    file = ConfigurationLoader.ResolvePath(file);
                    isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false);
                    manager = new DatasetFileManager(file, isAsync);
                    break;

                case Dydra:
                    //Get the Account Name and Store
                    String account = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog));
                    if (account == null) return false;
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;

                    //Get User Credentials
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                    if (user != null)
                    {
                        manager = new DydraConnector(account, store, user);
                    }
                    else
                    {
                        manager = new DydraConnector(account, store);
                    }
                    break;

                case FourStore:
                    //Get the Server and whether Updates are enabled
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableUpdates), true);
                    manager = new FourStoreConnector(server, enableUpdates);
                    break;

                case Fuseki:
                    //Get the Server URI
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    manager = new FusekiConnector(server);
                    break;

                case InMemory:
                    //Get the Dataset/Store
                    INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset));
                    if (datasetObj != null)
                    {
                        temp = ConfigurationLoader.LoadObject(g, datasetObj);
                        if (temp is ISparqlDataset)
                        {
                            manager = new InMemoryManager((ISparqlDataset)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface");
                        }
                    }
                    else
                    {
                        //If no dnr:usingDataset try dnr:usingStore instead
                        storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore));
                        if (storeObj != null)
                        {
                            temp = ConfigurationLoader.LoadObject(g, storeObj);
                            if (temp is IInMemoryQueryableStore)
                            {
                                manager = new InMemoryManager((IInMemoryQueryableStore)temp);
                            }
                            else
                            {
                                throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface");
                            }
                        }
                        else
                        {
                            //If no dnr:usingStore either then create a new empty store
                            manager = new InMemoryManager();
                        }
                    }
                    break;

                case Joseki:
                    //Get the Query and Update URIs
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    String queryService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryPath));
                    if (queryService == null) return false;
                    String updateService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdatePath));
                    if (updateService == null)
                    {
                        manager = new JosekiConnector(server, queryService);
                    }
                    else
                    {
                        manager = new JosekiConnector(server, queryService, updateService);
                    }
                    break;

                case ReadOnly:
                    //Get the actual Manager we are wrapping
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                    temp = ConfigurationLoader.LoadObject(g, storeObj);
                    if (temp is IGenericIOManager)
                    {
                        manager = new ReadOnlyConnector((IGenericIOManager)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IGenericIOManager interface");
                    }
                    break;

                case ReadOnlyQueryable:
                    //Get the actual Manager we are wrapping
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                    temp = ConfigurationLoader.LoadObject(g, storeObj);
                    if (temp is IQueryableGenericIOManager)
                    {
                        manager = new QueryableReadOnlyConnector((IQueryableGenericIOManager)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableGenericIOManager interface");
                    }
                    break;

                case Sesame:
                case SesameV5:
                case SesameV6:
                    //Get the Server and Store ID
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                    if (user != null && pwd != null)
                    {
                        manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd });
                    }
                    else
                    {
                        manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store });
                    }
                    break;

                case Sparql:
                    //Get the Endpoint URI or the Endpoint
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpointUri));

                    //What's the load mode?
                    String loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode));
                    SparqlConnectorLoadMethod loadMode = SparqlConnectorLoadMethod.Construct;
                    if (loadModeRaw != null)
                    {
                        try
                        {
#if SILVERLIGHT
                            loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw, false);
#else
                            loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw);
#endif
                        }
                        catch
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid");
                        }
                    }

                    if (server == null)
                    {
                        INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint));
                        if (endpointObj == null) return false;
                        temp = ConfigurationLoader.LoadObject(g, endpointObj);
                        if (temp is SparqlRemoteEndpoint)
                        {
                            manager = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint");
                        }
                    }
                    else
                    {
                        //Are there any Named/Default Graph URIs
                        IEnumerable<Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri))
                                                     where def.NodeType == NodeType.Uri
                                                     select ((IUriNode)def).Uri;
                        IEnumerable<Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyNamedGraphUri))
                                                       where named.NodeType == NodeType.Uri
                                                       select ((IUriNode)named).Uri;
                        if (defGraphs.Any() || namedGraphs.Any())
                        {
                            manager = new SparqlConnector(new SparqlRemoteEndpoint(new Uri(server), defGraphs, namedGraphs), loadMode);
                        }
                        else
                        {
                            manager = new SparqlConnector(new Uri(server), loadMode);
                        }                        
                    }
                    break;

                case SparqlHttpProtocol:
                    //Get the Service URI
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    manager = new SparqlHttpProtocolConnector(new Uri(server));
                    break;

                case Stardog:
                    //Get the Server and Store
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;

                    //Get User Credentials
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                    //Get Reasoning Mode
                    StardogReasoningMode reasoning = StardogReasoningMode.None;
                    String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode));
                    if (mode != null)
                    {
                        try
                        {
                            reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode);
                        }
                        catch
                        {
                            reasoning = StardogReasoningMode.None;
                        }
                    }

                    if (user != null && pwd != null)
                    {
                        manager = new StardogConnector(server, store, reasoning, user, pwd);
                    }
                    else
                    {
                        manager = new StardogConnector(server, store, reasoning);
                    }
                    break;

                case Talis:
                    //Get the Store Name and User credentials
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                    if (user != null && pwd != null)
                    {
                        manager = new TalisPlatformConnector(store, user, pwd);
                    }
                    else
                    {
                        manager = new TalisPlatformConnector(store);
                    }
                    break;
            }

            obj = manager;
            return (manager != null);
        }
예제 #29
0
        public List<LearningObjectContextModel> GetSugestaoObjetos(string UserID)
        {
            if(hardware == null) return null;
            StardogConnector dog = new StardogConnector("http://*****:*****@"PREFIX onto: <http://www.owl-ontologies.com/OntoAdapt2.owl#> ");
            strb.Append(@"SELECT *  { ");
            // tipo de conexão
            strb.AppendFormat("onto:{0} onto:DeviceTypeConnection  \"{1}\". ", hardware.model_name, hardware.type_Connection);
            strb.Append("?s onto:hasLOMediaType ?MediaType.");
            strb.Append("}");

            SparqlResultSet resultsNoReasoning = dog.Query(strb.ToString()) as SparqlResultSet;

            List<SparqlResult> lista = resultsNoReasoning.ToList();

            //se não achou objetos com formatos disponivel pega qualquer um e formata.

            return LearningObjectsList(lista);
        }
예제 #30
0
 /// <summary>
 /// Delete and insert the provided graphs
 /// </summary>
 /// <param name="name">URI of graph; leave null for default graph</param>
 /// <param name="gInsert">Graph object containing data to insert</param>
 /// <param name="gDelete">Graph object containing data to delete</param>
 /// <returns></returns>
 public static bool UpdateGraph(Uri name, Graph gInsert, Graph gDelete)
 {
     using (StardogConnector dog = new StardogConnector(ConnectionString(), ConnectionDatabase(), ConnectionUser(), ConnectionPassword()))
     {
         dog.UpdateGraph(name, gInsert.Triples, gDelete.Triples);
     }
     return true;
 }
예제 #31
0
    /// <summary>
    /// Execute insert or delete SPARQL queries against Stardog;
    /// separate multiple statements with a semicolon
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    public static bool Update(string command)
    {
        using (StardogConnector dog = new StardogConnector(ConnectionString(), ConnectionDatabase(), ConnectionUser(), ConnectionPassword()))
        {

            try
            {

                dog.Begin(); // wrap all the statements in this command into one transaction; otherwise stardog will run them as separate transactions

                GenericUpdateProcessor processor = new GenericUpdateProcessor(dog);

                SparqlUpdateParser parser = new SparqlUpdateParser();

                processor.ProcessCommandSet(parser.ParseFromString(Prefixes() + command));

                dog.Commit();

                return true;

            }
            catch (Exception err)
            {

                try
                {
                    dog.Rollback();
                }
                catch { }

                throw err;

            }

        }
    }
예제 #32
0
    /// <summary>
    /// Exdecute a SPARQL query and return the results
    /// </summary>
    /// <param name="command">Your SPARQL query</param>
    /// <param name="rm">Reasoning mode; default is none</param>
    /// <returns></returns>
    public static SparqlResultSet Query(string command, StardogReasoningMode rm = StardogReasoningMode.None)
    {
        using (StardogConnector dog = new StardogConnector(ConnectionString(), ConnectionDatabase(), rm, ConnectionUser(), ConnectionPassword()))
        {
            Object results = dog.Query(Prefixes() + command);

            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;
                return rset;
            }
            else
            {
                throw new Exception("query failed " + command);

                return null;
            }
        }
    }
예제 #33
0
        private List<LearningObjectContextModel> LearningObjectsList(List<SparqlResult> lista)
        {
            List<LearningObjectContextModel> toReturn = new List<LearningObjectContextModel>();

            foreach (SparqlResult rlt in lista)
            {
                StardogConnector dog = new StardogConnector("http://*****:*****@"PREFIX onto: <http://www.owl-ontologies.com/OntoAdapt2.owl#> ");
                strb.Append(@"SELECT ?x ?Idiom ?F { ");
                // tipo de conexão
                strb.Append(" OPTIONAL {");
                strb.AppendFormat("onto:{0} onto:LOLink  ?x ", RemoveURLFromOntoloryResults(rlt[0].ToString()));
                strb.Append(".}");
                strb.Append(" OPTIONAL {");
                strb.AppendFormat("onto:{0} onto:LO_Idiom ?Idiom ", RemoveURLFromOntoloryResults(rlt[0].ToString()));
                strb.Append(".}");
                strb.Append(" OPTIONAL {");
                strb.AppendFormat("onto:{0} onto:LearningObjectFormat ?F", RemoveURLFromOntoloryResults(rlt[0].ToString()));
                strb.Append(".}");
                strb.Append(".}");

                SparqlResultSet resultsNoReasoning = dog.Query(strb.ToString()) as SparqlResultSet;
                List<SparqlResult> listaObjs = resultsNoReasoning.ToList();
                foreach (SparqlResult rltLO in listaObjs)
                {
                    LearningObjectContextModel lo = new LearningObjectContextModel();
                    //lo.LOLink = rltLO[0].ToString();
                    toReturn.Add(lo);
                }

            }
            return toReturn;
        }
예제 #34
0
    /// <summary>
    /// Execute insert or delete SPARQL queries against Stardog;
    /// separate multiple statements with a semicolon
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    public static bool Update(string command)
    {
        using (StardogConnector dog = new StardogConnector(ConnectionString(), ConnectionDatabase(), ConnectionUser(), ConnectionPassword()))
        {

            GenericUpdateProcessor processor = new GenericUpdateProcessor(dog);

            SparqlUpdateParser parser = new SparqlUpdateParser();

            processor.ProcessCommandSet(parser.ParseFromString(Prefixes() + command));

        }

        return true;
    }
예제 #35
0
        public static List<String> ListAllLearningObjectWithComunidade(String strComunidade)
        {
            StardogConnector dog = new StardogConnector("http://*****:*****@"PREFIX onto: <http://www.owl-ontologies.com/OntoAdapt2.owl#> ");
            strb.Append("       SELECT ?Estudantes  { ?Estudantes onto:ComunidadeLO \"" + strComunidade);
            strb.Append("\".}");

            SparqlResultSet resultsNoReasoning = dog.Query(strb.ToString()) as SparqlResultSet;

            List<SparqlResult> lista = resultsNoReasoning.ToList();

            List<String> toReturn = new List<string>();
            foreach (SparqlResult rlt in lista)
            {
                toReturn.Add(RemoveURLFromOntoloryResults(rlt[0].ToString()));
            }
            return toReturn;
        }
예제 #36
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strComunidade"></param>
        /// <param name="LearningObject"></param>
        /// <returns></returns>
        public static HardwareModel GetUserDeviceWithComunidade(String strComunidade, String User)
        {
            HardwareModel modelToReturn = new HardwareModel();
            StardogConnector dog = new StardogConnector("http://*****:*****@"PREFIX onto: <http://www.owl-ontologies.com/OntoAdapt2.owl#> ");
            strb.Append(@"SELECT ?Dev  { ");
            strb.AppendFormat("onto:{0} onto:ComunidadeMoodle  \"{1}\". ", User, strComunidade);
            strb.AppendFormat("onto:{0} onto:hasDevice ?Dev. ", User);
            //strb.Append("?Dev onto:DeviceID ?DevID");
            strb.Append("}");

            SparqlResultSet resultsNoReasoning = dog.Query(strb.ToString()) as SparqlResultSet;

            List<SparqlResult> lista = resultsNoReasoning.ToList();

            List<String> toReturn = new List<string>();

            foreach (SparqlResult rlt in lista)
            {
                modelToReturn.Device_ID = RemoveURLFromOntoloryResults(rlt[0].ToString());
            }
            return modelToReturn;
        }