本文整理汇总了C#中VDS.RDF.Graph.GetTriplesWithSubject方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.GetTriplesWithSubject方法的具体用法?C# Graph.GetTriplesWithSubject怎么用?C# Graph.GetTriplesWithSubject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VDS.RDF.Graph
的用法示例。
在下文中一共展示了Graph.GetTriplesWithSubject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateContent
public override StorageContent CreateContent(CatalogContext context)
{
IGraph catalogEntry = new Graph();
INode catalogEntrySubject = catalogEntry.CreateUriNode(GetItemAddress());
// catalog infrastructure fields
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(GetItemType()));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(_itemType));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(Schema.DataTypes.Permalink));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.CatalogTimeStamp), catalogEntry.CreateLiteralNode(TimeStamp.ToString("O"), Schema.DataTypes.DateTime));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.CatalogCommitId), catalogEntry.CreateLiteralNode(CommitId.ToString()));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Published), catalogEntry.CreateLiteralNode(_publicationDetails.Published.ToString("O"), Schema.DataTypes.DateTime));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.TenantId), catalogEntry.CreateLiteralNode(_publicationDetails.TenantId));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Tenant), catalogEntry.CreateLiteralNode(_publicationDetails.TenantName));
Uri ownerUri = _publicationDetails.Owner.GetUri(GetItemAddress());
INode ownerSubject = catalogEntry.CreateUriNode(ownerUri);
catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.NameIdentifier), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.NameIdentifier));
//catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Name), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Name));
catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.GivenName), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.GivenName));
catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Surname), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Surname));
//catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Iss), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Iss));
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Owner), ownerSubject);
// visibility
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Visibility), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Visibility.ToString()));
switch (_publicationDetails.Visibility.Visibility)
{
case PublicationVisibility.VisibilityScope.Organization:
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Organization), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Organization));
break;
case PublicationVisibility.VisibilityScope.Subscription:
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Subscription), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Subscription));
break;
}
// listed
catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Listed), catalogEntry.CreateLiteralNode(_isListed.ToString(), Schema.DataTypes.Boolean));
// add the nuspec metadata
Uri nuspecSubject = _nuspec["@id"].ToObject<Uri>();
IGraph nuspecGraph = Utils.CreateGraph(_nuspec);
// Any statements made about this @id in the nuspec we want to make about the catalog items @id
// - catalog readers can then apply this logic in reverse
// - by so doing the catalog entry becomes an audit entry for the data
catalogEntry.Merge(nuspecGraph, false);
foreach (Triple triple in catalogEntry.GetTriplesWithSubject(catalogEntry.CreateUriNode(nuspecSubject)))
{
catalogEntry.Assert(catalogEntrySubject, triple.Predicate.CopyNode(catalogEntry), triple.Object.CopyNode(catalogEntry));
}
GraphHelpers.MaterializeInference(catalogEntry);
SetIdVersionFromGraph(catalogEntry);
// create JSON content
string json = Utils.CreateJson(catalogEntry, _context);
StorageContent content = new StringStorageContent(json, "application/json", "no-store");
return content;
}
示例2: GraphSubGraphMatching
public void GraphSubGraphMatching()
{
Graph parent = new Graph();
FileLoader.Load(parent, "InferenceTest.ttl");
Graph subgraph = new Graph();
subgraph.NamespaceMap.Import(parent.NamespaceMap);
subgraph.Assert(parent.GetTriplesWithSubject(parent.CreateUriNode("eg:FordFiesta")));
//Check method calls
Dictionary<INode, INode> mapping;
Console.WriteLine("Doing basic sub-graph matching with no BNode tests");
Assert.IsTrue(parent.HasSubGraph(subgraph, out mapping), "Failed to match the sub-graph as expected");
Assert.IsFalse(parent.IsSubGraphOf(subgraph, out mapping), "Parent should not be a sub-graph of the sub-graph");
Assert.IsFalse(subgraph.HasSubGraph(parent, out mapping), "Sub-graph should not have parent as its sub-graph");
Assert.IsTrue(subgraph.IsSubGraphOf(parent, out mapping), "Failed to match the sub-graph as expected");
Console.WriteLine("OK");
Console.WriteLine();
//Add an extra triple into the Graph which will cause it to no longer be a sub-graph
Console.WriteLine("Adding an extra Triple so the sub-graph is no longer such");
subgraph.Assert(new Triple(subgraph.CreateUriNode("eg:Rocket"), subgraph.CreateUriNode("rdf:type"), subgraph.CreateUriNode("eg:AirVehicle")));
Assert.IsFalse(parent.HasSubGraph(subgraph, out mapping), "Sub-graph should no longer be considered a sub-graph");
Assert.IsFalse(subgraph.IsSubGraphOf(parent, out mapping), "Sub-graph should no longer be considered a sub-graph");
Console.WriteLine("OK");
Console.WriteLine();
//Reset the sub-graph
Console.WriteLine("Resetting the sub-graph");
subgraph = new Graph();
subgraph.NamespaceMap.Import(parent.NamespaceMap);
subgraph.Assert(parent.GetTriplesWithSubject(parent.CreateUriNode("eg:FordFiesta")));
Console.WriteLine("Adding additional information to the parent Graph, this should not affect the fact that the sub-graph is a sub-graph of it");
Assert.IsTrue(parent.HasSubGraph(subgraph, out mapping), "Failed to match the sub-graph as expected");
Assert.IsFalse(parent.IsSubGraphOf(subgraph, out mapping), "Parent should not be a sub-graph of the sub-graph");
Assert.IsFalse(subgraph.HasSubGraph(parent, out mapping), "Sub-graph should not have parent as its sub-graph");
Assert.IsTrue(subgraph.IsSubGraphOf(parent, out mapping), "Failed to match the sub-graph as expected");
Console.WriteLine("OK");
Console.WriteLine();
//Remove stuff from parent graph so it won't match any more
Console.WriteLine("Removing stuff from parent graph so that it won't have the sub-graph anymore");
parent.Retract(parent.GetTriplesWithSubject(parent.CreateUriNode("eg:FordFiesta")));
Assert.IsFalse(parent.HasSubGraph(subgraph, out mapping), "Parent should no longer contian the sub-graph");
Assert.IsFalse(subgraph.IsSubGraphOf(parent, out mapping), "Parent should no longer contain the sub-graph");
Console.WriteLine("OK");
Console.WriteLine();
}
示例3: ProcessList
private static void ProcessList(INode listNode, Graph g, Action<INode, Graph> processAction)
{
var first =
g.GetTriplesWithSubject(listNode).Where(
t => (t.Predicate as UriNode).Uri.ToString().Equals(RdfFirst.ToString())).Select(t => t.Object).
FirstOrDefault();
var rest =
g.GetTriplesWithSubject(listNode).Where(
t => (t.Predicate as UriNode).Uri.ToString().Equals(RdfRest.ToString())).Select(t => t.Object).
FirstOrDefault();
if (first != null)
{
processAction(first, g);
}
if (rest != null)
{
ProcessList(rest, g, processAction);
}
}