public void refreshRDFGraphOLD() { var rdfGraphWithDefs = FindOrCreateKB("rdfMT"); var rdfGraph = rdfGraphWithDefs.RdfStore.rdfGraph; EnsureGraphPrefixes(rdfGraph); // Possibly called by the Sparql endpoint before servicing a query // Is there anything we want to update rdfGraph with ? var bingingsList = new ListOfBindings(); string mt = "spindleMT"; askQuery(ParseQuery("triple(S,P,O)", mt), mt, true, bingingsList, null); RdfRules newTriples = new RdfRules(rdfGraph); foreach (var bindings in bingingsList) { //foreach (string k in bindings.Keys) //{ rdfGraphAssert(rdfGraph, MakeTriple(GraphWithDef.PartToRdf(bindings["S"], newTriples), GraphWithDef.PartToRdf(bindings["P"], newTriples), GraphWithDef.PartToRdf(bindings["O"], newTriples))); string rdfLine = String.Format(@"<robokind:{0}> <robokind:{1}> <robokind:{2}> .", bindings["S"].ToString(), bindings["P"].ToString(), bindings["O"].ToString()); StringParser.Parse(rdfGraph, rdfLine); // } } newTriples.AssertTriples(rdfGraphWithDefs.definations, true, true); }
public void AddRequirement(INode s, string sp, Part o) { AddRequirement(MakeTriple(s, GraphWithDef.PredicateToProperty(sp), GraphWithDef.PartToRdf(o, this), false)); }
public void pushRulesToGraph(string mt, PNode rdfGraphWithDefs, bool includeInherited) { // Possibly called by the Sparql endpoint before servicing a query // Is there anything we want to update rdfGraph with ? PNode focus = FindOrCreateKB(mt); var bingingsList = new ListOfBindings(); askQuery(ParseQuery("triple(S,P,O)", mt), mt, includeInherited, bingingsList, null); bool useTripeQuery = true; if (bingingsList == null || bingingsList.Count <= 0) { useTripeQuery = false; var triples = findVisibleKBRules(mt, new List <string>(), includeInherited); foreach (Rule rule in triples) { try { rdfGraphWithDefs.AddRuleToRDF(rule); } catch (Exception e) { Warn(e); } } return; } var rdfGraph = rdfGraphWithDefs.rdfGraph; if (!useTripeQuery) { return; } var newTriples = new RdfRules(rdfGraphWithDefs.definations); EnsureGraphPrefixes(rdfGraph); foreach (Dictionary <string, Part> bindings in bingingsList) { Part psubj = bindings["S"]; Part ppred = bindings["P"]; Part pobj = bindings["O"]; INode subj = GraphWithDef.PartToRdf(psubj, newTriples); INode pred = GraphWithDef.PartToRdf(ppred, newTriples); INode obj = GraphWithDef.PartToRdf(pobj, newTriples); if (subj is ILiteralNode) { Warn("Subj was a literal (not supported) [{0} {1} {2}]", subj, pred, obj); continue; } if (!(pred is IUriNode)) { Warn("Pred was not a uri (not supported) [{0} {1} {2}]", subj, pred, obj); continue; } //foreach (string k in bindings.Keys) //{ rdfGraphAssert(rdfGraph, MakeTriple(subj, pred, obj)); //string rdfLine = String.Format(@"<{0}> <{1}> <{2}> .", bindings["S"].ToString(), bindings["P"].ToString(), bindings["O"].ToString()); //StringParser.Parse(rdfGraph, rdfLine); // } } newTriples.RequirementsMet = true; newTriples.AssertTriples(rdfGraphWithDefs.definations, true, true); }