public void Persist1() { LinqTripleStore store = new LinqTripleStore(CreateMemoryStore()); Track t = new Track() { AlbumName = "Test Album", ArtistName = "Some Artist", Comment = "blah de blah", GenreName = "Easy Listening", InstanceUri = "http://example.org/music/someAlbum/tracks/1", Title = "Track 1", Rating = 5, Year = "2010" }; Assert.IsTrue(store.SupportsPersistence, "Persistence should be supported by in-memory stores"); Console.WriteLine(store.UpdateProcessor.GetSaveCommandText(t, null)); store.UpdateProcessor.SaveObject(t, null); IQueryable<Track> qry = new RdfDataContext(store).ForType<Track>(); IQueryable<Track> q = from x in qry where x.ArtistName == "Some Artist" select x; Assert.IsTrue(q.Count() > 0, "Expected 1 or more results"); Assert.IsTrue(q.Count() == 1, "Expected only 1 result"); }
/// <summary> /// Initializes a new instance of the <see cref="ObjectDeserialiserQuerySink"/> class. /// </summary> /// <param name="originalType">the original type that the query was made against.</param> /// <param name="instanceType">the type of the object that must be returned.</param> /// <param name="instanceName">Name of the instance (i.e the alias used in both the LINQ and SPARQL queries).</param> /// <param name="distinct">if set to <c>true</c> discard duplicate answers.</param> /// <param name="selectExpression">The select expression (derived from the the LINQ query). Used to help in deserialisation.</param> /// <param name="context">The data context that will monitor the objects created (not yet used).</param> public ObjectDeserialiserQuerySink( Type originalType, Type instanceType, string instanceName, bool distinct, MethodCallExpression selectExpression, RdfDataContext context) { #region Tracing #line hidden if (Logger.IsDebugEnabled) { Logger.Debug("Deserialising {0}.", instanceType.Name); } #line default #endregion SelectExpression = selectExpression; this.originalType = originalType; this.instanceType = instanceType; InstanceName = instanceName; Distinct = distinct; DataContext = context; IncomingResults = new ArrayList(); }
private static void TestConnectionCreationForTripleStore(LinqTripleStore ts1) { IRdfContext context = new RdfDataContext(ts1); QueryFactory<Track> factory = new QueryFactory<Track>(ts1.QueryMethod, context); IRdfQuery<Track> qry1 = context.ForType<Track>(); IRdfConnection<Track> rdfConnection = factory.CreateConnection(qry1); Assert.IsNotNull(rdfConnection); }
public void TestEndsWith() { TripleStore ts = CreateSparqlTripleStore(); IRdfQuery<Album> qry = new RdfDataContext(ts).ForType<Album>(); var q = from a in qry where a.Name.EndsWith("podcasts") select a; List<Album> al = new List<Album>(q); Assert.IsTrue(al.Count == 1); Assert.IsTrue(al[0].Name == "Rory Blyth - podcasts"); }
public void TestCompare() { TripleStore ts = CreateSparqlTripleStore(); IRdfQuery<Album> qry = new RdfDataContext(ts).ForType<Album>(); var q = from a in qry where a.Name.Contains("Thomas") select a; List<Album> al = new List<Album>(q); Assert.AreEqual(1, al.Count); Assert.AreEqual("Thomas Laqueur - History Lectures", al[0].Name); }
public void TestStartsWith() { TripleStore ts = CreateSparqlTripleStore(); IRdfQuery<Album> qry = new RdfDataContext(ts).ForType<Album>(); var q = from a in qry where a.Name.StartsWith("Thomas") select a; List<Album> al = new List<Album>(q); Assert.IsTrue(al.Count == 1); Assert.IsTrue(al[0].Name == "Thomas Laqueur - History Lectures"); }
public void Query1() { var ts = new TripleStore(CreateMemoryStore()); IQueryable<Track> qry = new RdfDataContext(ts).ForType<Track>(); IQueryable<Track> q = from t in qry where t.ArtistName == "Thomas Laqueur" select t; var resultList = new List<Track>(); resultList.AddRange(q); }
public void Query3() { TripleStore ts = CreateOnlineTripleStore(); IRdfQuery<Track> qry = new RdfDataContext(ts).ForType<Track>(); // should deduce that it is N3 and open correctly Track[] q = (from t in qry where Convert.ToInt32(t.Year) > 1998 && t.GenreName == "Rory Blyth: The Smartest Man in the World" select t).ToArray(); Assert.IsTrue(q.Length > 0); }
public void Test1() { LinqTripleStore ts = CreateSparqlTripleStore(); IRdfQuery<Track> qry = new RdfDataContext(ts).ForType<Track>(); var q = from t in qry where t.Year == "2007" && t.GenreName == "Rory Blyth: The Smartest Man in the World" select new {t.Title, t.FileLocation}; foreach(var track in q){ Console.WriteLine(track.Title + ": " + track.FileLocation); } }
public void JosekiQueryWithProjection() { TripleStore ts = new TripleStore(@"http://localhost:2020/music"); IRdfQuery<Track> qry = new RdfDataContext(ts).ForType<Track>(); var q = from t in qry where t.Year == "2007" && t.GenreName == "Rory Blyth: The Smartest Man in the World" select new { t.Title, t.FileLocation }; foreach (var track in q) { Console.WriteLine(track.Title + ": " + track.FileLocation); } }
public void PersistToGraph1() { LinqTripleStore store = new LinqTripleStore(CreateMemoryStore()); Track t = new Track() { AlbumName = "Test Album", ArtistName = "Some Artist", Comment = "blah de blah", GenreName = "Easy Listening", InstanceUri = "http://example.org/music/someAlbum/tracks/1", Title = "Track 1", Rating = 5, Year = "2010" }; Assert.IsTrue(store.SupportsPersistence, "Persistence should be supported by in-memory stores"); String text = store.UpdateProcessor.GetSaveCommandText(t, "http://example.org/someGraph"); Console.WriteLine(text); Assert.IsTrue(text.Contains("GRAPH <"), "Persistence Command should have contained a GRAPH clause"); store.UpdateProcessor.SaveObject(t, "http://example.org/someGraph"); RdfDataContext context = new RdfDataContext(store); IQueryable<Track> qry = context.ForType<Track>(); IQueryable<Track> q = from x in qry where x.ArtistName == "Some Artist" select x; Assert.IsTrue(q.Count() > 0, "Expected 1 or more results"); Assert.IsTrue(q.Count() == 1, "Expected only 1 result"); //Try setting Graph to non-existent Graph - should then throw an error try { context.DefaultGraph = "http://example.org/noSuchGraph"; int count = q.Count(); Assert.Fail("Should have thrown an error as tried to query a non-existent Graph"); } catch { Console.WriteLine("Errored as expected when a non-existent Graph was used"); } //Try setting Graph to correct Graph, should then get the 1 result as expected context.DefaultGraph = "http://example.org/someGraph"; Assert.IsTrue(q.Count() == 1, "Expected only 1 result"); }
public void CreateQueryTest_InMemoryTripleStore() { LinqTripleStore ts = CreateLinqTripleStore(); IRdfContext context = new RdfDataContext(ts); QueryFactory<Track> factory = new QueryFactory<Track>(ts.QueryMethod, context); Assert.AreEqual(factory.QueryType, ts.QueryMethod); IRdfQuery<Track> query = factory.CreateQuery<Track>(); Assert.IsNotNull(query); Assert.IsTrue(query is LinqToSparqlQuery<Track>); }
/// <summary> /// Assigns the <see cref="RdfDataContext"/> to the instance. /// </summary> /// <remarks> /// this is used in case it needs it to lazily load references later on. /// </remarks> /// <param name="obj">the object that has just been deserialised.</param> /// <param name="dataContext">The <see cref="RdfDataContext"/> through which the query was run that led to the instance being deserialised.</param> private void AssignDataContext(OwlInstanceSupertype obj, RdfDataContext dataContext) { if (obj != null) { obj.DataContext = DataContext; } // TODO: assign event handlers for NotifyPropertyChanged }
public void TestGetAllTasks() { RdfDataContext ctx = new RdfDataContext(CreateSparqlTripleStore()); var q = (from t in ctx.ForType<Task>() select t).ToArray().Distinct(); Assert.IsTrue(q.Count() == 12); }
public void CreateQueryTest_PersistentTripleStore() { TripleStore ts = CreatePersistentTripleStore(); IRdfContext context = new RdfDataContext(ts); QueryFactory<Track> factory = new QueryFactory<Track>(ts.QueryType, context); Assert.AreEqual(factory.QueryType, ts.QueryType); IRdfQuery<Track> query = factory.CreateQuery<Track>(); Assert.IsNotNull(query); Assert.IsTrue(query is RdfN3Query<Track>); }
public void Query5() { TripleStore ts = CreateOnlineTripleStore(); var ctx = new RdfDataContext(ts); IRdfQuery<Track> qry = ctx.ForType<Track>(); IQueryable<Track> q = from t in qry where t.GenreName == "Rory Blyth: The Smartest Man in the World" select t; foreach (Track track in q) { track.Rating = 5; } ctx.SubmitChanges(); }
public void CreateExpressionTranslatorTest() { TripleStore ts = CreateOnlineSparqlTripleStore(); IRdfContext context = new RdfDataContext(ts); QueryFactory<Track> factory = new QueryFactory<Track>(ts.QueryType, context); Assert.AreEqual(factory.QueryType, ts.QueryType); IQueryFormatTranslator translator = factory.CreateExpressionTranslator(); Assert.IsNotNull(translator); Assert.IsTrue(translator is LinqToSparqlExpTranslator<Track>); }
public void SparqlQueryUsingCachedResults() { TripleStore ts = CreateSparqlTripleStore(); IRdfQuery<Track> qry = new RdfDataContext(ts).ForType<Track>(); var q = from t in qry where t.Year == "2007" && t.GenreName == "Rory Blyth: The Smartest Man in the World" select new {t.Title, t.FileLocation}; foreach (var track in q) { Console.WriteLine(track.Title + ": " + track.FileLocation); } // this should not invoke query parsing or execution foreach (var track in q) { Console.WriteLine("Title: " + track.Title); } }
public void SparqlQueryOrdered() { TripleStore ts = CreateSparqlTripleStore(); IRdfQuery<Track> qry = new RdfDataContext(ts).ForType<Track>(); var q = from t in qry where t.Year == "2006" && t.GenreName == "History 5 | Fall 2006 | UC Berkeley" orderby t.FileLocation select new {t.Title, t.FileLocation}; foreach (var track in q) { Console.WriteLine(track.Title + ": " + track.FileLocation); } }
public void SparqlQueryAll() { TripleStore ts = CreateSparqlTripleStore(); IRdfQuery<Track> qry = new RdfDataContext(ts).ForType<Track>(); IQueryable<Track> q = from t in qry select t; var lt = new List<Track>(q); foreach (Track track in q) { Console.WriteLine("Track: " + track.Title); } Assert.IsTrue(lt.Count > 1); }