本文整理汇总了C#中IGraph.GetTriplesWithSubject方法的典型用法代码示例。如果您正苦于以下问题:C# IGraph.GetTriplesWithSubject方法的具体用法?C# IGraph.GetTriplesWithSubject怎么用?C# IGraph.GetTriplesWithSubject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraph
的用法示例。
在下文中一共展示了IGraph.GetTriplesWithSubject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindRdfDataObject
private IDataObject BindRdfDataObject(IUriNode dataObjectResource, IGraph graph)
{
var triples =
graph.GetTriplesWithSubject(dataObjectResource)
.Where(t => t.Subject is IUriNode && t.Predicate is IUriNode)
.Select(t => MakeTriple(t.Subject, t.Predicate, t.Object));
return MakeDataObject(dataObjectResource.Uri.ToString(), triples);
}
示例2: Collect
public static void Collect(IGraph source, INode subject, IGraph destination, ISet<string> exclude)
{
foreach (Triple triple in source.GetTriplesWithSubject(subject))
{
destination.Assert(triple.CopyTriple(destination));
if (triple.Object is IUriNode && !exclude.Contains(((IUriNode)triple.Object).Uri.ToString()))
{
Collect(source, triple.Object, destination, exclude);
}
}
}
示例3: BindRdfDataObject
private IDataObject BindRdfDataObject(IUriNode dataObjectResource, IGraph graph)
{
var triples = new List<Triple>();
foreach (var t in graph.GetTriplesWithSubject(dataObjectResource))
{
if (t.Subject is IUriNode && t.Predicate is IUriNode)
{
// Only handling triples that have a URI predicate
// subject will always be a UriNode, because that is what we used in the lookup
var subject = (t.Subject as IUriNode).Uri.ToString();
var predicate = (t.Predicate as IUriNode).Uri.ToString();
if (t.Object is ILiteralNode)
{
var lit = t.Object as ILiteralNode;
triples.Add(new Triple
{
Subject = subject,
Predicate = predicate,
IsLiteral = true,
Object = lit.Value,
DataType = lit.DataType == null ? Constants.DefaultDatatypeUri : lit.DataType.ToString(),
LangCode = lit.Language
});
}
else if (t.Object is IUriNode)
{
var uriNode = t.Object as IUriNode;
triples.Add(new Triple
{
Subject = subject,
Predicate = predicate,
IsLiteral = false,
Object = uriNode.Uri.ToString()
});
}
}
}
var dataObject = _storeContext.MakeDataObject(dataObjectResource.Uri.ToString()) as DataObject;
dataObject.BindTriples(triples);
return dataObject;
}
示例4: 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;
}
示例5: 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>();
}
}
}
示例6: BindRdfDataObjects
public IEnumerable<IDataObject> BindRdfDataObjects(IGraph graph)
{
var distinctSubjects = new System.Collections.Generic.HashSet<INode>();
foreach (var t in graph.Triples)
{
distinctSubjects.Add(t.Subject);
}
return distinctSubjects.Select(s =>
MakeDataObject(s.ToString(),
graph.GetTriplesWithSubject(s).Select(t =>
MakeTriple(t.Subject, t.Predicate, t.Object))));
}
示例7: GetUpdateGraph
private UpdateGraph GetUpdateGraph(INode graphData, IGraph g)
{
var dataUri = g.GetTriplesWithSubjectPredicate(graphData, g.CreateUriNode(UtGraph)).FirstOrDefault();
if (dataUri == null)
{
dataUri = g.GetTriplesWithSubjectPredicate(graphData, g.CreateUriNode(UtData)).FirstOrDefault();
}
if (dataUri == null)
{
var allTriples = g.GetTriplesWithSubject(graphData).ToList();
throw new Exception("No data for graph");
}
var graphLabel = g.GetTriplesWithSubjectPredicate(graphData, g.CreateUriNode(RdfsLabel)).First();
return new UpdateGraph{
Data = (dataUri.Object as IUriNode).Uri,
Uri = new Uri(graphLabel.Object.ToString())
};
}