예제 #1
0
        public JsonNetResult PluralAndGender()
        {
            string name = Request.Form["name"];

            CultureInfo ci = CultureInfo.GetCultureInfo(regex.Match(name).Groups["lang"].Value);

            string text = Request.Form["text"];

            return(this.JsonNet(new
            {
                gender = NaturalLanguageTools.GetGender(text, ci),
                plural = NaturalLanguageTools.Pluralize(text, ci)
            }));
        }
예제 #2
0
        internal static LocalizedType ImportXml(Type type, DescriptionOptions opts, LocalizedAssembly assembly, XElement x)
        {
            string?description = !opts.IsSetAssert(DescriptionOptions.Description, type) ? null :
                                 (x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("Description")?.Value) ??
                                 (!assembly.IsDefault ? null : DescriptionManager.DefaultTypeDescription(type));

            var xMembers = x?.Elements("Member")
                           .Select(m => KeyValuePair.Create(m.Attribute("Name").Value, m.Attribute("Description").Value))
                           .Distinct(m => m.Key)
                           .ToDictionary();

            LocalizedType result = new LocalizedType
            {
                Type     = type,
                Options  = opts,
                Assembly = assembly,

                Description       = description,
                PluralDescription = !opts.IsSetAssert(DescriptionOptions.PluralDescription, type) ? null :
                                    ((x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("PluralDescription")?.Value) ??
                                     (!assembly.IsDefault ? null : type.GetCustomAttribute <PluralDescriptionAttribute>()?.PluralDescription) ??
                                     (description == null ? null : NaturalLanguageTools.Pluralize(description, assembly.Culture))),

                Gender = !opts.IsSetAssert(DescriptionOptions.Gender, type) ? null :
                         ((x?.Attribute("Gender")?.Value.Single()) ??
                          (!assembly.IsDefault ? null : type.GetCustomAttribute <GenderAttribute>()?.Gender) ??
                          (description == null ? null : NaturalLanguageTools.GetGender(description, assembly.Culture))),

                Members = !opts.IsSetAssert(DescriptionOptions.Members, type) ? null :
                          (from m in GetMembers(type)
                           where DescriptionManager.OnShouldLocalizeMember(m)
                           let value = xMembers?.TryGetC(m.Name) ?? (!assembly.IsDefault ? null : DescriptionManager.DefaultMemberDescription(m))
                                       where value != null
                                       select KeyValuePair.Create(m.Name, value))
                          .ToDictionary()
            };

            return(result);
        }
예제 #3
0
 public string?Gender(string culture, [Required, FromBody] string text)
 {
     return(NaturalLanguageTools.GetGender(text, CultureInfo.GetCultureInfo(culture))?.ToString());
 }
예제 #4
0
    public static string GetPropertyHelp(PropertyRoute pr)
    {
        string?validations = Validator.TryGetPropertyValidator(pr)?.Let(vs => vs.Validators.Where(v => !(v is NotNullValidatorAttribute)).CommaAnd(v => v.HelpMessage));

        if (validations.HasText())
        {
            validations = HelpMessage.Should.NiceToString() + validations;
        }

        validations += ".";

        if (Reflector.IsIEntity(pr.Type))
        {
            Implementations imp = Schema.Current.FindImplementations(pr);

            return(EntityProperty(pr, pr.Type, imp.TypeLinks(pr.Type)) + validations);
        }
        else if (pr.Type.IsLite())
        {
            Type cleanType = Lite.Extract(pr.Type) !;

            Implementations imp = Schema.Current.FindImplementations(pr);

            return(EntityProperty(pr, cleanType, imp.TypeLinks(cleanType)) + validations);
        }
        else if (Reflector.IsEmbeddedEntity(pr.Type))
        {
            return(EntityProperty(pr, pr.Type, pr.Type.NiceName()));
        }
        else if (Reflector.IsMList(pr.Type))
        {
            Type elemType = pr.Type.ElementType() !;

            if (elemType.IsIEntity())
            {
                Implementations imp = Schema.Current.FindImplementations(pr.Add("Item"));

                return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), imp.TypeLinks(elemType)) + validations);
            }
            else if (elemType.IsLite())
            {
                Implementations imp = Schema.Current.FindImplementations(pr.Add("Item"));

                return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), imp.TypeLinks(Lite.Extract(elemType) !)) + validations);
            }
            else if (Reflector.IsEmbeddedEntity(elemType))
            {
                return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), elemType.NiceName()) + validations);
            }
            else
            {
                string valueType = ValueType(pr.Add("Item"));
                return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), valueType) + validations);
            }
        }
        else if (pr.Type.UnNullify() == typeof(PrimaryKey))
        {
            var vt = ValueType(PrimaryKey.Type(pr.RootType), false, null, null);
            return(HelpMessage._0IsThePrimaryKeyOf1OfType2.NiceToString().FormatWith(pr.PropertyInfo !.NiceName(), pr.RootType.NiceName(), vt) + validations);
        }
        else
        {
            string valueType = ValueType(pr);

            return(HelpMessage._0IsA1.NiceToString().ForGenderAndNumber(NaturalLanguageTools.GetGender(valueType)).FormatWith(pr.PropertyInfo !.NiceName(), valueType) + validations);
        }
    }