Example #1
0
 public override object Visit(SwrlStatement e)
 {
     isBody = false;
     e.slp.accept(this);
     isBody = true;
     e.slc.accept(this);
     return(e);
 }
Example #2
0
        public override object Visit(SwrlStatement e)
        {
            var id = Interlocked.Increment(ref swrl_cnt).ToString();

            id2stmt.Add("swrl-" + 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();
            }
            if (e.modality == Statement.Modality.IS)
            {
                sb.Append("[swrl-" + id + ": ");
                inSwrlBody = true;
                e.slp.accept(this);
                sb.Append(" -> ");
                if (model != null && debugSWRL)
                {
                    sb.Append(" debugTraceBuiltIn (" + iid + "),");
                }
                inSwrlBody = false;
                e.slc.accept(this);
                sb.AppendLine("]");
            }
            else if (modalCheckerRules)
            {
                bool normal = (e.modality == Statement.Modality.CAN || e.modality == Statement.Modality.SHOULD || e.modality == Statement.Modality.MUST);
                sb.Append("[swrl-modal-body-" + id + ": ");
                inSwrlBody = true;
                e.slp.accept(this);
                sb.Append(" -> ");
                if (model != null)
                {
                    sb.Append(" modalCheckerBuiltIn (0," + (normal ? "0," : "1,") + iid + ")");
                }
                inSwrlBody = false;
                sb.AppendLine("]");

                sb.Append("[swrl-modal-head-" + id + ": ");
                inSwrlBody = true;
                e.slp.accept(this);
                sb.Append(", ");
                e.slc.accept(this);
                sb.Append(" -> ");
                if (model != null)
                {
                    sb.Append(" modalCheckerBuiltIn (1," + (normal ? "0," : "1,") + iid + ")");
                }
                inSwrlBody = false;
                sb.AppendLine("]");
            }
            return(null);
        }
Example #3
0
        public object Visit(SwrlStatement e)
        {
#if USE_SWRL
            if (e.modality != Statement.Modality.IS)
            {
                return(CreateNull());
            }

            return(SUBS(e.slp, e.slc));
#else
            return(CreateNull());
#endif
        }
Example #4
0
 public virtual object Visit(SwrlStatement e)
 {
     e.slp.accept(this);
     e.slc.accept(this);
     return(e);
 }
Example #5
0
 public override object Visit(SwrlStatement e)
 {
     builtinFound = true;
     return(null);
 }
