Example #1
0
        public void Update()
        {
            if (IsAvailable)
            {
                if (IsRunning && !IsPaused)
                {
                    Keywordable receiver = null;
                    lock (syncRoot)
                    {
                        if (resultReceiver != null &&
                            (resultReceiver != lastReceiver ||
                             (DateTime.Now - lastMatchTime) > DEBOUNCE_TIME))
                        {
                            lastReceiver   = resultReceiver;
                            receiver       = resultReceiver;
                            resultReceiver = null;
                        }
                        lastMatchTime = DateTime.Now;
                    }

                    if (receiver != null)
                    {
                        receiver.ActivateEvent();
                    }
                }
                else if (IsPermitted && !IsStarting)
                {
                    Setup();
                }
            }
        }
Example #2
0
 public void RemoveKeywordable(Keywordable keywordable)
 {
     lock (syncRoot)
     {
         keywordables.Remove(keywordable);
     }
 }
Example #3
0
 public void AddKeywordable(Keywordable keywordable)
 {
     lock (syncRoot)
     {
         keywordables.MaybeAdd(keywordable);
     }
 }
Example #4
0
        protected void ProcessText(string text, bool isComplete)
        {
            if (!string.IsNullOrEmpty(text))
            {
                var resultText = new string(text
                                            .ToLowerInvariant()
                                            .Where(IsWordChar)
                                            .ToArray());

                if (!string.IsNullOrEmpty(resultText))
                {
                    var         maxSimilarity = 0f;
                    Keywordable receiver      = null;
                    string      match         = null;
                    foreach (var keywordable in keywordables)
                    {
                        foreach (var keyword in keywordable.keywords)
                        {
                            var similarity = keyword.Similarity(resultText);
                            if (similarity > maxSimilarity)
                            {
                                match         = keyword;
                                maxSimilarity = similarity;
                                receiver      = keywordable;
                            }
                        }
                    }

                    ScreenDebugger.Print($"{text} => {resultText} = {match} ({Units.Converter.Label(maxSimilarity, Units.UnitOfMeasure.Proportion, Units.UnitOfMeasure.Percent)})");

                    if (isComplete && maxSimilarity < minimumCompleteSimilarity ||
                        !isComplete && maxSimilarity < minimumIncompleteSimilarity)
                    {
                        receiver = null;
                    }

                    lock (syncRoot)
                    {
                        resultReceiver = receiver;
                    }
                }
            }
        }