public string GetWordByID(int wordID, int languageIndex)
    {
        string result = "";

        if (!_wordDictionary.ContainsKey(wordID))
        {
            return(result);
        }
        WordStruct currStruct = _wordDictionary[wordID];

        switch (languageIndex)
        {
        case 0:
            result = currStruct._wordTextCN;
            break;

        case 1:
            result = currStruct._wordTextEN;
            break;

        case 2:
            result = currStruct._wordTextJP;
            break;

        case 3:
            result = currStruct._wordTextOther;
            break;
        }

        return(result);
    }
Esempio n. 2
0
        // Builds word data and outputs information to console
        public void ParseString(string parseValue)
        {
            // Save the original value
            _originalString = parseValue;

            // Replace all breaks and set as lowercase value
            parseValue = Regex.Replace(parseValue, @"[\u000A\u000B\u000C\u000D\u2028\u2029\u0085]+", String.Empty).ToLower();

            // Creates a list of each sentence
            string[] sentences = GetSentences(parseValue);

            // Creates a list of unique words in alphabetical order
            string[] words = GetWords(parseValue);

            // Loop through the list of words
            _words = new List <WordStruct>();
            foreach (string word in words)
            {
                // Loop through the list of sentences adding to the word structure
                WordStruct currWord = new WordStruct(word);
                for (int i = 0; i < sentences.Length; i++)
                {
                    currWord.AddValues(i, Regex.Matches(sentences[i].ToLower(), word).Count);
                }

                // Add the completed structure to the list
                _words.Add(currWord);
            }
        }
    public override bool Load(SecurityElement element)
    {
        if (element.Tag != "Items")
        {
            return(false);
        }
        if (element.Children != null)
        {
            foreach (SecurityElement childrenElement in element.Children)
            {
                WordStruct currStruct = new WordStruct();

                currStruct._wordID        = StrParser.ParseDecInt(StrParser.ParseStr(childrenElement.Attribute("ID"), ""), 0);
                currStruct._wordTextCN    = StrParser.ParseStr(childrenElement.Attribute("CN"), "");
                currStruct._wordTextEN    = StrParser.ParseStr(childrenElement.Attribute("EN"), "");
                currStruct._wordTextJP    = StrParser.ParseStr(childrenElement.Attribute("JP"), "");
                currStruct._wordTextOther = StrParser.ParseStr(childrenElement.Attribute("Other"), "");

                _wordDictionary.Add(currStruct._wordID, currStruct);
            }
        }
        else
        {
            return(false);
        }
        return(true);
    }
Esempio n. 4
0
        private void searchWordTree(Tree node, string seekWord, int seekIndex, string foundWord, int dist, int maxDist)
        {
            if (seekIndex < seekWord.Length)
            {
                char i = seekWord[seekIndex++];
                if (node.child.ContainsKey(i))
                {
                    foundWord += i;
                    searchWordTree(node.child[i], seekWord, seekIndex, foundWord, dist, maxDist);
                }
            }
            else
            {
                if (dist++ > maxDist)
                {
                    return;
                }
                if (node.rating > 0)
                {
                    WordStruct temp = new WordStruct();
                    temp.word   = new string(foundWord.ToCharArray());
                    temp.rating = (float)node.rating / (float)dist;

                    foundWordList.Add(temp);
                }

                foreach (var item in node.child)
                {
                    foundWord += item.Key;
                    searchWordTree(item.Value, seekWord, seekIndex, foundWord, dist, maxDist);
                    foundWord = foundWord.Remove(foundWord.Length - 1);
                }
            }
        }
Esempio n. 5
0
 internal StringWord(string source)
 {
     Source          = source;
     Mode            = ParseMode.Nhaml;
     Row             = 1;
     Column          = 1;
     IndexActualChar = 0;
     PreviousChar    = ' ';
     PreviousWord    = new WordStruct();
 }
