Ejemplo n.º 1
0
        public object Visit(Subsumption e)
        {
            if (e.modality != Statement.Modality.IS)
            {
                return(CreateNull());
            }

            //for Functional Role
            if (lockind.get() == LocalityKind.Bottom)
            {
                if (e.C is Top)
                {
                    if (e.D is NumberRestriction)
                    {
                        var restr = e.D as NumberRestriction;
                        if ((restr.C is Top) && ((restr.Kind == "≤" && int.Parse(restr.N) == 1) || (restr.Kind == "<" && int.Parse(restr.N) == 2)))
                        {
                            return(FUNCR(restr.R));
                        }
                    }
                }
            }

            //Subsumption of concepts
            return(SUBS(e.C, e.D));
        }
Ejemplo n.º 2
0
        public override object Visit(Subsumption e)
        {
            var iC = getSingleNamgedInstance(e.C);
            var iD = getSingleNamgedInstance(e.D);

            if (iC != null)
            {
                if (iD != null)
                {
                    var list = new InstanceList(null)
                    {
                        List = new List <Instance>(new Instance[] { iC, iD })
                    };
                    return(new SameInstances(null, list, e.modality));
                }
                else
                {
                    return(ConvertToAbox(iC, e.modality, e.D));
                }
            }
            return(e);
        }
Ejemplo n.º 3
0
        public override object Visit(Subsumption e)
        {
            if (e.modality == Statement.Modality.IS)
            {
                if (e.C is CogniPy.CNL.DL.Atomic)
                {
                    if (e.D is CogniPy.CNL.DL.SomeRestriction || e.D is CogniPy.CNL.DL.SomeValueRestriction)
                    {
                        var tpl = SolveSingleSome((e.C as CNL.DL.Atomic).id, e.D);
                        if (tpl != null)
                        {
                            var idx = Interlocked.Increment(ref sme_cnt).ToString();
                            sb.Append("[sme-" + idx + ": ");
                            id2stmt.Add("sme-" + idx, e);
                            sb.Append("(?X rdf:type " + tpl.Item1 + ") -> (?X " + tpl.Item2 + " " + tpl.Item3 + ")");
                            appendDebugString(sb, e);
                            sb.AppendLine("]");
                        }
                    }
                    else if (e.D is CNL.DL.ConceptAnd)
                    {
                        var  A     = e.D as CNL.DL.ConceptAnd;
                        bool found = false;
                        foreach (var x in A.Exprs)
                        {
                            var tpl = SolveSingleSome((e.C as CNL.DL.Atomic).id, x);
                            if (tpl != null)
                            {
                                if (!found)
                                {
                                    found = true;
                                    var idx = Interlocked.Increment(ref sme_cnt).ToString();
                                    sb.Append("[sme-" + idx + ": (?X rdf:type " + tpl.Item1 + ") -> ");
                                    id2stmt.Add("sme-" + idx, e);
                                }
                                sb.Append("(?X " + tpl.Item2 + " " + tpl.Item3 + ")");
                            }
                        }
                        if (found)
                        {
                            appendDebugString(sb, e);
                            sb.AppendLine("]");
                        }
                    }
                }
                return(base.Visit(e));
            }
            else if (modalCheckerRules)
            {
                var id = Interlocked.Increment(ref swrl_cnt).ToString();
                id2stmt.Add("subsumption-modal-body-" + id, e);
                string iid = null;
                if (model != null)
                {
                    //                iid = model.createTypedLiteral("\"" + id.ToString() + "\"", org.apache.jena.datatypes.xsd.XSDDatatype.XSDstring).toString();
                    DL.Serializer ser = new Serializer();
                    var           dl  = ser.Serialize(e);
                    iid = model.createTypedLiteral("\'" + dl.Replace("\'", "\\\'").ToString() + "\'", org.apache.jena.datatypes.xsd.XSDDatatype.XSDstring).toString();
                }

                TransformToJenaRules jenarulesTransform = new TransformToJenaRules();
                jenarulesTransform.setOWLDataFactory(owlNC);
                string ruleC = null;
                string ruleD = null;
                try
                {
                    ruleC = jenarulesTransform.ConvertToGetInstancesOf(e.C);
                    ruleD = jenarulesTransform.ConvertToGetInstancesOf(e.D);

                    bool normal = (e.modality == Statement.Modality.CAN || e.modality == Statement.Modality.SHOULD || e.modality == Statement.Modality.MUST);
                    sb.Append("[subsumption-modal-body-" + id + ": ");
                    sb.Append(ruleC);
                    sb.Append(" -> ");
                    if (model != null)
                    {
                        sb.Append(" modalCheckerBuiltIn (0," + (normal ? "0," : "1,") + iid + ")");
                    }
                    sb.AppendLine("]");
                    sb.Append("[subsumption-modal-head-" + id + ": ");
                    sb.Append(ruleC);
                    sb.Append(",");
                    sb.Append(ruleD);
                    sb.Append(" -> ");
                    if (model != null)
                    {
                        sb.Append(" modalCheckerBuiltIn (1," + (normal ? "0," : "1,") + iid + ")");
                    }
                    appendDebugString(sb, e);
                    sb.AppendLine("]");
                }
                catch (CogniPy.Executing.HermiTClient.ReasoningServiceException)
                {
                    ruleC = "";
                    ruleD = "";
                }
                catch
                {
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }