public static DlName ToDL(EnName eng, CogniPy.CNL.EN.endict.WordKind kind) { var parts = eng.Split(); DlName.Parts dlp = new DlName.Parts(); dlp.term = parts.term; dlp.local = parts.kind == EnName.Parts.Kind.BigName; dlp.quoted = parts.quoted; if (parts.quoted || parts.kind != EnName.Parts.Kind.Name || kind == endict.WordKind.NormalForm) { dlp.name = parts.name; } else { var name = parts.name; var arr = name.Split(new char[] { '-' }); if (kind == endict.WordKind.SimplePast || kind == endict.WordKind.PastParticiple || kind == endict.WordKind.PluralFormVerb) { arr[0] = CNLFactory.lex.toDL_Simple(arr[0], kind); } else if (kind == endict.WordKind.PluralFormNoun) { arr[arr.Length - 1] = CNLFactory.lex.toDL_Simple(arr[arr.Length - 1], kind); } dlp.name = string.Join("-", arr); } return(dlp.Combine()); }
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()); }
/// <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()); }