Example #6
0
        public static Statement TransformSwrlToDL(SwrlStatement e)
        {
            if (e.slc.list.Count == 1)
            {
                var conc = getSimpleDLFormOfSwrlItem(e.slc.list[0]);
                if (conc != null && conc.Item1 != null && conc.Item2 is Node)
                {
                    Dictionary <string, List <object> > nodes = new Dictionary <string, List <object> >();
                    Dictionary <string, Dictionary <string, HashSet <string> > > links    = new Dictionary <string, Dictionary <string, HashSet <string> > >();
                    Dictionary <string, Dictionary <string, HashSet <string> > > invlinks = new Dictionary <string, Dictionary <string, HashSet <string> > >();
                    HashSet <Tuple <string, string, string> > pendinglinks = new HashSet <Tuple <string, string, string> >();
                    foreach (var p in e.slp.list)
                    {
                        var pred = getSimpleDLFormOfSwrlItem(p);
                        if (pred == null)
                        {
                            return(e);
                        }
                        if (pred.Item2 is DLLink)
                        {
                            var l = pred.Item2 as DLLink;
                            if (!links.ContainsKey(l.I))
                            {
                                links.Add(l.I, new Dictionary <string, HashSet <string> >());
                            }
                            if (!links[l.I].ContainsKey(l.J))
                            {
                                links[l.I].Add(l.J, new HashSet <string>());
                            }
                            links[l.I][l.J].Add(l.R);
                            pendinglinks.Add(Tuple.Create(l.I, l.J, l.R));
                            if (!invlinks.ContainsKey(l.J))
                            {
                                invlinks.Add(l.J, new Dictionary <string, HashSet <string> >());
                            }
                            if (!invlinks[l.J].ContainsKey(l.I))
                            {
                                invlinks[l.J].Add(l.I, new HashSet <string>());
                            }
                            invlinks[l.J][l.I].Add(l.R);
                        }
                        else
                        {
                            if (!nodes.ContainsKey(pred.Item1))
                            {
                                nodes.Add(pred.Item1, new List <object>());
                            }
                            if (!alreadyExists(nodes[pred.Item1], pred.Item2))
                            {
                                nodes[pred.Item1].Add(pred.Item2);
                            }
                        }
                    }

                    Func <string, List <Node> > act = null;

                    HashSet <string> alreadyDone = new HashSet <string>();

                    act = new Func <string, List <Node> >((xname) =>
                    {
                        alreadyDone.Add(xname);
                        List <Node> torkn = new List <Node>();

                        foreach (var kv in nodes)
                        {
                            if (kv.Key == xname)
                            {
                                var r = getAllAs <Node>(kv.Value);
                                if (r == null)
                                {
                                    return(null);
                                }
                                torkn.AddRange(r);
                            }
                            else
                            {
                                if (links.ContainsKey(xname) && links[xname].ContainsKey(kv.Key))
                                {
                                    if (links[xname][kv.Key].Count > 1)
                                    {
                                        return(null);
                                    }
                                    var R = links[xname][kv.Key].First();
                                    pendinglinks.Remove(Tuple.Create(xname, kv.Key, R));
                                    if (nodes[kv.Key].First() is Node)
                                    {
                                        var r = getAllAs <Node>(nodes[kv.Key]);
                                        if (r == null)
                                        {
                                            return(null);
                                        }
                                        if (!alreadyDone.Contains(kv.Key))
                                        {
                                            var cc = act(kv.Key);
                                            if (cc == null)
                                            {
                                                return(null);
                                            }
                                            r.AddRange(cc);
                                        }
                                        torkn.Add(new CNL.DL.SomeRestriction(null, new CNL.DL.Atomic(null)
                                        {
                                            id = R
                                        }, new CNL.DL.ConceptAnd(null)
                                        {
                                            Exprs = r
                                        }));
                                    }
                                    else
                                    {
                                        var r = getAllAs <AbstractBound>(nodes[kv.Key]);
                                        if (r == null)
                                        {
                                            return(null);
                                        }
                                        torkn.Add(new CNL.DL.SomeValueRestriction(null, new CNL.DL.Atomic(null)
                                        {
                                            id = R
                                        }, new CNL.DL.BoundAnd(null)
                                        {
                                            List = r
                                        }));
                                    }
                                }
                                else if (invlinks.ContainsKey(xname) && invlinks[xname].ContainsKey(kv.Key))
                                {
                                    if (invlinks[xname][kv.Key].Count > 1)
                                    {
                                        return(null);
                                    }
                                    var R = invlinks[xname][kv.Key].First();
                                    pendinglinks.Remove(Tuple.Create(xname, kv.Key, R));
                                    if (nodes[kv.Key].First() is Node)
                                    {
                                        var r = getAllAs <Node>(nodes[kv.Key]);
                                        if (r == null)
                                        {
                                            return(null);
                                        }
                                        if (!alreadyDone.Contains(kv.Key))
                                        {
                                            var cc = act(kv.Key);
                                            if (cc == null)
                                            {
                                                return(null);
                                            }
                                            r.AddRange(cc);
                                        }
                                        torkn.Add(new CNL.DL.SomeRestriction(null, new CNL.DL.RoleInversion(null, new CNL.DL.Atomic(null)
                                        {
                                            id = R
                                        }), new CNL.DL.ConceptAnd(null)
                                        {
                                            Exprs = r
                                        }));
                                    }
                                    else
                                    {
                                        return(null);
                                    }
                                }
                                else
                                {
                                    return(null);
                                }
                            }
                        }

                        return(torkn);
                    });

                    var rr = act(conc.Item1);
                    if (rr == null)
                    {
                        return(e);
                    }

                    if (pendinglinks.Count > 0)
                    {
                        return(e);
                    }

                    return(new CNL.DL.Subsumption(null, new CNL.DL.ConceptAnd(null)
                    {
                        Exprs = rr
                    }, (Node)conc.Item2, Statement.Modality.IS));
                }
            }
            return(e);
        }