コード例 #1
0
        public CogniPy.CNL.DL.DlName ToDL(OwlName owlname, CNL.EN.endict lex, Func <string, string> ns2pfx, EntityKind madeFor)
        {
            var    parts     = owlname.Split();
            string defaultNs = ns2pfx(null);

            if (string.IsNullOrWhiteSpace(parts.ns))
            {
                parts.ns = defaultNs;
            }

            string pfx = null;

            if (!IRIParser.AreNamespacesEqual(defaultNs, parts.ns))
            {
                pfx = ns2pfx(parts.ns);
            }

            var mth      = bregexp.Match(parts.name);
            var captures = mth.Groups["g"].Captures;
            var dlp      = new DlName.Parts()
            {
                term = pfx
            };

            if (mth.Success &&
                ((!bigConcept && (
                      ((madeFor == EntityKind.Instance) && char.IsUpper(parts.name.First())) ||
                      ((madeFor == EntityKind.Concept || madeFor == EntityKind.DataRole || madeFor == EntityKind.Role) && char.IsLower(parts.name.First()))
                      )) ||
                 (bigConcept && (
                      ((madeFor == EntityKind.Instance) && char.IsUpper(parts.name.First())) ||
                      ((madeFor == EntityKind.Concept || madeFor == EntityKind.DataRole || madeFor == EntityKind.Role) && char.IsLower(parts.name.First()))
                      ))))
            {
                dlp.quoted = false;
                StringBuilder sb    = new StringBuilder();
                var           first = true;
                foreach (var n in captures)
                {
                    var ss = n.ToString();
                    if (first)
                    {
                        first = false;
                        if (madeFor == EntityKind.Role || madeFor == EntityKind.DataRole)
                        {
                            var nn = lex.toDL_Simple(ss, CNL.EN.endict.WordKind.PastParticiple);
                            sb.Append(nn);
                            continue;
                        }
                    }
                    else
                    {
                        sb.Append("-");
                    }
                    sb.Append(madeFor == EntityKind.Instance ? char.ToUpper(ss[0]) : char.ToLower(ss[0]));
                    sb.Append(ss.Substring(1));
                }
                dlp.name = sb.ToString();
            }
            else
            {
                dlp.quoted = true;
                dlp.name   = parts.name;
            }

            return(dlp.Combine());
        }
コード例 #2
0
        /// <summary>
        /// Translate an OWLname to a CNL (DL) name
        /// </summary>
        /// <param name="owlname">the OWL name</param>
        /// <param name="lex"></param>
        /// <param name="ns2pfx"></param>
        /// <param name="madeFor">the type of this entity (Concept, Instance, Role,...)</param>
        /// <returns></returns>
        public CogniPy.CNL.DL.DlName ToDL(OwlName owlname, CNL.EN.endict lex, Func <string, string> ns2pfx, EntityKind madeFor)
        {
            var    parts     = owlname.Split();
            string defaultNs = ns2pfx(null);

            if (string.IsNullOrWhiteSpace(parts.ns))
            {
                parts.ns = defaultNs;
            }

            string pfx = null;

            if (!IRIParser.AreNamespacesEqual(defaultNs, parts.ns))
            {
                pfx = ns2pfx(parts.ns);
            }

            var dlp = new DlName.Parts()
            {
                term = pfx
            };

            if (parts.name.StartsWith("⊤"))
            {
                dlp.name = "⊤";
                if (parts.name.Contains("."))
                {
                    dlp.name = "[" + dlp.name + "]";
                }
                dlp.quoted = false;
            }
            else
            {
                var  name_part  = parts.name;
                bool isVBigName = parts.global;
                var  sufix      = "";
                if (madeFor == EntityKind.SWRLVariable)
                {
                    var a = name_part.Split('_');
                    if (a.Length == 2)
                    {
                        name_part = a.First();
                        sufix     = a.Last();
                    }
                }
                Match mth = null;
                if (!isVBigName)
                {
                    mth = regexp.Match(name_part);
                }
                Match mth2 = null;
                if (isVBigName || !mth.Success)
                {
                    mth2 = vbregexp.Match(name_part);
                }
                if (name_part != "" &&
                    (
                        (mth != null && mth.Success &&
                         (
                             ((madeFor == EntityKind.SWRLVariable || madeFor == EntityKind.Instance) && char.IsUpper(name_part.First())) ||
                             ((madeFor == EntityKind.Concept || madeFor == EntityKind.DataRole || madeFor == EntityKind.SWRLVariable || madeFor == EntityKind.Role) && char.IsLower(name_part.First()))
                         )) ||
                        (mth2 != null && mth2.Success && madeFor == EntityKind.Instance)
                    ))
                {
                    var grps = (mth != null && mth.Success) ? mth.Groups["g"].Captures : mth2.Groups["g"].Captures;
                    var urps = (mth != null && mth.Success) ? mth.Groups["u"].Captures : mth2.Groups["u"].Captures;
                    dlp.quoted = false;
                    StringBuilder sb      = new StringBuilder();
                    var           first   = true;
                    bool          success = true;
                    foreach (var n in grps)
                    {
                        var ss = n.ToString();
                        if (first)
                        {
                            first = false;
                            if (madeFor == EntityKind.Role || madeFor == EntityKind.DataRole)
                            {
                                var nn = lex.toDL_Simple(ss, CNL.EN.endict.WordKind.PastParticiple);
                                if (lex.toN_Simple(nn, CNL.EN.endict.WordKind.PastParticiple) != ss)
                                {
                                    success    = false;
                                    dlp.quoted = true;
                                    dlp.name   = parts.name + (string.IsNullOrEmpty(sufix) ? "" : "_" + sufix);
                                    break;
                                }
                                sb.Append(nn);
                                continue;
                            }
                        }
                        else
                        {
                            sb.Append("-");
                        }
                        sb.Append(madeFor == EntityKind.Instance && !(urps.Count > 0) ? char.ToUpper(ss[0]) : char.ToLower(ss[0]));
                        sb.Append(ss.Substring(1));
                    }
                    if (success)
                    {
                        dlp.name = sb.ToString() + (string.IsNullOrEmpty(sufix) ? "" : "_" + sufix);
                        if (urps.Count > 0)
                        {
                            dlp.name = "[" + dlp.name + "]";
                        }
                    }
                }
                else
                {
                    dlp.quoted = true;
                    dlp.name   = parts.name + (string.IsNullOrEmpty(sufix) ? "" : "_" + sufix);
                }
            }

            if (madeFor == EntityKind.Instance)
            {
                dlp.name = IRIParser.decodeIRI(dlp.name);
            }

            dlp.local = ((madeFor == EntityKind.Instance) && !parts.global);

            return(dlp.Combine());
        }