Example #1
0
 private void Initialize()
 {
     this.head  = null;
     this.next  = null;
     this.root  = null;
     this.state = 0;
 }
        // HTS_Question_load: Load questions from file
        public bool Load(HTS_File fp)
        {
            if (fp == null)
            {
                return(false);
            }

            string tToken;

            HTS_Pattern pattern, last_pattern;

            Initialize();

            // get question name
            m_Word = fp.GetPatternToken();

            if (string.IsNullOrEmpty(m_Word) == true)
            {
                return(false);
            }

            // get pattern list
            tToken = fp.GetPatternToken();
            if (string.IsNullOrEmpty(tToken) == true)
            {
                Initialize();
                return(false);
            }

            last_pattern = null;
            if (tToken == "{")
            {
                while (true)
                {
                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        Initialize();
                        return(false);
                    }

                    pattern = new HTS_Pattern();
                    if (m_Head != null)
                    {
                        last_pattern.next = pattern;
                    }
                    else
                    {
                        // first time
                        m_Head = pattern;
                    }

                    pattern.word = tToken;
                    pattern.next = null;

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        Initialize();
                        return(false);
                    }

                    if (tToken == "}")
                    {
                        break;
                    }

                    last_pattern = pattern;
                }
            }

            return(true);
        }
 private void Initialize()
 {
     m_Word = null;
     m_Head = null;
     next   = null;
 }
Example #4
0
        // HTS_Tree_parse_pattern: parse pattern specified for each tree
        public void ParsePattern(string tString)
        {
            // {xxx,yyy,zzz} または {(xxx,yyy,zzz)} というパターンから値を切り出す
            HTS_Pattern pattern, last_pattern;

            this.head    = null;
            last_pattern = null;

            int i, l = tString.Length;
            int p, q;

            for (i = 0; i < l; i++)
            {
                if (tString[i] == '{')
                {
                    break;
                }
            }

            if (i >= l)
            {
                return;
            }

            i++;

            if (i >= l)
            {
                return;
            }

            if (tString[i] == '(')
            {
                i++;
            }

            if (i >= l)
            {
                return;
            }

            p = i;

            for (i = p; i < l; i++)
            {
                if (tString[i] == '}')
                {
                    break;
                }
            }

            if (i >= l)
            {
                return;
            }

            i--;

            if (tString[i] == ')')
            {
                i--;
            }

            q = i;

            //----------------------------------

            l = q - p + 1;

            string s = tString.Substring(p, l);

            s = s + ",";

            l++;

            p = 0;


            // parse pattern
            while (p < l)
            {
                pattern = new HTS_Pattern();
                if (this.head != null)
                {
                    last_pattern.next = pattern;
                }
                else
                {
                    this.head = pattern;
                }

                for (i = p; i < l; i++)
                {
                    if (s[i] == ',')
                    {
                        break;
                    }
                }

                pattern.word = s.Substring(p, i - p);
                p            = i + 1;

                pattern.next = null;
                last_pattern = pattern;
            }
        }