本文整理汇总了C#中IGraph.GetTriplesWithPredicate方法的典型用法代码示例。如果您正苦于以下问题:C# IGraph.GetTriplesWithPredicate方法的具体用法?C# IGraph.GetTriplesWithPredicate怎么用?C# IGraph.GetTriplesWithPredicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraph
的用法示例。
在下文中一共展示了IGraph.GetTriplesWithPredicate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterToEnumerable
private IEnumerable<Triple> FilterToEnumerable(SelectFilter filter, IGraph g)
{
//Want to build an IEnumerable based on the Filter
IEnumerable<Triple> ts = Enumerable.Empty<Triple>();
INode s, p, o;
int hash = (g.BaseUri == null) ? new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode() : g.BaseUri.GetEnhancedHashCode();
if (filter.Subjects != null)
{
if (filter.Predicates != null)
{
//Subject-Predicate filter
foreach (Entity subj in filter.Subjects)
{
s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
foreach (Entity pred in filter.Predicates)
{
p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
ts = ts.Concat(g.GetTriplesWithSubjectPredicate(s, p));
}
}
}
else if (filter.Objects != null)
{
//Subject-Object filter
foreach (Entity subj in filter.Subjects)
{
s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
foreach (Resource obj in filter.Objects)
{
o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
ts = ts.Concat(g.GetTriplesWithSubjectObject(s, o));
}
}
}
else
{
//Subjects filter
foreach (Entity subj in filter.Subjects)
{
s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
ts = ts.Concat(g.GetTriplesWithSubject(s));
}
}
}
else if (filter.Predicates != null)
{
if (filter.Objects != null)
{
//Predicate-Object Filter
foreach (Entity pred in filter.Predicates)
{
p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
foreach (Resource obj in filter.Objects)
{
o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
ts = ts.Concat(g.GetTriplesWithPredicateObject(p, o));
}
}
}
else
{
//Predicate Filter
foreach (Entity pred in filter.Predicates)
{
p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
ts = ts.Concat(g.GetTriplesWithPredicate(p));
}
}
}
else if (filter.Objects != null)
{
//Object Filter
foreach (Resource obj in filter.Objects)
{
o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
ts = ts.Concat(g.GetTriplesWithObject(o));
}
}
else
{
//Everything is null so this is a Select All
ts = g.Triples;
}
return ts;
}
示例2: Initialise
/// <summary>
/// Initialises the Reasoner
/// </summary>
/// <param name="g">Rules Graph</param>
public void Initialise(IGraph g)
{
INode implies = g.CreateUriNode(new Uri("http://www.w3.org/2000/10/swap/log#implies"));
foreach (Triple t in g.GetTriplesWithPredicate(implies))
{
if (t.Subject.NodeType == NodeType.GraphLiteral && t.Object.NodeType == NodeType.GraphLiteral)
{
this.TryCreateRule(t);
}
}
}
示例3: TemplateToEnumerable
/// <summary>
/// Converts a SemWeb Statement Template to an IEnumerable of Triples
/// </summary>
/// <param name="template">Statement Template</param>
/// <param name="g">Graph the Template should be created for</param>
/// <returns></returns>
private IEnumerable<Triple> TemplateToEnumerable(Statement template, IGraph g)
{
INode s, p, o;
int hash;
if (g.BaseUri == null)
{
hash = new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode();
}
else
{
hash = g.BaseUri.GetEnhancedHashCode();
}
if (template.Subject is Variable)
{
if (template.Predicate is Variable)
{
if (template.Object is Variable)
{
//All three things are variables so this just checks that some Triple(s) are present
return g.Triples;
}
else
{
//Subject & Predicate are Variables
//Convert the Object and do a WithObject().Any() call
o = SemWebConverter.FromSemWeb(template.Object, this.GetMapping(hash, g));
return g.GetTriplesWithObject(o);
}
}
else if (template.Object is Variable)
{
//Subject & Object are variables
//Convert the Predicate and do a WithPredicate() call
p = SemWebConverter.FromSemWeb(template.Predicate, this.GetMapping(hash, g));
return g.GetTriplesWithPredicate(p);
}
else
{
//Subject is a Variable
//Convert the Predicate and Object and do a WithPredicateObject() call
p = SemWebConverter.FromSemWeb(template.Predicate, this.GetMapping(hash, g));
o = SemWebConverter.FromSemWeb(template.Object, this.GetMapping(hash, g));
return g.GetTriplesWithPredicateObject(p, o);
}
}
else if (template.Predicate is Variable)
{
if (template.Object is Variable)
{
//Predicate & Object are Variables
//Convert the Subject and do a WithSubject() call
s = SemWebConverter.FromSemWeb(template.Subject, this.GetMapping(hash, g));
return g.GetTriplesWithSubject(s);
}
else
{
//Predicate is a Variable
//Convert the Subject and Object and do a WithSubjectObject() call
s = SemWebConverter.FromSemWeb(template.Subject, this.GetMapping(hash, g));
o = SemWebConverter.FromSemWeb(template.Object, this.GetMapping(hash, g));
return g.GetTriplesWithSubjectObject(s, o);
}
}
else if (template.Object is Variable)
{
//Object is a Variable
//Convert the Subject and Predicate and do a WithSubjectPredicate() call
s = SemWebConverter.FromSemWeb(template.Subject, this.GetMapping(hash, g));
p = SemWebConverter.FromSemWeb(template.Predicate, this.GetMapping(hash, g));
return g.GetTriplesWithSubjectPredicate(s, p);
}
else
{
//Just convert the Triple and do a Contains() call
Triple t = SemWebConverter.FromSemWeb(template, this.GetMapping(hash, g));
if (g.ContainsTriple(t))
{
return t.AsEnumerable();
}
else
{
return Enumerable.Empty<Triple>();
}
}
}
示例4: Reverse
public static void Reverse(IGraph graph, Uri existingProperty, Uri reverseProperty)
{
var existingTriples = graph
.GetTriplesWithPredicate(graph.CreateUriNode(existingProperty))
.ToList();
graph.Retract(existingTriples);
INode predicate = graph.CreateUriNode(reverseProperty);
foreach (var existingTriple in existingTriples)
{
graph.Assert(existingTriple.Object, predicate, existingTriple.Subject);
}
}