本文整理汇总了C#中VDS.RDF.Graph.GetTriplesWithPredicate方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.GetTriplesWithPredicate方法的具体用法?C# Graph.GetTriplesWithPredicate怎么用?C# Graph.GetTriplesWithPredicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VDS.RDF.Graph
的用法示例。
在下文中一共展示了Graph.GetTriplesWithPredicate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessIncludes
private static void ProcessIncludes(Graph g)
{
var includeTriple =
g.GetTriplesWithPredicate(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include")).
FirstOrDefault();
while(includeTriple != null) {
if (includeTriple.Object.NodeType == NodeType.Blank)
{
ProcessList(includeTriple.Object, g, ProcessInclude);
}
else
{
ProcessInclude(includeTriple.Object, g);
}
g.Retract(includeTriple);
includeTriple = g.GetTriplesWithPredicate(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include")).
FirstOrDefault();
}
}
示例2: Main
public static void Main(String[] args)
{
StreamWriter output = new StreamWriter("AllegroGraphTest.txt");
Console.SetOut(output);
try
{
Console.WriteLine("## AllegroGraph Test");
Console.WriteLine();
//Load the Graph we want to use as a Test
Graph g = new Graph();
TurtleParser ttlparser = new TurtleParser();
ttlparser.Load(g, "InferenceTest.ttl");
Console.WriteLine("Test Graph contains the following Triples:");
ShowGraph(g);
Console.WriteLine();
//Load another Graph
Graph h = new Graph();
h.BaseUri = new Uri("http://example.org/test");
Notation3Parser n3parser = new Notation3Parser();
n3parser.Load(h, "test.n3");
Console.WriteLine("Second Test Graph contains the following Triples:");
ShowGraph(h);
Console.WriteLine();
Console.WriteLine("Trying to create a test store in the test catalog");
AllegroGraphConnector agraph = new AllegroGraphConnector("http://localhost:9875/", "test", "test");
Console.WriteLine("Store Created OK");
Console.WriteLine();
Console.WriteLine("Trying to add data to the Store");
agraph.SaveGraph(g);
agraph.SaveGraph(h);
Console.WriteLine("Saved OK");
Console.WriteLine();
Console.WriteLine("Trying to load data from the Store");
Graph i = new Graph();
agraph.LoadGraph(i, String.Empty);
ShowGraph(i);
Console.WriteLine();
i = new Graph();
agraph.LoadGraph(i, new Uri("http://example.org/test"));
ShowGraph(i);
Console.WriteLine("Loaded OK");
Console.WriteLine();
Console.WriteLine("Trying to update data in the Store");
List<Triple> toRemove = g.GetTriplesWithPredicate(g.CreateUriNode("rdf:type")).ToList();
Triple toAdd = new Triple(g.CreateUriNode(new Uri("http://example.org/")), g.CreateUriNode("rdf:type"), g.CreateLiteralNode("Added Triple Test"));
agraph.UpdateGraph(String.Empty, new List<Triple>() { toAdd }, toRemove);
Console.WriteLine("Updated OK");
Console.WriteLine();
Console.WriteLine("Trying a SPARQL ASK query against the store");
Object results = agraph.Query("ASK WHERE {?s ?p ?o}");
Console.WriteLine("Got results OK");
ShowResults(results);
Console.WriteLine();
Console.WriteLine("Trying a SPARQL SELECT query against the store");
results = agraph.Query("SELECT * WHERE {?s ?p ?o}");
Console.WriteLine("Got results OK");
ShowResults(results);
Console.WriteLine();
}
catch (RdfStorageException storeEx)
{
reportError(output, "RDF Storage Error", storeEx);
}
catch (RdfParseException parseEx)
{
reportError(output, "RDF Parsing Error", parseEx);
}
catch (RdfQueryException queryEx)
{
reportError(output, "RDF Query Error", queryEx);
}
catch (RdfException rdfEx)
{
reportError(output, "RDF Error", rdfEx);
}
catch (WebException webEx)
{
reportError(output, "HTTP Error", webEx);
}
catch (Exception ex)
{
reportError(output, "Error", ex);
}
finally
{
output.Close();
}
}