本文整理汇总了C#中Graph.CreateUriNode方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.CreateUriNode方法的具体用法?C# Graph.CreateUriNode怎么用?C# Graph.CreateUriNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.CreateUriNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParsingRdfXmlAmpersands
public void ParsingRdfXmlAmpersands()
{
List<IRdfWriter> writers = new List<IRdfWriter>()
{
new RdfXmlWriter(),
new FastRdfXmlWriter()
};
IRdfReader parser = new RdfXmlParser();
Graph g = new Graph();
g.BaseUri = new Uri("http://example.org/ampersandsInRdfXml");
g.Assert(new Triple(g.CreateUriNode(), g.CreateUriNode(new Uri("http://example.org/property")), g.CreateUriNode(new Uri("http://example.org/a&b"))));
g.Assert(new Triple(g.CreateUriNode(), g.CreateUriNode(new Uri("http://example.org/property")), g.CreateLiteralNode("A & B")));
foreach (IRdfWriter writer in writers)
{
try
{
Console.WriteLine(writer.GetType().ToString());
String temp = StringWriter.Write(g, writer);
Console.WriteLine(temp);
Graph h = new Graph();
StringParser.Parse(h, temp);
Assert.AreEqual(g, h, "Graphs should be equal");
Console.WriteLine();
}
catch (Exception ex)
{
TestTools.ReportError("Error", ex, true);
}
}
}
示例2: SparqlDefaultGraphExists3
public void SparqlDefaultGraphExists3()
{
SqlDataset dataset = new SqlDataset(new MicrosoftSqlStoreManager("localhost", "unit_test", "example", "password"));
//Create Default Graph only if required
if (!dataset.HasGraph(null))
{
Graph g = new Graph();
g.Assert(g.CreateUriNode(new Uri("http://example.org/subject")), g.CreateUriNode(new Uri("http://example.org/predicate")), g.CreateUriNode(new Uri("http://example.org/object")));
dataset.AddGraph(g);
dataset.Flush();
}
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString("ASK WHERE { GRAPH ?g { ?s ?p ?o }}");
LeviathanQueryProcessor lvn = new LeviathanQueryProcessor(dataset);
Object results = lvn.ProcessQuery(q);
if (results is SparqlResultSet)
{
Assert.IsTrue(((SparqlResultSet)results).Result);
}
else
{
Assert.Fail("ASK Query did not return a SPARQL Result Set as expected");
}
dataset.Flush();
}
示例3: SparqlFunctionsIsNumeric
public void SparqlFunctionsIsNumeric()
{
Graph g = new Graph();
IUriNode subj = g.CreateUriNode(new Uri("http://example.org/subject"));
IUriNode pred = g.CreateUriNode(new Uri("http://example.org/predicate"));
g.Assert(subj, pred, (12).ToLiteral(g));
g.Assert(subj, pred, g.CreateLiteralNode("12"));
g.Assert(subj, pred, g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeNonNegativeInteger)));
g.Assert(subj, pred, g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeNonPositiveInteger)));
g.Assert(subj, pred, g.CreateLiteralNode("1200", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)));
g.Assert(subj, pred, ((byte)50).ToLiteral(g));
g.Assert(subj, pred, g.CreateLiteralNode("-50", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)));
g.Assert(subj, pred, g.CreateLiteralNode("-50", new Uri(XmlSpecsHelper.XmlSchemaDataTypeUnsignedByte)));
g.Assert(subj, pred, g.CreateUriNode(new Uri("http://example.org")));
TripleStore store = new TripleStore();
store.Add(g);
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString("SELECT ?obj (IsNumeric(?obj) AS ?IsNumeric) WHERE { ?s ?p ?obj }");
Object results = store.ExecuteQuery(q);
Assert.IsTrue(results is SparqlResultSet, "Result should be a SPARQL Result Set");
TestTools.ShowResults(results);
}
示例4: NodesDistinct
public void NodesDistinct()
{
Graph g = new Graph();
List<INode> test = new List<INode>()
{
g.CreateUriNode("rdf:type"),
g.CreateUriNode(new Uri("http://example.org")),
g.CreateBlankNode(),
g.CreateBlankNode(),
null,
g.CreateBlankNode("test"),
g.CreateLiteralNode("Test text"),
g.CreateLiteralNode("Test text", "en"),
g.CreateLiteralNode("Test text", new Uri(XmlSpecsHelper.XmlSchemaDataTypeString)),
g.CreateUriNode("rdf:type"),
null,
g.CreateUriNode(new Uri("http://example.org#test")),
g.CreateUriNode(new Uri("http://example.org"))
};
foreach (INode n in test.Distinct())
{
if (n != null)
{
Console.WriteLine(n.ToString());
}
else
{
Console.WriteLine("null");
}
}
}
示例5: StaticSkosReasoner
/// <summary>
/// Creates a new instance of the SKOS Reasoner
/// </summary>
public StaticSkosReasoner()
{
Graph g = new Graph();
g.NamespaceMap.AddNamespace("skos", new Uri(SKOSNamespace));
this._rdfType = g.CreateUriNode("rdf:type");
this._skosBroader = g.CreateUriNode("skos:broader");
this._skosConcept = g.CreateUriNode("skos:Concept");
this._skosNarrower = g.CreateUriNode("skos:narrower");
}
示例6: WritingCollectionCompressionEmpty2
public void WritingCollectionCompressionEmpty2()
{
Graph g = new Graph();
g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
INode rdfType = g.CreateUriNode("rdf:type");
g.Assert(g.CreateUriNode("ex:subj"), g.CreateUriNode("ex:pred"), g.CreateUriNode("rdf:nil"));
CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
WriterHelper.FindCollections(context);
Assert.AreEqual(0, context.Collections.Count, "Expected 0 Collection to be found");
this.CheckCompressionRoundTrip(g);
}
示例7: StorageFourStoreAddTriples
public void StorageFourStoreAddTriples()
{
StorageFourStoreDeleteGraph();
StorageFourStoreSaveGraph();
Graph g = new Graph();
List<Triple> ts = new List<Triple>();
ts.Add(new Triple(g.CreateUriNode(new Uri("http://example.org/subject")), g.CreateUriNode(new Uri("http://example.org/predicate")), g.CreateUriNode(new Uri("http://example.org/object"))));
FourStoreConnector fourstore = new FourStoreConnector(FourStoreTestUri);
fourstore.UpdateGraph("http://example.org/4storeTest", ts, null);
fourstore.LoadGraph(g, "http://example.org/4storeTest");
Assert.IsTrue(ts.All(t => g.ContainsTriple(t)), "Added Triple should not have been in the Graph");
}
示例8: SparqlDefaultGraphExists2
public void SparqlDefaultGraphExists2()
{
TripleStore store = new TripleStore();
Graph g = new Graph();
g.Assert(g.CreateUriNode(new Uri("http://example.org/subject")), g.CreateUriNode(new Uri("http://example.org/predicate")), g.CreateUriNode(new Uri("http://example.org/object")));
store.Add(g);
Object results = store.ExecuteQuery("ASK WHERE { GRAPH <dotnetrdf:default-graph> { ?s ?p ?o }}");
if (results is SparqlResultSet)
{
Assert.IsTrue(((SparqlResultSet)results).Result);
}
else
{
Assert.Fail("ASK Query did not return a SPARQL Result Set as expected");
}
}
示例9: GraphDiffAddedGroundTriples
public void GraphDiffAddedGroundTriples()
{
Graph g = new Graph();
Graph h = new Graph();
FileLoader.Load(g, "InferenceTest.ttl");
FileLoader.Load(h, "InferenceTest.ttl");
//Add additional Triple to 2nd Graph
IUriNode spaceVehicle = h.CreateUriNode("eg:SpaceVehicle");
IUriNode subClass = h.CreateUriNode("rdfs:subClassOf");
IUriNode vehicle = h.CreateUriNode("eg:Vehicle");
h.Assert(new Triple(spaceVehicle, subClass, vehicle));
GraphDiffReport report = g.Difference(h);
TestTools.ShowDifferences(report);
Assert.IsFalse(report.AreEqual, "Graphs should not have been reported as equal");
Assert.IsTrue(report.AddedTriples.Any(), "Difference should have reported some Added Triples");
}
示例10: GraphEventBubbling
public void GraphEventBubbling()
{
try
{
this._graphAdded = false;
this._graphRemoved = false;
this._graphChanged = false;
//Create Store and Graph add attach handlers to Store
TripleStore store = new TripleStore();
Graph g = new Graph();
store.GraphAdded += this.HandleGraphAdded;
store.GraphRemoved += this.HandleGraphRemoved;
store.GraphChanged += this.HandleGraphChanged;
//Add the Graph to the Store which should fire the GraphAdded event
store.Add(g);
Assert.IsTrue(this._graphAdded, "GraphAdded event of the Triple Store should have fired");
//Assert a Triple
INode s = g.CreateBlankNode();
INode p = g.CreateUriNode("rdf:type");
INode o = g.CreateUriNode("rdfs:Class");
Triple t = new Triple(s, p, o);
g.Assert(t);
Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired");
//Retract the Triple
this._graphChanged = false;
g.Retract(t);
Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired");
//Remove the Graph from the Store which should fire the GraphRemoved event
store.Remove(g.BaseUri);
Assert.IsTrue(this._graphRemoved, "GraphRemoved event of the Triple Store should have fired");
}
catch (Exception ex)
{
TestTools.ReportError("Error", ex, true);
}
}
示例11: StaticRdfsReasoner
/// <summary>
/// Creates a new instance of the Static RdfsReasoner
/// </summary>
public StaticRdfsReasoner()
{
Graph g = new Graph();
this._rdfType = g.CreateUriNode("rdf:type");
this._rdfsClass = g.CreateUriNode("rdfs:Class");
this._rdfsSubClass = g.CreateUriNode("rdfs:subClassOf");
this._rdfProperty = g.CreateUriNode("rdf:Property");
this._rdfsSubProperty = g.CreateUriNode("rdfs:subPropertyOf");
this._rdfsDomain = g.CreateUriNode("rdfs:domain");
this._rdfsRange = g.CreateUriNode("rdfs:range");
}
示例12: EnsureTestData
private void EnsureTestData(int triples, String file, ITripleFormatter formatter)
{
if (!File.Exists(file))
{
Graph g = new Graph();
g.NamespaceMap.AddNamespace(String.Empty, new Uri("http://example.org/node#"));
int padding = triples.ToString().Length;
using (StreamWriter writer = new StreamWriter(file))
{
for (int i = 1; i <= triples; i++)
{
IUriNode temp = g.CreateUriNode(":" + i);
writer.WriteLine(formatter.Format(new Triple(temp, temp, temp)));
}
writer.Close();
}
}
}
示例13: WritingCollectionCompressionNamedListNodes3
public void WritingCollectionCompressionNamedListNodes3()
{
Graph g = new Graph();
INode data1 = g.CreateBlankNode();
g.Assert(data1, g.CreateUriNode(new Uri("http://property")), g.CreateLiteralNode("test1"));
INode data2 = g.CreateBlankNode();
g.Assert(data2, g.CreateUriNode(new Uri("http://property")), g.CreateLiteralNode("test2"));
INode listEntry1 = g.CreateUriNode(new Uri("http://test/1"));
INode rdfFirst = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListFirst));
INode rdfRest = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListRest));
INode rdfNil = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListNil));
g.Assert(listEntry1, rdfFirst, data1);
g.Assert(listEntry1, rdfRest, rdfNil);
INode listEntry2 = g.CreateUriNode(new Uri("http://test/2"));
g.Assert(listEntry2, rdfFirst, data2);
g.Assert(listEntry2, rdfRest, listEntry1);
INode root = g.CreateUriNode(new Uri("http://root"));
g.Assert(root, g.CreateUriNode(new Uri("http://list")), listEntry2);
NTriplesFormatter formatter = new NTriplesFormatter();
Console.WriteLine("Original Graph");
foreach (Triple t in g.Triples)
{
Console.WriteLine(t.ToString(formatter));
}
Console.WriteLine();
CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
WriterHelper.FindCollections(context);
Console.WriteLine(context.Collections.Count + " Collections Found");
Console.WriteLine();
System.IO.StringWriter strWriter = new System.IO.StringWriter();
CompressingTurtleWriter writer = new CompressingTurtleWriter();
writer.CompressionLevel = WriterCompressionLevel.High;
writer.Save(g, strWriter);
Console.WriteLine("Compressed Turtle");
Console.WriteLine(strWriter.ToString());
Console.WriteLine();
Graph h = new Graph();
TurtleParser parser = new TurtleParser();
StringParser.Parse(h, strWriter.ToString());
Console.WriteLine("Graph after Round Trip to Compressed Turtle");
foreach (Triple t in h.Triples)
{
Console.WriteLine(t.ToString(formatter));
}
Assert.AreEqual(g, h, "Graphs should be equal");
}
示例14: WritingCollectionCompressionNamedListNodes2
public void WritingCollectionCompressionNamedListNodes2()
{
Graph g = new Graph();
g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
INode n = g.CreateUriNode("ex:listRoot");
INode m = g.CreateUriNode("ex:listItem");
INode rdfType = g.CreateUriNode("rdf:type");
INode rdfFirst = g.CreateUriNode("rdf:first");
INode rdfRest = g.CreateUriNode("rdf:rest");
INode rdfNil = g.CreateUriNode("rdf:nil");
g.Assert(g.CreateUriNode("ex:subj"), g.CreateUriNode("ex:pred"), n);
g.Assert(n, rdfFirst, g.CreateLiteralNode("first"));
g.Assert(n, rdfRest, m);
g.Assert(m, rdfFirst, g.CreateLiteralNode("second"));
g.Assert(m, rdfRest, rdfNil);
CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
WriterHelper.FindCollections(context);
Assert.AreEqual(0, context.Collections.Count, "Expected no collections to be found");
this.CheckCompressionRoundTrip(g);
}
示例15: WritingCollectionCompressionComplex1
public void WritingCollectionCompressionComplex1()
{
SparqlConnector connector = new SparqlConnector(new VDS.RDF.Query.SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql")));
Graph g = new Graph();
g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
g.NamespaceMap.AddNamespace("dnr", new Uri(ConfigurationLoader.ConfigurationNamespace));
INode n = g.CreateBlankNode();
g.Assert(g.CreateUriNode("ex:subj"), g.CreateUriNode("dnr:genericManager"), n);
ConfigurationSerializationContext sContext = new ConfigurationSerializationContext(g);
sContext.NextSubject = n;
connector.SerializeConfiguration(sContext);
CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
WriterHelper.FindCollections(context);
Assert.AreEqual(2, context.Collections.Count, "Expected 2 collections");
this.CheckCompressionRoundTrip(g);
}