/**
         * 执行识别
         *
         * @param segResult      粗分结果
         * @param wordNetOptimum 粗分结果对应的词图
         * @param wordNetAll     全词图
         */
        public static void Recognition(LinkedList <Vertex> segResult, WordNet wordNetOptimum, WordNet wordNetAll)
        {
            StringBuilder sbName      = new StringBuilder();
            int           appendTimes = 0;

            char[] charArray = wordNetAll.charArray;
            BaseSearcher <KeyValuePair <String, char> > searcher = JapanesePersonDictionary.getSearcher(charArray);
            KeyValuePair <String, char> entry;
            int activeLine = 1;
            int preOffset  = 0;
            //while ((entry = searcher.next()) != null)
            //{
            //    char label = entry.Value;
            //    String key = entry.Key;
            //    int offset = searcher.getOffset();
            //    if (preOffset != offset)
            //    {
            //        if (appendTimes > 1 && sbName.Length > 2) // 日本人名最短为3字
            //        {
            //            insertName(sbName.ToString(), activeLine, wordNetOptimum, wordNetAll);
            //        }
            //        sbName.Length = 0;
            //        appendTimes = 0;
            //    }
            //    if (appendTimes == 0)
            //    {
            //        if (label == JapanesePersonDictionary.X)
            //        {
            //            sbName.Append(key);
            //            ++appendTimes;
            //            activeLine = offset + 1;
            //        }
            //    }
            //    else
            //    {
            //        if (label == JapanesePersonDictionary.M)
            //        {
            //            sbName.Append(key);
            //            ++appendTimes;
            //        }
            //        else
            //        {
            //            if (appendTimes > 1 && sbName.Length > 2)
            //            {
            //                insertName(sbName.ToString(), activeLine, wordNetOptimum, wordNetAll);
            //            }
            //            sbName.Length = 0;
            //            appendTimes = 0;
            //        }
            //    }
            //    preOffset = offset + key.Length;
            //}
            //if (sbName.Length > 0)
            //{
            //    if (appendTimes > 1)
            //    {
            //        insertName(sbName.ToString(), activeLine, wordNetOptimum, wordNetAll);
            //    }
            //}
        }
        public string Search(BaseSearcher searcher)
        {
            var vm = Wtm.CreateVM <FrameworkMenuListVM2>();

            vm.Searcher = searcher;
            return(vm.GetJson(enumToString: false));
        }
Beispiel #3
0
        /// <summary>
        /// CustomDictionary是一份全局的用户自定义词典,可以随时增删,影响全部分词器。
        /// CustomDictionary主词典文本路径是data/dictionary/custom/CustomDictionary.txt,
        /// 用户可以在此增加自己的词语(不推荐);
        /// 也可以单独新建一个文本文件,
        /// 通过配置文件CustomDictionaryPath=data/dictionary/custom/CustomDictionary.txt;
        /// 我的词典.txt;来追加词典(推荐)。
        /// 始终建议将相同词性的词语放到同一个词典文件里,便于维护和分享。
        /// 词典格式
        ///每一行代表一个单词,格式遵从[单词][词性A][A的频次][词性B][B的频次] ... 如果不填词性则表示采用词典的默认词性。
        ///词典的默认词性默认是名词n,可以通过配置文件修改:全国地名大全.txt ns; 如果词典路径后面空格紧接着词性,则该词典默认是该词性。
        ///关于用户词典的更多信息请参考词典说明一章。
        ///《Trie树分词》https://www.hankcs.com/program/java/tire-tree-participle.html
        ///《Aho Corasick自动机结合DoubleArrayTrie极速多模式匹配》
        ///https://www.hankcs.com/program/algorithm/aho-corasick-double-array-trie.html
        /// </summary>
        /// <param name="str"></param>
        public void Segement_CustomerDic(string str)
        {
            // 动态增加
            CustomDictionary.add("攻城狮");
            // 强行插入
            CustomDictionary.insert("白富美", "nz 1024");
            // 删除词语(注释掉试试)
            //        CustomDictionary.remove("攻城狮");
            Console.WriteLine(CustomDictionary.add("单身狗", "nz 1024 n 1"));
            Console.WriteLine(CustomDictionary.get("单身狗"));

            string text = "攻城狮逆袭单身狗,迎娶白富美,走上人生巅峰";  // 怎么可能噗哈哈!

            // DoubleArrayTrie分词
            var arrayTrieHit = new AhoCorasickDoubleArrayTrieHitEx(text);

            CustomDictionary.parseText(text, arrayTrieHit);
            // 首字哈希之后二分的trie树分词
            BaseSearcher searcher = CustomDictionary.getSearcher(text);
            var          entry    = searcher.next();

            while (entry != null)
            {
                Console.WriteLine(entry);
                entry = searcher.next();
            }

            // 标准分词
            Console.WriteLine(HanLP.segment(text));

            // Note:动态增删不会影响词典文件
            // 目前CustomDictionary使用DAT储存词典文件中的词语,用BinTrie储存动态加入的词语,前者性能高,后者性能低
            // 之所以保留动态增删功能,一方面是历史遗留特性,另一方面是调试用;未来可能会去掉动态增删特性。
        }
