Esempio n. 1
0
        public async Task <ActionResult <TagsResult> > Tags([FromBody] TagsRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId,
                                                               MenuUtils.ContentPermissions.Add, MenuUtils.ContentPermissions.Edit))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var spliter = new WordSpliter(_contentTagRepository);
            var tags    = await spliter.GetKeywordsAsync(request.Content, request.SiteId, 10);

            return(new TagsResult
            {
                Tags = tags
            });
        }
Esempio n. 2
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Common.appSettings.TF_LocX  = Convert.ToString((int)this.Left);
            Common.appSettings.TF_LocY  = Convert.ToString((int)this.Top);
            Common.appSettings.TF_SizeW = Convert.ToString((int)this.ActualWidth);
            Common.appSettings.TF_SizeH = Convert.ToString((int)this.ActualHeight);

            if (hook != null)
            {
                hook.Stop();
                hook = null;
            }

            if (Common.textHooker != null)
            {
                Common.textHooker.Sevent -= DataRecvEventHandler;
                Common.textHooker.StopHook();
                Common.textHooker = null;
            }

            dtimer.Stop();
            dtimer       = null;
            _wordSpliter = null;
            //立即清一次,否则重复打开翻译窗口会造成异常:Mecab处理类库异常
            GC.Collect();
        }
