public virtual void Create() { var lc = l.Const; var rc = r.Const; switch (NullablePairExt.Get(lc, rc)) { case NP.bothNull: Operator = result => @operator(l.Operator(result), r.Operator(result)); TypedOperator = result => ApplyTyped(l.TypedOperator(result), r.TypedOperator(result)); AggregateLevel = SetAggregateLevel(l.AggregateLevel, r.AggregateLevel); break; case NP.leftNull: Operator = result => @operator(l.Operator(result), rc.Content); TypedOperator = result => ApplyTyped(l.TypedOperator(result), rc); AggregateLevel = l.AggregateLevel; break; case NP.rigthNull: Operator = result => @operator(lc.Content, r.Operator(result)); TypedOperator = result => ApplyTyped(lc, r.TypedOperator(result)); AggregateLevel = r.AggregateLevel; break; case NP.bothNotNull: Const = ApplyTyped(lc, rc); break; } }
public SparqlStrAfter(SparqlExpression str, SparqlExpression pattern) { // TODO: Complete member initialization // str.SetExprType(ExpressionTypeEnum.@stringOrWithLang); // pattern.SetExprType(ExpressionTypeEnum.@stringOrWithLang); // SetExprType(ExpressionTypeEnum.@stringOrWithLang); switch (NullablePairExt.Get(str.Const, pattern.Const)) { case NP.bothNull: this.Operator = result => StringAfter(str.Operator(result), pattern.Operator(result)); this.AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel); this.TypedOperator = result => str.TypedOperator(result).Change(o => StringAfter(o, (string)pattern.TypedOperator(result).Content)); break; case NP.leftNull: this.Operator = result => StringAfter(str.Operator(result), (string)pattern.Const.Content); this.TypedOperator = result => pattern.Const.Change(o => StringAfter(str.Operator(result), o)); this.AggregateLevel = str.AggregateLevel; break; case NP.rigthNull: this.Operator = result => StringAfter((string)str.Const.Content, pattern.Operator(result)); this.TypedOperator = result => str.Const.Change(o => StringAfter(o, (string)pattern.Operator(result).Content)); this.AggregateLevel = pattern.AggregateLevel; break; case NP.bothNotNull: this.Const = new OV_bool(this.StringAfter((string)str.Const.Content, (string)pattern.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } }
public SparqlSameTerm(SparqlExpression str, SparqlExpression pattern) { switch (NullablePairExt.Get(str.Const, pattern.Const)) { case NP.bothNull: Operator = result => str.TypedOperator(result).Equals(pattern.TypedOperator(result)); AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel); break; case NP.leftNull: Operator = result => str.TypedOperator(result).Equals(pattern.Const); AggregateLevel = str.AggregateLevel; break; case NP.rigthNull: Operator = result => str.Const.Equals(pattern.TypedOperator(result)); AggregateLevel = pattern.AggregateLevel; break; case NP.bothNotNull: Const = new OV_bool(str.Const.Equals(pattern.Const)); break; default: throw new ArgumentOutOfRangeException(); } TypedOperator = result => new OV_bool(Operator(result)); }
public virtual void Create() { var lc = this.l.Const; var rc = this.r.Const; switch (NullablePairExt.Get(lc, rc)) { case NP.bothNull: this.Operator = result => this.@operator(this.l.Operator(result), this.r.Operator(result)); this.TypedOperator = result => this.ApplyTyped(this.l.TypedOperator(result), this.r.TypedOperator(result)); this.AggregateLevel = SetAggregateLevel(this.l.AggregateLevel, this.r.AggregateLevel); break; case NP.leftNull: this.Operator = result => this.@operator(this.l.Operator(result), rc.Content); this.TypedOperator = result => this.ApplyTyped(this.l.TypedOperator(result), rc); this.AggregateLevel = this.l.AggregateLevel; break; case NP.rigthNull: this.Operator = result => this.@operator(lc.Content, this.r.Operator(result)); this.TypedOperator = result => this.ApplyTyped(lc, this.r.TypedOperator(result)); this.AggregateLevel = this.r.AggregateLevel; break; case NP.bothNotNull: this.Const = this.ApplyTyped(lc, rc); break; } }
public SparqlStrStarts(SparqlExpression str, SparqlExpression pattern) { switch (NullablePairExt.Get(str.Const, pattern.Const)) { case NP.bothNull: Operator = result => str.Operator(result).StartsWith(pattern.Operator(result)); TypedOperator = result => str.TypedOperator(result).Change(o => o.StartsWith(pattern.Operator(result))); AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel); break; case NP.leftNull: Operator = result => str.Operator(result).StartsWith(pattern.Const.Content); TypedOperator = result => str.TypedOperator(result).Change(o => o.StartsWith(pattern.Const.Content)); AggregateLevel = str.AggregateLevel; break; case NP.rigthNull: Operator = result => ((string)str.Const.Content).StartsWith(pattern.Operator(result)); TypedOperator = result => str.Const.Change(o => o.StartsWith(pattern.Operator(result))); AggregateLevel = pattern.AggregateLevel; break; case NP.bothNotNull: Const = str.Const.Change(o => o.StartsWith(pattern.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } }
public void SetStartPosition(SparqlExpression substr) { this.substExpression = substr; switch (NullablePairExt.Get(this.strExpression.Const, this.substExpression.Const)) { case NP.bothNull: this.Operator = result => this.strExpression.Operator(result).Substring(this.substExpression.Operator(result)); this.TypedOperator = result => this.strExpression.TypedOperator(result) .Change(o => o.Substring(this.substExpression.Operator(result))); this.AggregateLevel = SetAggregateLevel(this.strExpression.AggregateLevel, this.substExpression.AggregateLevel); break; case NP.leftNull: this.Operator = result => this.strExpression.Operator(result).Substring(this.substExpression.Const.Content); this.TypedOperator = result => this.substExpression.Const. Change(o => this.strExpression.Operator(result).Substring(o)); this.AggregateLevel = this.strExpression.AggregateLevel; break; case NP.rigthNull: this.Operator = result => ((string)this.strExpression.Const.Content).Substring(this.substExpression.Operator(result)); this.TypedOperator = result => this.strExpression.Const.Change(o => o.Substring(this.substExpression.Operator(result))); this.AggregateLevel = this.substExpression.AggregateLevel; break; case NP.bothNotNull: this.Const = this.strExpression.Const.Change(o => o.Substring(this.substExpression.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } }
public SparqlStrBefore(SparqlExpression str, SparqlExpression pattern) { switch (NullablePairExt.Get(str.Const, pattern.Const)) { case NP.bothNull: Operator = result => StringBefore(str.Operator(result), pattern.Operator(result)); AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel); TypedOperator = result => str.TypedOperator(result).Change(o => StringBefore(o, (string)pattern.TypedOperator(result).Content)); break; case NP.leftNull: Operator = result => StringBefore(str.Operator(result), (string)pattern.Const.Content); TypedOperator = result => pattern.Const.Change(o => StringBefore(str.Operator(result), o)); AggregateLevel = str.AggregateLevel; break; case NP.rigthNull: Operator = result => StringBefore((string)str.Const.Content, pattern.Operator(result)); TypedOperator = result => str.Const.Change(o => StringBefore(o, (string)pattern.Operator(result).Content)); AggregateLevel = pattern.AggregateLevel; break; case NP.bothNotNull: Const = new OV_bool(StringBefore((string)str.Const.Content, (string)pattern.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } }
public SparqlStrEnds(SparqlExpression str, SparqlExpression pattern) { switch (NullablePairExt.Get(str.Const, pattern.Const)) { case NP.bothNull: this.Operator = result => ((string)str.Operator(result)).EndsWith(pattern.Operator(result)); this.AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel); this.TypedOperator = result => str.TypedOperator(result).Change(o => ((string)o).EndsWith((string)pattern.TypedOperator(result).Content)); break; case NP.leftNull: this.Operator = result => ((string)str.Operator(result)).EndsWith((string)pattern.Const.Content); this.TypedOperator = result => pattern.Const.Change(o => ((string)str.Operator(result)).EndsWith(o)); this.AggregateLevel = str.AggregateLevel; break; case NP.rigthNull: this.Operator = result => ((string)str.Const.Content).EndsWith(pattern.Operator(result)); this.TypedOperator = result => str.Const.Change(o => ((string)o).EndsWith((string)pattern.Operator(result).Content)); this.AggregateLevel = pattern.AggregateLevel; break; case NP.bothNotNull: this.Const = new OV_bool(((string)str.Const.Content).EndsWith((string)pattern.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } }
public SparqlStringLang(SparqlExpression literalExpression, SparqlExpression langExpression) { switch (NullablePairExt.Get(literalExpression.Const, langExpression.Const)) { case NP.bothNull: Operator = literalExpression.Operator; TypedOperator = result => new OV_langstring((string)literalExpression.Operator(result), (string)langExpression.Operator(result)); AggregateLevel = SetAggregateLevel(literalExpression.AggregateLevel, langExpression.AggregateLevel); break; case NP.leftNull: Operator = literalExpression.Operator; TypedOperator = result => new OV_langstring((string)literalExpression.Operator(result), (string)langExpression.Const.Content); AggregateLevel = literalExpression.AggregateLevel; break; case NP.rigthNull: Operator = result => literalExpression.Const.Content; TypedOperator = result => new OV_langstring((string)literalExpression.Const.Content, langExpression.Operator(result)); AggregateLevel = langExpression.AggregateLevel; break; case NP.bothNotNull: Const = new OV_langstring((string)literalExpression.Const.Content, (string)langExpression.Const.Content); break; default: throw new ArgumentOutOfRangeException(); } }
public SparqlStrDataType(SparqlExpression sparqlExpression1, SparqlExpression sparqlExpression2, NodeGenerator q) { // TODO: Complete member initialization switch (NullablePairExt.Get(sparqlExpression1.Const, sparqlExpression2.Const)) { case NP.bothNull: TypedOperator = result => q.CreateLiteralNode((string)sparqlExpression1.Operator(result), (string)sparqlExpression2.Operator(result)); Operator = res => sparqlExpression1.Operator(res); AggregateLevel = SetAggregateLevel(sparqlExpression1.AggregateLevel, sparqlExpression2.AggregateLevel); break; case NP.leftNull: TypedOperator = result => q.CreateLiteralNode((string)sparqlExpression1.Operator(result), (string)sparqlExpression2.Const.Content); Operator = res => sparqlExpression1.Operator(res); AggregateLevel = sparqlExpression1.AggregateLevel; break; case NP.rigthNull: TypedOperator = result => q.CreateLiteralNode((string)sparqlExpression1.Const.Content, (string)sparqlExpression2.Operator(result)); Operator = res => sparqlExpression1.Const.Content; AggregateLevel = sparqlExpression2.AggregateLevel; break; case NP.bothNotNull: Const = q.CreateLiteralNode((string)sparqlExpression1.Const.Content, (string)sparqlExpression2.Const.Content); break; default: throw new ArgumentOutOfRangeException(); } }
internal void SetRegex(SparqlExpression patternExpression) { var varConst = this.variableExpression.Const; this.pattern = patternExpression; var patternConst = patternExpression.Const; Regex regex; switch (NullablePairExt.Get(this.pattern, varConst)) { case NP.bothNull: break; case NP.leftNull: this.Operator = result => { string patternStr = (string)patternExpression.TypedOperator(result).Content; regex = this.CreateRegex(patternStr); return(regex.IsMatch((string)varConst.Content)); }; this.AggregateLevel = patternExpression.AggregateLevel; break; case NP.rigthNull: var content = (string)patternConst.Content; regex = this.CreateRegex(content); var varExpression = this.variableExpression as SparqlVarExpression; if (varExpression != null && isSimple.IsMatch(content)) { this.Operator = result => { if (result.ContainsKey(varExpression.Variable)) { return(regex.IsMatch(varExpression.Operator(result))); } return(this.store.GetTriplesWithTextObject(varExpression.Operator(result)) .Select(this.Selector(result, varExpression.Variable))); }; } else { this.Operator = result => regex.IsMatch(this.variableExpression.Operator(result)); } this.AggregateLevel = this.variableExpression.AggregateLevel; break; case NP.bothNotNull: regex = this.CreateRegex((string)patternConst.Content); this.Const = new OV_bool(regex.IsMatch((string)this.variableExpression.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } this.TypedOperator = result => new OV_bool(this.Operator(result)); }
public SparqlLangMatches(SparqlExpression value, SparqlExpression langExpression) { // value.SetExprType(ObjectVariantEnum.Str); //todo lang // langExpression.SetExprType(ObjectVariantEnum.Str); //todo lang switch (NullablePairExt.Get(value.Const, langExpression.Const)) { case NP.bothNull: this.Operator = result => { var lang = value.Operator(result); var langRange = langExpression.Operator(result); return(Equals(langRange.Content, "*") ? !string.IsNullOrWhiteSpace(langRange.Content) : Equals(lang, langRange)); }; this.AggregateLevel = SetAggregateLevel(value.AggregateLevel, langExpression.AggregateLevel); break; case NP.leftNull: var rlang = langExpression.Const.Content; this.Operator = result => { var lang = value.Operator(result); return(Equals(rlang, "*") ? !string.IsNullOrWhiteSpace(lang) : Equals(lang, rlang)); }; this.AggregateLevel = value.AggregateLevel; break; case NP.rigthNull: var llang = value.Const.Content; if (llang.Equals("*")) { this.Operator = result => !string.IsNullOrWhiteSpace(langExpression.Operator(result)); } else { this.Operator = result => Equals(llang, langExpression.Operator(result)); } this.AggregateLevel = langExpression.AggregateLevel; break; case NP.bothNotNull: var ll = value.Const.Content; var rl = langExpression.Const.Content; this.Const = new OV_bool(Equals(rl, "*") ? !string.IsNullOrWhiteSpace((string)ll) : Equals(ll, rl)); break; default: throw new ArgumentOutOfRangeException(); } this.TypedOperator = result => new OV_bool(this.Operator(result)); }
public IEnumerable <SparqlResult> Run(IEnumerable <SparqlResult> variableBindings) { var firstVar = sNode as VariableNode; var secondVar = oNode as VariableNode; foreach (var variableBinding in variableBindings) { ObjectVariants s = firstVar == null ? sNode : variableBinding[firstVar]; ObjectVariants o = secondVar == null ? oNode : variableBinding[secondVar]; switch (NullablePairExt.Get(s, o)) { case NP.bothNull: foreach (var subjectNode in q.Store.GetAllSubjects()) { yield return(variableBinding.Add(subjectNode, firstVar, subjectNode, secondVar)); variableBinding[secondVar] = null; foreach (var tr in triples.Aggregate(Enumerable.Repeat(variableBinding, 1), (enumerable, triple) => triple.Run(enumerable))) { yield return(tr); } } continue; case NP.leftNull: yield return(variableBinding.Add(o, firstVar)); variableBinding[firstVar] = null; break; case NP.rigthNull: yield return(variableBinding.Add(s, secondVar)); variableBinding[secondVar] = null; break; case NP.bothNotNull: if (s.Equals(o)) { yield return(variableBinding); } break; default: throw new ArgumentOutOfRangeException(); } //todo optimize foreach (var tr in triples.Aggregate(Enumerable.Repeat(variableBinding, 1), (enumerable, triple) => triple.Run(enumerable))) { yield return(tr); } } }
public SparqlOrExpression(SparqlExpression l, SparqlExpression r) { this._l = l; this._r = r; // l.SetExprType(ObjectVariantEnum.Bool); // r.SetExprType(ObjectVariantEnum.Bool); // SetExprType(ObjectVariantEnum.Bool); switch (NullablePairExt.Get(l.Const, r.Const)) { case NP.bothNull: this.Operator = res => l.Operator(res) || r.Operator(res); this.AggregateLevel = SetAggregateLevel(l.AggregateLevel, r.AggregateLevel); break; case NP.leftNull: if ((bool)l.Const.Content) { this.Const = new OV_bool(true); } else { this.Operator = r.Operator; this.AggregateLevel = r.AggregateLevel; } break; case NP.rigthNull: if ((bool)r.Const.Content) { this.Const = new OV_bool(true); } else { this.Operator = l.Operator; this.AggregateLevel = l.AggregateLevel; } break; case NP.bothNotNull: this.Const = new OV_bool((bool)l.Const.Content || (bool)r.Const.Content); break; default: throw new ArgumentOutOfRangeException(); } this.TypedOperator = result => new OV_bool(this.Operator(result)); }
public SparqlAndExpression(SparqlExpression l, SparqlExpression r) { //l.SetExprType(ObjectVariantEnum.Bool); //r.SetExprType(ObjectVariantEnum.Bool); //SetExprType(ObjectVariantEnum.Bool); switch (NullablePairExt.Get(l.Const, r.Const)) { case NP.bothNull: Operator = res => l.Operator(res) && r.Operator(res); break; case NP.leftNull: if (!(bool)l.Const.Content) { Const = new OV_bool(false); } else { Operator = r.Operator; AggregateLevel = r.AggregateLevel; } break; case NP.rigthNull: if (!(bool)r.Const.Content) { Const = new OV_bool(false); } else { Operator = l.Operator; AggregateLevel = l.AggregateLevel; } break; case NP.bothNotNull: Const = new OV_bool((bool)l.Const.Content && (bool)r.Const.Content); break; default: throw new ArgumentOutOfRangeException(); } TypedOperator = result => new OV_bool(Operator(result)); }
internal void SetRegex(SparqlExpression patternExpression) { var varConst = variableExpression.Const; var patternConst = patternExpression.Const; Regex regex; switch (NullablePairExt.Get(patternConst, varConst)) { case NP.bothNull: break; case NP.leftNull: Operator = result => { var pattern = patternExpression.TypedOperator(result).Content; regex = CreateRegex((string)pattern); return(regex.IsMatch((string)varConst.Content)); }; AggregateLevel = patternExpression.AggregateLevel; break; case NP.rigthNull: regex = CreateRegex((string)patternConst.Content); if (varConst != null) { Const = new OV_bool(regex.IsMatch((string)varConst.Content)); } else { Operator = result => regex.IsMatch(variableExpression.Operator(result)); AggregateLevel = variableExpression.AggregateLevel; } break; case NP.bothNotNull: regex = CreateRegex((string)patternConst.Content); Const = new OV_bool(regex.IsMatch((string)variableExpression.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } TypedOperator = result => new OV_bool(Operator(result)); }
public void SetStartPosition(SparqlExpression value) { startExpression = value; switch (NullablePairExt.Get(strExpression.Const, startExpression.Const)) { case NP.bothNull: Operator = result => strExpression.Operator(result).Substring(startExpression.Operator(result)); TypedOperator = result => strExpression.TypedOperator(result) .Change(o => o.Substring(startExpression.Operator(result))); AggregateLevel = SetAggregateLevel(strExpression.AggregateLevel, startExpression.AggregateLevel); break; case NP.leftNull: Operator = result => strExpression.Operator(result).Substring(startExpression.Const.Content); TypedOperator = result => startExpression.Const. Change(o => strExpression.Operator(result).Substring(o)); AggregateLevel = strExpression.AggregateLevel; break; case NP.rigthNull: Operator = result => ((string)strExpression.Const.Content).Substring(startExpression.Operator(result)); TypedOperator = result => strExpression.Const.Change(o => o.Substring(startExpression.Operator(result))); AggregateLevel = startExpression.AggregateLevel; break; case NP.bothNotNull: Const = strExpression.Const.Change(o => o.Substring(startExpression.Const.Content)); break; default: throw new ArgumentOutOfRangeException(); } }
public SparqlEqualsExpression(SparqlExpression l, SparqlExpression r, NodeGenerator ng) { var lc = l.Const; var rc = r.Const; switch (NullablePairExt.Get(lc, rc)) { case NP.bothNull: Operator = result => l.TypedOperator(result).Equals(r.TypedOperator(result)); AggregateLevel = SetAggregateLevel(l.AggregateLevel, r.AggregateLevel); break; case NP.leftNull: if (rc.Variant == ObjectVariantEnum.Iri) { OV_iriint rcCoded = null; Operator = result => { var lVal = l.TypedOperator(result); if (lVal.Variant == ObjectVariantEnum.Iri) { return(lVal.Equals(rc)); } if (lVal.Variant == ObjectVariantEnum.IriInt) { if (rcCoded == null) { rcCoded = (OV_iriint)ng.GetUri((string)rc.Content); } return(((OV_iriint)lVal).code == rcCoded.code); } else { throw new AggregateException(); } }; } else { Operator = result => l.TypedOperator(result).Equals(rc); } AggregateLevel = l.AggregateLevel; break; case NP.rigthNull: if (lc.Variant == ObjectVariantEnum.Iri) { OV_iriint lcCoded = null; Operator = result => { var rVal = r.TypedOperator(result); if (rVal.Variant == ObjectVariantEnum.Iri) { return(rVal.Equals(lc)); } if (rVal.Variant == ObjectVariantEnum.IriInt) { if (lcCoded == null) { lcCoded = (OV_iriint)ng.GetUri((string)lc.Content); } return(((OV_iriint)rVal).code == lcCoded.code); } else { throw new AggregateException(); } }; } else { Operator = result => lc.Equals(r.TypedOperator(result)); } AggregateLevel = r.AggregateLevel; break; case NP.bothNotNull: Const = new OV_bool(lc.Equals(rc)); break; } TypedOperator = result => new OV_bool(Operator(result)); }
public IEnumerable <SparqlResult> Run(IEnumerable <SparqlResult> variableBindings) { var bindings = variableBindings; Queue <ObjectVariants> newSubjects = new Queue <ObjectVariants>(); ObjectVariants[] fromVariable = null; ObjectVariants o = null; ObjectVariants s = null; switch (NullablePairExt.Get(sVariableNode, oVariableNode)) { case NP.bothNull: return(TestSOConnection(Subject, Object) ? bindings : Enumerable.Empty <SparqlResult>()); case NP.leftNull: newSubjects.Enqueue(Subject); return(bindings.SelectMany(binding => { o = binding[oVariableNode]; if (o != null) { return TestSOConnection(Subject, o) ? Enumerable.Repeat(binding, 1) : Enumerable.Empty <SparqlResult>(); } else { if (fromVariable == null) { fromVariable = GetAllSConnections(Subject).ToArray(); } return fromVariable.Select(node => binding.Add(node, oVariableNode)); } })); case NP.rigthNull: return(bindings.SelectMany(binding => { s = binding[sVariableNode]; if (s != null) { return TestSOConnection(s, Object) ? Enumerable.Repeat(binding, 1) : Enumerable.Empty <SparqlResult>(); } else { if (fromVariable == null) { fromVariable = GetAllOConnections(Object).ToArray(); } return fromVariable.Select(node => binding.Add(node, sVariableNode)); } })); case NP.bothNotNull: return(bindings.SelectMany(binding => { s = binding[sVariableNode]; o = binding[oVariableNode]; switch (NullablePairExt.Get(s, o)) { case NP.bothNotNull: if ((useCache && TestSOConnectionFromCache(s, o)) || (TestSOConnection(s, o))) { return Enumerable.Repeat(binding, 1); } else { return Enumerable.Empty <SparqlResult>(); } case NP.rigthNull: return GetAllSConnections(s).Select(node => binding.Add(node, oVariableNode)); break; case NP.leftNull: return GetAllOConnections(o).Select(node => binding.Add(node, sVariableNode)); break; case NP.bothNull: useCache = true; bothVariablesChache = predicatePath.CreateTriple(sVariableNode, oVariableNode, q) .Aggregate(Enumerable.Repeat(new SparqlResult(q), 1), (enumerable, triple) => triple.Run(enumerable)) .Select( r => new KeyValuePair <ObjectVariants, ObjectVariants>(r[sVariableNode], r[oVariableNode])) .ToArray(); return bothVariablesCacheBySubject.Keys.SelectMany(GetAllSConnections, (sbj, node) => binding.Add(sbj, sVariableNode, node, oVariableNode)); default: throw new ArgumentOutOfRangeException(); } })); default: throw new ArgumentOutOfRangeException(); } }