static void Main(string[] args) { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterCallingAssembly(); var store = StoreFactory.CreateStore("provider=dotnetrdf"); var model = store.GetModel(new Uri("http://inrupt.net/model")); var moy = model.CreateResource <Person>(new Uri("http://moisesj.inrupt.net")); moy.FirstName = "Moises"; moy.LastName = "Jaramillo"; moy.Birtday = DateTime.Parse("1/1/1900"); moy.Commit(); var liz = model.CreateResource <Person>(new Uri("http://lizadj.inrupt.net")); liz.FirstName = "Elizabeth"; liz.LastName = "Daly"; liz.Birtday = DateTime.Parse("2/2/1900"); liz.Commit(); QueryFromTheStore(model); }
/// <summary>Activates the interaction between the Trinity library and an active Virtuoso database.</summary> public void Initialise() { StoreFactory.LoadProvider <VirtuosoStoreProvider>(); Store.InitializeFromConfiguration(Path.Combine(Environment.CurrentDirectory, "ontologies.config")); OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterCallingAssembly(); }
public void Setup() { Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterAssembly(Assembly.GetExecutingAssembly()); }
static void Main() { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterCallingAssembly(); // Load the virtuoso store provider StoreFactory.LoadProvider <VirtuosoStoreProvider>(); // Connect to the virtuoso store IStore store = StoreFactory.CreateStore("provider=virtuoso;host=127.0.0.1;port=1111;uid=dba;pw=dba;rule=urn:example/ruleset"); store.InitializeFromConfiguration(Path.Combine(Environment.CurrentDirectory, "ontologies.config")); // Uncomment to log all executed queries to the console. // store.Log = (query) => Console.WriteLine(query); // A model is where we collect resources logically belonging together Model = store.GetModel(new Uri("http://example.com/model")); Model.Clear(); Drug ibu = Model.CreateResource <Drug>(new Uri("https://www.hexal.de/patienten/produkte/IbuHEXAL-akut")); ibu.ActiveIngredient = "Ibuprophene"; ibu.ProprietaryName = "IbuHEXAL akut"; ibu.Commit(); Patient john = Model.CreateResource <Patient>(new Uri("http://example.com/patient/john")); john.FirstName = "John"; john.LastName = "Doe"; john.BirthDate = new DateTime(2000, 1, 1); john.Drugs.Add(ibu); john.Commit(); Person alice = Model.CreateResource <Person>(new Uri("http://example.com/person/alice")); alice.FirstName = "Alice"; alice.LastName = "Doe"; alice.BirthDate = new DateTime(2000, 1, 1); alice.Commit(); var theDoeFamily = from person in Model.AsQueryable <Person>(true) where person.LastName.StartsWith("d", StringComparison.InvariantCultureIgnoreCase) select person; foreach (var p in theDoeFamily) { Console.WriteLine($"Name: {p.FirstName} {p.LastName} Birthdate: {p.BirthDate}"); } Console.WriteLine(); Console.WriteLine("Press ANY key to close.."); Console.ReadLine(); }
public void Setup() { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterAssembly(Assembly.GetExecutingAssembly()); TinyVirtuoso.TinyVirtuoso v = new TinyVirtuoso.TinyVirtuoso(Environment.CurrentDirectory); instance = v.GetOrCreateInstance("NUnit"); instance.Start(true); ConnectionString = instance.GetTrinityConnectionString(); HostAndPort = instance.Configuration.Parameters.ServerPort; }
public void Setup() { Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); OntologyDiscovery.AddAssembly(typeof(AbstractMappingClass).Assembly); MappingDiscovery.RegisterAssembly(typeof(AbstractMappingClass).Assembly); //ConnectionString = _instance.GetTrinityConnectionString(); //HostAndPort = _instance.Configuration.Parameters.ServerPort; }
static void Main() { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterCallingAssembly(); // Create a temporary memory store. IStore store = StoreFactory.CreateStore("provider=dotnetrdf"); // Uncomment to log all executed queries to the console. // store.Log = (query) => Console.WriteLine(query); // A model is where we collect resources logically belonging together Model = store.GetModel(new Uri("http://example.com/model")); Person john = Model.CreateResource <Person>(new Uri("http://example.com/person/john")); john.FirstName = "John"; john.LastName = "Doe"; john.BirthDate = new DateTime(2010, 1, 1); john.Commit(); Person alice = Model.CreateResource <Person>(new Uri("http://example.com/person/alice")); alice.FirstName = "Alice"; alice.LastName = "Doe"; alice.BirthDate = new DateTime(2000, 1, 1); alice.Commit(); Person alice2 = Model.GetResource <Person>(new Uri("http://example.com/person/alice")); var john2 = Model.GetResource <Person>(new Uri("http://example.com/person/john")) as Person; alice2.KnownPersons.Add(john2); alice2.Commit(); john2.Commit(); var theDoeFamily = from person in Model.AsQueryable <Person>() where person.LastName.StartsWith("d", StringComparison.InvariantCultureIgnoreCase) select person; foreach (var p in theDoeFamily) { Console.WriteLine($"Name: {p.FirstName} {p.LastName} Birthdate: {p.BirthDate}"); } Model.DeleteResource(new Uri("http://example.com/person/alice")); Model.DeleteResource(new Uri("http://example.com/person/john")); Console.WriteLine($"Empty: {Model.IsEmpty}"); Console.WriteLine(); Console.WriteLine("Press ANY key to close.."); Console.ReadLine(); }
public void SetUp() { if (ResourceMappingTest.RegisteredOntology == false) { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterAssembly(Assembly.GetExecutingAssembly()); ResourceMappingTest.RegisteredOntology = true; } Store = StoreFactory.CreateStore("provider=dotnetrdf"); Uri testModel = new Uri("ex:Test"); Model = Store.CreateModel(testModel); }
public void SetUp() { if (ResourceMappingTest.RegisteredOntology == false) { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterAssembly(Assembly.GetExecutingAssembly()); ResourceMappingTest.RegisteredOntology = true; } Store = StoreFactory.CreateStore("provider=stardog;host=http://localhost:5820;uid=admin;pw=admin;sid=test"); Uri testModel = new Uri("ex:Test"); Model = Store.CreateModel(testModel); }
public void TestGetRdfClasses() { List <Class> classTypes = MappingDiscovery.GetRdfClasses(typeof(BaseClass)).ToList(); Assert.AreEqual(1, classTypes.Count()); Assert.Contains(MappingTestOntology.BaseClass, classTypes); classTypes = MappingDiscovery.GetRdfClasses(typeof(SubClass)).ToList(); Assert.AreEqual(1, classTypes.Count()); Assert.Contains(MappingTestOntology.SubClass, classTypes); classTypes = MappingDiscovery.GetRdfClasses(typeof(AnotherBaseClas)).ToList(); Assert.AreEqual(2, classTypes.Count()); Assert.Contains(MappingTestOntology.BaseClass, classTypes); Assert.Contains(MappingTestOntology.BaseClass, classTypes); }
public void LazyLoadResourceTest() { MappingDiscovery.RegisterCallingAssembly(); IModel model = GetModel(); model.Clear(); Uri testRes1 = new Uri("semio:test:testInstance"); Uri testRes2 = new Uri("semio:test:testInstance2"); MappingTestClass t1 = model.CreateResource <MappingTestClass>(testRes1); MappingTestClass2 t2 = model.CreateResource <MappingTestClass2>(new Uri("semio:test:testInstance2")); t1.uniqueResourceTest = t2; // TODO: Debug messsage, because t2 was not commited t1.Commit(); MappingTestClass p1 = model.GetResource <MappingTestClass>(testRes1); //Assert.AreEqual(null, p1.uniqueResourceTest); var v = p1.ListValues(TestOntology.uniqueResourceTest); Assert.AreEqual(t2.Uri.OriginalString, (v.First() as IResource).Uri.OriginalString); model.DeleteResource(t1); model.DeleteResource(t2); t1 = model.CreateResource <MappingTestClass>(testRes1); t2 = model.CreateResource <MappingTestClass2>(new Uri("semio:test:testInstance2")); t2.Commit(); t1.uniqueResourceTest = t2; t1.Commit(); IResource tr1 = model.GetResource(testRes1, t1.GetType()) as Resource; Assert.AreEqual(typeof(MappingTestClass), tr1.GetType()); MappingTestClass2 p2 = model.GetResource <MappingTestClass2>(testRes2); Assert.AreEqual(t2, p1.uniqueResourceTest); model.Clear(); }
public void TestGetBaseClasses() { List <Class> baseTypes = new List <Class>(); MappingDiscovery.GetBaseTypes(typeof(BaseClass), ref baseTypes); Assert.AreEqual(0, baseTypes.Count()); baseTypes = new List <Class>(); MappingDiscovery.GetBaseTypes(typeof(SubClass), ref baseTypes); Assert.AreEqual(1, baseTypes.Count()); Assert.Contains(MappingTestOntology.BaseClass, baseTypes); baseTypes = new List <Class>(); MappingDiscovery.GetBaseTypes(typeof(SubSubClass), ref baseTypes); Assert.AreEqual(2, baseTypes.Count()); Assert.Contains(MappingTestOntology.BaseClass, baseTypes); Assert.Contains(MappingTestOntology.SubClass, baseTypes); }
public void TestGetMatchingTypes() { Class[] types = new[] { MappingTestOntology.BaseClass }; var res = MappingDiscovery.GetMatchingTypes(types, typeof(BaseClass), false); Assert.AreEqual(1, res.Length); Assert.AreEqual(typeof(BaseClass), res.First()); types = new[] { MappingTestOntology.BaseClass, MappingTestOntology.SubClass }; res = MappingDiscovery.GetMatchingTypes(types, typeof(BaseClass), true); //Assert.AreEqual(1, res.Length); Assert.AreEqual(typeof(SubClass), res.First()); types = new[] { MappingTestOntology.SubClass, MappingTestOntology.BaseClass }; res = MappingDiscovery.GetMatchingTypes(types, typeof(BaseClass), true); //Assert.AreEqual(1, res.Length); Assert.AreEqual(typeof(SubClass), res.First()); }
public void Setup() { Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); StoreFactory.LoadProvider <VirtuosoStoreProvider>(); OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterAssembly(Assembly.GetExecutingAssembly()); OntologyDiscovery.AddAssembly(typeof(AbstractMappingClass).Assembly); MappingDiscovery.RegisterAssembly(typeof(AbstractMappingClass).Assembly); FileInfo location = new FileInfo(Assembly.GetExecutingAssembly().Location); DirectoryInfo folder = new DirectoryInfo(Path.Combine(location.DirectoryName, "nunit")); if (folder.Exists) { folder.Delete(true); } folder.Create(); ConnectionString = "provider=virtuoso;host=127.0.0.1;port=1111;uid=dba;pw=dba"; HostAndPort = "localhost:1111"; }
private Dictionary <string, T> FindResourceTypes <T>(bool inferencingEnabled) where T : Resource { Dictionary <string, T> result = new Dictionary <string, T>(); Dictionary <string, List <Class> > types = new Dictionary <string, List <Class> >(); string p; INode s, o; // _tripleProvider.Reset(); // Collect all types for every resource in the types dictionary. // I was going to use _queryResults.Select(), but that doesn't work with Virtuoso. while (_tripleProvider.HasNext) { s = _tripleProvider.S; p = _tripleProvider.P.ToString(); o = _tripleProvider.O; _tripleProvider.SetNext(); if (o.NodeType == NodeType.Uri && p == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") { if (s is IUriNode) { string suri = ((IUriNode)s).Uri.OriginalString; string obj = ((IUriNode)o).Uri.OriginalString; if (!types.ContainsKey(suri)) { types.Add(suri, new List <Class>()); } if (OntologyDiscovery.Classes.ContainsKey(obj)) { types[suri].Add(OntologyDiscovery.Classes[obj]); } else { types[suri].Add(new Class(new Uri(obj))); } } } } // Iterate over all types and find the right class and instatiate it. foreach (string subject in types.Keys) { Type[] classType = MappingDiscovery.GetMatchingTypes(types[subject], typeof(T), inferencingEnabled); if (classType.Length > 0) { #if DEBUG if (classType.Length > 1) { var msg = "Info: There is more that one assignable type for <{0}>. It was initialized as <{1}>."; Debug.WriteLine(string.Format(msg, subject, classType[0].Name)); } #endif T resource = (T)Activator.CreateInstance(classType[0], new Uri(subject)); resource.Model = _model; resource.IsNew = false; result[subject] = resource; } #if DEBUG else if (typeof(T) != typeof(Resource)) { string msg = "Info: No assignable type found for <{0}>."; if (inferencingEnabled) { msg += " Try disabling inference."; } Debug.WriteLine(string.Format(msg, subject)); } #endif } return(result); }
public static void Discover() { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterCallingAssembly(); }
/// <summary> /// This method gets the RDF classes from the query result /// and tries to match it to a C# class. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="subjectColumn"></param> /// <param name="preducateColumn"></param> /// <param name="objectColumn"></param> /// <param name="queryResults"></param> /// <param name="inferencingEnabled"></param> /// <returns></returns> private Dictionary <string, T> FindResourceTypes <T>(DataTable queryResults, string subjectColumn, string preducateColumn, string objectColumn, bool inferencingEnabled = false) where T : Resource { Dictionary <string, T> result = new Dictionary <string, T>(); Dictionary <string, List <Class> > types = new Dictionary <string, List <Class> >(); string s, p, o; // Collect all types for every resource in the types dictionary. // I was going to use _queryResults.Select(), but that doesn't work with Virtuoso. foreach (DataRow row in queryResults.Rows) { s = row[subjectColumn].ToString(); p = row[preducateColumn].ToString(); if (p == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") { o = row[objectColumn].ToString(); if (!types.ContainsKey(s)) { types.Add(s, new List <Class>()); } if (OntologyDiscovery.Classes.ContainsKey(o)) { types[s].Add(OntologyDiscovery.Classes[o]); } else { types[s].Add(new Class(new Uri(o))); } } } // Iterate over all types and find the right class and instatiate it. foreach (string subject in types.Keys) { IList <Type> classType = MappingDiscovery.GetMatchingTypes(types[subject], typeof(T), inferencingEnabled); if (classType.Count > 0) { #if DEBUG if (classType.Count > 1) { string msg = "Info: There is more that one assignable type for <{0}>. It was initialized using the first."; Debug.WriteLine(string.Format(msg, subject)); } #endif T resource = (T)Activator.CreateInstance(classType[0], new UriRef(subject)); resource.SetModel(_model); resource.IsNew = false; result[subject] = resource; } #if DEBUG else if (typeof(T) != typeof(Resource)) { string msg = "Info: No assignable type found for <{0}>."; if (inferencingEnabled) { msg += " Try disabling inference."; } Debug.WriteLine(string.Format(msg, subject)); } #endif } return(result); }