public void SparqlPropertyPathEvaluationInverseNegatedPropertySet() { EnsureTestData(); NegatedSet path = new NegatedSet(Enumerable.Empty <Property>(), new Property[] { new Property(this._factory.CreateUriNode(new Uri(RdfSpecsHelper.RdfType))) }); ISparqlAlgebra algebra = this.GetAlgebra(path); SparqlEvaluationContext context = new SparqlEvaluationContext(null, this._data); BaseMultiset results = algebra.Evaluate(context); TestTools.ShowMultiset(results); Assert.IsFalse(results.IsEmpty, "Results should not be empty"); }
protected override Int32 VisitNegatedSet(NegatedSet negatedSet, Unit argument) { var hash = new HashCode(); foreach (var character in negatedSet.Characters) { hash.Add(character); } foreach (Range <Char> range in negatedSet.Ranges) { hash.Add(range); } foreach (UnicodeCategory category in negatedSet.UnicodeCategories) { hash.Add(category); } foreach (GrammarNode <Char> node in negatedSet.Nodes) { hash.Add(this.Visit(node, argument)); } return(hash.ToHashCode()); }
/// <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 SparqlPropertyPathTransformationNegatedPropertyInverseSet() { NegatedSet path = new NegatedSet(Enumerable.Empty <Property>(), new Property[] { new Property(this._factory.CreateUriNode(new Uri(RdfSpecsHelper.RdfType))) }); this.RunTest(path, new String[] { "NegatedPropertySet" }); }