Esempio n. 6
0
        /// <summary>
        ///		Obtiene la siguiente palabra
        /// </summary>
        internal WordStruct GetNextWord()
        {
            WordStruct word = new WordStruct();

            // Obtiene la siguiente cadena (o null si ha terminado con el archivo)
            if (IsEof())
            {
                word.IsEof = true;
            }
            else
            {
                // Salta los espacios
                SkipSpaces();
                // Asigna la fila y columna (cuando se han saltado los espacios)
                word.Row    = Row;
                word.Column = Column;
                word.Indent = Indent;
                // Dependiendo del modo ...
                switch (Mode)
                {
                case ParseMode.Nhaml:
                    word.Content = GetNextStringNhaml();
                    break;

                case ParseMode.Comment:
                    word.Content = GetNextStringComment();
                    break;

                case ParseMode.ExpressionCode:
                case ParseMode.ExpressionNhaml:
                    word.Content = GetNextStringExpression();
                    break;

                case ParseMode.Code:
                    word.Content = GetNextStringCode();
                    break;

                case ParseMode.CodeBlock:
                    word.Content = GetNextStringBlockCode();
                    break;
                }
            }
            // Guarda la palabra anterior
            PreviousWord = word;
            // Devuelve la palabra
            return(word);
        }
Esempio n. 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            var topNode = new TreeNode();

            topNode.Text = "";
            topNode.Text = "程序";
            treeView1.Nodes.Clear();
            treeView1.Nodes.Add(topNode);
            String phrase = "";
            String error  = "";
            String dfa    = "";

            //词法分析
            c.lexexe(textBox1.Text, out phrase, out error, out dfa);
            textBox2.Text  = phrase; //词法分析结果
            textBox4.Text  = "词法分析错误:\r\n";
            textBox4.Text += error;  //出现的错误
            textBox5.Text  = dfa;
            String             sen   = "";
            List <Information> list  = new List <Information>();
            Information        first = new Information(0, "开始", "程序");

            list = j.parsexe(phrase, out sen, out error);
            list.Add(first);
            Bind(topNode, list, "程序");
            ArrayList z = new ArrayList();

            z             = j.treelist;
            textBox7.Text = "树的先序结构" + "\r\n";
            foreach (String tmp in z)
            {
                textBox7.Text += tmp + "\r\n";
            }
            textBox3.Text = sen;



            textBox4.Text += "\r\n语法分析错误:\r\n";
            textBox4.Text += error;
            String table = "";

            this.dataGridView2.Rows.Clear();
            foreach (DictionaryEntry m in j.products)
            {
                String    ks = "";
                ArrayList o  = (ArrayList)m.Value;
                foreach (Product k in o)
                {
                    //int index = this.dataGridView2.Rows.Add();
                    table += k.getLeft() + "->";
                    ks     = k.getLeft() + "->";
                    //this.dataGridView2.Rows[index].Cells[0].Value = k.getLeft();

                    foreach (String tmp in k.getRight())
                    {
                        table += tmp + " ";
                        ks    += tmp + " ";
                        //ks += k.getRight() + "";
                    }
                    //this.dataGridView2.Rows[index].Cells[1].Value = ks;
                    int index = this.dataGridView2.Rows.Add();
                    this.dataGridView2.Rows[index].Cells[0].Value = ks;
                    table += "\t" + "when";
                    ks     = "";
                    foreach (String tmp in k.getSelect())
                    {
                        table += "<" + tmp + ">";
                        ks    += tmp + " ";
                    }
                    this.dataGridView2.Rows[index].Cells[1].Value = ks;
                    table += "\r\n";
                }
            }


            this.dataGridView1.Rows.Clear();
            Hashtable fuhaobiao = Meaning.fuhaoBiao;

            foreach (DictionaryEntry d in fuhaobiao)
            {
                FuHao fuhao = (FuHao)d.Value;
                int   index = this.dataGridView1.Rows.Add();
                this.dataGridView1.Rows[index].Cells[0].Value = fuhao.name;
                this.dataGridView1.Rows[index].Cells[1].Value = fuhao.width;
                this.dataGridView1.Rows[index].Cells[2].Value = fuhao.offset;
                this.dataGridView1.Rows[index].Cells[3].Value = fuhao.type;
            }
            dataGridView1.Sort(dataGridView1.Columns[2], ListSortDirection.Ascending);
            textBox6.Text = table;



            string ac = "";
            string ak = "";

            foreach (DictionaryEntry m in j.nTerminals)
            {
                WordStruct o = (WordStruct)m.Value;
                ac = ak = "";
                int index3 = this.dataGridView3.Rows.Add();
                int index4 = this.dataGridView4.Rows.Add();
                this.dataGridView3.Rows[index3].Cells[0].Value = o.getDecri();
                this.dataGridView4.Rows[index4].Cells[0].Value = o.getDecri();
                foreach (string s in o.getFirst())
                {
                    ac += s + " ";
                }
                foreach (string s in o.getFollow())
                {
                    ak += s + " ";
                }
                this.dataGridView3.Rows[index3].Cells[1].Value = ac;
                this.dataGridView4.Rows[index4].Cells[1].Value = ak;
            }



            textBox11.Text  = Meaning.yuyi;
            textBox11.Text += (Meaning.line + 1) + "\tend\r\n";//输出end 终结语义分析
        }
