本文整理汇总了C#中SparqlEvaluationContext.CheckTimeout方法的典型用法代码示例。如果您正苦于以下问题:C# SparqlEvaluationContext.CheckTimeout方法的具体用法?C# SparqlEvaluationContext.CheckTimeout怎么用?C# SparqlEvaluationContext.CheckTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparqlEvaluationContext
的用法示例。
在下文中一共展示了SparqlEvaluationContext.CheckTimeout方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
/// <summary>
/// Evaluates an ExistsJoin
/// </summary>
/// <param name="context">Evaluation Context</param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
BaseMultiset initialInput = context.InputMultiset;
BaseMultiset lhsResult = context.Evaluate(this._lhs);//this._lhs.Evaluate(context);
context.CheckTimeout();
if (lhsResult is NullMultiset)
{
context.OutputMultiset = lhsResult;
}
else if (lhsResult.IsEmpty)
{
context.OutputMultiset = new NullMultiset();
}
else
{
//Only execute the RHS if the LHS had results
context.InputMultiset = lhsResult;
BaseMultiset rhsResult = context.Evaluate(this._rhs);//this._rhs.Evaluate(context);
context.CheckTimeout();
context.OutputMultiset = lhsResult.ExistsJoin(rhsResult, this._mustExist);
context.CheckTimeout();
}
context.InputMultiset = context.OutputMultiset;
return context.OutputMultiset;
}
示例2: Evaluate
/// <summary>
/// Evaluates the Minus join by evaluating the LHS and RHS and substracting the RHS results from the LHS
/// </summary>
/// <param name="context">Evaluation Context</param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
BaseMultiset initialInput = context.InputMultiset;
BaseMultiset lhsResult = context.Evaluate(this._lhs);//this._lhs.Evaluate(context);
context.CheckTimeout();
if (lhsResult is NullMultiset)
{
context.OutputMultiset = lhsResult;
}
else if (lhsResult.IsEmpty)
{
context.OutputMultiset = new NullMultiset();
}
else if (this._lhs.Variables.IsDisjoint(this._rhs.Variables))
{
//If the RHS is disjoint then there is no need to evaluate the RHS
context.OutputMultiset = lhsResult;
}
else
{
//If we get here then the RHS is not disjoint so it does affect the ouput
//Only execute the RHS if the LHS had results
//context.InputMultiset = lhsResult;
context.InputMultiset = initialInput;
BaseMultiset rhsResult = context.Evaluate(this._rhs);//this._rhs.Evaluate(context);
context.CheckTimeout();
context.OutputMultiset = lhsResult.MinusJoin(rhsResult);
context.CheckTimeout();
}
context.InputMultiset = context.OutputMultiset;
return context.OutputMultiset;
}
示例3: Evaluate
/// <summary>
/// Evaluates the Union
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
//Create a copy of the evaluation context for the RHS
SparqlEvaluationContext context2 = new SparqlEvaluationContext(context.Query, context.Data, context.Processor);
if (!(context.InputMultiset is IdentityMultiset))
{
context2.InputMultiset = new Multiset();
foreach (ISet s in context.InputMultiset.Sets)
{
context2.InputMultiset.Add(s.Copy());
}
}
IGraph activeGraph = context.Data.ActiveGraph;
IGraph defaultGraph = context.Data.DefaultGraph;
ParallelEvaluateDelegate d = new ParallelEvaluateDelegate(this.ParallelEvaluate);
IAsyncResult lhs = d.BeginInvoke(this._lhs, context, activeGraph, defaultGraph, null, null);
IAsyncResult rhs = d.BeginInvoke(this._rhs, context2, activeGraph, defaultGraph, null, null);
WaitHandle.WaitAll(new WaitHandle[] { lhs.AsyncWaitHandle, rhs.AsyncWaitHandle });
bool rhsOk = false;
try
{
BaseMultiset lhsResult = d.EndInvoke(lhs);
rhsOk = true;
BaseMultiset rhsResult = d.EndInvoke(rhs);
context.CheckTimeout();
context.OutputMultiset = lhsResult.Union(rhsResult);
context.CheckTimeout();
context.InputMultiset = context.OutputMultiset;
return context.OutputMultiset;
}
catch
{
if (!rhsOk)
{
//Clean up the RHS evaluation call if the LHS has errored
try
{
d.EndInvoke(rhs);
}
catch
{
//Ignore this error as we're already going to throw the other error
}
}
throw;
}
}
示例4: Evaluate
/// <summary>
/// Evaluates the BGP against the Evaluation Context
/// </summary>
/// <param name="context">Evaluation Context</param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
if (this._triplePatterns.Count > 0)
{
for (int i = 0; i < this._triplePatterns.Count; i++)
{
if (i == 0)
{
//If the 1st thing in a BGP is a BIND/LET/FILTER the Input becomes the Identity Multiset
if (this._triplePatterns[i] is FilterPattern || this._triplePatterns[i] is BindPattern || this._triplePatterns[i] is LetPattern)
{
if (this._triplePatterns[i] is BindPattern)
{
if (context.InputMultiset.ContainsVariable(((BindPattern)this._triplePatterns[i]).VariableName)) throw new RdfQueryException("Cannot use a BIND assigment to BIND to a variable that has previously been declared");
}
else
{
context.InputMultiset = new IdentityMultiset();
}
}
}
//Create a new Output Multiset
context.OutputMultiset = new Multiset();
this._triplePatterns[i].Evaluate(context);
//If at any point we've got an Empty Multiset as our Output then we terminate BGP execution
if (context.OutputMultiset.IsEmpty) break;
//Check for Timeout before attempting the Join
context.CheckTimeout();
//If this isn't the first Pattern we do Join/Product the Output to the Input
if (i > 0)
{
if (context.InputMultiset.IsDisjointWith(context.OutputMultiset))
{
//Disjoint so do a Product
context.OutputMultiset = context.InputMultiset.ProductWithTimeout(context.OutputMultiset, context.RemainingTimeout);
}
else
{
//Normal Join
context.OutputMultiset = context.InputMultiset.Join(context.OutputMultiset);
}
}
//Then the Input for the next Pattern is the Output from the previous Pattern
context.InputMultiset = context.OutputMultiset;
}
if (context.TrimTemporaryVariables)
{
//Trim the Multiset - this eliminates any temporary variables
context.OutputMultiset.Trim();
}
}
else
{
//For an Empty BGP we just return the Identity Multiset
context.OutputMultiset = new IdentityMultiset();
}
//If we've ended with an Empty Multiset then we turn it into the Null Multiset
//to indicate that this BGP did not match anything
if (context.OutputMultiset is Multiset && context.OutputMultiset.IsEmpty) context.OutputMultiset = new NullMultiset();
//Return the Output Multiset
return context.OutputMultiset;
}
示例5: Evaluate
//.........这里部分代码省略.........
List<String> existingVars = (from v in this._pattern.Variables
where context.InputMultiset.ContainsVariable(v)
select v).ToList();
if (existingVars.Any() || context.Query.Bindings != null)
{
//Pre-bound variables/BINDINGS clause so do substitution and execution
//Build the set of possible bindings
HashSet<ISet> bindings = new HashSet<ISet>();
if (context.Query.Bindings != null && !this._pattern.Variables.IsDisjoint(context.Query.Bindings.Variables))
{
//Possible Bindings comes from BINDINGS clause
//In this case each possibility is a distinct binding tuple defined in the BINDINGS clause
foreach (BindingTuple tuple in context.Query.Bindings.Tuples)
{
bindings.Add(new Set(tuple));
}
}
else
{
//Possible Bindings get built from current input (if there was a BINDINGS clause the variables it defines are not in this SERVICE clause)
//In this case each possibility only contains Variables bound so far
foreach (ISet s in context.InputMultiset.Sets)
{
Set t = new Set();
foreach (String var in existingVars)
{
t.Add(var, s[var]);
}
bindings.Add(t);
}
}
//Execute the Query for every possible Binding and build up our Output Multiset from all the results
foreach (ISet s in bindings)
{
//Q: Should we continue processing here if and when we hit an error?
foreach (String var in s.Variables)
{
sparqlQuery.SetVariable(var, s[var]);
}
SparqlResultSet results = endpoint.QueryWithResultSet(sparqlQuery.ToString());
context.CheckTimeout();
foreach (SparqlResult r in results)
{
Set t = new Set(r);
foreach (String var in s.Variables)
{
t.Add(var, s[var]);
}
context.OutputMultiset.Add(t);
}
}
return context.OutputMultiset;
}
else
{
//No pre-bound variables/BINDINGS clause so just execute the query
//Try and get a Result Set from the Service
SparqlResultSet results = endpoint.QueryWithResultSet(sparqlQuery.ToString());
//Transform this Result Set back into a Multiset
foreach (SparqlResult r in results.Results)
{
context.OutputMultiset.Add(new Set(r));
}
return context.OutputMultiset;
}
#endif
}
catch (Exception ex)
{
if (this._silent && !bypassSilent)
{
//If Evaluation Errors are SILENT is specified then a Multiset containing a single set with all values unbound is returned
//Unless some of the SPARQL queries did return results in which we just return the results we did obtain
if (context.OutputMultiset.IsEmpty)
{
Set s = new Set();
foreach (String var in this._pattern.Variables.Distinct())
{
s.Add(var, null);
}
context.OutputMultiset.Add(s);
}
return context.OutputMultiset;
}
else
{
throw new RdfQueryException("Query execution failed because evaluating a SERVICE clause failed - this may be due to an error with the remote service", ex);
}
}
}
示例6: Evaluate
/// <summary>
/// Evaluates the Ask Union
/// </summary>
/// <param name="context">Evaluation Context</param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
BaseMultiset initialInput = context.InputMultiset;
BaseMultiset lhsResult = context.Evaluate(this._lhs);//this._lhs.Evaluate(context);
context.CheckTimeout();
if (lhsResult.IsEmpty)
{
//Only evaluate the RHS if the LHS was empty
context.InputMultiset = initialInput;
BaseMultiset rhsResult = context.Evaluate(this._rhs);//this._rhs.Evaluate(context);
context.CheckTimeout();
context.OutputMultiset = lhsResult.Union(rhsResult);
context.CheckTimeout();
context.InputMultiset = context.OutputMultiset;
}
else
{
context.OutputMultiset = lhsResult;
}
return context.OutputMultiset;
}
示例7: StreamingEvaluate
private BaseMultiset StreamingEvaluate(SparqlEvaluationContext context, int pattern, out bool halt)
{
halt = false;
//Handle Empty BGPs
if (pattern == 0 && this._triplePatterns.Count == 0)
{
context.OutputMultiset = new IdentityMultiset();
return context.OutputMultiset;
}
BaseMultiset initialInput, localOutput, results;
//Set up the Input and Output Multiset appropriately
switch (pattern)
{
case 0:
//Input is as given and Output is new empty multiset
initialInput = context.InputMultiset;
localOutput = new Multiset();
break;
case 1:
//Input becomes current Output and Output is new empty multiset
initialInput = context.OutputMultiset;
localOutput = new Multiset();
break;
default:
//Input is join of previous input and ouput and Output is new empty multiset
if (context.InputMultiset.IsDisjointWith(context.OutputMultiset))
{
//Disjoint so do a Product
initialInput = context.InputMultiset.Product(context.OutputMultiset);
}
else
{
//Normal Join
initialInput = context.InputMultiset.Join(context.OutputMultiset);
}
localOutput = new Multiset();
break;
}
context.InputMultiset = initialInput;
context.OutputMultiset = localOutput;
//Get the Triple Pattern we're evaluating
ITriplePattern temp = this._triplePatterns[pattern];
int resultsFound = 0;
if (temp is TriplePattern)
{
//Find the first Triple which matches the Pattern
TriplePattern tp = (TriplePattern)temp;
foreach (Triple t in tp.GetTriples(context))
{
//Remember to check for Timeout during lazy evaluation
context.CheckTimeout();
if (tp.Accepts(context, t))
{
resultsFound++;
context.OutputMultiset.Add(tp.CreateResult(t));
//Recurse unless we're the last pattern
if (pattern < this._triplePatterns.Count - 1)
{
results = this.StreamingEvaluate(context, pattern + 1, out halt);
//If recursion leads to a halt then we halt and return immediately
if (halt) return results;
//Otherwise we need to keep going here
//So must reset our input and outputs before continuing
context.InputMultiset = initialInput;
context.OutputMultiset = new Multiset();
resultsFound--;
}
else
{
//If we're at the last pattern and we've found a match then we can halt
halt = true;
//Generate the final output and return it
if (context.InputMultiset.IsDisjointWith(context.OutputMultiset))
{
//Disjoint so do a Product
context.OutputMultiset = context.InputMultiset.ProductWithTimeout(context.OutputMultiset, context.QueryTimeout - context.QueryTime);
}
else
{
//Normal Join
context.OutputMultiset = context.InputMultiset.Join(context.OutputMultiset);
}
return context.OutputMultiset;
}
}
}
}
else if (temp is FilterPattern)
//.........这里部分代码省略.........
示例8: Evaluate
/// <summary>
/// Evaluates the Lazy Union
/// </summary>
/// <param name="context">Evaluation Context</param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
BaseMultiset initialInput = context.InputMultiset;
if (this._lhs is Extend || this._rhs is Extend) initialInput = new IdentityMultiset();
context.InputMultiset = initialInput;
BaseMultiset lhsResult = context.Evaluate(this._lhs);//this._lhs.Evaluate(context);
context.CheckTimeout();
if (lhsResult.Count >= this._requiredResults || this._requiredResults == -1)
{
//Only evaluate the RHS if the LHS didn't yield sufficient results
context.InputMultiset = initialInput;
BaseMultiset rhsResult = context.Evaluate(this._rhs);//this._rhs.Evaluate(context);
context.CheckTimeout();
context.OutputMultiset = lhsResult.Union(rhsResult);
context.CheckTimeout();
context.InputMultiset = context.OutputMultiset;
}
else
{
context.OutputMultiset = lhsResult;
}
return context.OutputMultiset;
}
示例9: StreamingEvaluate
//.........这里部分代码省略.........
if (temp is TriplePattern)
{
//Find the first Triple which matches the Pattern
TriplePattern tp = (TriplePattern)temp;
IEnumerable<Triple> ts = tp.GetTriples(context);
//In the case that we're lazily evaluating an optimisable ORDER BY then
//we need to apply OrderBy()'s to our enumeration
//This only applies to the 1st pattern
if (pattern == 0)
{
if (context.Query != null)
{
if (context.Query.OrderBy != null && context.Query.IsOptimisableOrderBy)
{
IComparer<Triple> comparer = context.Query.OrderBy.GetComparer(tp);
if (comparer != null)
{
ts = ts.OrderBy(t => t, comparer);
}
else
{
//Can't get a comparer so can't optimise
this._requiredResults = -1;
}
}
}
}
foreach (Triple t in ts)
{
//Remember to check for Timeouts during Lazy Evaluation
context.CheckTimeout();
if (tp.Accepts(context, t))
{
resultsFound++;
if (tp.IndexType == TripleIndexType.NoVariables)
{
localOutput = new IdentityMultiset();
context.OutputMultiset = localOutput;
}
else
{
context.OutputMultiset.Add(tp.CreateResult(t));
}
//Recurse unless we're the last pattern
if (pattern < this._triplePatterns.Count - 1)
{
results = this.StreamingEvaluate(context, pattern + 1, out halt);
//If recursion leads to a halt then we halt and return immediately
if (halt && results.Count >= this._requiredResults && this._requiredResults != -1)
{
return results;
}
else if (halt)
{
if (results.Count == 0)
{
//If recursing leads to no results then eliminate all outputs
//Also reset to prevResults to -1
resultsFound = 0;
localOutput = new Multiset();