public void SparqlSetDistinct1() { INode a = this._factory.CreateBlankNode(); INode b1 = (1).ToLiteral(this._factory); INode b2 = (2).ToLiteral(this._factory); Set x = new Set(); x.Add("a", a); x.Add("_:b", b1); Set y = new Set(); y.Add("a", a); y.Add("_:b", b2); Assert.AreNotEqual(x, y); Multiset data = new Multiset(); data.Add(x); data.Add(y); Assert.AreEqual(2, data.Count); Table table = new Table(data); Distinct distinct = new Distinct(table); //Distinct should yield a single result since temporary variables //are stripped SparqlEvaluationContext context = new SparqlEvaluationContext(null, null); BaseMultiset results = distinct.Evaluate(context); Assert.AreEqual(1, results.Count); Assert.IsFalse(results.ContainsVariable("_:b")); }
public void SparqlSetDistinct2() { INode a = this._factory.CreateBlankNode(); INode b1 = (1).ToLiteral(this._factory); INode b2 = (2).ToLiteral(this._factory); Set x = new Set(); x.Add("a", a); x.Add("_:b", b1); Set y = new Set(); y.Add("a", a); y.Add("_:b", b2); Assert.NotEqual(x, y); Multiset data = new Multiset(); data.Add(x); data.Add(y); Assert.Equal(2, data.Count); Table table = new Table(data); Distinct distinct = new Distinct(table, true); //Distinct should yield two result and temporary variables should still //be present SparqlEvaluationContext context = new SparqlEvaluationContext(null, null); BaseMultiset results = distinct.Evaluate(context); Assert.Equal(2, results.Count); Assert.True(results.ContainsVariable("_:b")); }
public override void OnStreamEnds() { foreach (var currentDeveloperDay in _currentDeveloperDays) { _developerDays.Add(currentDeveloperDay); } _currentDeveloperDays.Clear(); }
public void Contains() { Multiset <string> multiset = new Multiset <string>(); multiset.Add("a"); Assert.IsTrue(multiset.Contains("a")); multiset.Add("a"); Assert.IsTrue(multiset.Contains("a")); multiset.Remove("a"); multiset.Remove("a"); Assert.IsFalse(multiset.Contains("a")); }
public void Contains() { Multiset<string> multiset = new Multiset<string>(); multiset.Add("a"); Assert.IsTrue(multiset.Contains("a")); multiset.Add("a"); Assert.IsTrue(multiset.Contains("a")); multiset.Remove("a"); multiset.Remove("a"); Assert.IsFalse(multiset.Contains("a")); }
public object VisitNonEmptyMultiset(KpLinguaParser.NonEmptyMultisetContext context) { var multiset = new Multiset(); foreach (var multisetAtomContext in context.multisetAtom()) { multiset.Add(multisetAtomContext.Accept(this) as Multiset); } return(multiset); }
public void Count() { Multiset <string> multiset = new Multiset <string>(); Assert.AreEqual(0, multiset.Count); multiset.Add("a"); multiset.Add("a"); Assert.AreEqual(2, multiset.Count); multiset.Remove("a"); Assert.AreEqual(1, multiset.Count); multiset.Add("b"); Assert.AreEqual(2, multiset.Count); multiset.Remove("a"); multiset.Remove("b"); Assert.AreEqual(0, multiset.Count); }
public void Count() { Multiset<string> multiset = new Multiset<string>(); Assert.AreEqual(0, multiset.Count); multiset.Add("a"); multiset.Add("a"); Assert.AreEqual(2, multiset.Count); multiset.Remove("a"); Assert.AreEqual(1, multiset.Count); multiset.Add("b"); Assert.AreEqual(2, multiset.Count); multiset.Remove("a"); multiset.Remove("b"); Assert.AreEqual(0, multiset.Count); }
private static void Multiset(ListNode<int> head) { Multiset<int> multiset = new Multiset<int>(); ListNode<int> previous = null; while(head != null) { if (multiset.Contains(head.Value)) previous.Next = head.Next; else { previous = head; multiset.Add(head.Value); } head = head.Next; } }
public virtual BaseMultiset GetMultiset(IStore store) { var ms = new Multiset(Columns); foreach (var row in Rows) { var set = new Set(); for (int i = 0; i < Columns.Count; i++) { if (row[i] > 0) { set.Add(Columns[i], MakeNode(store, row[i])); } } ms.Add(set); } return(ms); }
/// <summary> /// Converts a Bindings Clause to a Multiset /// </summary> /// <returns></returns> public BaseMultiset ToMultiset() { if (this._vars.Any()) { Multiset m = new Multiset(); foreach (String var in this._vars) { m.AddVariable(var); } foreach (BindingTuple tuple in this._tuples) { m.Add(new Set(tuple)); } return(m); } else { return(new IdentityMultiset()); } }
private static void Multiset(ListNode <int> head) { Multiset <int> multiset = new Multiset <int>(); ListNode <int> previous = null; while (head != null) { if (multiset.Contains(head.Value)) { previous.Next = head.Next; } else { previous = head; multiset.Add(head.Value); } head = head.Next; } }
public void SparqlMultisetLeftJoin() { //Create a load of Nodes to use in the tests Graph g = new Graph(); g.NamespaceMap.AddNamespace(String.Empty, new Uri("http://example.org")); IUriNode s1 = g.CreateUriNode(":s1"); IUriNode s2 = g.CreateUriNode(":s2"); IUriNode p1 = g.CreateUriNode(":p1"); IUriNode p2 = g.CreateUriNode(":p2"); IUriNode rdfsLabel = g.CreateUriNode("rdfs:label"); ILiteralNode o1 = g.CreateLiteralNode("Some Text"); ILiteralNode o2 = g.CreateLiteralNode("1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)); //Create an ID and Null Multiset IdentityMultiset id = new IdentityMultiset(); NullMultiset nullset = new NullMultiset(); //Create and Populate a Multiset Multiset m = new Multiset(); Set s = new Set(); s.Add("s", s1); s.Add("p", p1); s.Add("o", o1); m.Add(s); s = new Set(); s.Add("s", s2); s.Add("p", p2); s.Add("o", o2); m.Add(s); //Create and Populate another Multiset Multiset n = new Multiset(); s = new Set(); s.Add("s", s1); s.Add("label", o1); n.Add(s); //Create and Populate another Multiset Multiset d = new Multiset(); s = new Set(); s.Add("s1", s1); s.Add("p1", p1); s.Add("o1", o1); d.Add(s); s = new Set(); s.Add("s1", s2); s.Add("p1", p2); s.Add("o1", o2); d.Add(s); //Show the Sets Console.WriteLine("LHS"); foreach (ISet set in m.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); Console.WriteLine("RHS"); foreach (ISet set in n.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); Console.WriteLine("D"); foreach (ISet set in d.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Join to Identity Console.WriteLine("Join ID-LHS"); BaseMultiset join = id.Join(m); foreach (ISet set in join.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Join to Identity Console.WriteLine("Join LHS-ID"); join = m.Join(id); foreach (ISet set in join.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Join to Null Console.WriteLine("Join NULL-LHS"); join = nullset.Join(m); foreach (ISet set in join.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Join to Null Console.WriteLine("Join LHS-NULL"); join = m.Join(nullset); foreach (ISet set in join.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a LeftJoin Console.WriteLine("LeftJoin NULL-LHS"); BaseMultiset leftjoin = nullset.LeftJoin(m, new ConstantTerm(new BooleanNode(null, true))); foreach (ISet set in leftjoin.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a LeftJoin Console.WriteLine("LeftJoin LHS-NULL"); leftjoin = m.LeftJoin(nullset, new ConstantTerm(new BooleanNode(null, true))); foreach (ISet set in leftjoin.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Join Console.WriteLine("Join LHS-RHS"); join = m.Join(n); foreach (ISet set in join.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a LeftOuterJoin Console.WriteLine("LeftJoin LHS-RHS"); leftjoin = m.LeftJoin(n, new ConstantTerm(new BooleanNode(null, true))); foreach (ISet set in leftjoin.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Produce Console.WriteLine("Product LHS-RHS"); BaseMultiset product = m.Product(n); foreach (ISet set in product.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Join to Self Console.WriteLine("Product LHS-D"); product = m.Product(d); foreach (ISet set in product.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); //Try a Union Console.WriteLine("Union LHS-RHS"); BaseMultiset union = m.Union(n); foreach (ISet set in union.Sets) { Console.WriteLine(set.ToString()); } Console.WriteLine(); }
public static void Add(Multiset <Pattern> excluded, Pattern add) { excluded.Add(add); }
/// <summary> /// Handles a Result by adding it to the Multiset. /// </summary> /// <param name="result">Result.</param> /// <returns></returns> protected override bool HandleResultInternal(SparqlResult result) { _mset.Add(new Set(result)); return(true); }
public static void Add(Multiset<Pattern> excluded, Pattern add) { excluded.Add(add); }