本文整理汇总了C#中Graph.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.Merge方法的具体用法?C# Graph.Merge怎么用?C# Graph.Merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.Merge方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyToGraph
public void ApplyToGraph(Graph graph)
{
using (_gate.DisposableWait())
{
using (var graphTransaction = new GraphTransactionScope())
{
graph.Merge(this.Graph);
foreach (var deferredProperty in _deferredPropertySets)
{
var nodeToSet = graph.Nodes.Get(deferredProperty.Item1.Id);
nodeToSet.SetValue(deferredProperty.Item2, deferredProperty.Item3);
}
graphTransaction.Complete();
}
}
}
示例2: CreateGraphForParameter
/// <summary>
/// Creates the graph for a given parameter, the other parameters are considered fixed by the interpretation context
/// </summary>
/// <param name="context">The interpretation context</param>
/// <param name="parameter">The parameter for the X axis</param>
/// <param name="explain"></param>
/// <returns></returns>
public virtual Graph CreateGraphForParameter(InterpretationContext context, Parameter parameter,
ExplanationPart explain)
{
Graph retVal = Graph;
if (retVal == null)
{
retVal = new Graph();
foreach (Case cas in Cases)
{
if (PreconditionSatisfied(context, cas, parameter, explain))
{
Graph subGraph = cas.Expression.CreateGraph(context, parameter, explain);
ReduceGraph(context, subGraph, cas, parameter, explain);
retVal.Merge(subGraph);
}
}
}
return retVal;
}
示例3: SetActiveGraph
/// <summary>
/// Sets the Active Graph for the SPARQL query
/// </summary>
/// <param name="graphUris">URIs of the Graphs which form the Active Graph</param>
/// <remarks>Helper function used primarily in the execution of GRAPH Clauses</remarks>
public void SetActiveGraph(IEnumerable<Uri> graphUris)
{
if (graphUris.Count() == 1)
{
//If only 1 Graph Uri call the simpler SetActiveGraph method which will be quicker
this.SetActiveGraph(graphUris.First());
}
else
{
//Multiple Graph URIs
//Build a merged Graph of all the Graph URIs
Graph g = new Graph();
foreach (Uri u in graphUris)
{
if (this.HasGraph(u))
{
g.Merge(this[u], true);
}
//else
//{
// throw new RdfQueryException("A Graph with URI '" + u.ToString() + "' does not exist in this Triple Store, a GRAPH Clause cannot be used to change the Active Graph to a Graph that doesn't exist");
//}
}
//Push current Active Graph on the Stack
this._activeGraphs.Value.Push(this._activeGraph.Value);
//Set the new Active Graph
this._activeGraph.Value = g;
}
}
示例4: GraphMerging
public void GraphMerging()
{
try
{
//Load the Test RDF
TurtleParser ttlparser = new TurtleParser();
Graph g = new Graph();
Graph h = new Graph();
Assert.IsNotNull(g);
Assert.IsNotNull(h);
ttlparser.Load(g, "MergePart1.ttl");
ttlparser.Load(h, "MergePart2.ttl");
Console.WriteLine("Merge Test Data Loaded OK");
Console.WriteLine();
Console.WriteLine("Graph 1 Contains");
foreach (Triple t in g.Triples)
{
Console.WriteLine(t.ToString());
}
Console.WriteLine();
Console.WriteLine("Graph 2 Contains");
foreach (Triple t in h.Triples)
{
Console.WriteLine(t.ToString());
}
Console.WriteLine();
Console.WriteLine("Attempting Graph Merge");
g.Merge(h);
Console.WriteLine();
foreach (Triple t in g.Triples)
{
Console.WriteLine(t.ToString());
}
Assert.AreEqual(8, g.Triples.Count, "Expected 8 Triples after the Merge");
//Use a GraphViz Generator to picture this
Console.WriteLine();
Console.WriteLine("Visualizing Merged Graph as SVG with GraphViz");
GraphVizGenerator gvzgen = new GraphVizGenerator("svg");
gvzgen.Generate(g, "MergeTest.svg", false);
Console.WriteLine("Visualisation created as MergeTest.svg");
//Same merge into an Empty Graph
Console.WriteLine();
Console.WriteLine("Combining the two Graphs with two Merge operations into an Empty Graph");
Graph i = new Graph();
//Need to reload g from disk
g = new Graph();
ttlparser.Load(g, "MergePart1.ttl");
//Do the actual merge
i.Merge(g);
i.Merge(h);
Console.WriteLine();
foreach (Triple t in i.Triples)
{
Console.WriteLine(t.ToString());
}
Assert.AreEqual(8, i.Triples.Count, "Expected 8 Triples after the Merge");
}
catch (Exception ex)
{
TestTools.ReportError("Other Exception", ex, true);
}
}
示例5: SetDefaultGraph
/// <summary>
/// Sets the Default Graph
/// </summary>
/// <param name="graphUris">Graph URIs</param>
public void SetDefaultGraph(IEnumerable<Uri> graphUris)
{
if (!graphUris.Any())
{
this.SetDefaultGraphInternal(new Graph());
this._defaultGraphUris.Value.Push(Enumerable.Empty<Uri>());
}
else if (graphUris.Count() == 1)
{
this.SetDefaultGraph(graphUris.First());
}
else
{
//Multiple Graph URIs
//Build a merged Graph of all the Graph URIs
Graph g = new Graph();
foreach (Uri u in graphUris)
{
if (this.HasGraph(u))
{
g.Merge(this[u], true);
}
}
this.SetDefaultGraphInternal(g);
this._defaultGraphUris.Value.Push(graphUris.ToList());
}
}
示例6: SetActiveGraph
/// <summary>
/// Sets the Active Graph for the SPARQL query
/// </summary>
/// <param name="graphUris">URIs of the Graphs which form the Active Graph</param>
/// <remarks>Helper function used primarily in the execution of GRAPH Clauses</remarks>
public void SetActiveGraph(IEnumerable<Uri> graphUris)
{
if (!graphUris.Any())
{
this.SetActiveGraph((Uri)null);
}
else if (graphUris.Count() == 1)
{
//If only 1 Graph Uri call the simpler SetActiveGraph method which will be quicker
this.SetActiveGraph(graphUris.First());
}
else
{
//Multiple Graph URIs
//Build a merged Graph of all the Graph URIs
Graph g = new Graph();
foreach (Uri u in graphUris)
{
if (this.HasGraph(u))
{
g.Merge(this[u], true);
}
}
this.SetActiveGraphInternal(g);
this._activeGraphUris.Value.Push(graphUris.ToList());
}
}
示例7: ProcessPost
/// <summary>
/// Processes a POST operation
/// </summary>
/// <param name="context">HTTP Context</param>
/// <remarks>
/// <para>
/// <strong>Warning: </strong> If the underlying <see cref="IGenericIOManager">IGenericIOManager</see> is read-only then this operation returns a 403 Forbidden.
/// </para>
/// <para>
/// Otherwise this is implemented using <see cref="IGenericIOManager.UpdateGraph">UpdateGraph()</see> if updates are supported, if not then the Graph has to be loaded, the POSTed data merged into it and then the Graph is saved again.
/// </para>
/// </remarks>
public override void ProcessPost(HttpContext context)
{
//If the Manager is read-only then a 403 Forbidden will be returned
if (this._manager.IsReadOnly)
{
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return;
}
IGraph g = this.ParsePayload(context);
if (g == null) return;
Uri graphUri = this.ResolveGraphUri(context, g);
if (this._manager.UpdateSupported)
{
this._manager.UpdateGraph(graphUri, g.Triples, Enumerable.Empty<Triple>());
}
else
{
//If the Manager does not support update we attempt to get around this by loading the Graph
//appending the additions to it (via merging) and then saving it back to the Store
Graph current = new Graph();
this._manager.LoadGraph(current, graphUri);
current.Merge(g);
this._manager.SaveGraph(current);
}
}
示例8: SparqlUpdateModifyWithOptional2
public void SparqlUpdateModifyWithOptional2()
{
Graph g = new Graph();
g.LoadFromFile("InferenceTest.ttl");
g.BaseUri = new Uri("http://example.org/vehicles/");
Graph def = new Graph();
def.Merge(g);
TripleStore store = new TripleStore();
store.Add(g);
store.Add(def);
Graph expected = new Graph();
expected.NamespaceMap.Import(g.NamespaceMap);
expected.Merge(g);
expected.Retract(expected.GetTriplesWithPredicate(expected.CreateUriNode("rdf:type")));
expected.Retract(expected.GetTriplesWithPredicate(expected.CreateUriNode("eg:Speed")));
String update = "PREFIX ex: <http://example.org/vehicles/> DELETE { ?s a ?type . ?s ex:Speed ?speed } INSERT { } USING <http://example.org/vehicles/> WHERE { ?s a ?type . OPTIONAL { ?s ex:Speed ?speed } }";
this.TestUpdate(store, expected, update);
}
示例9: QueryWithResultGraph
//.........这里部分代码省略.........
//Limit the number of simultaneous requests we make to the user defined level (default 4)
//We do this limiting check before trying to issue a request so that when the last request
//is issued we'll always drop out of the loop and move onto our WaitAll()
while (count >= this._maxSimultaneousRequests)
{
//First check that the count of active requests is accurate
int active = asyncResults.Count(r => !r.IsCompleted);
if (active < count)
{
//Some of the requests have already completed so we don't need to wait
count = active;
break;
}
else if (active > count)
{
//There are more active requests then we thought
count = active;
}
//While the number of requests is at/above the maximum we'll wait for any of the requests to finish
//Then we can decrement the count and if this drops back below our maximum then we'll go back into the
//main loop and fire off our next request
WaitHandle.WaitAny(asyncResults.Select(r => r.AsyncWaitHandle).ToArray());
count--;
}
//Make an asynchronous query to the next endpoint
AsyncQueryWithResultGraph d = new AsyncQueryWithResultGraph(endpoint.QueryWithResultGraph);
asyncCalls.Add(d);
IAsyncResult asyncResult = d.BeginInvoke(sparqlQuery, null, null);
asyncResults.Add(asyncResult);
count++;
}
//Wait for all our requests to finish
int waitTimeout = (base.Timeout > 0) ? base.Timeout : System.Threading.Timeout.Infinite;
WaitHandle.WaitAll(asyncResults.Select(r => r.AsyncWaitHandle).ToArray(), waitTimeout);
//Check for and handle timeouts
if (!this._ignoreFailedRequests && !asyncResults.All(r => r.IsCompleted))
{
for (int i = 0; i < asyncCalls.Count; i++)
{
try
{
asyncCalls[i].EndInvoke(asyncResults[i]);
}
catch
{
//Exceptions don't matter as we're just ensuring all the EndInvoke() calls are made
}
}
throw new RdfQueryTimeoutException("Federated Querying failed due to one/more endpoints failing to return results within the Timeout specified which is currently " + (base.Timeout / 1000) + " seconds");
}
//Now merge all the results together
HashSet<String> varsSeen = new HashSet<string>();
Graph merged = new Graph();
for (int i = 0; i < asyncCalls.Count; i++)
{
//Retrieve the result for this call
AsyncQueryWithResultGraph call = asyncCalls[i];
IGraph g;
try
{
g = call.EndInvoke(asyncResults[i]);
}
catch (Exception ex)
{
if (!this._ignoreFailedRequests)
{
//Clean up in the event of an error
for (int j = i + 1; j < asyncCalls.Count; j++)
{
try
{
asyncCalls[j].EndInvoke(asyncResults[j]);
}
catch
{
//Exceptions don't matter as we're just ensuring all the EndInvoke() calls are made
}
}
//If a single request fails then the entire query fails
throw new RdfQueryException("Federated Querying failed due to the query against the endpoint '" + this._endpoints[i] + "' failing", ex);
}
else
{
//If we're ignoring failed requests we continue here
continue;
}
}
//Merge the result into the final results
merged.Merge(g);
}
return merged;
}