public void SetUp() { string connectionString = SetupClass.ConnectionString; Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString)); Model = Store.GetModel(new Uri("http://example.org/TestModel")); if (!Model.IsEmpty) { Model.Clear(); } OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/")); OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/")); OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#")); OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); OntologyDiscovery.AddNamespace("dbpedia", new Uri("http://dbpedia.org/ontology/")); OntologyDiscovery.AddNamespace("dbpprop", new Uri("http://dbpedia.org/property/")); OntologyDiscovery.AddNamespace("schema", new Uri("http://schema.org/")); OntologyDiscovery.AddNamespace("nie", new Uri("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#")); OntologyDiscovery.AddNamespace("nco", new Uri("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#")); OntologyDiscovery.AddNamespace("sfo", sfo.GetNamespace()); OntologyDiscovery.AddNamespace(nfo.GetPrefix(), nfo.GetNamespace()); Model.Clear(); for (int i = 0; i < 100; i++) { IResource resource0 = Model.CreateResource(); resource0.AddProperty(rdf.type, nco.PersonContact); resource0.AddProperty(nco.fullname, Guid.NewGuid().ToString()); resource0.Commit(); } }
public void SetUp() { OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/")); OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/")); OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#")); OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); OntologyDiscovery.AddNamespace("dbpedia", new Uri("http://dbpedia.org/ontology/")); OntologyDiscovery.AddNamespace("dbpprop", new Uri("http://dbpedia.org/property/")); OntologyDiscovery.AddNamespace("schema", new Uri("http://schema.org/")); OntologyDiscovery.AddNamespace("nie", new Uri("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#")); OntologyDiscovery.AddNamespace("nco", new Uri("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#")); OntologyDiscovery.AddNamespace("sfo", sfo.GetNamespace()); OntologyDiscovery.AddNamespace(nfo.GetPrefix(), nfo.GetNamespace()); Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", SetupClass.ConnectionString)); Store.InitializeFromConfiguration(); Model = Store.GetModel(new Uri("http://example.org/TestModel")); Model.Clear(); IResource hans = Model.CreateResource(new Uri("http://example.org/Hans")); hans.AddProperty(rdf.type, nco.PersonContact); hans.AddProperty(nco.fullname, "Hans Wurscht"); hans.AddProperty(nco.birthDate, DateTime.Now); hans.AddProperty(nco.blogUrl, "http://blog.com/Hans"); IResource pagerNumber0 = Model.CreateResource(new Uri("http://example.org/Hans/pagerNumber#0")); pagerNumber0.AddProperty(rdf.type, nco.PagerNumber); pagerNumber0.AddProperty(dc.date, DateTime.Today); pagerNumber0.AddProperty(nco.creator, hans); pagerNumber0.Commit(); IResource phoneNumber0 = Model.CreateResource(new Uri("http://example.org/Hans/phoneNumber#0")); phoneNumber0.AddProperty(rdf.type, nco.PhoneNumber); phoneNumber0.AddProperty(dc.date, DateTime.Today.AddDays(1)); phoneNumber0.AddProperty(nco.creator, hans); phoneNumber0.Commit(); IResource phoneNumber1 = Model.CreateResource(new Uri("http://example.org/Hans/phoneNumber#1")); phoneNumber1.AddProperty(rdf.type, nco.PhoneNumber); phoneNumber1.AddProperty(dc.date, DateTime.Today.AddDays(2)); phoneNumber1.AddProperty(nco.creator, hans); phoneNumber1.Commit(); hans.AddProperty(nco.hasContactMedium, pagerNumber0); hans.AddProperty(nco.hasPhoneNumber, phoneNumber0); hans.AddProperty(nco.hasPhoneNumber, phoneNumber1); hans.Commit(); IResource acme = Model.CreateResource(new Uri("http://example.org/ACME")); acme.AddProperty(rdf.type, nco.OrganizationContact); acme.AddProperty(nco.fullname, "ACME"); acme.AddProperty(nco.creator, hans); acme.Commit(); }
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 SetUp() { string connectionString = SetupClass.ConnectionString; _store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString)); _model = _store.GetModel(new Uri("ex:TestModel")); if (!_model.IsEmpty) { _model.Clear(); } OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#")); OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/")); OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/")); }
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 IEnumerable <T> GenerateResources <T>() where T : Resource { List <T> result = new List <T>(); if (0 < _tripleProvider.Count) { // A dictionary mapping URIs to the generated resource objects. Dictionary <string, IResource> cache = new Dictionary <string, IResource>(); Dictionary <string, T> types = FindResourceTypes <T>(_query.IsInferenceEnabled); _tripleProvider.Reset(); foreach (KeyValuePair <string, T> resourceType in types) { cache.Add(resourceType.Key, resourceType.Value); } // A handle to the currently built resource which may spare the lookup in the dictionary. T currentResource = null; while (_tripleProvider.HasNext) { Uri predUri; INode s, o; Property p; s = _tripleProvider.S; predUri = _tripleProvider.P; o = _tripleProvider.O; _tripleProvider.SetNext(); p = OntologyDiscovery.GetProperty(predUri); if (s is IUriNode) { Uri sUri = (s as IUriNode).Uri; if (currentResource != null && currentResource.Uri.OriginalString == sUri.OriginalString) { // We already have the handle to the resource which the property should be added to. } else if (cache.ContainsKey(sUri.OriginalString)) { currentResource = cache[sUri.OriginalString] as T; // In this case we may have encountered a resource which was // added to the cache by the object value handler below. if (!result.Contains(currentResource)) { result.Add(currentResource); } } else { try { currentResource = (T)Activator.CreateInstance(typeof(T), sUri); currentResource.IsNew = false; currentResource.IsSynchronized = true; currentResource.Model = _model; cache.Add(sUri.OriginalString, currentResource); result.Add(currentResource); } catch { #if DEBUG Debug.WriteLine("[SparqlQueryResult] Info: Could not create resource " + sUri.OriginalString); #endif continue; } } } else if (s is BlankNode) { //TODO Debugger.Break(); } else { Debugger.Break(); } if (o is IUriNode) { Uri uri = (o as IUriNode).Uri; if (currentResource.HasPropertyMapping(p, uri.GetType())) { currentResource.AddPropertyToMapping(p, uri, false); } else if (cache.ContainsKey(uri.OriginalString)) { currentResource.AddPropertyToMapping(p, cache[uri.OriginalString], true); currentResource.IsNew = false; currentResource.IsSynchronized = false; currentResource.Model = _model; } else { Resource r = new Resource(uri); r.IsNew = false; cache.Add(uri.OriginalString, r); currentResource.AddPropertyToMapping(p, r, true); currentResource.IsNew = false; currentResource.IsSynchronized = false; currentResource.Model = _model; } } else if (o is BlankNode) { } else { currentResource.AddPropertyToMapping(p, ParseCellValue(o), true); } } } foreach (T r in result) { yield return(r); } }
public static void Discover() { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); MappingDiscovery.RegisterCallingAssembly(); }
public void TestDiscovery() { OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); var l = OntologyDiscovery.Classes; }
public void SetUp() { string connectionString = SetupClass.ConnectionString; Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString)); Model = Store.GetModel(new Uri("http://example.org/TestModel")); if (!Model.IsEmpty) { Model.Clear(); } OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/")); OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/")); OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#")); OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); OntologyDiscovery.AddNamespace("dbpedia", new Uri("http://dbpedia.org/ontology/")); OntologyDiscovery.AddNamespace("dbpprop", new Uri("http://dbpedia.org/property/")); OntologyDiscovery.AddNamespace("schema", new Uri("http://schema.org/")); OntologyDiscovery.AddNamespace("nie", new Uri("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#")); OntologyDiscovery.AddNamespace("nco", new Uri("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#")); OntologyDiscovery.AddNamespace("sfo", sfo.GetNamespace()); OntologyDiscovery.AddNamespace(nfo.GetPrefix(), nfo.GetNamespace()); Model.Clear(); IResource resource0 = Model.CreateResource(new Uri("http://example.org/Hans")); resource0.AddProperty(rdf.type, nco.PersonContact); resource0.AddProperty(nco.fullname, "Hans Wurscht"); resource0.AddProperty(nco.birthDate, DateTime.Now); resource0.AddProperty(nco.blogUrl, "http://blog.com/Hans"); resource0.Commit(); IResource resource1 = Model.CreateResource(new Uri("http://example.org/Task")); resource1.AddProperty(rdf.type, tmo.Task); resource1.AddProperty(tmo.taskName, "Eine Aufgabe."); resource1.AddProperty(nco.creator, resource0); resource1.Commit(); IResource resource2 = Model.CreateResource(new Uri("http://example.org/Doc#1")); resource2.AddProperty(rdf.type, nfo.Document); resource2.AddProperty(dc.date, DateTime.Today); resource2.AddProperty(nco.creator, resource0); resource2.Commit(); // NOTE: The different name influences the ordering of the resource in query results. IResource resource3 = Model.CreateResource(new Uri("http://example.org/Boc#2")); resource3.AddProperty(rdf.type, nfo.Document); resource3.AddProperty(dc.date, DateTime.Today.AddHours(1)); resource3.AddProperty(nco.creator, resource0); resource3.Commit(); IResource resource4 = Model.CreateResource(new Uri("http://example.org/Doc#3")); resource4.AddProperty(rdf.type, nfo.Document); resource4.AddProperty(dc.date, DateTime.Today.AddHours(2)); resource4.AddProperty(nco.creator, resource0); resource4.Commit(); }
/// <summary> /// Tries to marshall the data in the _queryResults variable as Resource objects. /// </summary> /// <typeparam name="T">The Resource type.</typeparam> /// <returns>An enumeration of marshalled objects of the given type.</returns> private IEnumerable <T> GenerateResources <T>(DataTable queryResults) where T : Resource { List <T> result = new List <T>(); if (0 < queryResults.Columns.Count) { // A list of global scope variables without the ?. Used to access the // subject, predicate and object variable in statement providing queries. string[] vars = _query.GetGlobalScopeVariableNames(); bool providesStatements = _query.ProvidesStatements(); // A dictionary mapping URIs to the generated resource objects. Dictionary <string, IResource> cache = new Dictionary <string, IResource>(); Dictionary <string, T> types = FindResourceTypes <T>( queryResults, queryResults.Columns[0].ColumnName, queryResults.Columns[1].ColumnName, queryResults.Columns[2].ColumnName, _query.IsInferenceEnabled); foreach (KeyValuePair <string, T> resourceType in types) { cache.Add(resourceType.Key, resourceType.Value); } // A handle to the currently built resource which may spare the lookup in the dictionary. T currentResource = null; foreach (DataRow row in queryResults.Rows) { // NOTE: We create an UriRef for correct equality comparision with fragment identifiers. UriRef s, predUri; Property p; object o; if (_query.QueryType == SparqlQueryType.Describe || _query.QueryType == SparqlQueryType.Construct) { s = new UriRef(row[0].ToString()); predUri = new UriRef(row[1].ToString()); o = ParseCellValue(row[2]); } else if (_query.QueryType == SparqlQueryType.Select && providesStatements) { s = new UriRef(row[vars[0]].ToString()); predUri = new UriRef(row[vars[1]].ToString()); o = ParseCellValue(row[vars[2]]); } else { break; } p = OntologyDiscovery.GetProperty(predUri); if (currentResource != null && currentResource.Uri.OriginalString == s.OriginalString) { // We already have the handle to the resource which the property should be added to. } else if (cache.ContainsKey(s.OriginalString)) { currentResource = cache[s.OriginalString] as T; // In this case we may have encountered a resource which was // added to the cache by the object value handler below. if (!result.Contains(currentResource)) { result.Add(currentResource); } } else { try { currentResource = (T)Activator.CreateInstance(typeof(T), s); currentResource.IsNew = false; currentResource.IsSynchronized = true; currentResource.SetModel(_model); cache.Add(s.OriginalString, currentResource); result.Add(currentResource); } catch { #if DEBUG Debug.WriteLine("[SparqlQueryResult] Info: Could not create resource " + s.OriginalString); #endif continue; } } if (currentResource == null) { continue; } if (o is UriRef) { UriRef uri = o as UriRef; if (cache.ContainsKey(uri.OriginalString)) { currentResource.AddPropertyToMapping(p, cache[uri.OriginalString], true); currentResource.IsNew = false; currentResource.IsSynchronized = false; currentResource.SetModel(_model); } else { Resource r = new Resource(uri) { IsNew = false }; cache.Add(uri.OriginalString, r); currentResource.AddPropertyToMapping(p, r, true); currentResource.IsNew = false; currentResource.IsSynchronized = false; currentResource.SetModel(_model); } } else { currentResource.AddPropertyToMapping(p, o, true); } } } foreach (T r in result) { yield return(r); } }