亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ruleparser.cs

?? 在.net環境下用C#開發的模糊控制函數庫
?? CS
?? 第 1 頁 / 共 2 頁
字號:
        {
            //
            // Extract single conditions
            //
            List<IExpression> expressions = ExtractSingleCondidtions(conditionExpression, input, lexems);

            if (expressions.Count == 0)
            {
                throw new Exception("No valid conditions found in conditions part of the rule.");
            }

            ICondition cond = ParseConditionsRecurse(expressions, lexems);

            //
            // Return conditions
            //
            if (cond is Conditions)
            {
                return (Conditions)cond;
            }
            else
            {
                Conditions conditions = new Conditions();
                return conditions;
            }
        }

        static private int FindPairBracket(List<IExpression> expressions, Dictionary<string, Lexem> lexems)
        {
            //
            // Assume that '(' stands at first place
            //

            int bracketsOpened = 1;
            int closeBracket = -1;
            for (int i = 1; i < expressions.Count; i++)
            {
                if (expressions[i] == lexems["("])
                {
                    bracketsOpened++;
                }
                else if (expressions[i] == lexems[")"])
                {
                    bracketsOpened--;
                    if (bracketsOpened == 0)
                    {
                        closeBracket = i;
                        break;
                    }
                }
            }

            return closeBracket;
        }

        static private ICondition ParseConditionsRecurse(List<IExpression> expressions, Dictionary<string, Lexem> lexems)
        {
            if (expressions.Count < 1)
            {
                throw new Exception("Empty condition found.");
            }

            if (expressions[0] == lexems["("] && FindPairBracket(expressions, lexems) == expressions.Count)
            {
                //
                // Remove extra brackets
                //
                return ParseConditionsRecurse(expressions.GetRange(1, expressions.Count - 2), lexems);
            }
            else if (expressions.Count == 1 && expressions[0] is ConditionExpression)
            {
                //
                // Return single conditions
                //
                return ((ConditionExpression)expressions[0]).Condition;
            }
            else
            {
                //
                // Parse list of one level conditions connected by or/and
                //
                List<IExpression> copyExpressions = expressions.GetRange(0, expressions.Count);
                Conditions conds = new Conditions();
                bool setOrAnd = false;
                while (copyExpressions.Count > 0)
                {
                    ICondition cond = null;
                    if (copyExpressions[0] == lexems["("])
                    {
                        //
                        // Find pair bracket
                        //
                        int closeBracket = FindPairBracket(copyExpressions, lexems);
                        if (closeBracket == -1)
                        {
                            throw new Exception("Parenthesis error.");
                        }

                        cond = ParseConditionsRecurse(copyExpressions.GetRange(1, closeBracket - 1), lexems);
                        copyExpressions.RemoveRange(0, closeBracket + 1);
                    }
                    else if (copyExpressions[0] is ConditionExpression)
                    {
                        cond = ((ConditionExpression)copyExpressions[0]).Condition;
                        copyExpressions.RemoveAt(0);
                    }
                    else
                    {
                        throw new ArgumentException(string.Format("Wrong expression in condition part at '{0}'"),copyExpressions[0].Text );
                    }

                    //
                    // And condition to the list
                    //
                    conds.Conditins.Add(cond);

                    if (copyExpressions.Count > 0)
                    {
                        if (copyExpressions[0] == lexems["and"] || copyExpressions[0] == lexems["or"])
                        {
                            if (copyExpressions.Count < 2)
                            {
                                throw new Exception(string.Format("Error at {0} in condition part.", copyExpressions[0].Text));
                            }

                            //
                            // Set and/or for conditions list
                            //
                            OperatorType newOp = (copyExpressions[0] == lexems["and"]) ? OperatorType.And : OperatorType.Or;

                            if (setOrAnd)
                            {
                                if (conds.Op != newOp)
                                {
                                    throw new Exception("At the one nesting level cannot be mixed and/or operations.");
                                }
                            }
                            else
                            {
                                conds.Op = newOp;
                                setOrAnd = true;
                            }
                            copyExpressions.RemoveAt(0);
                        }
                        else
                        {
                            throw new Exception(string.Format("{1} cannot goes after {0}", copyExpressions[0].Text, copyExpressions[1].Text));
                        }
                    }
                }

                return conds;
            }
        }

        static private SingleCondition ParseConclusion(List<IExpression> conditionExpression, List<FuzzyVariable> output, Dictionary<string, Lexem> lexems)
        {

            List<IExpression> copyExpression = conditionExpression.GetRange(0, conditionExpression.Count);

            //
            // Remove extra brackets
            //
            while (
                copyExpression.Count >= 2 &&
                (copyExpression[0] == lexems["("] && copyExpression[conditionExpression.Count - 1] == lexems[")"]))
            {
                copyExpression = copyExpression.GetRange(1, copyExpression.Count - 2);
            }

            if (copyExpression.Count != 3)
            {
                throw new Exception("Conclusion part of the rule should be in form: 'variable is term'");
            }

            //
            // Parse variable
            //
            Lexem exprVariable = (Lexem)copyExpression[0];
            if (!(exprVariable is VarLexem))
            {
                throw new Exception(string.Format("Wrong identifier '{0}' in conclusion part of the rule.", exprVariable.Text));
            }

            VarLexem varLexem = (VarLexem)exprVariable;
            if (varLexem.Input == true)
            {
                throw new Exception("The variable in conclusion part must be an output variable.");
            }
            
            //
            // Parse 'is' lexem
            //
            Lexem exprIs = (Lexem)copyExpression[1];
            if (exprIs != lexems["is"])
            {
                throw new Exception(string.Format("'is' keyword must go after {0} identifier.", varLexem.Text));
            }

            //
            // Parse term
            //
            Lexem exprTerm = (Lexem)copyExpression[2];
            if (!(exprTerm is TermLexem))
            {
                throw new Exception(string.Format("Wrong identifier '{0}' in conclusion part of the rule.", exprTerm.Text));
            }

            TermLexem termLexem = (TermLexem)exprTerm;
            if (!varLexem.Var.Terms.Contains(termLexem.Term))
            {
                throw new Exception(string.Format("The term ({0}) in conclusion part does not belong to the specified variable ({1}).", termLexem.Text, varLexem.Text));
            }

            //
            // Return fuzzy rule's conclusion
            //
            return new SingleCondition(varLexem.Var, termLexem.Term, false);
        }

        static public FuzzyRule Parse(string rule, List<FuzzyVariable> input, List<FuzzyVariable> output)
        {
            if (rule.Length == 0)
            {
                throw new ArgumentException("Rule cannot be empty.");
            }

            //
            // Surround brakes with spaces, remove double spaces
            //
            System.Text.StringBuilder sb = new StringBuilder();
            foreach (char ch in rule)
            {
                if (ch == ')' || ch == '(')
                {
                    if (sb.Length > 0 && sb[sb.Length - 1] == ' ')
                    {
                        // Do not duplicate spaces
                    }
                    else
                    {
                        sb.Append(' ');
                    }

                    sb.Append(ch);
                    sb.Append(' ');
                }
                else
                {
                    if (ch == ' ' && sb.Length > 0 && sb[sb.Length - 1] == ' ')
                    {
                        // Do not duplicate spaces
                    }
                    else
                    {
                        sb.Append(ch);
                    }
                }
            }

            //
            // Remove spaces
            //
            string prepRule = sb.ToString().Trim();

            //
            // Build lexems dictionary
            //
            List<Lexem> lexems = BuildLexemsList(input, output);
            Dictionary<string, Lexem> lexemsDict = new Dictionary<string, Lexem>();
            foreach (Lexem lexem in lexems)
            {
                lexemsDict.Add(lexem.Text, lexem);
            }

            //
            // At first we parse lexems
            //
            List<IExpression> expressions = ParseLexems(prepRule, lexemsDict);
            if (expressions.Count == 0)
            {
                throw new System.Exception("No valid identifiers found.");
            }
            
            //
            // Find condition & conclusion parts part
            //
            if (expressions[0] != lexemsDict["if"])
            {
                throw new System.Exception("'if' should be the first identifier.");
            }

            int thenIndex = -1;
            for (int i = 1; i < expressions.Count; i++)
            {
                if (expressions[i] == lexemsDict["then"])
                {
                    thenIndex = i;
                    break;
                }
            }

            if (thenIndex == -1)
            {
                throw new System.Exception("'then' identifier not found.");
            }

            int conditionLen = thenIndex - 1;
            if (conditionLen < 1)
            {
                throw new System.Exception("Condition part of the rule not found.");
            }

            int conclusionLen = expressions.Count - thenIndex - 1;
            if (conclusionLen < 1)
            {
                throw new System.Exception("Conclusion part of the rule not found.");
            }

            List<IExpression> conditionExpressions = expressions.GetRange(1, conditionLen);
            List<IExpression> conclusionExpressions = expressions.GetRange(thenIndex + 1, conclusionLen);

            Conditions conditions = ParseConditions(conditionExpressions, input, lexemsDict);
            SingleCondition conclusion = ParseConclusion(conclusionExpressions, output, lexemsDict);

            FuzzyRule resultRule = new FuzzyRule(input, output);
            resultRule.Condition = conditions;
            resultRule.Conclusion = conclusion;
            return resultRule;
        }
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人h动漫精品一区二区| 欧美色成人综合| 国产自产2019最新不卡| 国产精品系列在线播放| 国产成人久久精品77777最新版本| 久久精品国产精品亚洲红杏| 国产成人精品在线看| 色呦呦网站一区| 精品国产伦一区二区三区观看体验| 精品毛片乱码1区2区3区| 中文字幕一区二区视频| 午夜av电影一区| 欧美一级日韩免费不卡| 欧美成人女星排名| 欧美日韩专区在线| 欧美日韩中字一区| 91国偷自产一区二区三区观看| 激情文学综合丁香| 亚洲免费电影在线| 日韩电影在线一区二区三区| 日一区二区三区| 国产精华液一区二区三区| 91网页版在线| 91精品国产色综合久久不卡蜜臀| 欧美日韩精品欧美日韩精品 | 日韩av电影天堂| 成人av资源在线观看| 8v天堂国产在线一区二区| 17c精品麻豆一区二区免费| 国产一区二区三区在线看麻豆| 在线免费观看日韩欧美| 亚洲天堂免费看| 国产精品小仙女| 精品国产髙清在线看国产毛片| 亚洲国产精品久久人人爱蜜臀| 成人久久视频在线观看| 久久精品视频一区二区三区| 日本欧美肥老太交大片| 欧美日韩免费电影| 亚洲国产视频一区| 欧美美女激情18p| 亚洲永久免费视频| 欧美在线免费播放| 一区二区三区美女| 欧美日韩中文字幕一区| 1000精品久久久久久久久| 成人在线视频首页| 国产精品久久久久久久午夜片| 国产真实乱子伦精品视频| 欧美不卡一区二区三区| 美女久久久精品| 久久久精品免费观看| 色网站国产精品| 日本亚洲欧美天堂免费| 久久久无码精品亚洲日韩按摩| 99综合电影在线视频| 美女视频黄 久久| 亚洲色图视频网站| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 99vv1com这只有精品| 美女诱惑一区二区| 一区二区三区欧美久久| 久久这里只精品最新地址| 欧美性生活久久| 顶级嫩模精品视频在线看| 亚洲综合一区在线| 中文子幕无线码一区tr| 3atv在线一区二区三区| 97精品久久久久中文字幕| 精品一区免费av| 五月天中文字幕一区二区| 亚洲精品国产第一综合99久久| 久久亚洲综合av| 91精品国产综合久久久蜜臀粉嫩| 成人aaaa免费全部观看| 国v精品久久久网| 国产在线精品一区二区夜色| 日韩激情视频网站| 亚洲美女在线国产| 亚洲精品国产无天堂网2021| 国产拍揄自揄精品视频麻豆| 久久精品一区八戒影视| 国产精品美女久久久久aⅴ| 国产精品蜜臀在线观看| 亚洲欧美一区二区不卡| 婷婷久久综合九色国产成人| 久色婷婷小香蕉久久| 成人午夜在线免费| 欧美在线视频全部完| 日韩欧美一级特黄在线播放| 国产欧美精品一区二区三区四区 | 久久超碰97中文字幕| 91性感美女视频| 日韩视频在线永久播放| 国产精品久久久久影院| 日本成人在线网站| 99视频精品在线| 日韩一区二区三区在线观看| 国产精品欧美综合在线| 蜜桃精品视频在线观看| 成人黄色在线网站| 欧美日韩一区小说| 综合中文字幕亚洲| 激情文学综合网| 色婷婷久久久综合中文字幕 | 久久综合久久久久88| 狠狠色狠狠色合久久伊人| 69久久夜色精品国产69蝌蚪网| 国产精品国产三级国产专播品爱网 | 99re成人精品视频| 日韩欧美卡一卡二| 青青青伊人色综合久久| 欧美日韩久久一区| 天天综合日日夜夜精品| 欧美巨大另类极品videosbest| 亚洲天堂精品在线观看| 在线观看亚洲专区| 午夜成人免费电影| 2023国产一二三区日本精品2022| 久久99精品久久久久久久久久久久| 欧美肥妇毛茸茸| 久久99久久99小草精品免视看| 久久精品欧美日韩| 欧美亚日韩国产aⅴ精品中极品| 一区二区三区四区国产精品| 国产丶欧美丶日本不卡视频| 欧美激情一区二区在线| 成人在线综合网站| 亚洲欧洲成人精品av97| 欧美日韩三级在线| 免费看欧美美女黄的网站| 久久久亚洲国产美女国产盗摄| 一本到三区不卡视频| 日韩成人免费在线| 久久这里只有精品视频网| 欧洲亚洲国产日韩| 国产乱人伦偷精品视频不卡| 中文字幕中文字幕一区二区 | 国产一区美女在线| 美日韩一区二区| 亚洲成人av福利| 亚洲成a人v欧美综合天堂下载| 国产精品久久看| 欧美mv和日韩mv的网站| 欧美丰满美乳xxx高潮www| a4yy欧美一区二区三区| 成人丝袜视频网| 成人午夜电影网站| 不卡一二三区首页| 成人99免费视频| 99免费精品视频| 欧美日韩aaaaa| 在线免费不卡电影| thepron国产精品| 国产91在线观看丝袜| 国产一区二区在线观看视频| 久久国产精品99久久久久久老狼 | 精品在线观看免费| 日韩国产在线一| 日韩国产高清在线| 国产成人欧美日韩在线电影 | 日韩欧美一级二级| 国产欧美一区二区精品性色超碰| 国产精品三级av| 亚洲成人资源网| 粉嫩绯色av一区二区在线观看| 97久久精品人人澡人人爽| 91 com成人网| 国产精品午夜免费| 亚洲国产中文字幕在线视频综合| 午夜精品久久久久久久99水蜜桃 | 福利电影一区二区| 欧美视频一区二| 国产午夜亚洲精品羞羞网站| 三级成人在线视频| 国产盗摄一区二区三区| 欧美一区二区国产| 亚洲视频 欧洲视频| 另类中文字幕网| 欧美优质美女网站| 欧美一区二区视频在线观看2020| 国产精品污www在线观看| 美女一区二区三区| 欧美日韩精品一区二区在线播放| 久久女同精品一区二区| 亚洲福利一二三区| 在线看不卡av| 午夜精品福利一区二区三区蜜桃| 91原创在线视频| 亚洲猫色日本管| 日本高清无吗v一区| 国产精品久久久久一区| 高清免费成人av| 国产人伦精品一区二区| 国内精品久久久久影院一蜜桃| 日韩欧美123| 亚洲精品国产精品乱码不99 | 欧美另类z0zxhd电影| 天天av天天翘天天综合网 | 8v天堂国产在线一区二区|