internal static Func <IEnumerable <Action> > sPO(PolarTripleStore store, SparqlNode sEntityCode, VariableNode pParameter, VariableNode oParameter) { return(() => store .GetTriplesWithSubject(sEntityCode.Value) .Select(triple => new Action(() => { pParameter.Value = triple.Predicate; oParameter.Value = triple.Object; }))); }
public SparqlResultSet Run(PolarTripleStore store) { ResultSet.Store = store; SparqlWhere.CreateNodes(store); foreach (SparqlNode filterConstant in FilterConstants) { filterConstant.CreateNode(store); } SparqlWhere.Run(ResultSet); switch (ResultSet.ResultType) { case ResultType.Describe: ResultSet.GraphResult = store.CreateGraph(); var variablesIndexes = variables.Select(s => ResultSet.Variables[s].index).ToArray(); foreach (var result in ResultSet.Results) { foreach (var variableIndex in variablesIndexes) { foreach (var triple in store.GetTriplesWithSubject(result[variableIndex])) { ResultSet.GraphResult.Assert(triple); } foreach (var triple in store.GetTriplesWithObject(result[variableIndex])) { ResultSet.GraphResult.Assert(triple); } } } ResultSet.GraphResult.Build(); break; case ResultType.Select: foreach (var func in ListSolutionModifiersOrder) { ResultSet.Results = new List <SparqlResult>(func(ResultSet.Results)); } if (!all) { ResultSet = new SparqlResultSet(ResultSet, variables); } ResultSet.DistinctReduse(isDistinct, isReduce); foreach (var func in ListSolutionModifiersCount) { ResultSet.Results = new List <SparqlResult>(func(ResultSet.Results)); } break; case ResultType.Construct: ResultSet.GraphResult = store.CreateGraph(); foreach (var result in ResultSet.Results) { Func <SparqlNode, INode> GetValueNode = node => { if (node is VariableNode) { return(result[(node as VariableNode).index]); } SparqlUriNode uriNode = node as SparqlUriNode; if (uriNode != null) { return(store.GetUriNode(uriNode.Uri) ?? ResultSet.GraphResult.CreateUriNode(uriNode.Uri)); } SparqlLiteralNode literlNode = node as SparqlLiteralNode; if (literlNode != null) { return(store.GetLiteralNode(literlNode.type.Uri, literlNode.Content, literlNode.lang) ?? (literlNode.lang != null ? ResultSet.GraphResult.CreateLiteralNode(literlNode.Content.ToString(), literlNode.lang) : ResultSet.GraphResult.CreateLiteralNode(literlNode.Content.ToString(), literlNode.type.Uri))); } throw new NotImplementedException(); }; foreach (var sparqlTriplet in Construct.Triples.Cast <SparqlTriple>()) { ResultSet.GraphResult.Assert(new Triple(GetValueNode(sparqlTriplet.Subj), GetValueNode(sparqlTriplet.Pred), GetValueNode(sparqlTriplet.Obj))); } } ResultSet.GraphResult.Build(); break; case ResultType.Ask: break; default: throw new ArgumentOutOfRangeException(); } return(ResultSet); }