コード例 #1
0
ファイル: TrieCCC.cs プロジェクト: chunc/hw2
    /// <summary>
    /// This function adds new characters from page titles into the Trie structure
    /// </summary>
    /// <param name="line">Reads each line of word</param>
    public void addToTrie(string line)
    {
        Tnode current = root;
        Tnode tmp     = null;

        foreach (char ch in line)
        {
            if (current.children == null)
            {
                current.children = new Dictionary <char, Tnode>();
            }

            if (!current.children.ContainsKey(ch))
            {
                tmp = new Tnode()
                {
                    value = ch
                };
                current.children.Add(ch, tmp);
            }

            current = current.children[ch];
        }

        current.isWord = true;
    }
コード例 #2
0
ファイル: TrieCCC.cs プロジェクト: chunc/hw2
    /// <summary>
    /// Searches Trie structure to see if there is matching word
    /// </summary>
    /// <param name="word">String that client enters</param>
    /// <returns>List of matching words</returns>
    public List <string> searchPrefix(string word)
    {
        List <string> results = new List <string>();
        Tnode         current = root;
        string        prefix  = String.Empty;

        foreach (char c in word)
        {
            if (current.children.ContainsKey(c))
            {
                prefix += c;
                current = current.children[c];
            }
            else
            {
                break;
            }
        }

        if (current.isWord && results.Count < 10)
        {
            results.Add(prefix);
        }

        traverseTrie(prefix, current, results);

        return(results);
    }
コード例 #3
0
ファイル: TrieCCC.cs プロジェクト: chunc/hw2
 public TrieStuff()
 {
     root = new Tnode()
     {
         value = ' '
     };
 }
コード例 #4
0
    public Tnode(Tnode p)
    {
        i_pathT       = p.i_pathT;
        iParent_pathT = p.iParent_pathT;
        pos           = p.pos;
//        ang = p.ang;
    }
コード例 #5
0
ファイル: HMMSegment.cs プロジェクト: weiguang3100/iveely
        private void Insert(string tmp, int sp)
        {
            Tnode now = root;
            int   ptr = 0;

            while (ptr < tmp.Length)
            {
                char t = tmp[ptr];
                if (!now.mp.ContainsKey(t))
                {
                    now.mp[t] = new Tnode();
                }
                now = now.mp[t];
                ptr++;
            }
            now.ed = true;
            now.sum++;
            now.each[sp]++;
        }
