Esempio n. 1
0
        // JSON Encode and Decode //
        public static LinguisticRule fromJson(string JsonData)
        {
            JSONObject     LRJSO  = new JSONObject(JsonData);
            LinguisticRule Result = new LinguisticRule(
                LRJSO.GetField("Value").str,
                LRJSO.GetField("Rule").str);

            Result.implicationMethod =
                FuzzyImplication.TryParse(
                    LRJSO.GetField("Implication").str);
            Result._operator =
                FuzzyOperator.TryParse(
                    LRJSO.GetField("Operator").str);
            return(Result);
        }
Esempio n. 2
0
        // Constructor
        public static LinguisticVariable fromJson(string jsonData)
        {
            LinguisticVariable result = new LinguisticVariable();
            JSONObject         MFJSO  = new JSONObject(jsonData);
            string             type   = MFJSO.GetField("Type").str;

            if (!type.Equals("Linguistics") && !type.Equals("Fuzzy"))
            {
                return(null);
            }
            result.linguisticVariableVersion = MFJSO.GetField("Version").str;
            switch (result.JsonVersion)
            {
            case "0.1":
                result.linguisticName =
                    MFJSO.GetField("LinguisticVariable").str;
                result.minimumValue =
                    MFJSO.GetField("MinimumValue").n;
                result.rangeLength =
                    MFJSO.GetField("RangeLength").n;
                foreach (JSONObject MF in
                         MFJSO.GetField("LinguisticValues").list)
                {
                    result.membershipFunctions.Add(
                        MembershipFunction.fromJson(MF.Print())
                        );
                }
                if (MFJSO.HasField("LinguisticRule"))
                {
                    foreach (JSONObject Rule in
                             MFJSO.GetField("LinguisticRule").list)
                    {
                        result.linguisticRules.Add(
                            LinguisticRule.fromJson(Rule.Print()));
                    }
                }
                break;

            default:
                break;
            }
            return(result);
        }