本文整理汇总了C#中ISparqlExpression.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# ISparqlExpression.Evaluate方法的具体用法?C# ISparqlExpression.Evaluate怎么用?C# ISparqlExpression.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISparqlExpression
的用法示例。
在下文中一共展示了ISparqlExpression.Evaluate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplaceFunction
/// <summary>
/// Creates a new SPARQL Replace function
/// </summary>
/// <param name="text">Text Expression</param>
/// <param name="find">Search Expression</param>
/// <param name="replace">Replace Expression</param>
/// <param name="options">Options Expression</param>
public ReplaceFunction(ISparqlExpression text, ISparqlExpression find, ISparqlExpression replace, ISparqlExpression options)
{
this._textExpr = text;
//Get the Pattern
if (find is ConstantTerm)
{
//If the Pattern is a Node Expression Term then it is a fixed Pattern
IValuedNode n = find.Evaluate(null, 0);
if (n.NodeType == NodeType.Literal)
{
//Try to parse as a Regular Expression
try
{
string p = n.AsString();
Regex temp = new Regex(p);
//It's a Valid Pattern
this._fixedPattern = true;
this._find = p;
}
catch
{
//No catch actions
}
}
}
this._findExpr = find;
//Get the Replace
if (replace is ConstantTerm)
{
//If the Replace is a Node Expresison Term then it is a fixed Pattern
IValuedNode n = replace.Evaluate(null, 0);
if (n.NodeType == NodeType.Literal)
{
this._replace = n.AsString();
this._fixedReplace = true;
}
}
this._replaceExpr = replace;
//Get the Options
if (options != null)
{
if (options is ConstantTerm)
{
this.ConfigureOptions(options.Evaluate(null, 0), false);
}
this._optionExpr = options;
}
}
示例2: StringJoinFunction
/// <summary>
/// Creates a new ARQ String Join function
/// </summary>
/// <param name="sepExpr">Separator Expression</param>
/// <param name="expressions">Expressions to concatentate</param>
public StringJoinFunction(ISparqlExpression sepExpr, IEnumerable<ISparqlExpression> expressions)
{
if (sepExpr is ConstantTerm)
{
IValuedNode temp = sepExpr.Evaluate(null, 0);
if (temp.NodeType == NodeType.Literal)
{
this._separator = temp.AsString();
this._fixedSeparator = true;
}
else
{
this._sep = sepExpr;
}
}
else
{
this._sep = sepExpr;
}
this._exprs.AddRange(expressions);
}
示例3: RegexFunction
/// <summary>
/// Creates a new Regex() function expression
/// </summary>
/// <param name="text">Text to apply the Regular Expression to</param>
/// <param name="pattern">Regular Expression Pattern</param>
/// <param name="options">Regular Expression Options</param>
public RegexFunction(ISparqlExpression text, ISparqlExpression pattern, ISparqlExpression options)
{
this._textExpr = text;
this._patternExpr = pattern;
//Get the Pattern
if (pattern is ConstantTerm)
{
//If the Pattern is a Node Expression Term then it is a fixed Pattern
INode n = pattern.Evaluate(null, 0);
if (n.NodeType == NodeType.Literal)
{
//Try to parse as a Regular Expression
try
{
string p = ((ILiteralNode)n).Value;
Regex temp = new Regex(p);
//It's a Valid Pattern
this._fixedPattern = true;
//this._useInStr = p.ToCharArray().All(c => Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c));
this._pattern = p;
}
catch
{
//No catch actions
}
}
}
//Get the Options
if (options != null)
{
this._optionExpr = options;
if (options is ConstantTerm)
{
this.ConfigureOptions(options.Evaluate(null, 0), false);
this._fixedOptions = true;
if (this._fixedPattern) this._regex = new Regex(this._pattern, this._options);
}
}
else
{
if (this._fixedPattern) this._regex = new Regex(this._pattern);
}
}
示例4: LeftJoin
/// <summary>
/// Does a Left Join of this Multiset to another Multiset where the Join is predicated on the given Expression
/// </summary>
/// <param name="other">Other Multiset</param>
/// <param name="expr">Expression</param>
/// <returns></returns>
public override BaseMultiset LeftJoin(BaseMultiset other, ISparqlExpression expr)
{
//If the Other is the Identity/Null Multiset the result is this Multiset
if (other is IdentityMultiset) return this;
if (other is NullMultiset) return this;
if (other.IsEmpty) return this;
Multiset joinedSet = new Multiset();
LeviathanLeftJoinBinder binder = new LeviathanLeftJoinBinder(joinedSet);
SparqlEvaluationContext subcontext = new SparqlEvaluationContext(binder);
//Find the First Variable from this Multiset which is in both Multisets
//If there is no Variable from this Multiset in the other Multiset then this
//should be a Join operation instead of a LeftJoin
List<String> joinVars = this._variables.Where(v => other.Variables.Contains(v)).ToList();
if (joinVars.Count == 0)
{
//Calculate a Product filtering as we go
foreach (ISet x in this.Sets)
{
bool standalone = false;
foreach (ISet y in other.Sets)
{
ISet z = x.Join(y);
try
{
joinedSet.Add(z);
if (!expr.Evaluate(subcontext, z.ID).AsSafeBoolean())
{
joinedSet.Remove(z.ID);
standalone = true;
}
}
catch
{
joinedSet.Remove(z.ID);
standalone = true;
}
}
if (standalone) joinedSet.Add(x.Copy());
}
}
else
{
//This is the old algorithm which is correct but has complexity O(n^2) so it scales terribly
//foreach (ISet x in this.Sets)
//{
// IEnumerable<ISet> ys = other.Sets.Where(s => joinVars.All(v => x[v] == null || s[v] == null || x[v].Equals(s[v])));
// //IEnumerable<ISet> ys = other.Sets.Where(s => s.IsCompatibleWith(x, joinVars));
// bool standalone = false;
// int i = 0;
// foreach (ISet y in ys)
// {
// i++;
// ISet z = x.Join(y);
// try
// {
// joinedSet.Add(z);
// if (!expr.Evaluate(subcontext, z.ID).AsSafeBoolean())
// {
// joinedSet.Remove(z.ID);
// standalone = true;
// }
// }
// catch
// {
// joinedSet.Remove(z.ID);
// standalone = true;
// }
// }
// if (standalone || i == 0) joinedSet.Add(x);
//}
//This is the new Join algorithm which is also correct but is O(2n) so much faster and scalable
//Downside is that it does require more memory than the old algorithm
List<HashTable<INode, int>> values = new List<HashTable<INode, int>>();
List<List<int>> nulls = new List<List<int>>();
foreach (String var in joinVars)
{
values.Add(new HashTable<INode, int>(HashTableBias.Enumeration));
nulls.Add(new List<int>());
}
//First do a pass over the LHS Result to find all possible values for joined variables
HashSet<int> matched = new HashSet<int>();
HashSet<int> standalone = new HashSet<int>();
foreach (ISet x in this.Sets)
{
int i = 0;
foreach (String var in joinVars)
{
INode value = x[var];
if (value != null)
{
//.........这里部分代码省略.........
示例5: CheckArgument
private IValuedNode CheckArgument(ISparqlExpression expr, SparqlEvaluationContext context, int bindingID, Func<Uri, bool> argumentTypeValidator)
{
IValuedNode temp = expr.Evaluate(context, bindingID);
if (temp != null)
{
if (temp.NodeType == NodeType.Literal)
{
ILiteralNode lit = (ILiteralNode)temp;
if (lit.DataType != null)
{
if (argumentTypeValidator(lit.DataType))
{
//Appropriately typed literals are fine
return temp;
}
else
{
throw new RdfQueryException("Unable to evaluate an XPath substring as one of the argument expressions returned a typed literal with an invalid type");
}
}
else if (argumentTypeValidator(UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeString)))
{
//Untyped Literals are treated as Strings and may be returned when the argument allows strings
return temp;
}
else
{
throw new RdfQueryException("Unable to evalaute an XPath substring as one of the argument expressions returned an untyped literal");
}
}
else
{
throw new RdfQueryException("Unable to evaluate an XPath substring as one of the argument expressions returned a non-literal");
}
}
else
{
throw new RdfQueryException("Unable to evaluate an XPath substring as one of the argument expressions evaluated to null");
}
}