Beispiel #4
0
        /// <summary>
        /// 开始执行检索
        /// </summary>
        public void StartSearch(string targetStr, SearchProgressModel searchProgressModel)
        {
            Reset();
            var mft = new MFTScanner();

            SearchProgress = searchProgressModel;
            List <string> fileFullPaths = new List <string>();

            //遍历磁盘,获取文件名
            foreach (var item in DriveInfo.GetDrives().Where(drive => drive.DriveType == DriveType.Fixed))
            {
                fileFullPaths.AddRange(mft.EnumerateFiles(item.Name).ToList());
            }
            SearchProgress.TotalFileCount = fileFullPaths.Count;

            //对全磁盘的文件名称进行关键字搜索(文件名和文件后缀)
            fileFullPaths = BaseSearcher.SearchFileAndSuffix(targetStr, fileFullPaths);
            //对余下的内容进行文件内容搜索
            Parallel.ForEach(_searchers, search =>
            {
                search.StartSearch(targetStr, fileFullPaths);
            });

            SearchProgress.SearchedFileCount = SearchProgress.TotalFileCount;
        }
Beispiel #5
0
        public async Task <QueryData <T> > StartSearchTree <T>(string url, BaseSearcher searcher, QueryPageOptions options) where T : class, new()
        {
            var rv = await WtmBlazor.Api.CallSearchApi <T>(url, searcher, options);

            QueryData <T> data = new QueryData <T>();

            if (rv.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var idpro = typeof(T).GetSingleProperty("ID");
                if (rv.Data?.Data != null)
                {
                    foreach (var item in rv.Data.Data)
                    {
                        string pid = idpro.GetValue(item)?.ToString();
                        item.SetPropertyValue("Children", new List <T>(rv.Data.Data.AsQueryable().CheckParentID(pid)));
                    }
                }
                data.Items      = rv.Data?.Data.AsQueryable().CheckParentID(null);
                data.TotalCount = rv.Data?.Count ?? 0;
            }
            if (rv.StatusCode == System.Net.HttpStatusCode.Forbidden)
            {
                await WtmBlazor.Toast.Error(WtmBlazor.Localizer["Sys.Error"], WtmBlazor.Localizer["Sys.NoPrivilege"]);
            }
            return(data);
        }
        public IActionResult ExportExcel(BaseSearcher searcher)
        {
            var vm = Wtm.CreateVM <FrameworkMenuListVM2>();

            vm.Searcher     = searcher;
            vm.SearcherMode = ListVMSearchModeEnum.Export;
            return(vm.GetExportData());
        }
Beispiel #7
0
 /// <summary>
 /// 当前登陆人角色不在其中
 /// </summary>
 /// <param name="BaseSearcher">传入this</param>
 /// <param name="ID">当前登陆人ID</param>
 /// <returns></returns>
 public static bool NoContainRoles(this BaseSearcher BaseSearcher, Guid ID)
 {
     try
     {
         var FrameworkRoleList = GetFrameworkRoleObject(BaseSearcher.DC, ID);
         return(FrameworkRoleList != null && FrameworkRoleList.Where(x => ContainRoles.IndexOf(x.RoleName) >= 0) !.Count() <= 0);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #8
0
        public async Task <QueryData <T> > StartSearch <T>(string url, BaseSearcher searcher, QueryPageOptions options) where T : class, new()
        {
            var rv = await WtmBlazor.Api.CallSearchApi <T>(url, searcher, options);

            QueryData <T> data = new QueryData <T>();

            if (rv.StatusCode == System.Net.HttpStatusCode.OK)
            {
                data.Items      = rv.Data?.Data;
                data.TotalCount = rv.Data?.Count ?? 0;
            }
            if (rv.StatusCode == System.Net.HttpStatusCode.Forbidden)
            {
                await WtmBlazor.Toast.Error(WtmBlazor.Localizer["Sys.Error"], WtmBlazor.Localizer["Sys.NoPrivilege"]);
            }
            return(data);
        }
	private string[] GetResult(string searchKey)
	{
		//		return AssetDatabase.FindAssets(searchKey);
		searcher = searcher ?? new SimpleSearcher();
		return searcher.Search(searchKey);
	}
Beispiel #10
0
        public async Task <ApiResult <WtmApiResult <T> > > CallSearchApi <T>(string url, BaseSearcher searcher, QueryPageOptions options) where T : class, new()
        {
            searcher.Page  = options.PageIndex;
            searcher.Limit = options.PageItems;
            if (string.IsNullOrEmpty(options.SortName) == false && options.SortOrder != SortOrder.Unset)
            {
                searcher.SortInfo = new SortInfo
                {
                    Property  = options.SortName,
                    Direction = options.SortOrder == SortOrder.Desc ? SortDir.Desc : SortDir.Asc
                };
            }
            else
            {
                searcher.SortInfo = null;
            }
            var rv = await CallAPI <WtmApiResult <T> >(url, HttpMethodEnum.POST, searcher);

            return(rv);
        }
 private string[] GetResult(string searchKey)
 {
     //		return AssetDatabase.FindAssets(searchKey);
     searcher = searcher ?? new SimpleSearcher();
     return(searcher.Search(searchKey));
 }