Esempio n. 1
0
        //Returns true if this node is a descendent of the specified node or this node and the specified
        //node are the same node, false otherwise.
        public Boolean isDescendent(Tire t)
        {
            Tire r = this;

            while (r != null)
            {
                if (r == t)
                {
                    return(true);
                }
                r = r.parent;
            }
            return(false);
        }
Esempio n. 2
0
        //Check if the specified string is in the trie
        //Retrun value if contains, 0 if hasPrefix, else -1
        public int contains(String s)
        {
            Tire t = getNode(s);

            if (t == null)
            {
                return(-1);
            }
            if (t.isWord)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 3
0
        //Inserts the trie at the specified index.
        // If successful, the parent of the specified trie is updated to be this trie.
        public void insertChild(Tire t, int index)
        {
            if (index < 0 || index > numChildren)
            {
                throw new ArgumentException("required: index >= 0 && index <= numChildren");
            }

            if (t == null)
            {
                throw new ArgumentException("cannot add null child");
            }

            if (t.parent != null)
            {
                throw new ArgumentException("specified child still belongs to parent");
            }
            if (hasChar(t.ch))
            {
                throw new ArgumentException("duplicate chars not allowed");
            }

            if (isDescendent(t))
            {
                throw new ArgumentException("cannot add cyclic reference");
            }

            t.parent = this;

            if (numChildren == child.Length)
            {
                Tire[] arr = new Tire[2 * (numChildren + 1)];
                for (int i = 0; i < numChildren; i++)
                {
                    arr[i] = child[i];
                }
                child = arr;
            }

            for (int i = numChildren; i > index; i--)
            {
                child[i] = child[i - 1];
            }
            child[index] = t;
            numChildren++;
        }
Esempio n. 4
0
        private ArrayList endingChar;    //Ending characters
        //Vector

        /*******************************************************************/
        /************************ Constructor ******************************/
        /*******************************************************************/
        public LongParseTree(Tire dict, ArrayList indexList, ArrayList typeList)
        {
            this.dict      = dict;
            this.indexList = indexList;
            this.typeList  = typeList;
            frontDepChar   = new ArrayList();
            rearDepChar    = new ArrayList();
            tonalChar      = new ArrayList();
            endingChar     = new ArrayList();

            //Adding front-dependent characters
            frontDepChar.AddRange(new string[] { "ะ", "ั", "า", "ำ", "ิ", "ี", "ึ", "ื", "ุ", "ู", "ๅ", "็", "์", "ํ" });

            //Adding rear-dependent characters
            rearDepChar.AddRange(new string[] { "ั", "ื", "เ", "แ", "โ", "ใ", "ไ", "ํ" });

            //Adding tonal characters
            tonalChar.AddRange(new string[] { "่", "้", "๊", "๋" });

            //Adding ending characters
            endingChar.AddRange(new string[] { "ๆ", "ฯ" });
        }
Esempio n. 5
0
 //Inserts the trie as the last child
 protected void addChild(Tire t)
 {
     insertChild(t, numChildren);
 }