/// <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(); }
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); }
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(); }
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 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 static void Discover() { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterCallingAssembly(); }