Esempio n. 3
0
        public void AddInputPromptWordCite(string txt)
        {
            if (txt.xIsNullOrEmptyOrSpace())
            {
                return;
            }

            if (_prompDict.ContainsKey(txt))
            {
                var prompt = _prompDict.xTryGetValue(txt, null);
                if (prompt != null)
                {
                    prompt.UpdateLatestUse(txt);
                }
            }
            else
            {
                var wdDict     = WordSpliter.Split(txt, true);
                int wordsCount = wdDict.Values.Sum(k => k.Count);
                if (wordsCount > 0)
                {
                    var prompt = InputPromptString.Create(txt, wordsCount, wdDict, null);
                    if (_prompDict.TryAdd(txt, prompt))
                    {
                        foreach (var w in wdDict)
                        {
                            GetInputPromptWordCite(w.Key).Add(prompt);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public TranslateWindow()
        {
            InitializeComponent();

            _isShowSource = true;
            _isLocked     = false;

            _gameTextHistory = new Queue <string>();

            this.Topmost = true;
            UI_Init();
            IsOCRingFlag = false;


            _wordSpliter = WordSpliterAuto(Common.appSettings.WordSpliter);

            _textSpeechHelper = new TextSpeechHelper();
            if (Common.appSettings.ttsVoice == "")
            {
                Growl.InfoGlobal(Application.Current.Resources["TranslateWin_NoTTS_Hint"].ToString());
            }
            else
            {
                _textSpeechHelper.SetTTSVoice(Common.appSettings.ttsVoice);
                _textSpeechHelper.SetVolume(Common.appSettings.ttsVolume);
                _textSpeechHelper.SetRate(Common.appSettings.ttsRate);
            }

            if (Common.appSettings.xxgPath != string.Empty)
            {
                _dict = new XxgJpzhDict();
                _dict.DictInit(Common.appSettings.xxgPath, string.Empty);
            }

            IsPauseFlag  = true;
            _translator1 = TranslatorAuto(Common.appSettings.FirstTranslator);
            _translator2 = TranslatorAuto(Common.appSettings.SecondTranslator);

            _beforeTransHandle = new BeforeTransHandle(Convert.ToString(Common.GameID), Common.UsingSrcLang, Common.UsingDstLang);
            _afterTransHandle  = new AfterTransHandle(_beforeTransHandle);

            _artificialTransHelper = new ArtificialTransHelper(Convert.ToString(Common.GameID));

            if (Common.transMode == 1)
            {
                Common.textHooker.Sevent += DataRecvEventHandler;
            }
            else if (Common.transMode == 2)
            {
                MouseKeyboardHook_Init();
            }

            toggleRec.ToolTip = Common.appSettings.ATon ? REC_OFF: REC_ON;
            updateToggleRecDisplay(false);
        }
Esempio n. 5
0
        public void AddOrUpdateInputPromptWordCite(ShortcutEntity shortcut)
        {
            if (shortcut == null || (string.IsNullOrEmpty(shortcut.Title) && string.IsNullOrEmpty(shortcut.Text)))
            {
                return;
            }
            var text = string.Concat(shortcut.Code, " ", shortcut.Title, " ", shortcut.Text);

            text = text.Trim().ToLower();
            var key = shortcut.Text.xToBanJiaoAndRemoveCharThatAsciiValueLessThan32AndToLower();

            if (_prompDict.ContainsKey(key))
            {
                var prompt = _prompDict.xTryGetValue(key, null);
                if (prompt != null)
                {
                    prompt.AddUseCount(1);
                }
            }
            else
            {
                var wdDict    = WordSpliter.Split(text, true);
                int wordCount = wdDict.Values.Sum(k => k.Count);
                if (wordCount > 0)
                {
                    var prompt = InputPromptString.Create(text, wordCount, wdDict, shortcut);
                    if (_prompDict.TryAdd(key, prompt))
                    {
                        foreach (var w in wdDict)
                        {
                            GetInputPromptWordCiteData(w.Key).Add(prompt);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public void Page_Load(object sender, EventArgs e)
        {
            var type      = Request["type"];
            var retString = string.Empty;

            if (type == TypeGetTitles)
            {
                var siteId    = TranslateUtils.ToInt(Request["siteId"]);
                var channelId = TranslateUtils.ToInt(Request["channelId"]);
                var title     = Request["title"];
                var titles    = GetTitles(siteId, channelId, title);

                Page.Response.Write(titles);
                Page.Response.End();

                return;
            }
            if (type == TypeGetWordSpliter)
            {
                var siteId   = TranslateUtils.ToInt(Request["siteId"]);
                var contents = Request.Form["content"];
                var tags     = WordSpliter.GetKeywords(contents, siteId, 10);

                Page.Response.Write(tags);
                Page.Response.End();

                return;
            }

            if (type == TypeGetTags)
            {
                var siteId = TranslateUtils.ToInt(Request["siteId"]);
                var tag    = Request["tag"];
                var tags   = GetTags(siteId, tag);

                Page.Response.Write(tags);
                Page.Response.End();

                return;
            }

            if (type == TypeGetDetection)
            {
                var content   = Request.Form["content"];
                var arraylist = DataProvider.KeywordDao.GetKeywordListByContent(content);
                var keywords  = TranslateUtils.ObjectCollectionToString(arraylist);

                Page.Response.Write(keywords);
                Page.Response.End();
            }
            else if (type == TypeGetDetectionReplace)
            {
                var content     = Request.Form["content"];
                var keywordList = DataProvider.KeywordDao.GetKeywordListByContent(content);
                var keywords    = string.Empty;
                if (keywordList.Count > 0)
                {
                    var list = DataProvider.KeywordDao.GetKeywordInfoList(keywordList);
                    foreach (var keywordInfo in list)
                    {
                        keywords += keywordInfo.Keyword + "|" + keywordInfo.Alternative + ",";
                    }
                    keywords = keywords.TrimEnd(',');
                }
                Page.Response.Write(keywords);
                Page.Response.End();
            }

            Page.Response.Write(retString);
            Page.Response.End();
        }
Esempio n. 7
0
 static WordSpliter()
 {
     End = new WordSpliter();
     Start = new WordSpliter();
 }
Esempio n. 8
0
        public List <InputPromptString> GetInputSugestion(string input, Dictionary <long, double> contextNumiid = null, int maxCount = 5)
        {
            if (input.xIsNullOrEmptyOrSpace())
            {
                return(null);
            }
            input = input.Trim().ToLower();
            var wdDict     = WordSpliter.Split(input, true);
            var promptDict = new Dictionary <InputPromptString, double>();

            foreach (var wd in wdDict)
            {
                var word         = wd.Key;
                var wordCiteData = GetInputPromptWordCite(word);
                var items        = wordCiteData.Items;
                foreach (var prompt in items)
                {
                    if (promptDict.ContainsKey(prompt))
                    {
                        promptDict[prompt] += 1.0;
                    }
                    else
                    {
                        promptDict.Add(prompt, 1.0);
                    }
                }
            }
            var scorePrompts = new List <ItemScore <InputPromptString> >();

            if (promptDict.Count > 0)
            {
                var inputWords = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var kv in promptDict)
                {
                    var score = kv.Value;
                    var text  = kv.Key.Text;
                    if (inputWords.Length == 1)
                    {
                        if (text.StartsWith(inputWords[0]))
                        {
                            score *= (4 + input.Length / 10);
                        }
                        else if (text.Contains(inputWords[0]))
                        {
                            score *= (2 + input.Length / 10);
                        }
                    }
                    else if (ContainsAllWords(text, inputWords))
                    {
                        score *= (2 + input.Length / 10);
                    }
                    if (kv.Key.IsShortcutOrRuleAnswer)
                    {
                        score *= 3.0;
                    }
                    scorePrompts.Add(new ItemScore <InputPromptString>(kv.Key, score));
                }
            }
            scorePrompts = scorePrompts.OrderByDescending(k => k.Score).Take(maxCount * 50).ToList();
            if (!scorePrompts.xIsNullOrEmpty())
            {
                double scoreWeight     = 0.4;
                double useCountWeight  = 0.15;
                double latestUseWeight = 0.35;
                var    maxScore        = scorePrompts.Max(k => k.Score);
                var    minScore        = scorePrompts.Min(k => k.Score);
                var    maxLatestUse    = scorePrompts.Max(k => k.Item.LatestUse);
                var    minLatestUse    = scorePrompts.Min(k => k.Item.LatestUse);
                var    maxUseCount     = scorePrompts.Max(k => k.Item.UseCount);
                var    minUseCount     = scorePrompts.Min(k => k.Item.UseCount);
                double scoreSeed       = (maxScore - minScore == 0.0) ? 0.0 : (scoreWeight / (maxScore - minScore));
                double useCountSeed    = (maxUseCount - minUseCount == 0) ? 0.0 : (useCountWeight / (maxUseCount - minUseCount));
                double latestUseSeed   = ((maxLatestUse - minLatestUse).TotalSeconds == 0.0) ? 0.0 : (latestUseWeight / ((maxLatestUse - minLatestUse).TotalSeconds));
                foreach (var item in scorePrompts)
                {
                    double scoreVal      = (item.Score - minScore) * scoreSeed;
                    double useCountVal   = 0.0;
                    double lastestUseVal = 0.0;
                    if (item.Item != null)
                    {
                        useCountVal   = (double)(item.Item.UseCount - minUseCount) * useCountSeed;
                        lastestUseVal = (item.Item.LatestUse - minLatestUse).TotalSeconds * latestUseSeed;
                    }
                    item.Score = scoreVal + useCountVal + lastestUseVal;
                }
            }
            return(scorePrompts.OrderByDescending(k => k.Score).Select(k => k.Item).Take(maxCount).ToList());
        }