コード例 #6
0
ファイル: TrieCCC.cs プロジェクト: chunc/hw2
    /// <summary>
    /// Recursive function to traverse through every Trie node
    /// </summary>
    /// <param name="word">Prefix or string that client inputs</param>
    /// <param name="root">Node</param>
    /// <param name="results">List of matching words</param>
    public void traverseTrie(string word, Tnode root, List <string> results)
    {
        if (root.children == null)
        {
            return;
        }

        foreach (Tnode node in root.children.Values)
        {
            string temp = word + node.value;
            if (node.isWord)
            {
                if (results.Count >= 10)
                {
                    break;
                }
                else
                {
                    results.Add(temp);
                }
            }
            traverseTrie(temp, node, results);
        }
    }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: OlegBrest/EVE-Planetary
        private void UpdateDt(object obj)
        {
            while (MaxThreads < 0)
            {
                Thread.Sleep(10);
            }
            ;
            MaxThreads--;
            ThreadStrInt StrInt = (ThreadStrInt)obj;
            string       IDs;
            int          rowsCnt;

            IDs     = StrInt._str;
            rowsCnt = StrInt._int;
            XmlDocument doc1 = new XmlDocument();

            doc1.Load("https://api.evemarketer.com/ec/marketstat?typeid=" + IDs + "&regionlimit=10000002");

            XmlElement  root      = doc1.DocumentElement;
            XmlNodeList TypeNodes = root.SelectNodes("/exec_api/marketstat/type");

            Invoke((MethodInvoker) delegate
            {
                MainPricesDT.BeginLoadData();
                foreach (XmlNode Tnode in TypeNodes)
                {
                    try
                    {
                        int curRow = 0;
                        PriceKeys.TryGetValue(Tnode.Attributes["id"].Value, out curRow);
                        XmlNode Bnodes = Tnode.SelectSingleNode("buy");
                        XmlNode Snodes = Tnode.SelectSingleNode("sell");

                        double Bmin = Convert.ToDouble(Bnodes["min"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Bmax = Convert.ToDouble(Bnodes["max"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Bavg = Convert.ToDouble(Bnodes["avg"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Bmed = Convert.ToDouble(Bnodes["median"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);

                        double Smin = Convert.ToDouble(Snodes["min"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Smax = Convert.ToDouble(Snodes["max"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Savg = Convert.ToDouble(Snodes["avg"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Smed = Convert.ToDouble(Snodes["median"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);


                        MainPricesDT.Rows[curRow]["Buy(min)"]    = Bmin;
                        MainPricesDT.Rows[curRow]["Buy(max)"]    = Bmax;
                        MainPricesDT.Rows[curRow]["Buy(avg)"]    = Bavg;
                        MainPricesDT.Rows[curRow]["Buy(median)"] = Bmed;
                        MainPricesDT.Rows[curRow]["Buy(self)"]   = MainPricesDT.Rows[curRow]["Buy(self)"].ToString() == "" ? 0 : MainPricesDT.Rows[curRow]["Buy(self)"];

                        MainPricesDT.Rows[curRow]["Sell(min)"]    = Smin;
                        MainPricesDT.Rows[curRow]["Sell(max)"]    = Smax;
                        MainPricesDT.Rows[curRow]["Sell(avg)"]    = Savg;
                        MainPricesDT.Rows[curRow]["Sell(median)"] = Smed;
                        MainPricesDT.Rows[curRow]["Sell(self)"]   = MainPricesDT.Rows[curRow]["Sell(self)"].ToString() == "" ? 0 : MainPricesDT.Rows[curRow]["Sell(self)"];

                        /*Invoke((MethodInvoker)delegate
                         * {*/
                        ProgressBarPrice.Value++;
                        if (ProgressBarPrice.Value == ProgressBarPrice.Maximum)
                        {
                            ProgressBarPrice.Value = 0;
                            ShowPriceDGV();
                        }
                        //});
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                MainPricesDT.EndLoadData();
            });
            MaxThreads++;
        }
コード例 #8
0
ファイル: HMMSegment.cs プロジェクト: weiguang3100/iveely
        //分词,同时标注词性
        public Tuple <string[], string[]> SplitToArray(string text)
        {
            string now = text;

            if (now.Length == 0)
            {
                return(null);
            }
            int ptr = 0;

            Tans[] ans = new Tans[10005];
            int    s   = 0;

            while (ptr < now.Length)
            {
                if (now[ptr] == '\r' && now[ptr + 1] == '\n')
                {
                    ptr += 2;
                    continue;
                }
                ans[s] = new Tans();
                int   deep = 0;
                Tnode trie = root;
                for (int i = 0; i + ptr < now.Length; ++i)
                {
                    char t = now[i + ptr];
                    if (!trie.mp.ContainsKey(t))
                    {
                        break;
                    }
                    trie = trie.mp[t];
                    if (trie.ed)
                    {
                        deep       = i + 1;
                        ans[s].str = "";
                        for (int j = 0; j < deep; ++j)
                        {
                            ans[s].str += now[ptr + j];
                        }
                        if (s == 0)
                        {
                            for (int j = 0; j <= K; ++j)
                            {
                                if (trie.sum > 0)
                                {
                                    ans[s].each[j] = trie.each[j] * 1.0 / trie.sum;
                                }
                                else
                                {
                                    ans[s].each[j] = 0;
                                }
                                ans[s].last[j] = -1;
                            }
                        }
                        else
                        {
                            for (int j = 0; j < K; ++j)
                            {
                                int    save = -1;
                                double big  = -1;
                                for (int r = 0; r <= K; ++r)
                                {
                                    if (ans[s - 1].each[r] * p[r, j] > big)
                                    {
                                        big  = ans[s - 1].each[r] * p[r, j];
                                        save = r;
                                    }
                                }
                                ans[s].each[j] = big * trie.each[j] * 1.0 / trie.sum;
                                ans[s].last[j] = save;
                            }
                            ans[s].each[K] = 0;
                        }
                    }
                }
                if (deep == 0)
                {
                    deep++;
                    for (int j = 0; j < K; ++j)
                    {
                        ans[s].each[j] = 0;
                    }
                    ans[s].each[K] = 1;
                    ans[s].str     = "";
                    for (int j = 0; j < deep; ++j)
                    {
                        ans[s].str += now[ptr + j];
                    }
                    if (s == 0)
                    {
                        ans[s].last[K] = -1;
                    }
                    else
                    {
                        int    save = -1;
                        double big  = -1;
                        for (int r = 0; r <= K; ++r)
                        {
                            if (ans[s - 1].each[r] > big)
                            {
                                big  = ans[s - 1].each[r];
                                save = r;
                            }
                        }
                        ans[s].last[K] = save;
                    }
                }
                ptr += deep;
                s++;
            }
            int[]  optlist = new int[10005];
            double bb      = -1;

            for (int i = 0; i <= K; ++i)
            {
                if (ans[s - 1].each[i] > bb)
                {
                    optlist[s - 1] = i;
                    bb             = ans[s - 1].each[i];
                }
            }
            for (int i = s - 1; i >= 1; --i)
            {
                int da, db;
                da             = optlist[i];
                db             = ans[i].last[da];
                optlist[i - 1] = db;
            }
            List <string> words     = new List <string>();
            List <string> semantics = new List <string>();

            for (int i = 0; i < s; ++i)
            {
                words.Add(ans[i].str);
                semantics.Add(rtrans[optlist[i]]);
            }
            return(new Tuple <string[], string[]>(words.ToArray(), semantics.ToArray()));
        }