2019年2月19日 星期二

Unity 射線扇形

以下程式碼先以DrawLin方式呈現射線大概位置
再處理射線部分。

若是成功會呈現出以下圖片:




-----------------------------------
static public void LookAround(Transform targets)
{
    float viewRadius = 10f; // 視野距離
    float viewAngleStep = 20; // 射線數量
    // 射線從左邊開始,角度為-45;
    Vector3 forwardLeft = Quaternion.Euler(0, -45, 0) * targets.forward * viewRadius;
        
    for(int i =0; i <= viewAngleStep; i++){
            
     // 射線由forwardLeft基礎點偏轉
 Vector3 vector = Quaternion.Euler(0, (90 / viewAngleStep)* i, 0) * forwardLeft;
        // targets位置 + vector = 射線最終位置     
        Vector3 pos = targets.position + vector;
 Debug.DrawLine(targets.position, pos, Color.red);
    }
}
------------------------------------------
以下是透過射線,以DrawLin方式呈現
如果成功會呈現以下圖:










------------------------------------------
static public void LookAround(Transform targets)
{
    float viewRadius = 10f; // 視野距離
    float viewAngleStep = 20; // 射線數量
    // 射線從左邊開始,角度為-45;
    Vector3 forwardLeft = Quaternion.Euler(0, -45, 0) * targets.forward * viewRadius;
        
    for(int i =0; i <= viewAngleStep; i++){
            
     // 射線由forwardLeft基礎點偏轉
 Vector3 vector = Quaternion.Euler(0, (90 / viewAngleStep)* i, 0) * forwardLeft;

   // 建立射線
        Ray ray = new Ray(targets.position, vector);
        RaycastHit hits = new RaycastHit();

 // Layer 碰撞偵測
        int mask = LayerMask.GetMask("Point");
        Physics.Raycast(ray, out hits, mask);

        // targets位置 + vector = 射線最終位置     
        Vector3 pos = targets.position + vector;
 Debug.DrawLine(targets.position, pos, Color.red);

 // 射線碰撞到,就當碰撞點
 if(hits.transform != null)
     pos = hits.point;

 Debug.DrawLine(targets.position, pos, Color.red);

 // 碰到敵人在處理
 if(hits.transform != null && hits.transform.gameObject.layer.Equals(LayerMask.NameToLayer("Point")))
 {
     // 射線長度
     Vector3 dis  = targets.position - hits.collider.transform.position;
     float value = dis.sqrMagnitude;
     Debug.Log(hits.collider.gameObject + "距離: " + value);
  }
 }
}

2019年2月12日 星期二

長詞優先法_決策決定

斷詞系統長詞優先法分為: 正向及反向,會產生岐異與未知詞上的問題,若是詞庫夠大就能解決了。
已解決了正反向優先詞重覆字問題 2018/4/09 15:00
已添加詞位標籤 2018/4/09 15:00
已修正正反向長詞優先順序錯誤 2018/10/15 11:45
優化程式碼撰寫 2019/01/01 16:45
已添加決策 2019/02/12 21:50

