// 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); }
// Functions // public string numericRule(List <LinguisticVariable> LingVars) { string[] splitRule = this.actualRule.Split(' '); string numericRule = ""; LinguisticVariable foundVar = null; foreach (string word in splitRule) { if (foundVar == null) { if (LingVars.Exists(v => v.Name.Equals(word))) { foundVar = LingVars.Find(v => v.Name.Equals(word)); } else { numericRule += word + " "; } } else { if (foundVar.membershipFunctions.Exists( f => f.membershipValue. linguistic.Equals(word))) { numericRule += foundVar.membershipFunctions.Find( f => f.membershipValue. linguistic.Equals(word)) .membershipValue.fuzzy + " "; foundVar = null; } else { numericRule += word + " "; foundVar = null; } } } return(numericRule.Trim()); }