public string ConvertToGetTypesOf(CNL.DL.Node n, List <string> roles, List <string> attributes, out Dictionary <string, string> roleBinding, out Dictionary <string, string> attributeBinding, out string defaultIntance, int offset, int pageSize, bool useTypeOf = false, bool direct = true, string order = "NONE") { var rr = ConvertToGetTypesOfDetails(n, roles, attributes, out roleBinding, out attributeBinding, out defaultIntance, useTypeOf, direct, order); var distinct = rr[0]; var selectVars = rr[1]; var whereBlock = rr[2]; var filterBlock = rr[3]; var whereBlock2 = rr[4]; var orderByBlock = rr[5]; var q = PREAMBLE + "SELECT " + distinct + selectVars + "\r\n" + "WHERE {" + (whereBlock2 != null ? "{" : "") + whereBlock; if (filterBlock != null) { q += " FILTER (" + filterBlock + ")"; } if (whereBlock2 != null) { q += "} UNION {"; q += whereBlock2; q += "}"; } q += "}"; if (orderByBlock != null) { q += orderByBlock; } q += (pageSize > -1 ? " LIMIT " + pageSize + " OFFSET " + offset : string.Empty); return(q); }
List <List <string> > RELINST(string I, CNL.DL.Node R, string J) { if (isLocalInstanceName(I) && isLocalInstanceName(J)) { // for local instance we have e.I = E R. J where e.I = (e.I | BOT) List <List <string> > A; List <List <string> > B; { var inter = lockind.get() == LocalityKind.Top ? Intersect(AnalizeConTop(R, "R"), CreateSimple("I" + ":" + J)) : CreateNull(); A = Cumulate(CreateSimple("I" + ":" + I), inter); } { var inter = lockind.get() == LocalityKind.Top ? Intersect(AnalizeConTop(R, "R"), CreateSimple("I" + ":" + I)) : CreateNull(); B = Cumulate(CreateSimple("I" + ":" + J), inter); } return(Intersect(A, B)); } else { if (lockind.get() == LocalityKind.Top) { return(AnalizeConTop(R, "R")); } } return(CreateNull()); }
public string ConvertToGetRelatedConceptOf(CNL.DL.Node n, bool meanSuperConcept, bool direct, bool includeTopBot, int offset, int pageSize, bool useTypeOf = false, string order = "NONE") { this.useTypeOf = useTypeOf; freeVarIdBase = 0; string selectVars; string whereBlock; bool distinct = false; bool ordering = order != "NONE"; using (activeFreeVarId.set(newFreeVarId())) { var sparqlNode = n.accept(this) as SparqlNode; if (n is CogniPy.CNL.DL.Top) { sparqlNode = new SparqlTop(owlNC, sparqlNode.GetFreeVariableId()); } distinct = sparqlNode.UseDistinct(); selectVars = sparqlNode.GetFreeVariableId(); whereBlock = sparqlNode.ToCombinedBlock(meanSuperConcept, false, direct, includeTopBot, true); if (ordering) { whereBlock += ". " + selectVars + " <http://www.ontorion.com#label> ?z1"; } } return(PREAMBLE + "SELECT " + (distinct ? "DISTINCT " : " ") + selectVars + "\r\n" + "WHERE {" + whereBlock + "}" + (ordering ? string.Format(" ORDER BY {0}(?z1) ", order) : string.Empty) + (pageSize > -1 ? " LIMIT " + pageSize + " OFFSET " + offset : string.Empty)); }
List <List <string> > EXISTS(CNL.DL.Node R, CNL.DL.Node C) { if (analizeCase.get() == LocalityKind.Bottom) { if (lockind.get() == LocalityKind.Bottom) { return(Cumulate(AnalizeConBottom(R, "R"), AnalizeConBottom(C, "C"))); } else { return(AnalizeConBottom(C, "C")); } } else { if (lockind.get() == LocalityKind.Top) { if (C is InstanceSet) { if ((C as InstanceSet).Instances.Count() > 0) { return(AnalizeConTop(R, "R")); } } else { return(Intersect(AnalizeConTop(R, "R"), AnalizeConTop(C, "C"))); } } } return(CreateNull()); }
List <List <string> > EXISTSVAL(CNL.DL.Node R) { if (analizeCase.get() == LocalityKind.Bottom) { if (lockind.get() == LocalityKind.Bottom) { return(AnalizeConBottom(R, "D")); } } return(CreateNull()); }
List <List <string> > SELFREF(CNL.DL.Node R) { if (analizeCase.get() == lockind.get()) { return(AnalizeCon(R, "R", lockind.get())); } else { return(CreateNull()); } }
List <List <string> > RINV(CNL.DL.Node R) { if (analizeCase.get() == LocalityKind.Bottom) { return(AnalizeConBottom(R, "R")); } else { return(CreateNull()); } }
public List <List <string> > INSOF(CNL.DL.Node C, string I) { if (isLocalInstanceName(I)) { // for local instance we have e.I [= e.C where e.I = (e.I | BOT) return(SUBS(I, C)); } else { return(AnalizeConTop(C, "C")); } }
public string ConvertToSolutionExists(CNL.DL.Node n, bool useTypeOf = false) { this.useTypeOf = useTypeOf; freeVarIdBase = 0; using (activeFreeVarId.set(newFreeVarId())) { var sparqlNode = n.accept(this) as SparqlNode; return(PREAMBLE + "ASK {" + sparqlNode.ToCombinedBlock(false) + "}"); } }
public string ConvertToGetInstancesOf(CNL.DL.Node n) { freeVarIdBase = 0; string selectVars; string whereBlock; string lhs; using (activeFreeVarId.set(newFreeVarId())) { var sparqlNode = n.accept(this) as JenaNode; lhs = sparqlNode.GetFreeVariableId(); selectVars = sparqlNode.GetFreeVariableId(); whereBlock = sparqlNode.ToCombinedBlock(); } return(whereBlock); }
List <List <string> > COMPLEXROLINC(List <CNL.DL.Node> Chain, CNL.DL.Node R) { if (lockind.get() == LocalityKind.Bottom) { List <List <string> > ret = CreateNull(); foreach (var S in Chain) { ret = Cumulate(ret, AnalizeConBottom(S, "R")); } return(ret); } else { return(AnalizeConTop(R, "R")); } }
List <List <string> > INSVAL(string I, CNL.DL.Node D) { if (isLocalInstanceName(I)) { var inter = lockind.get() == LocalityKind.Top ? AnalizeConTop(D, "D") : CreateNull(); return(Cumulate(CreateSimple("I" + ":" + I), inter)); } else { if (lockind.get() == LocalityKind.Top) { return(AnalizeConTop(D, "D")); } } return(CreateNull()); }
public string ConvertToGetSubconceptsOf(CNL.DL.Node n, bool direct, bool includeTopBot, int offset, int pageSize, bool useTypeOf = false, string order = "NONE") { return(ConvertToGetRelatedConceptOf(n, false, direct, includeTopBot, offset, pageSize, useTypeOf, order)); }
public string[] ConvertToGetTypesOfDetails(CNL.DL.Node n, List <string> roles, List <string> attributes, out Dictionary <string, string> roleBinding, out Dictionary <string, string> attributeBinding, out string defaultIntance, bool useTypeOf = false, bool direct = true, string order = "NONE") { this.useTypeOf = useTypeOf; freeVarIdBase = 0; roleBinding = null; attributeBinding = null; string selectVars; string whereBlock; string whereBlock2 = null; string orderByBlock = null; string filterBlock = null; bool distinct = false; string lhs; bool ordering = order != "NONE"; if (n is InstanceSet) { var insts = (n as InstanceSet).Instances; if (insts.Count != 1) { throw new InvalidOperationException(); } defaultIntance = (insts.First() as NamedInstance).name; lhs = ToOwlName(defaultIntance, ARS.EntityKind.Instance); using (activeFreeVarId.set(newFreeVarId())) { selectVars = activeFreeVarId.get(); whereBlock = lhs + (useTypeOf ? " rdf:type " : " rdf:instanceOf ") + activeFreeVarId.get(); defaultIntance = null; var flt = lhs + "!=" + activeFreeVarId.get(); filterBlock = "( " + flt + " && " + activeFreeVarId.get() + " != owl:Thing" + " && " + activeFreeVarId.get() + " != owl:Nothing" + " )"; if (direct) { string freeId2 = "?x1"; if (freeId2 == activeFreeVarId.get()) { freeId2 = "?x2"; } var minusBody = whereBlock.Replace(activeFreeVarId.get(), freeId2) + ".\r\n"; minusBody += freeId2 + " rdfs:subClassOf " + activeFreeVarId.get() + ".\r\n"; minusBody += "FILTER(" + freeId2 + "!=" + activeFreeVarId.get() + ")" + ".\r\n"; minusBody += "FILTER(" + freeId2 + "!=" + lhs + ")" + ".\r\n"; minusBody += "FILTER(" + lhs + "!=" + activeFreeVarId.get() + ")" + ".\r\n"; whereBlock += ". MINUS {" + minusBody + "}"; } } } else { throw new InvalidOperationException(); } if (ordering) { whereBlock += ". " + selectVars + " <http://www.ontorion.com#label> ?z1"; orderByBlock = string.Format(" ORDER BY {0}(?z1) ", order); distinct = true; } if (roles != null) { roleBinding = new Dictionary <string, string>(); foreach (var role in roles) { var roleId = newFreeVarId(); roleBinding.Add(roleId.Substring(1), role); selectVars += " " + roleId; whereBlock += "\r\nOPTIONAL {" + lhs + " " + ToOwlName(role, ARS.EntityKind.DataRole) + " " + roleId + "}"; } } if (attributes != null) { attributeBinding = new Dictionary <string, string>(); foreach (var attr in attributes) { var attrId = newFreeVarId(); attributeBinding.Add(attrId.Substring(1), attr); selectVars += " " + attrId; whereBlock += "\r\nOPTIONAL {" + lhs + " " + ToOwlName(attr, ARS.EntityKind.DataRole) + " " + attrId + "}"; } } return(new string[] { (distinct ? "DISTINCT " : " "), selectVars, whereBlock, filterBlock, whereBlock2, orderByBlock }); }
List <List <string> > ONLY_C(CNL.DL.Node R, CNL.DL.Node C) { return(NEGA(() => EXISTS(R, C))); }
List <List <string> > ONLYVAL(CNL.DL.Node R) { return(NEGA(() => EXISTSVAL(R))); }
List <List <string> > SUBS(CNL.DL.Node C, CNL.DL.Node D) { return(Cumulate(AnalizeConBottom(C, "C"), AnalizeConTop(D, "C"))); }
List <List <string> > SUBS_NEG(CNL.DL.Node C, CNL.DL.Node D) { return(Cumulate(AnalizeConBottom(C, "C"), AnalizeConTop(new CNL.DL.ConceptNot(null, D), "C"))); }
List <List <string> > NEGA(CNL.DL.Node C) { return(AnalizeCon(C, "C", analizeCase.get() == LocalityKind.Bottom ? LocalityKind.Top : LocalityKind.Bottom)); }
List <List <string> > SUBS(string I, CNL.DL.Node D) { return(Cumulate(ATOM_INST(I), AnalizeConTop(D, "C"))); }
List <List <string> > ONLY(CNL.DL.Node R, CNL.DL.Node C) { return(NEGA(() => EXISTS(R, new ConceptNot(null, C)))); }
List <List <string> > DATAROLINC(CNL.DL.Node R, CNL.DL.Node S) { return(AnalizeCon(lockind.get() == LocalityKind.Bottom ? R : S, "D", lockind.get())); }
public string[] ConvertToGetInstancesOfDetails(CNL.DL.Node n, List <string> roles, List <string> attributes, out Dictionary <string, string> roleBinding, out Dictionary <string, string> attributeBinding, out string defaultIntance, bool useTypeOf = false, bool direct = true, string order = "NONE") { this.useTypeOf = useTypeOf; freeVarIdBase = 0; roleBinding = null; attributeBinding = null; string selectVars; string whereBlock; string whereBlock2 = null; string orderByBlock = null; string filterBlock = null; bool distinct = false; string lhs; bool ordering = order != "NONE"; if (n is InstanceSet) { var insts = (n as InstanceSet).Instances; defaultIntance = (insts.First() as NamedInstance).name; if (insts.Count == 1) { lhs = ToOwlName(defaultIntance, ARS.EntityKind.Instance); selectVars = "?z0"; whereBlock = "?z0" + (useTypeOf ? " rdf:type " : " rdf:instanceOf ") + "<http://www.w3.org/2002/07/owl#NamedIndividual>"; whereBlock2 = "?z0 owl:sameAs " + lhs; filterBlock = "?z0 = " + lhs; } else if (insts.Count > 1) { lhs = string.Join(",", (from i in insts select ToOwlName((i as NamedInstance).name, ARS.EntityKind.Instance))); selectVars = "?z0"; whereBlock = "?z0" + (useTypeOf ? " rdf:type " : " rdf:instanceOf ") + "<http://www.w3.org/2002/07/owl#NamedIndividual>"; whereBlock2 = null; filterBlock = "?z0 IN (" + lhs + ")"; } else { throw new InvalidOperationException(); } } else { using (activeFreeVarId.set(newFreeVarId())) { var sparqlNode = n.accept(this) as SparqlNode; distinct = sparqlNode.UseDistinct(); lhs = sparqlNode.GetFreeVariableId(); selectVars = sparqlNode.GetFreeVariableId(); whereBlock = sparqlNode.ToCombinedBlock(false, true, direct, true, false); defaultIntance = null; } } if (ordering) { whereBlock += ". " + selectVars + " <http://www.ontorion.com#label> ?z1"; orderByBlock = string.Format(" ORDER BY {0}(?z1) ", order); distinct = true; } if (roles != null) { roleBinding = new Dictionary <string, string>(); foreach (var role in roles) { var roleId = newFreeVarId(); roleBinding.Add(roleId.Substring(1), role); selectVars += " " + roleId; whereBlock += "\r\nOPTIONAL {" + lhs + " " + ToOwlName(role, ARS.EntityKind.DataRole) + " " + roleId + "}"; } } if (attributes != null) { attributeBinding = new Dictionary <string, string>(); foreach (var attr in attributes) { var attrId = newFreeVarId(); attributeBinding.Add(attrId.Substring(1), attr); selectVars += " " + attrId; whereBlock += "\r\nOPTIONAL {" + lhs + " " + ToOwlName(attr, ARS.EntityKind.DataRole) + " " + attrId + "}"; } } return(new string[] { (distinct ? "DISTINCT " : " "), selectVars, whereBlock, filterBlock, whereBlock2, orderByBlock }); }
// TOOLS List <List <string> > FUNCR(CNL.DL.Node R) { return(AnalizeConBottom(R, "R")); }