---顯示介面 (c#)---

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Layout : LongWordsFirst2 {

    public Text systemMessage, inputMessage, result, runStatus;
    public InputField userField;
    public Button buttonEnter;
    public Button buttonRefill;
    public Button exit;
    public Image inputMessageBackground;
    public Button Sort;

    // 顯示文字結果
    public Text resultText;
    public Scrollbar scrollbarResult;

    private int timeSort = 0;

    /// 
    /// 確定
    /// 
    void btnOnClick_Enter()
    {
        cuttingReady();
    }

    /// 
    /// 重填
    /// 
    void btnOnClick_Refill()
    {
        /*inputFieldType(userField, 0.6f, 1, 1, 1).text = "";
        messageType = "";*/
        Application.LoadLevel("NLTK_NEW");
    }

    /// 
    /// 顯示結果
    /// 
    void btnOnClick_Sort()
    {
        try
        {
            StartCoroutine(logWordResultSystematics());
            resultTextType(resultText).text = resultMessageType; // display result Message
        }
        catch { }
    }

    /// 
    /// 離開應用程式
    /// 
    void btnOnClick_Exit()
    {
        Application.Quit();
        MySQL.MySQL.closeSqlConnection();
    }

    /// 
    /// button Component
    /// btn: button Obj
    /// width / height: button Obj posistion
    /// sizeX / sizeY: button Obj size
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    Button buttonType(Button btn, float width, float height, float sizeX, float sizeY)
    {
        try
        {
            btn.transform.position = new Vector2(Screen.width / 2 * width, Screen.height / 2 * height);
            // posistion
            btn.transform.position = new Vector2(Screen.width / 2 * width, Screen.height / 2 * height);
            // imageSize
            btn.image.rectTransform.sizeDelta = new Vector2(Screen.width / 2 * sizeX, sizeY);

            switch (btn.name)
            {
                case "Enter":
                    btn.onClick.AddListener(() => btnOnClick_Enter());
                    break;
                case "Refill":
                    btn.onClick.AddListener(() => btnOnClick_Refill());
                    break;
                case "Exit":
                    btn.onClick.AddListener(() => btnOnClick_Exit());
                    break;
                case "Sort":
                btn.onClick.AddListener(() => btnOnClick_Sort());                  
                    break;

            }
        }
        catch { }

        return btn;
    }

    /// 
    /// inputField Component
    /// InputField: inputField Obj
    /// message: sentence message
    /// width / height: inputField Obj posistion
    /// sizeX / sizeY: inputField size
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    InputField inputFieldType(InputField inputField,float width, float height, float sizeX, float sizeY)
    {
        inputField.transform.position = new Vector2(Screen.width / 2 * width, Screen.height / 2 * height);
        inputField.image.rectTransform.sizeDelta = new Vector2(Screen.width / 2 * sizeX, Screen.height / 2 * sizeY);

        return inputField;
    }

    /// 
    /// scrollbarType
    /// Scrollbar: scrollbar obj
    /// width / height: scrollbar obj posistion
    /// sizeX / sizeY: scrollbar obj size
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    Scrollbar scrollbarType(Scrollbar scrollbar, float width, float height)
    {
        try
        {
            scrollbar.transform.position = new Vector2(Screen.width / 2 * width, Screen.height / 2 * height);
        }
        catch { }

        return scrollbar;
    }

    // Text 屬性
    Text textType(Text text, string message, int fontsize, Color color, float width, float height)
    {
        try
        {
            Color col = new Color(color.r, color.g, color.b);

            // posistion 
            text.rectTransform.position = new Vector2(Screen.width / 2 * width, Screen.height / 2 * height);

            text.text = message;
            text.fontSize = fontsize;
            text.color = col;
        }
        catch { }
        return text;
    }

    /// 
    /// ImageType
    /// Image: image obj
    /// width / height: image obj posistion
    /// sizeX / sizeY: image obj size
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    /// 
    Image ImageType(Image image, float width, float height, float sizeX, float sizeY)
    {
        try
        {
            // posistion
            image.rectTransform.position = new Vector2(Screen.width / 2 * width, Screen.height / 2 * height);

            // imageSize
            image.rectTransform.sizeDelta = new Vector2(Screen.width / 2 * sizeX, Screen.height / 2 * sizeY);
        }
        catch { }

        return image;
    }

    /// 
    /// resultTextType
    /// 
    /// 
    /// 
    Text resultTextType(Text text)
    {
        try
        {
            text.horizontalOverflow = HorizontalWrapMode.Wrap;
            text.verticalOverflow = VerticalWrapMode.Overflow;
        }
        catch { }

        return text;
    }

    void Start()
    {
        OpenDataBase(); // openDatabase

        textType(systemMessage, "歡迎使用系統", 25, Color.red, 0.3f, 1.8f); // title
        textType(inputMessage,"請輸入句子", 25, Color.red, 0.3f, 1.6f); // title

        buttonType(buttonEnter, 0.2f, 0.3f, 0.2f, 30); // enter button
        buttonType(buttonRefill, 0.6f, 0.3f, 0.2f, 30); // return input Message button
        buttonType(exit, 1f, 0.3f, 0.2f, 30); // exit button
        buttonType(Sort, 0.4f, 0.3f, 0.2f, 30); // sort button

        textType(result, "結果", 25, Color.red, 1.4f, 1.8f); // result
    }

    void Update()
    {
        messageType = inputFieldType(userField, 0.6f, 1, 1, 1).text; // user input Message
        ImageType(inputMessageBackground, 1.55f, 1.1f, 0.8f, 1.2f); // result background
        scrollbarType(scrollbarResult, 1.93f, 1.1f);
    }
}

---語料庫類別(c#)---

using System.Collections.Generic;
using System.Data;
using System;
using MySql.Data.MySqlClient;
using System.Text;


namespace MySQL
{
    public class MySQL
    {
        public static MySqlConnection mySqlConnection;

        // DataBase Ip;
        private static string HOST = "***.***.***.***";
        public static string HOST_TYPE
        {
            set { HOST = value; }
            get { return HOST; }
        }

        // DataBase user Id
        private static string ID = "********";
        public static string ID_TYPE
        {
            set { ID = value; }
            get { return ID; }
        }

        // DataBase password
        private static string PASSWORD = "******";
        public static string PASSWORD_TYPE
        {
            set { PASSWORD = value; }
            get { return PASSWORD; }
        }

        // DataBase Name
        private static string DATABASE = "*****";
        public static string DATABASE_TYPE
        {
            set { DATABASE = value; }
            get { return DATABASE; }
        }

        private static string PORT = "****";
        public static string PORT_TYPE
        {
            set { PORT = value; }
            get { return PORT; }
        }

        // 連線結果
        public static string RESULT = "";

        //  Connect to SQL
        public static void OpenSqlConnection(string connction)
        {
            try
            {
                mySqlConnection = new MySqlConnection(connction);
                mySqlConnection.Open();
                RESULT = mySqlConnection.ServerVersion;
            }
            catch
            {
                RESULT = "無法連接資料庫";
            }
        }

        // Close Sql
        public static void closeSqlConnection()
        {
            mySqlConnection.Close();
            mySqlConnection.Dispose();
            mySqlConnection = null;
        }

        // SQL Query
        public static void DOQUERY(string sqlQuery)
        {
            IDbCommand dbcommand = mySqlConnection.CreateCommand();
            dbcommand.CommandText = sqlQuery;
            IDataReader reader = dbcommand.ExecuteReader();
            reader.Close();
            reader = null;
            dbcommand.Dispose();
            dbcommand = null;
        }

        // Get DataSet
        public static DataSet GetDataSet(string sqlString)
        {
            DataSet ds = new DataSet();

            try
            {
                MySqlDataAdapter da = new MySqlDataAdapter(sqlString, mySqlConnection);
            }
            catch (Exception e)
            {
                throw new Exception("SQL:" + sqlString + "\n");
            }
            return ds;
        }

        /// 
        /// string to uft8
        /// message: sentence
        /// 
        /// 
        /// 
        public static string STRING_UTF8(string message)
        {
            UTF8Encoding encoder = new UTF8Encoding();
            byte[] bytes = Encoding.UTF8.GetBytes(message);
            string utf8ReturenString = encoder.GetString(bytes);

            return utf8ReturenString;
        }

        /// 
        /// INQUIRE_DATABASE
        ///  * dataBaseTitle : DataBaseName 
        ///  * dataBaseTitle : DataBaseName 
        ///  * numberingType : 0(Message)、1(Words)、2(Mark)、3(Words2)、4(Mark2)、5(Lexical) 
        ///  * message: message 
        /// 
        /// 
        /// 
        /// 
        /// 
        public static string INQUIRE_DATABASE(string dataBaseTitle, int numberingType, string message)
        {
            string sqlText = "select * from " + dataBaseTitle + " where Message='" + message + "'";

            string str = "";
        
            MySqlCommand cmd = new MySqlCommand(sqlText, mySqlConnection);
            MySqlDataReader data = cmd.ExecuteReader();

            while (data.Read())
            {
                try
                {
                    str = data[numberingType].ToString();
                }
                finally { }
            }
            data.Close();

            return str;
        }

        /// 
        /// 詞性標記顯示
        /// words: dataBase table[1]
        /// 
        /// 
        /// 
        public static string wordsMark(string words)
        {
            string str = "";

            switch (words.ToString())
            {
                case "A":
                    str = "非謂形容詞";
                    break;
                case "Caa":
                    str = "對等連接詞";
                    break;
                case "Cab":
                    str = "連接詞";
                    break;
                case "Cba":
                    str = "連接詞";
                    break;
                case "Cbb":
                    str = "關聯連接詞";
                    break;
                case "Da":
                    str = "數量副詞";
                    break;
                case "Dfa":
                    str = "動詞前副詞";
                    break;
                case "Dfb":
                    str = "動詞後副詞";
                    break;
                case "Di":
                    str = "時態標記";
                    break;
                case "Dk":
                    str = "句副詞";
                    break;
                case "D":
                    str = "副詞";
                    break;
                case "Na":
                    str = "普通名詞";
                    break;
                case "Nb":
                    str = "專有名詞";
                    break;
                case "Nc":
                    str = "地方詞";
                    break;
                case "Ncd":
                    str = "位置詞";
                    break;
                case "Nd":
                    str = "時間詞";
                    break;
                case "Neu":
                    str = "數量定詞";
                    break;
                case "Nes":
                    str = "特指定詞";
                    break;
                case "Nep":
                    str = "指代定詞";
                    break;
                case "Neqa":
                    str = "數量定詞";
                    break;
                case "Neqb":
                    str = "數量定詞(後置)";
                    break;
                case "Nf":
                    str = "量詞";
                    break;
                case "Ng":
                    str = "後置詞";
                    break;
                case "Nh":
                    str = "代名詞";
                    break;
                case "Nv":
                    str = "名物化動詞";
                    break;
                case "I":
                    str = "感嘆詞";
                    break;
                case "P":
                    str = "介詞";
                    break;
                case "T":
                    str = "語助詞";
                    break;
                case "VA":
                    str = "動作不及物動詞";
                    break;
                case "VAC":
                    str = "動作使動動詞";
                    break;
                case "VB":
                    str = "動作類及物動詞";
                    break;
                case "VC":
                    str = "動作及物動詞";
                    break;
                case "VCL":
                    str = "動作接地方賓語動詞";
                    break;
                case "VD":
                    str = "雙賓動詞";
                    break;
                case "VE":
                    str = "動作句賓動詞";
                    break;
                case "VF":
                    str = "動作謂賓動詞";
                    break;
                case "VG":
                    str = "分類動詞";
                    break;
                case "VH":
                    str = "狀態不及物動詞";
                    break;
                case "VHC":
                    str = "狀態使動動詞";
                    break;
                case "VI":
                    str = "狀態類及物動詞";
                    break;
                case "VJ":
                    str = "狀態及物動詞";
                    break;
                case "VK":
                    str = "狀態句賓動詞";
                    break;
                case "VL":
                    str = "狀態謂賓動詞";
                    break;
                case "V_2":
                    str = "不及物連接動詞";
                    break;
                case "DE":
                    str = "狀態感嘆詞";
                    break;
                case "SHI":
                    str = "不及物狀態動詞";
                    break;
                case "FW":
                    str = "外文";
                    break;
                case "COMMACATEGORY":
                    str = "逗號";
                    break;
                case "DASHCATEGORY":
                    str = "破折號";
                    break;
                case "ETCCATEGORY":
                    str = "刪節號";
                    break;
                case "EXCLAMATIONCATEGORY":
                    str = "感嘆號";
                    break;
                case "PARENTHESISCATEGORY":
                    str = "括號";
                    break;
                case "PAUSECATEGORY":
                    str = "頓號";
                    break;
                case "PERIODCATEGORY":
                    str = "句號";
                    break;
                case "QUESTIONCATEGORY":
                    str = "問號";
                    break;
                case "SEMICOLONCATEGORY":
                    str = "分號";
                    break;
                case "SPCHANGECATEGORY":
                    str = "雙直號";
                    break;
            }
            return str;
        }
    }
}

---斷詞工具 (c#)---
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace SegmentationSymbolTool
{
    public class SegmentationSymbol2
    {
        // 斷詞標記括號
        private string[] specialSymbol = new string[] { "(", ")" };
        // 斷字狀態
        private string statusBroken;

        // 刪除特殊符號
        public string delectSymbol(string userMessage)
        {
            string strs = userMessage;

            for (int x = 0; x < specialSymbol.Length; x++)
                strs = strs.Replace(specialSymbol[x], " ");

            return strs;
        }

        /// 
        /// 斷字字數
        ///  status: sentence Lenght 
        /// 
        /// 
        private void status_conter(int status)
        {
            statusBroken = "";

            for (int x = 0; x <= status; x++)
                statusBroken += @"\S";
        }

        /// 
        /// 刪除訊息
        /// message: sentence
        /// status: Hyphenation state
        /// 
        /// 
        /// 
        /// 
        public string delectWord(string message, int status)
        {
            string str = message;

            return str.Remove(status).ToString();
        }

        /// 
        /// 斷字狀態
        /// message: sentence
        /// status: Hyphenation state
        /// 
        /// 
        /// 
        /// 
        public List brokenSatus(string message, int status)
        {
            status_conter(status);

            List match = new List();
            MatchCollection splitResult = Regex.Matches(message, statusBroken, RegexOptions.IgnoreCase);

            foreach (Match test in splitResult)
                match.Add(test);

            return match;
        }

        /// 
        /// 組合處理
        /// message: sentence
        /// int: Hyphenation state
        /// 
        /// 
        /// 
        /// 
        public List delect_Word_Combination(string message, int status)
        {
            status_conter(status);

            string str = message;
            List match = new List();
            List stringList = new List();

            MatchCollection splitResult = Regex.Matches(str, statusBroken, RegexOptions.IgnoreCase);
            foreach (Match test in splitResult)
                match.Add(test.ToString());
            foreach (string strs in match)
            {
                stringList.Add(str.Replace(strs, ""));

                return stringList;
            }

            return stringList;
        }

        /// 
        /// 斷字處理
        /// message: sentence
        /// status: Hyphenation state
        /// 
        /// 
        /// 
        /// 
        public List delect_oneWord(string message, int status)
        {
            status_conter(status);

            string str = message;
            List match = new List();
            List stringList = new List();

            MatchCollection splitResult = Regex.Matches(str, statusBroken, RegexOptions.IgnoreCase);
            foreach (Match test in splitResult)
                match.Add(test.ToString());
            foreach (string strs in match)
                stringList.Add(str.Replace(strs, ""));

            return stringList;
        }

        /// 
        /// grammarCombinationModule
        /// speech1: mark
        /// speech2: mark
        /// 
        /// 
        /// 
        /// 
        public string grammarCombinationModule(string speech1, string speech2)
        {
            string grmmar = "";

            if (speech1.Equals("A") && speech2.Equals("T") || speech1.Equals("A") && speech2.Equals("N") || speech1.Equals("A") && speech2.Equals("Nv") || speech1.Equals("A") && speech2.Equals("P")) grmmar = "A";
            else if (speech1.Equals("C") && speech2.Equals("A") || speech1.Equals("C") && speech2.Equals("N") || speech1.Equals("C") && speech2.Equals("DET") || speech1.Equals("C") && speech2.Equals("Nv") || speech1.Equals("C") && speech2.Equals("Vi") || speech1.Equals("C") && speech2.Equals("Vt")) grmmar = "C";
            else if (speech1.Equals("ADV") && speech2.Equals("A") || speech1.Equals("ADV") && speech2.Equals("ADV") || speech1.Equals("ADV") && speech2.Equals("Nv") || speech1.Equals("ADV") && speech2.Equals("Vi") || speech1.Equals("ADV") && speech2.Equals("Vt")) grmmar = "ADV";
            else if (speech1.Equals("ASP") && speech2.Equals("Nv") || speech1.Equals("ASP") && speech2.Equals("Vi") || speech1.Equals("ASP") && speech2.Equals("Vt")) grmmar = "ASP";
            else if (speech1.Equals("N") && speech2.Equals("Vi") || speech1.Equals("N") && speech2.Equals("Vt") || speech1.Equals("N") && speech2.Equals("T") || speech1.Equals("N") && speech2.Equals("C") || speech1.Equals("N") && speech2.Equals("POST") || speech1.Equals("N") && speech2.Equals("A") || speech1.Equals("N") && speech2.Equals("N") || speech1.Equals("N") && speech2.Equals("M") || speech1.Equals("N") && speech2.Equals("Nv")) grmmar = "N";
            else if (speech1.Equals("DET") && speech2.Equals("N") || speech1.Equals("DET") && speech2.Equals("Nv") || speech1.Equals("DET") && speech2.Equals("Vi") || speech1.Equals("DET") && speech2.Equals("Vt")) grmmar = "DET";
            else if (speech1.Equals("M") && speech2.Equals("T") || speech1.Equals("M") && speech2.Equals("N") || speech1.Equals("M") && speech2.Equals("Nv")) grmmar = "M";
            else if(speech1.Equals("P") && speech2.Equals("N") || speech1.Equals("P") && speech2.Equals("Nv") && speech1.Equals("P") && speech2.Equals("Vi") && speech1.Equals("P") && speech2.Equals("Vt")) grmmar = "P";
            else if(speech1.Equals("Vi") && speech2.Equals("Vt") || speech1.Equals("Vi") && speech2.Equals("N") && speech1.Equals("Vi") && speech2.Equals("ADV")) grmmar = "Vi";
            else if(speech1.Equals("Vt") && speech2.Equals("N") || speech1.Equals("Vt") && speech2.Equals("Vi") || speech1.Equals("Vt") && speech2.Equals("Adv") || speech1.Equals("Vt") && speech2.Equals("Vt")) grmmar = "Vt";
            else if(speech1.Equals("POST") && speech2.Equals("N") || speech1.Equals("POST") && speech2.Equals("A") || speech1.Equals("POST") && speech2.Equals("POST") || speech1.Equals("POST") && speech2.Equals("DET") || speech1.Equals("POST") && speech2.Equals("Nv") || speech1.Equals("POST") && speech2.Equals("Vi") || speech1.Equals("POST") && speech2.Equals("Vt")) grmmar = "POST";
            else if(speech1.Equals("A") && speech2.Equals("A")) grmmar = "A";
            else if(speech1.Equals("C") && speech2.Equals("C")) grmmar = "C";
            else if(speech1.Equals("ADV") && speech2.Equals("ADV")) grmmar = "ADV";
            else if(speech1.Equals("ASP") && speech2.Equals("ASP")) grmmar = "ASP";
            else if(speech1.Equals("N") && speech2.Equals("N")) grmmar = "N";
            else if(speech1.Equals("DET") && speech2.Equals("DET")) grmmar = "DET";
            else if(speech1.Equals("M") && speech2.Equals("M")) grmmar = "M";
            else if(speech1.Equals("P") && speech2.Equals("P")) grmmar = "P";
            else if(speech1.Equals("Vi") && speech2.Equals("Vi")) grmmar = "Vi";
            else if(speech1.Equals("Vt") && speech2.Equals("Vt")) grmmar = "Vt";
            else if(speech1.Equals("Vt") && speech2.Equals("Vt")) grmmar = "Vt";
            
            return grmmar;
        }
    }
}


---斷詞與其他功能類別 (c#)---
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text.RegularExpressions;
using System;

public class LongWordsFirst2 : MonoBehaviour
{
    // 斷詞工具
    private SegmentationSymbolTool.SegmentationSymbol2 segmentationSybolTool = new SegmentationSymbolTool.SegmentationSymbol2();

    // 斷字系統資料表
    private static string dataBasetitle = "glossary";

    // 顯示結果
    private string resultMessage;
    public string resultMessageType
    {
        get { return resultMessage; }
    }

    // 使用者輸入句子
    private string message = "";
    public  string messageType
    {
        set { message = value; }
        get { return message; }
    }

    // 正向長詞優先
    public string logeWordForward;

    // 反向長詞優先
    public string logeWordReverse;
    public string logeWordReverseType
    {
        get { return logeWordReverse; }
    }

    // 正向長詞優先長度, 反向長詞優先長度, 組合長度
    private int logeWordForwadLenght, logeWordReverseLenght;

    // 正向長詞優先結果
    private List logeWordForwardFunctionList = new List();
    public List logeWordForwardFunctionListType
    {
        get { return logeWordForwardFunctionList; }
    }

    // 反向長詞優先結果
    private List logeWordReverseFunctuinList = new List();

    // 正向長詞優先標記結果
    private List logeWordForwardLexicalFunctionList = new List();
    public List logeWordForwardLexicalFunctionListType
    {
        get { return logeWordForwardLexicalFunctionList; }
    }

    // 反向長詞優先結果
    public List logeWordReverseLexicalFunctionList = new List();
    public List logeWordReverseLexicalFunctionListType
    {
        get { return logeWordReverseLexicalFunctionList; }
    }

    // 反向長詞方向校正結果
    public List logeWordReverseCorrectionList = new List();
    public List logeWordReverseCorrectionListType
    {
        get { return logeWordReverseCorrectionList; }
    }

    // 正向長詞優先詞性變化
    private List logeWordForwardMark1List = new List();
    public List logeWordForwardMark1Type
    {
        get { return logeWordForwardMark1List; }
    }

    // 反向長詞優先詞性變化
    private List logeWordReverseMark1List = new List();
    public List logeWordReverseMark1Tpye
    {
        get { return logeWordReverseMark1List; }
    }

    // 決策結果
    public List decision_Realut =  new List();
    public List decision_RealutType
    {
        get{return decision_Realut;}
    }
    
    // 正向長詞變化組合合法
    private List legitimateLogeWord= new List();

    // 反向長詞變化組合合法
    private List legitimateLogeReverse = new List();

    // 詞性組合合法 List
    private List mark_Legitimate1= new List();
    
    private List mark_Legitimate2 = new List();

    public bool decisionSw1 = true, decisionSw2 = true, decisionSw1_1 = true; // 變化1決策
    public bool decisionSw3 = true, decisionSw4 = true, decisionSw3_3 = true; // 變化2決策
    

    // 打開資料庫
    public void OpenDataBase()
    {
        string connectionString = string.Format("Server = {0}; Database = {1}; UserID = {2}; Password = {3}; Port = {4};", MySQL.MySQL.HOST_TYPE, MySQL.MySQL.DATABASE_TYPE, MySQL.MySQL.ID_TYPE, MySQL.MySQL.PASSWORD_TYPE, MySQL.MySQL.PORT_TYPE);
        MySQL.MySQL.OpenSqlConnection(connectionString);
    }

    /// 
    /// 關閉資料庫
    /// 
    public void closeDataBase()
    {
        MySQL.MySQL.closeSqlConnection();
    }

    /// 
    /// 切字準備
    /// 優先執行
    /// 
    public void cuttingReady()
    {
        logeWordForward = message;
        logeWordReverse = message;

        logeWordForwadLenght = logeWordForward.Length;
        logeWordReverseLenght = logeWordReverse.Length;

        // 清除List
        logeWordForwardFunctionList.Clear();
        logeWordReverseFunctuinList.Clear();
        logeWordForwardLexicalFunctionList.Clear();
        logeWordReverseLexicalFunctionList.Clear();
        logeWordReverseCorrectionList.Clear();
        logeWordForwardMark1List.Clear();
        logeWordReverseMark1List.Clear();
        mark_Legitimate1.Clear();
        legitimateLogeWord.Clear();
        legitimateLogeReverse.Clear();
        mark_Legitimate2.Clear();
        decision_Realut.Clear();
      
        // 執行正向長詞優先
        StartCoroutine(loneWordForwardFunction());

        // 執行反向長詞優先
        StartCoroutine(longWordReverseFunction(0));

        // 正向長詞優先詞位標記
        StartCoroutine(logeWordForwardLexicalFunction(logeWordForwardFunctionList, logeWordForwardLexicalFunctionList));

        // 反向長詞優先方校校正
        StartCoroutine(logeWordReverseCorrectionFunction());

        // 反向長詞優先詞位標記
        StartCoroutine(logeWordForwardLexicalFunction(logeWordReverseCorrectionList, logeWordReverseLexicalFunctionList));

        // 正向長詞優先詞性變化1
        StartCoroutine(logeMakesFunction());

        // 詞性組合決策
        StartCoroutine(grmmarDecisionMaking());

        // 句子組合
        StartCoroutine(sentenceCombination());
    }

    /// 
    /// 檢查沒有數據
    /// Message: contence
    /// Database No Data
    /// 
    /// 
    /// 
    /// 
    private string inspection(string message, List list)
    {
        string str = message;

        foreach (string str1 in list)
        {
            str = str.Replace(str1, "");
        }

        return str;
    }

    /// 
    /// 反向長詞優先校正
    /// 
    IEnumerator logeWordReverseCorrectionFunction()
    {
        string str = "";
        while (true)
        {
            if (logeWordReverse.Equals(""))
            {
                for (int x = logeWordReverseFunctuinList.Count-1; x >= 0; x--)
                    logeWordReverseCorrectionList.Add(logeWordReverseFunctuinList[x]); 
                break;
            }

            yield return new WaitForSeconds(0.5f);
        }
    }

    /// 
    /// 詞位標籤
    /// longWord: positive longWord / reverse longWord
    /// LexicalResult: positive longWord Result / reverse longWord Result
    /// 
    /// 
    /// 
    /// 
    IEnumerator logeWordForwardLexicalFunction(List longWord, List LexicalResult)
    {
        int number = 0;

        while (true)
        {
            if (logeWordForward.Equals(""))
            {
                foreach (string str in longWord)
                {
                    LexicalResult.Add(MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 5, str));
                    number += 1;
                }

                // 限制迴圈執行
                if (number <= longWord.Count)
                    break;
            }

            yield return new WaitForSeconds(0.5f);
        }
    }

    /// 
    /// 正向長詞優先
    /// IEnumerator: unity執行序
    /// 
    /// 
    IEnumerator loneWordForwardFunction()
    {
        while (true)
        {
            foreach (Match match in segmentationSybolTool.brokenSatus(logeWordForward, logeWordForwadLenght))
            {
                if (match.ToString() == MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 0, match.ToString()))
                {
                    logeWordForwardFunctionList.Add(match.ToString());

                    logeWordForward = inspection(logeWordForward, logeWordForwardFunctionList);
                    logeWordForwadLenght = logeWordForward.Length;
                }
            }

            if (logeWordForwadLenght <= 0)
                logeWordForwadLenght = 0;
            else logeWordForwadLenght -= 1;

            yield return new WaitForSeconds(0.5f);
        }
    }

    /// 
    /// 後向長詞優先
    /// lenght: sentence lenght
    /// IEnumerator: unity 執行序
    /// 
    /// 
    /// 
    IEnumerator longWordReverseFunction(int lenght)
    {
        while (true)
        {
            foreach (Match match in segmentationSybolTool.brokenSatus(logeWordReverse, logeWordReverse.Length))
            {
                if (match.ToString() == MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 0, match.ToString()))
                {
                    logeWordReverseFunctuinList.Add(match.ToString());
                    logeWordReverse = segmentationSybolTool.delectWord(logeWordReverse, match.Length);
                }
            }

            try
            {
                foreach (string str in segmentationSybolTool.delect_Word_Combination(logeWordReverse, lenght))
                {
                    if (str == MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 0, str))
                    {
                        logeWordReverseFunctuinList.Add(str);
                        lenght = 0;
                        logeWordReverse = segmentationSybolTool.delectWord(logeWordReverse, logeWordReverse.Length - str.Length);
                    }
                }
                lenght += 1;

                if (logeWordReverse == MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 0, logeWordReverse))
                {
                    logeWordReverseFunctuinList.Add(logeWordReverse);
                    logeWordReverse = segmentationSybolTool.delectWord(logeWordReverse, logeWordReverse.Length - MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 0, logeWordReverse).Length);
                }

                if (lenght >= logeWordReverseLenght)
                    lenght = 0;

            }
            catch (Exception e) { logeWordReverseFunctuinList.Remove("");}

            yield return new WaitForSeconds(0.5f);

        }
    }

    /// 
    /// logeMakesFunction
    /// Variety1 and Variety2
    /// 
    /// 
    IEnumerator logeMakesFunction()
    {
        while (true)
        {
            if (logeWordForward.Equals(""))
            {
                // 正向長詞優先詞性變化1
                foreach (string str in logeWordForwardFunctionList)
                    logeWordForwardMark1List.Add(MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 2, str));

                // 反向長詞優先詞性變化1
                foreach(string str in logeWordReverseCorrectionList)
                    logeWordReverseMark1List.Add(MySQL.MySQL.INQUIRE_DATABASE(dataBasetitle, 2, str));

                break;
            }
            yield return new WaitForSeconds(0.5f);
        }
    }

    /// 
    /// grmmarDecisionMaking
    /// 
    /// 
    public IEnumerator grmmarDecisionMaking()
    {
        while (true)
        {
            // 正向變化
            Mark_LegitimateFunction1(logeWordForwardMark1List);
            legitimateLogeWord = mark_Legitimate1;
            legitimateLogeWord.Remove("");

            // 反向變化
            Mark_LegitimateFunction2(logeWordReverseMark1List);
            legitimateLogeReverse = mark_Legitimate2;
            legitimateLogeReverse.Remove("");

            // 決策
            for(int x=0; x < mark_Legitimate1.Count; x++){
                if(mark_Legitimate1[x].Equals("N"))
                    decisionSw1 = true;
                if(mark_Legitimate1[x].Equals("Vi") || mark_Legitimate1[x].Equals("Vt"))
                    decisionSw2 = true;

                Debug.Log(mark_Legitimate1[x]);
            }

            for(int x=0; x mark_Legitimate2.Count)
                    decision_Realut = logeWordForwardFunctionList;
                
            }else if(decisionSw3 && decisionSw3_3 && decisionSw4){
                if(mark_Legitimate1.Count < mark_Legitimate2.Count)
                    decision_Realut = logeWordReverseCorrectionList;
                       
            }else if(decisionSw1 && decisionSw1_1 && decisionSw2 
                && decisionSw3 && decisionSw3_3 && decisionSw4)
                decision_Realut.Add("兩個句子都可以");
        }
    }

    ///
    /// sentenceCombination
    ///
    /// 
    private IEnumerator sentenceCombination (){
       
        string logeForWordMessage = "";
        string logeReverseMeesage = "";
        
        while(true){

                if(logeWordForward.Equals("") && logeWordReverse.Equals("")){
                // 比對組合是否正確
                foreach(string str in logeWordForwardFunctionList)
                    logeForWordMessage += str;
    
                if(logeForWordMessage != messageType){
                    decisionSw1_1 = false;
                }else {
                    decisionSw1_1 = true;
                }

                foreach(string str in logeWordReverseCorrectionList)
                    logeReverseMeesage += str;
                    
                if(logeReverseMeesage != messageType){
                    decisionSw3_3 = false;
                }else{
                    decisionSw3_3 = true;
                }

                break;
            }
        
            yield return new WaitForSeconds(0.5f);
        }
    }

    // 詞性合法組合_正向變化2
    private List Mark_LegitimateFunction2(List MarList){

        string str = "";

         if(MarList.Count != null){
            for(int x=0; x Mark_LegitimateFunction1(List MarList){

        string str = "";

         if(MarList.Count != null){
            for(int x=0; x
    /// result Systematics
    /// 
    /// 
    public IEnumerator logWordResultSystematics()
    {
        string logeWordForwardMessage = "", logeWordReverseMessage = "";
        string decision_message  = "";

        string forwardWordSex = "", reverseWordWordSex = "";

        while (true)
        {
            if (logeWordForward.Equals(""))
            {
                foreach(string str in logeWordForwardFunctionList){
                    logeWordForwardMessage += str + " ";
                }

                foreach(string str in logeWordReverseCorrectionList)
                    logeWordReverseMessage += str + " ";
                        
                for(int x=0; x <= decision_Realut.Count -1; x++)
                    decision_message += decision_Realut[x] + "|" + " ";

                resultMessage = "正向長詞優先結果: \n" + logeWordForwardMessage + "\n\n" 
                    + "反向長詞優先結果: \n" + logeWordReverseMessage + "\n\n" + "決策選擇: \n" + decision_message;

               // break;
            }
            yield return new WaitForSeconds(0.5f);
        }
    }
}
---結果圖---