Esempio n. 8
0
        /// <summary>
        /// Background method that adds files
        /// </summary>
        void ScanAgent(object stateInfo)
        {
loop:
            int oldWordListCount = wordList.Count;  /* Required */

            // Wait until user will add new files to database
            scanAgentSignal.WaitOne();
            // For each file in queue that user has added
            while (fileQueue.Count > 0)
            {
                // Try to add file to database. If file already exists then go to next file in queue
                try
                {
                    // Wait and lock access to all collections while processing current file
                    locker.AcquireWriterLock(Timeout.Infinite);
                    // Get file path
                    string fileName = fileQueue.Dequeue();
                    // Refresh action status on form
                    Invoke(new ThreadStart(delegate { toolStripLabel.Text = "Processing file: " + fileName; }));
                    // Create file index as stack of WordStructs
                    Stack <WordStruct> stack = new Stack <WordStruct>();
                    // Add new file index to collection
                    collections.Add(fileName, stack);
                    // Open file and split it to words
                    using (StreamReader streamReader = new StreamReader(fileName, Encoding.GetEncoding(1251)))
                        for (int ln = 0; !streamReader.EndOfStream; ln++)
                        {
                            string line = streamReader.ReadLine().ToLower();
                            foreach (string word in line.Split(separators, StringSplitOptions.RemoveEmptyEntries))
                            {
                                // If word is not exists in dictionary yet then add it to dictionary
                                if (!wordList.Contains(word))
                                {
                                    wordList.Add(word);
                                }
                                // If word is not exists in current file yet then add it to collection
                                WordStruct wordStruct = new WordStruct(wordList.IndexOf(word), ln, line.IndexOf(word));
                                if (!stack.Contains(wordStruct, wordComparer))
                                {
                                    stack.Push(wordStruct);
                                }
                            }
                        }
                    // Resize all BitArrays
                    foreach (KeyValuePair <string, BitArray> pair in bitArrays)
                    {
                        pair.Value.Length = wordList.Count;
                    }
                    // Create file index as BitArray
                    bitArrays.Add(fileName, new BitArray(wordList.Count, false));
                    foreach (WordStruct word in stack)
                    {
                        bitArrays[fileName][word.index] = true;
                    }
                }
                catch (Exception error)
                {
                    // Could not open file or file already exists in database
                    if (MessageBox.Show(error.Message + "\nWould you like to continue?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        continue;
                    }
                    else
                    {
                        fileQueue.Clear();
                    }
                }
            }
    public object Clone()
    {
        WordStruct newWordStruct = (WordStruct)this.MemberwiseClone();

        return(newWordStruct);
    }