コード例 #1
0
ファイル: Form1.cs プロジェクト: yevgenish/Trie
        private void btnLoadFromFile_Click(object sender, EventArgs e)
        {
            string appPath  = Path.GetDirectoryName(Application.ExecutablePath);
            string fileName = "trie.txt";
            string filePath = Path.Combine(appPath, fileName);

            trie.Load(filePath);
        }
コード例 #2
0
ファイル: CRFModel.cs プロジェクト: gaoshoufenmu/HanLP.csharp
        public virtual bool LoadFromBin(ByteArray ba)
        {
            if (ba == null)
            {
                return(false);
            }
            try
            {
                var size = ba.NextInt_HighFirst();          // 使用Model目标的数据文件均与相应的原数据文件兼容,所以这里只讨论高位在前的情况
                id2tag = new string[size];
                tag2id = new Dictionary <string, int>(size);

                for (int i = 0; i < size; i++)
                {
                    id2tag[i]         = ba.NextUTFStr(true);
                    tag2id[id2tag[i]] = i;
                }

                var ffs = new FeatureFunction[ba.NextInt_HighFirst()];
                for (int i = 0; i < ffs.Length; i++)
                {
                    ffs[i] = new FeatureFunction();
                    ffs[i].Load(ba);
                }

                _ffTrie.Load(ba, ffs, true);
                size    = ba.NextInt_HighFirst();
                _ftList = new List <FeatureTemplate>(size);
                for (int i = 0; i < size; i++)
                {
                    var ft = new FeatureTemplate();
                    ft.Load(ba);
                    _ftList.Add(ft);
                }
                size = ba.NextInt_HighFirst();
                if (size == 0)
                {
                    return(true);
                }

                _matrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    _matrix[i] = new double[size];
                    for (int j = 0; j < size; j++)
                    {
                        _matrix[i][j] = ba.NextDouble_HighFirst();
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }