本文整理汇总了C#中IRdfHandler.HandleTriple方法的典型用法代码示例。如果您正苦于以下问题:C# IRdfHandler.HandleTriple方法的具体用法?C# IRdfHandler.HandleTriple怎么用?C# IRdfHandler.HandleTriple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRdfHandler
的用法示例。
在下文中一共展示了IRdfHandler.HandleTriple方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DescribeInternal
/// <summary>
/// Generates the Description for each of the Nodes to be described
/// </summary>
/// <param name="handler">RDF Handler</param>
/// <param name="context">SPARQL Evaluation Context</param>
/// <param name="nodes">Nodes to be described</param>
protected override void DescribeInternal(IRdfHandler handler, SparqlEvaluationContext context, IEnumerable<INode> nodes)
{
//Rewrite Blank Node IDs for DESCRIBE Results
Dictionary<String, INode> bnodeMapping = new Dictionary<string, INode>();
//Get Triples for this Subject
Queue<INode> bnodes = new Queue<INode>();
HashSet<INode> expandedBNodes = new HashSet<INode>();
foreach (INode n in nodes)
{
//Get Triples where the Node is the Subject
foreach (Triple t in context.Data.GetTriplesWithSubject(n))
{
if (t.Object.NodeType == NodeType.Blank)
{
if (!expandedBNodes.Contains(t.Object)) bnodes.Enqueue(t.Object);
}
if (!handler.HandleTriple(this.RewriteDescribeBNodes(t, bnodeMapping, handler))) ParserHelper.Stop();
}
//Get Triples where the Node is the Object
foreach (Triple t in context.Data.GetTriplesWithObject(n))
{
if (t.Subject.NodeType == NodeType.Blank)
{
if (!expandedBNodes.Contains(t.Subject)) bnodes.Enqueue(t.Subject);
}
if (!handler.HandleTriple(this.RewriteDescribeBNodes(t, bnodeMapping, handler))) ParserHelper.Stop();
}
//Compute the Blank Node Closure for this Subject
while (bnodes.Count > 0)
{
INode bsubj = bnodes.Dequeue();
if (expandedBNodes.Contains(bsubj)) continue;
expandedBNodes.Add(bsubj);
foreach (Triple t2 in context.Data.GetTriplesWithSubject(bsubj))
{
if (t2.Object.NodeType == NodeType.Blank)
{
if (!expandedBNodes.Contains(t2.Object)) bnodes.Enqueue(t2.Object);
}
if (!handler.HandleTriple(this.RewriteDescribeBNodes(t2, bnodeMapping, handler))) ParserHelper.Stop();
}
foreach (Triple t2 in context.Data.GetTriplesWithObject(bsubj))
{
if (t2.Subject.NodeType == NodeType.Blank)
{
if (!expandedBNodes.Contains(t2.Subject)) bnodes.Enqueue(t2.Subject);
}
if (!handler.HandleTriple(this.RewriteDescribeBNodes(t2, bnodeMapping, handler))) ParserHelper.Stop();
}
}
}
}
示例2: DescribeInternal
/// <summary>
/// Generates the Description for each of the Nodes to be described
/// </summary>
/// <param name="handler">RDF Handler</param>
/// <param name="context">SPARQL Evaluation Context</param>
/// <param name="nodes">Nodes to be described</param>
protected override void DescribeInternal(IRdfHandler handler, SparqlEvaluationContext context, IEnumerable<INode> nodes)
{
//Rewrite Blank Node IDs for DESCRIBE Results
Dictionary<String, INode> bnodeMapping = new Dictionary<string, INode>();
//Get Triples for this Subject
foreach (INode n in nodes)
{
//Get Triples where the Node is the Subject
foreach (Triple t in context.Data.GetTriplesWithSubject(n))
{
if (!handler.HandleTriple((this.RewriteDescribeBNodes(t, bnodeMapping, handler)))) ParserHelper.Stop();
}
//Get Triples where the Node is the Object
foreach (Triple t in context.Data.GetTriplesWithObject(n))
{
if (!handler.HandleTriple((this.RewriteDescribeBNodes(t, bnodeMapping, handler)))) ParserHelper.Stop();
}
}
}
示例3: DescribeInternal
/// <summary>
/// Generates the Description for each of the Nodes to be described
/// </summary>
/// <param name="handler">RDF Handler</param>
/// <param name="context">SPARQL Evaluation Context</param>
/// <param name="nodes">Nodes to be described</param>
protected override void DescribeInternal(IRdfHandler handler, SparqlEvaluationContext context, IEnumerable<INode> nodes)
{
//Rewrite Blank Node IDs for DESCRIBE Results
Dictionary<String, INode> bnodeMapping = new Dictionary<string, INode>();
foreach (INode n in nodes)
{
if (n.NodeType == NodeType.Uri)
{
IGraph g = context.Data[((IUriNode)n).Uri];
foreach (Triple t in g.Triples)
{
if (!handler.HandleTriple(this.RewriteDescribeBNodes(t, bnodeMapping, handler))) ParserHelper.Stop();
}
}
}
}
示例4: TryParseTriple
private void TryParseTriple(IRdfHandler handler, IToken s, IToken p, IToken o, Uri graphUri)
{
INode subj, pred, obj;
switch (s.TokenType)
{
case Token.BLANKNODEWITHID:
subj = handler.CreateBlankNode(s.Value.Substring(2));
break;
case Token.URI:
subj = ParserHelper.TryResolveUri(handler, s);
break;
default:
throw ParserHelper.Error("Unexpected Token '" + s.GetType().ToString() + "' encountered, expected a Blank Node/URI as the Subject of a Triple", s);
}
switch (p.TokenType)
{
case Token.URI:
pred = ParserHelper.TryResolveUri(handler, p);
break;
default:
throw ParserHelper.Error("Unexpected Token '" + p.GetType().ToString() + "' encountered, expected a URI as the Predicate of a Triple", p);
}
switch (o.TokenType)
{
case Token.BLANKNODEWITHID:
obj = handler.CreateBlankNode(o.Value.Substring(2));
break;
case Token.LITERAL:
obj = handler.CreateLiteralNode(o.Value);
break;
case Token.LITERALWITHDT:
String dtUri = ((LiteralWithDataTypeToken)o).DataType;
obj = handler.CreateLiteralNode(o.Value, new Uri(dtUri.Substring(1, dtUri.Length - 2)));
break;
case Token.LITERALWITHLANG:
obj = handler.CreateLiteralNode(o.Value, ((LiteralWithLanguageSpecifierToken)o).Language);
break;
case Token.URI:
obj = ParserHelper.TryResolveUri(handler, o);
break;
default:
throw ParserHelper.Error("Unexpected Token '" + o.GetType().ToString() + "' encountered, expected a Blank Node/Literal/URI as the Object of a Triple", o);
}
if (!handler.HandleTriple(new Triple(subj, pred, obj, graphUri))) throw ParserHelper.Stop();
}
示例5: HandleTriple
/// <summary>
/// Creates and handles a triple
/// </summary>
/// <param name="handler">Handler</param>
/// <param name="subject">Subject</param>
/// <param name="predicate">Predicate</param>
/// <param name="obj">Object</param>
/// <param name="datatype">Object Datatype</param>
/// <returns>True if parsing should continue, false otherwise</returns>
bool HandleTriple(IRdfHandler handler, string subject, string predicate, string obj, string datatype, bool isLiteral)
{
INode subjectNode;
if (subject.StartsWith("_"))
{
string nodeId = subject.Substring(subject.IndexOf(":") + 1);
subjectNode = handler.CreateBlankNode(nodeId);
}
else
{
subjectNode = handler.CreateUriNode(new Uri(subject));
}
INode predicateNode = handler.CreateUriNode(new Uri(predicate));
INode objNode;
if (isLiteral)
{
objNode = (datatype == null) ? handler.CreateLiteralNode((string)obj) : handler.CreateLiteralNode((string)obj, new Uri(datatype));
}
else
{
if (obj.StartsWith("_"))
{
string nodeId = obj.Substring(obj.IndexOf(":") + 1);
objNode = handler.CreateBlankNode(nodeId);
}
else
{
objNode = handler.CreateUriNode(new Uri(obj));
}
}
return handler.HandleTriple(new Triple(subjectNode, predicateNode, objNode));
}
示例6: HandleTriple
/// <summary>
/// Creates and handles a triple
/// </summary>
/// <param name="handler">Handler</param>
/// <param name="subject">Subject</param>
/// <param name="predicate">Predicate</param>
/// <param name="obj">Object</param>
/// <param name="datatype">Object Datatype</param>
/// <param name="isLiteral">isLiteral Object</param>
/// <returns>True if parsing should continue, false otherwise</returns>
bool HandleTriple(IRdfHandler handler, string subject, string predicate, string obj, string datatype, bool isLiteral)
{
INode subjectNode;
if (subject.StartsWith("_"))
{
string nodeId = subject.Substring(subject.IndexOf(":") + 1);
subjectNode = handler.CreateBlankNode(nodeId);
}
else
{
subjectNode = handler.CreateUriNode(new Uri(subject));
}
INode predicateNode = handler.CreateUriNode(new Uri(predicate));
INode objNode;
if (isLiteral)
{
if (datatype == "http://www.w3.org/2001/XMLSchema#boolean")
{
// sometimes newtonsoft.json appears to return boolean as string True and dotNetRdf doesn't appear to recognize that
obj = ((string)obj).ToLowerInvariant();
}
objNode = (datatype == null) ? handler.CreateLiteralNode((string)obj) : handler.CreateLiteralNode((string)obj, new Uri(datatype));
}
else
{
if (obj.StartsWith("_"))
{
string nodeId = obj.Substring(obj.IndexOf(":") + 1);
objNode = handler.CreateBlankNode(nodeId);
}
else
{
objNode = handler.CreateUriNode(new Uri(obj));
}
}
return handler.HandleTriple(new Triple(subjectNode, predicateNode, objNode));
}
示例7: TryParseTriple
private void TryParseTriple(XmlReader reader, IRdfHandler handler, Uri graphUri)
{
//Verify Node Name
if (!reader.Name.Equals("triple"))
{
throw Error("Unexpected Element <" + reader.Name + "> encountered, only an optional <id>/<uri> element followed by zero/more <triple> elements are permitted within a <graph> element", reader);
}
//Parse XML Nodes into RDF Nodes
INode subj, pred, obj;
subj = this.TryParseNode(reader, handler, TripleSegment.Subject);
pred = this.TryParseNode(reader, handler, TripleSegment.Predicate);
obj = this.TryParseNode(reader, handler, TripleSegment.Object);
if (reader.NodeType != XmlNodeType.EndElement) throw Error("Unexpected element type " + reader.NodeType.ToString() + " encountered, expected the </triple> element", reader);
if (!reader.Name.Equals("triple")) throw Error("Unexpected </" + reader.Name + "> encountered, expected a </triple> element", reader);
//Assert the resulting Triple
if (!handler.HandleTriple(new Triple(subj, pred, obj, graphUri))) throw ParserHelper.Stop();
}
示例8: QueryWithResultGraph
//.........这里部分代码省略.........
//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>();
bool cont = true;
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
//If the handler has previously told us to stop we skip this step
if (cont)
{
handler.StartRdf();
foreach (Triple t in g.Triples)
{
cont = handler.HandleTriple(t);
//Stop if the Handler tells us to
if (!cont) break;
}
handler.EndRdf(true);
}
}
}
示例9: HandleTriple
private static void HandleTriple(IRdfHandler handler, string subject, string predicate, string obj, string datatype, bool isLiteral)
{
INode subjectNode = (subject.StartsWith("_") ? (INode)handler.CreateBlankNode(subject.Substring(2)) : handler.CreateUriNode(new Uri(subject)));
INode predicateNode = handler.CreateUriNode(new Uri(predicate));
INode objNode;
if (isLiteral)
{
if (datatype == "http://www.w3.org/2001/XMLSchema#boolean")
{
obj = obj.ToLowerInvariant();
}
objNode = (datatype == null ? handler.CreateLiteralNode(obj) : handler.CreateLiteralNode(obj, new Uri(datatype)));
}
else
{
objNode = (obj.StartsWith("_") ? (INode)handler.CreateBlankNode(obj.Substring(2)) : handler.CreateUriNode(new Uri(obj)));
}
if (!handler.HandleTriple(new Triple(subjectNode, predicateNode, objNode)))
{
throw new InvalidOperationException(String.Format("Could not add triple {0} {1} {2} .", subjectNode, predicateNode, objNode));
}
}
示例10: LoadGraph
/// <summary>
/// Loads a Graph from the Quad Store
/// </summary>
/// <param name="handler">RDF Handler</param>
/// <param name="graphUri">URI of the Graph to Load</param>
public void LoadGraph(IRdfHandler handler, Uri graphUri)
{
if (graphUri == null) throw new RdfStorageException("Cannot load an unnamed Graph from Virtuoso as this would require loading the entirety of the Virtuoso Quad Store into memory!");
try
{
handler.StartRdf();
//Need to keep Database Open as Literals require extra trips to the Database to get additional
//information about Language and Type
this.Open(false);
DataTable data = this.LoadTriples(graphUri);
foreach (DataRow row in data.Rows)
{
Object s, p, o;
INode subj, pred, obj;
//Get Data
s = row["S"];
p = row["P"];
o = row["O"];
//Create Nodes
subj = this.LoadNode(handler, s);
pred = this.LoadNode(handler, p);
obj = this.LoadNode(handler, o);
//Assert Triple
if (!handler.HandleTriple(new Triple(subj, pred, obj))) ParserHelper.Stop();
}
handler.EndRdf(true);
this.Close(false);
}
catch (RdfParsingTerminatedException)
{
handler.EndRdf(true);
this.Close(false);
}
catch
{
handler.EndRdf(false);
this.Close(true);
throw;
}
}