public void SparqlPropertyPathEvaluationZeroLengthWithTermStart() { EnsureTestData(); FixedCardinality path = new FixedCardinality(new Property(this._factory.CreateUriNode(new Uri(RdfSpecsHelper.RdfType))), 0); ISparqlAlgebra algebra = this.GetAlgebra(path, new Graph().CreateUriNode(UriFactory.Create(ConfigurationLoader.ClassHttpHandler)), null); SparqlEvaluationContext context = new SparqlEvaluationContext(null, this._data); BaseMultiset results = algebra.Evaluate(context); TestTools.ShowMultiset(results); Assert.IsFalse(results.IsEmpty, "Results should not be empty"); }
public void SparqlPropertyPathEvaluationZeroLength() { EnsureTestData(); FixedCardinality path = new FixedCardinality(new Property(this._factory.CreateUriNode(new Uri(RdfSpecsHelper.RdfType))), 0); ISparqlAlgebra algebra = this.GetAlgebra(path); SparqlEvaluationContext context = new SparqlEvaluationContext(null, this._data); BaseMultiset results = algebra.Evaluate(context); TestTools.ShowMultiset(results); Assert.False(results.IsEmpty, "Results should not be empty"); }
public void SparqlPropertyPathEvaluationZeroLengthWithTermEnd() { EnsureTestData(); FixedCardinality path = new FixedCardinality(new Property(this._factory.CreateUriNode(new Uri(RdfSpecsHelper.RdfType))), 0); INode rdfsClass = this._factory.CreateUriNode(new Uri(NamespaceMapper.RDFS + "Class")); ISparqlAlgebra algebra = this.GetAlgebra(path, null, rdfsClass); SparqlEvaluationContext context = new SparqlEvaluationContext(null, this._data); BaseMultiset results = algebra.Evaluate(context); TestTools.ShowMultiset(results); Assert.IsFalse(results.IsEmpty, "Results should not be empty"); Assert.AreEqual(1, results.Count, "Expected 1 Result"); Assert.AreEqual(rdfsClass, results[1]["x"], "Expected 1 Result set to rdfs:Class"); }
/// <summary> /// Formats a SPARQL Property Path /// </summary> /// <param name="path">SPARQL Property Path</param> /// <returns></returns> protected virtual String FormatPath(ISparqlPath path) { StringBuilder output = new StringBuilder(); if (path is AlternativePath) { AlternativePath alt = (AlternativePath)path; output.Append('('); output.Append(this.FormatPath(alt.LhsPath)); output.Append(" | "); output.Append(this.FormatPath(alt.RhsPath)); output.Append(')'); } else if (path is FixedCardinality) { FixedCardinality card = (FixedCardinality)path; if (card.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(card.Path)); if (card.Path is BaseBinaryPath) { output.Append(')'); } output.Append('{'); output.Append(card.MaxCardinality); output.Append('}'); } else if (path is InversePath) { InversePath inv = (InversePath)path; output.Append('^'); if (inv.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(inv.Path)); if (inv.Path is BaseBinaryPath) { output.Append(')'); } } else if (path is NOrMore) { NOrMore nOrMore = (NOrMore)path; if (nOrMore.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(nOrMore.Path)); if (nOrMore.Path is BaseBinaryPath) { output.Append(')'); } output.Append('{'); output.Append(nOrMore.MinCardinality); output.Append(",}"); } else if (path is NToM) { NToM nToM = (NToM)path; if (nToM.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(nToM.Path)); if (nToM.Path is BaseBinaryPath) { output.Append(')'); } output.Append('{'); output.Append(nToM.MinCardinality); output.Append(','); output.Append(nToM.MaxCardinality); output.Append('}'); } else if (path is OneOrMore) { OneOrMore oneOrMore = (OneOrMore)path; if (oneOrMore.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(oneOrMore.Path)); if (oneOrMore.Path is BaseBinaryPath) { output.Append(')'); } output.Append('+'); } else if (path is Property) { Property prop = (Property)path; output.Append(this.Format(prop.Predicate, TripleSegment.Predicate)); } else if (path is SequencePath) { SequencePath seq = (SequencePath)path; output.Append(this.FormatPath(seq.LhsPath)); output.Append(" / "); output.Append(this.FormatPath(seq.RhsPath)); } else if (path is ZeroOrMore) { ZeroOrMore zeroOrMore = (ZeroOrMore)path; if (zeroOrMore.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(zeroOrMore.Path)); if (zeroOrMore.Path is BaseBinaryPath) { output.Append(')'); } output.Append('*'); } else if (path is ZeroOrOne) { ZeroOrOne zeroOrOne = (ZeroOrOne)path; if (zeroOrOne.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(zeroOrOne.Path)); if (zeroOrOne.Path is BaseBinaryPath) { output.Append(')'); } output.Append('?'); } else if (path is ZeroToN) { ZeroToN zeroToN = (ZeroToN)path; if (zeroToN.Path is BaseBinaryPath) { output.Append('('); } output.Append(this.FormatPath(zeroToN.Path)); if (zeroToN.Path is BaseBinaryPath) { output.Append(')'); } output.Append("{,"); output.Append(zeroToN.MaxCardinality); output.Append('}'); } else if (path is NegatedSet) { NegatedSet negSet = (NegatedSet)path; output.Append('!'); if (negSet.Properties.Count() + negSet.InverseProperties.Count() > 1) { output.Append('('); } foreach (Property p in negSet.Properties) { output.Append(this.FormatPath(p)); output.Append(" | "); } foreach (Property p in negSet.InverseProperties) { output.Append(this.FormatPath(p)); output.Append(" | "); } output.Remove(output.Length - 3, 3); if (negSet.Properties.Count() + negSet.InverseProperties.Count() > 1) { output.Append(')'); } } else { throw new RdfOutputException("Unable to Format an unknown ISparqlPath implementations as a String"); } return(output.ToString()); }
public void SparqlPropertyPathTransformationFixed10() { FixedCardinality path = new FixedCardinality(new Property(this._factory.CreateUriNode(new Uri(RdfSpecsHelper.RdfType))), 10); this.RunTest(path, new String[] { "BGP" }); }