本文整理汇总了C#中VDS.RDF.Graph.CreateLiteralNode方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.CreateLiteralNode方法的具体用法?C# Graph.CreateLiteralNode怎么用?C# Graph.CreateLiteralNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VDS.RDF.Graph
的用法示例。
在下文中一共展示了Graph.CreateLiteralNode方法的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: 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");
}
示例3: 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");
}
示例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: 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);
}
示例6: 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;
}
示例7: CreateContent
public 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("catalog", new Uri("http://nuget.org/catalog#"));
INode rdfTypePredicate = graph.CreateUriNode("rdf:type");
INode timeStampPredicate = graph.CreateUriNode("catalog:timeStamp");
Uri dateTimeDatatype = new Uri("http://www.w3.org/2001/XMLSchema#dateTime");
INode container = graph.CreateUriNode(_resourceUri);
graph.Assert(container, rdfTypePredicate, graph.CreateUriNode(GetContainerType()));
graph.Assert(container, timeStampPredicate, graph.CreateLiteralNode(_timeStamp.ToString(), dateTimeDatatype));
if (_parent != null)
{
graph.Assert(container, graph.CreateUriNode("catalog:parent"), graph.CreateUriNode(_parent));
}
AddCustomContent(container, graph);
INode itemPredicate = graph.CreateUriNode("catalog:item");
INode countPredicate = graph.CreateUriNode("catalog:count");
foreach (KeyValuePair<Uri, Tuple<Uri, IGraph, DateTime, int?>> item in GetItems())
{
INode itemNode = graph.CreateUriNode(item.Key);
graph.Assert(container, itemPredicate, itemNode);
graph.Assert(itemNode, rdfTypePredicate, graph.CreateUriNode(item.Value.Item1));
if (item.Value.Item2 != null)
{
graph.Merge(item.Value.Item2);
}
graph.Assert(itemNode, timeStampPredicate, graph.CreateLiteralNode(item.Value.Item3.ToString(), dateTimeDatatype));
if (item.Value.Item4 != null)
{
Uri integerDatatype = new Uri("http://www.w3.org/2001/XMLSchema#integer");
graph.Assert(itemNode, countPredicate, graph.CreateLiteralNode(item.Value.Item4.ToString(), integerDatatype));
}
}
JObject frame = context.GetJsonLdContext("context.Container.json", GetContainerType());
string content = Utils.CreateJson(graph, frame);
return content;
}
示例8: CreateContent
public override StorageContent CreateContent(CatalogContext context)
{
IGraph graph = new Graph();
INode subject = graph.CreateUriNode(GetItemAddress());
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.Package));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.Permalink));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.CatalogEntry), graph.CreateUriNode(_catalogUri));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Registration), graph.CreateUriNode(GetRegistrationAddress()));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageContent), graph.CreateUriNode(GetPackageContentAddress()));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Published), graph.CreateLiteralNode(GetPublishedDate().ToString("O"), Schema.DataTypes.DateTime));
graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Listed), graph.CreateLiteralNode(_listed.ToString(), Schema.DataTypes.Boolean));
JObject frame = context.GetJsonLdContext("context.Package.json", Schema.DataTypes.Package);
return new JTokenStorageContent(Utils.CreateJson(graph, frame), "application/json", "no-store");
}
示例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: 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());
}
示例11: 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);
}
}
示例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:DeletePackage"));
graph.Assert(subject, graph.CreateUriNode("nuget:id"), graph.CreateLiteralNode(_id));
graph.Assert(subject, graph.CreateUriNode("nuget:version"), graph.CreateLiteralNode(_version));
JObject frame = context.GetJsonLdContext("context.DeletePackage.json", GetItemType());
string content = Utils.CreateJson(graph, frame);
return content;
}
示例13: 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);
}
示例14: 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;
}
示例15: insertComunidadeMoodle
/// <summary>
///
/// </summary>
/// <param name="g"></param>
public void insertComunidadeMoodle(ref Graph g)
{
g = new Graph();
g.NamespaceMap.AddNamespace("onto", new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#"));
IUriNode sujeito = g.CreateUriNode("onto:" + student.Matricula);
INode rdfType = g.CreateUriNode("onto:ComunidadeMoodle");
ILiteralNode literal = g.CreateLiteralNode(student.ComunidadeMoodle);
Triple triple = new Triple(sujeito, rdfType, literal);
g.Assert(triple);
}