本文整理汇总了C#中VDS.RDF.Graph.Assert方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.Assert方法的具体用法?C# Graph.Assert怎么用?C# Graph.Assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VDS.RDF.Graph
的用法示例。
在下文中一共展示了Graph.Assert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override bool Execute(PipelinePackage package, PackagePipelineContext context)
{
DateTime? commitTimeStamp = PackagePipelineHelpers.GetCommitTimeStamp(context);
Guid? commitId = PackagePipelineHelpers.GetCommitId(context);
IGraph graph = new Graph();
INode resource = graph.CreateUriNode(context.Uri);
if (commitTimeStamp != null)
{
graph.Assert(
resource,
graph.CreateUriNode(Schema.Predicates.CatalogTimeStamp),
graph.CreateLiteralNode(commitTimeStamp.Value.ToString("O"), Schema.DataTypes.DateTime));
}
if (commitId != null)
{
graph.Assert(
resource,
graph.CreateUriNode(Schema.Predicates.CatalogCommitId),
graph.CreateLiteralNode(commitId.Value.ToString()));
}
context.StageResults.Add(new GraphPackageMetadata(graph));
return true;
}
示例2: Main
public static void Main(String[] args)
{
//Fill in the code shown on this page here to build your hello world application
Graph g = new Graph();
IUriNode dotNetRDF = g.CreateUriNode(new Uri("http://www.dotnetrdf.org"));
IUriNode says = g.CreateUriNode(new Uri("http://example.org/says"));
ILiteralNode helloWorld = g.CreateLiteralNode("Hello World");
ILiteralNode bonjourMonde = g.CreateLiteralNode("Bonjour tout le Monde", "fr");
g.Assert(new Triple(dotNetRDF, says, helloWorld));
g.Assert(new Triple(dotNetRDF, says, bonjourMonde));
foreach (Triple t in g.Triples)
{
Console.WriteLine(t.ToString());
}
NTriplesWriter ntwriter = new NTriplesWriter();
ntwriter.Save(g, "HelloWorld.nt");
RdfXmlWriter rdfxmlwriter = new RdfXmlWriter();
rdfxmlwriter.Save(g, "HelloWorld.rdf");
}
示例3: WritingBlankNodeOutput
public void WritingBlankNodeOutput()
{
//Create a Graph and add a couple of Triples which when serialized have
//potentially colliding IDs
Graph g = new Graph();
g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org"));
IUriNode subj = g.CreateUriNode("ex:subject");
IUriNode pred = g.CreateUriNode("ex:predicate");
IUriNode name = g.CreateUriNode("ex:name");
IBlankNode b1 = g.CreateBlankNode("autos1");
IBlankNode b2 = g.CreateBlankNode("1");
g.Assert(subj, pred, b1);
g.Assert(b1, name, g.CreateLiteralNode("First Triple"));
g.Assert(subj, pred, b2);
g.Assert(b2, name, g.CreateLiteralNode("Second Triple"));
TurtleWriter ttlwriter = new TurtleWriter();
ttlwriter.Save(g, "bnode-output-test.ttl");
TestTools.ShowGraph(g);
TurtleParser ttlparser = new TurtleParser();
Graph h = new Graph();
ttlparser.Load(h, "bnode-output-test.ttl");
TestTools.ShowGraph(h);
Assert.AreEqual(g.Triples.Count, h.Triples.Count, "Expected same number of Triples after serialization and reparsing");
}
示例4: CreateCommitMetadata
public static IGraph CreateCommitMetadata(Uri indexUri, CommitMetadata commitMetadata)
{
IGraph graph = new Graph();
if (commitMetadata.LastCreated != null)
{
graph.Assert(
graph.CreateUriNode(indexUri),
graph.CreateUriNode(Schema.Predicates.LastCreated),
graph.CreateLiteralNode(commitMetadata.LastCreated.Value.ToString("O"), Schema.DataTypes.DateTime));
}
if (commitMetadata.LastEdited != null)
{
graph.Assert(
graph.CreateUriNode(indexUri),
graph.CreateUriNode(Schema.Predicates.LastEdited),
graph.CreateLiteralNode(commitMetadata.LastEdited.Value.ToString("O"), Schema.DataTypes.DateTime));
}
if (commitMetadata.LastDeleted != null)
{
graph.Assert(
graph.CreateUriNode(indexUri),
graph.CreateUriNode(Schema.Predicates.LastDeleted),
graph.CreateLiteralNode(commitMetadata.LastDeleted.Value.ToString("O"), Schema.DataTypes.DateTime));
}
return graph;
}
示例5: TestCreateAssociationLinks
public void TestCreateAssociationLinks()
{
var testGraph = new Graph {BaseUri = new Uri("http://dbpedia.org/resource/")};
var film = testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/resource/Un_Chien_Andalou"));
var rdfType = testGraph.CreateUriNode(UriFactory.Create("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
testGraph.Assert(film,
rdfType,
testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/ontology/Film")));
testGraph.Assert(film,
testGraph.CreateUriNode(UriFactory.Create("http://xmlns.com/foaf/0.1/name")),
testGraph.CreateLiteralNode("Un Chien Andalou"));
var director = testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/resource/Luis_Bunuel"));
testGraph.Assert(director, rdfType, testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/ontology/Person")));
testGraph.Assert(film, testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/property/director")), director);
var mockRequest = new Mock<IODataRequestMessage>();
mockRequest.Setup(m => m.Url).Returns(new Uri("http://example.org/odata/Films('Un_Chien_Andalou')"));
var mock = new Mock<IODataResponseMessage>();
var mockStream = new MemoryStream();
mock.Setup(m => m.GetStream()).Returns(mockStream);
var generator = new ODataFeedGenerator(mockRequest.Object, mock.Object, _dbpediaMap, "http://example.org/odata/", new ODataMessageWriterSettings { Indent = true });
generator.CreateEntryFromGraph(testGraph, film.Uri.ToString(), "DBPedia.Film");
mockStream.Seek(0, SeekOrigin.Begin);
var streamXml = XDocument.Load(mockStream);
Assert.IsNotNull(streamXml);
Assert.IsNotNull(streamXml.Root);
Assert.AreEqual(XName.Get("entry", "http://www.w3.org/2005/Atom"), streamXml.Root.Name);
Console.WriteLine(streamXml.ToString());
}
示例6: CreatePageGraph
IGraph CreatePageGraph(INode subject, IGraph graph)
{
Graph pageGraph = new Graph();
Triple idTriple = graph.GetTriplesWithSubjectPredicate(subject, graph.CreateUriNode(Schema.Predicates.Id)).First();
Triple versionTriple = graph.GetTriplesWithSubjectPredicate(subject, graph.CreateUriNode(Schema.Predicates.Version)).First();
pageGraph.Assert(idTriple.CopyTriple(pageGraph));
pageGraph.Assert(versionTriple.CopyTriple(pageGraph));
return pageGraph;
}
示例7: CreateContent
public StorageContent CreateContent(CatalogContext context)
{
IGraph graph = new Graph();
INode rdfTypePredicate = graph.CreateUriNode(Schema.Predicates.Type);
INode timeStampPredicate = graph.CreateUriNode(Schema.Predicates.CatalogTimestamp);
INode commitIdPredicate = graph.CreateUriNode(Schema.Predicates.CatalogCommitId);
INode container = graph.CreateUriNode(_resourceUri);
graph.Assert(container, rdfTypePredicate, graph.CreateUriNode(GetContainerType()));
graph.Assert(container, timeStampPredicate, graph.CreateLiteralNode(_timeStamp.ToString("O"), Schema.DataTypes.DateTime));
graph.Assert(container, commitIdPredicate, graph.CreateLiteralNode(_commitId.ToString()));
if (_parent != null)
{
graph.Assert(container, graph.CreateUriNode(Schema.Predicates.Parent), graph.CreateUriNode(_parent));
}
AddCustomContent(container, graph);
INode itemPredicate = graph.CreateUriNode(Schema.Predicates.CatalogItem);
INode countPredicate = graph.CreateUriNode(Schema.Predicates.CatalogCount);
foreach (KeyValuePair<Uri, CatalogContainerItem> item in _items)
{
INode itemNode = graph.CreateUriNode(item.Key);
graph.Assert(container, itemPredicate, itemNode);
graph.Assert(itemNode, rdfTypePredicate, graph.CreateUriNode(item.Value.Type));
if (item.Value.PageContent != null)
{
graph.Merge(item.Value.PageContent);
}
graph.Assert(itemNode, timeStampPredicate, graph.CreateLiteralNode(item.Value.TimeStamp.ToString("O"), Schema.DataTypes.DateTime));
graph.Assert(itemNode, commitIdPredicate, graph.CreateLiteralNode(item.Value.CommitId.ToString()));
if (item.Value.Count != null)
{
graph.Assert(itemNode, countPredicate, graph.CreateLiteralNode(item.Value.Count.ToString(), Schema.DataTypes.Integer));
}
}
JObject frame = context.GetJsonLdContext("context.Container.json", GetContainerType());
// The below code could be used to compact data storage by using relative URIs.
//frame = (JObject)frame.DeepClone();
//frame["@context"]["@base"] = _resourceUri.ToString();
StorageContent content = new StringStorageContent(Utils.CreateJson(graph, frame), "application/json", "no-store");
return content;
}
示例8: CreateContent
public override StorageContent CreateContent(CatalogContext context)
{
using (IGraph graph = new Graph())
{
INode entry = graph.CreateUriNode(GetItemAddress());
// catalog infrastructure fields
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(GetItemType()));
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.Permalink));
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.CatalogTimeStamp), graph.CreateLiteralNode(TimeStamp.ToString("O"), Schema.DataTypes.DateTime));
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.CatalogCommitId), graph.CreateLiteralNode(CommitId.ToString()));
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Published), graph.CreateLiteralNode(_published.ToString("O"), Schema.DataTypes.DateTime));
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Id), graph.CreateLiteralNode(_id));
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.OriginalId), graph.CreateLiteralNode(_id));
graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Version), graph.CreateLiteralNode(_version));
SetIdVersionFromGraph(graph);
// create JSON content
JObject frame = context.GetJsonLdContext("context.Catalog.json", GetItemType());
StorageContent content = new StringStorageContent(Utils.CreateArrangedJson(graph, frame), "application/json", "no-store");
return content;
}
}
示例9: Execute
public override bool Execute(PipelinePackage package, PackagePipelineContext context)
{
string hash = GetHash(package.Stream);
long size = GetSize(package.Stream);
IGraph graph = new Graph();
INode subject = graph.CreateUriNode(context.Uri);
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageHashAlgorithm), graph.CreateLiteralNode("SHA512"));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageHash), graph.CreateLiteralNode(hash));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageSize), graph.CreateLiteralNode(size.ToString(), Schema.DataTypes.Integer));
context.StageResults.Add(new GraphPackageMetadata(graph));
return true;
}
示例10: ReplaceResourceUris
public static IGraph ReplaceResourceUris(IGraph original, IDictionary<string, Uri> replacements)
{
IGraph modified = new Graph();
foreach (Triple triple in original.Triples)
{
Uri subjectUri;
if (!replacements.TryGetValue(triple.Subject.ToString(), out subjectUri))
{
subjectUri = ((IUriNode)triple.Subject).Uri;
}
INode subjectNode = modified.CreateUriNode(subjectUri);
INode predicateNode = triple.Predicate.CopyNode(modified);
INode objectNode;
if (triple.Object is IUriNode)
{
Uri objectUri;
if (!replacements.TryGetValue(triple.Object.ToString(), out objectUri))
{
objectUri = ((IUriNode)triple.Object).Uri;
}
objectNode = modified.CreateUriNode(objectUri);
}
else
{
objectNode = triple.Object.CopyNode(modified);
}
modified.Assert(subjectNode, predicateNode, objectNode);
}
return modified;
}
示例11: AddTripleLiteral
/// <summary>
/// Adds the literal triple to a graph.
/// </summary>
/// <param name="graph">The graph.</param>
/// <param name="subject">The subject.</param>
/// <param name="predicate">The predicate.</param>
/// <param name="obj">The object (resource).</param>
/// <remarks></remarks>
public static void AddTripleLiteral(Graph graph, string subject, string predicate, string obj, string datatype)
{
string xmlSchemaDatatype;
switch (datatype)
{
case "Url":
xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeAnyUri;
break;
case "Date":
xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeDateTime;
break;
case "Integer":
xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeInteger;
break;
case "Ntext":
xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeString;
break;
case "Nvarchar":
xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeString;
break;
default:
xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeString;
break;
}
Triple triple = null;
if (subject.StartsWith("http") && predicate.StartsWith("http"))
{
triple = new Triple(
graph.CreateUriNode(new Uri(subject)),
graph.CreateUriNode(new Uri(predicate)),
graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
);
}
else if (!subject.StartsWith("http") && predicate.StartsWith("http"))
{
triple = new Triple(
graph.CreateUriNode(subject),
graph.CreateUriNode(new Uri(predicate)),
graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
);
}
else if (subject.StartsWith("http") && !predicate.StartsWith("http"))
{
triple = new Triple(
graph.CreateUriNode(new Uri(subject)),
graph.CreateUriNode(predicate),
graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
);
}
else if (!subject.StartsWith("http") && !predicate.StartsWith("http"))
{
triple = new Triple(
graph.CreateUriNode(subject),
graph.CreateUriNode(predicate),
graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
);
}
graph.Assert(triple);
}
示例12: CreateContent
public override string CreateContent(CatalogContext context)
{
IGraph graph = new Graph();
graph.NamespaceMap.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
graph.NamespaceMap.AddNamespace("nuget", new Uri("http://nuget.org/schema#"));
INode subject = graph.CreateUriNode(new Uri(GetBaseAddress() + GetItemIdentity()));
graph.Assert(subject, graph.CreateUriNode("rdf:type"), graph.CreateUriNode("nuget:DeleteRegistration"));
graph.Assert(subject, graph.CreateUriNode("nuget:id"), graph.CreateLiteralNode(_id));
JObject frame = context.GetJsonLdContext("context.DeletePackage.json", GetItemType());
string content = Utils.CreateJson(graph, frame);
return content;
}
示例13: Main
public static void Main(string[] args)
{
//Create a new Empty Graph
Graph g = new Graph();
//Define Namespaces
g.NamespaceMap.AddNamespace("pets", new Uri("http://example.org/pets"));
//Create Uri Nodes
IUriNode dog, fido, rob, owner, name, species, breed, lab;
dog = g.CreateUriNode("pets:Dog");
fido = g.CreateUriNode("pets:abc123");
rob = g.CreateUriNode("pets:def456");
owner = g.CreateUriNode("pets:hasOwner");
name = g.CreateUriNode("pets:hasName");
species = g.CreateUriNode("pets:isAnimal");
breed = g.CreateUriNode("pets:isBreed");
lab = g.CreateUriNode("pets:Labrador");
//Assert Triples
g.Assert(new Triple(fido, species, dog));
g.Assert(new Triple(fido, owner, rob));
g.Assert(new Triple(fido, name, g.CreateLiteralNode("Fido")));
g.Assert(new Triple(rob, name, g.CreateLiteralNode("Rob")));
g.Assert(new Triple(fido, breed, lab));
//Attempt to output GraphViz
try
{
Console.WriteLine("Writing GraphViz DOT file graph_building_example2.dot");
GraphVizWriter gvzwriter = new GraphVizWriter();
gvzwriter.Save(g, "graph_building_example2.dot");
Console.WriteLine("Creating a PNG got this Graph called graph_building_example2.png");
GraphVizGenerator gvzgen = new GraphVizGenerator("svg", "C:\\Program Files (x86)\\Graphviz2.20\\bin");
gvzgen.Format = "png";
gvzgen.Generate(g, "graph_building_example2.png", false);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
示例14: WritingRdfXmlLiteralsWithLanguageTags
public void WritingRdfXmlLiteralsWithLanguageTags()
{
Graph g = new Graph();
INode s = g.CreateUriNode(new Uri("http://example.org/subject"));
INode p = g.CreateUriNode(new Uri("http://example.org/predicate"));
INode o = g.CreateLiteralNode("string", "en");
g.Assert(s, p, o);
this.CheckRoundTrip(g);
}
示例15: CreatePageContent
public override IGraph CreatePageContent(CatalogContext context)
{
Uri resourceUri = new Uri(GetBaseAddress() + GetRelativeAddress());
Graph graph = new Graph();
INode subject = graph.CreateUriNode(resourceUri);
INode count = graph.CreateUriNode(new Uri("http://nuget.org/schema#count"));
INode itemGUID = graph.CreateUriNode(new Uri("http://nuget.org/schema#itemGUID"));
INode minDownloadTimestamp = graph.CreateUriNode(new Uri("http://nuget.org/schema#minDownloadTimestamp"));
INode maxDownloadTimestamp = graph.CreateUriNode(new Uri("http://nuget.org/schema#maxDownloadTimestamp"));
graph.Assert(subject, count, graph.CreateLiteralNode(_data.Count.ToString(), Schema.DataTypes.Integer));
graph.Assert(subject, itemGUID, graph.CreateLiteralNode(_itemGUID.ToString()));
graph.Assert(subject, minDownloadTimestamp, graph.CreateLiteralNode(_minDownloadTimestamp.ToString("O"), Schema.DataTypes.DateTime));
graph.Assert(subject, maxDownloadTimestamp, graph.CreateLiteralNode(_maxDownloadTimestamp.ToString("O"), Schema.DataTypes.DateTime));
return graph;
}