Exemple #1
0
        public void WordProcessor_LastWordHasArrived_LastWordProcessedEventHasBeenThrown()
        {
            var  wordCache          = MockRepository.GenerateMock <ICache>();
            bool addToCacheHappened = false;

            wordCache.Expect(x => x.Add(Arg <string> .Is.Anything, Arg <long> .Is.Anything))
            .Do(new Action <string, long>((a, b) => { addToCacheHappened = true; }));
            wordCache.Expect(x => x.Keys).Return(new[] { "something interesting" });
            bool wordProcessedEventHasBeenThrown = false;
            var  wordProcessedHandler            = new EventHandler <WordEventArgs>(new Action <object, WordEventArgs>((a, b) =>
                                                                                                                       { wordProcessedEventHasBeenThrown = true; }));
            var lastWordProcessedEventHasBeenThrown = false;
            var lastWordProcessedHandler            = new EventHandler(new Action <object, EventArgs>((a, b) =>
                                                                                                      { lastWordProcessedEventHasBeenThrown = true; }));
            var testArgs      = new WordEventArgs("something", 0, 1);
            var wordProcessor = new WordProcessor(wordCache);

            wordProcessor.WordProcessed     += new EventHandler <WordEventArgs>(wordProcessedHandler);
            wordProcessor.LastWordProcessed += new EventHandler(lastWordProcessedHandler);
            wordProcessor.ProcessWord(new object(), testArgs);

            Assert.IsTrue(addToCacheHappened);
            Assert.IsFalse(wordProcessedEventHasBeenThrown);
            Assert.IsTrue(lastWordProcessedEventHasBeenThrown);
        }
Exemple #2
0
 private void WordProcessedHandler(object sender, WordEventArgs args)
 {
     if (args.WordCount > 0)
     {
         analyzerProgressBar.Value = Convert.ToInt32(analyzerProgressBar.Maximum * args.WordSequenceNumber / args.WordCount);
     }
 }
Exemple #3
0
        // This function responds to an event and updates the GUI fields with all the
        // the information needed from the WordEventArgs fields.
        private void setWordInformation(Object o, WordEventArgs wea)
        {
            // Change the color to red, sleep for a second, then change it back.
            Color originalColor = btn_wordsOnOff.BackColor;

            btn_wordsOnOff.BackColor = Color.Red;
            System.Threading.Thread.Sleep(1000);
            btn_wordsOnOff.BackColor = originalColor;

            // Change all the GUI fields to reflect the new word.
            cb_PartOfSpeech.SelectedIndex = cb_PartOfSpeech.FindString(wea.Pos1);
            tb_HeadWord.Text        = wea.Headword;
            tb_Pronunciation.Text   = wea.Pronunciation;
            tb_CrossReference.Lines = wea.CrossReferences.ToArray();

            // Set the selections for the semantic and socialUsage listboxes.
            // Select none if there is no listing.
            lb_Semantics.SelectedIndex   = -1;
            lb_SocialUsage.SelectedIndex = -1;
            wea.SemainticFields.ForEach(delegate(string str)
            {
                lb_Semantics.SelectedItem = str;
            });
            wea.SocialUsage.ForEach(delegate(string str)
            {
                lb_SocialUsage.SelectedItem = str;
            });
        }
Exemple #4
0
 /// <summary>
 /// This method is invoked every 2 seconds and gets the word and displays it on window
 /// </summary>
 /// <param name="sender">sender of this event</param>
 /// <param name="e">properties of word to display</param>
 void DisplayWordHandler(object sender, WordEventArgs e)
 {
     //This is to prevent InvalidOperationException
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new DisplayWordEventHandler(DisplayWordHandler), new object[] { sender, e });
         return;
     }
     //set the words to labels and display
     lbSpellingFromEvent.Text = "Spelling from WordEventArgs is " + e.Spelling;
 }
Exemple #5
0
        /*****************************************************************************************
         * Function : displayRandomWords_DisplayWord() (Event)
         *
         * Description : Shows new words to user from .dll library every 15 seconds
         ******************************************************************************************/
        void displayRandomWords_DisplayWord(object sender, WordEventArgs e)
        {
            SqlConnection cs = new SqlConnection(connstr);

            string spelling = "Spelling : " + e.Word.Spelling;
            string meaning  = "Meaning : " + e.Word.Meaning;
            string example  = "Example : " + e.Word.Example;

            //builds the string builder
            StringBuilder str = new StringBuilder();

            //initializes the string array
            string[] strArr = new string[3];
            strArr[0] = spelling;
            strArr[1] = meaning;
            strArr[2] = example;

            //loops through the array
            foreach (string selectedItem in strArr)
            {
                //appends array items to string builder "str"
                str.AppendLine(selectedItem.ToString());
            }

            //Show the user new word every 15 seconds
            var result = MessageBox.Show(str.ToString(), "A New Word for you every 15 seconds!!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

            if (result == DialogResult.Yes)
            {
                cs.Open();
                cmd = new SqlCommand("insert into flash_word_table values('" + e.Word.Spelling + "' ,'" + e.Word.Meaning + "' ,'" + e.Word.Example + "');", cs);


                //count no of rows inserted
                int o = cmd.ExecuteNonQuery();
                MessageBox.Show(o + " :Record has been inserted successfully !!");

                //words.Add(new Word(spelling, meaning, sentence));

                SqlDataAdapter adap = new SqlDataAdapter("select * from flash_word_table", cs);

                ds = new DataSet();

                adap.Fill(ds);
                dgView2.DataSource = ds.Tables[0];
                // words1.Add(new Word(e.Word.Spelling, e.Word.Meaning, e.Word.Example));

                //dgViewUpdate();
                cs.Close();
            }
        }
Exemple #6
0
        /// <summary>
        /// This method is invoked every few seconds and sends a random word from the list
        /// </summary>
        /// <param name="state"></param>
        public void sendData(object state)
        {
            //Random class to get a index
            Random        randNum      = new Random();
            WordEventArgs WordEventObj = new WordEventArgs();
            //get the index and bind it to wordeventags
            int dataIndex = randNum.Next(0, ltDllData.Count);

            WordEventObj.Spelling = ltDllData[dataIndex].Spelling;
            if (DisplayWord != null)
            {
                DisplayWord.Invoke(this, WordEventObj);
            }
        }
Exemple #7
0
        public void WordProcessor_SomeExtraWordHasArrived_WordIsNotAddedToCache()
        {
            var  wordCache          = MockRepository.GenerateMock <ICache>();
            bool addToCacheHappened = false;

            wordCache.Expect(x => x.Add(Arg <string> .Is.Anything, Arg <long> .Is.Anything))
            .Do(new Action <string, long>((a, b) => { addToCacheHappened = true; }));
            var testArgs      = new WordEventArgs("something", 0, 0);
            var wordProcessor = new WordProcessor(wordCache);

            wordProcessor.ProcessWord(new object(), testArgs);

            Assert.IsFalse(addToCacheHappened);
        }
Exemple #8
0
        //*******************************************************************
        // method: sc_WEA(Object sender, WordEventArgs wea)
        // description: This message used to handle the WordEventArgs object
        //                  sent by the SpellChecker class
        // returns:void
        //*******************************************************************
        private void sc_WEA(Object sender, WordEventArgs wea)
        {
            //Flash the button red for 1 second
            WordsOnOffButt.BackColor = Color.Red;
            System.Threading.Thread.Sleep(1000);
            WordsOnOffButt.BackColor = default(Color);

            //Clear the selected items out of the big boxes
            semanticBox.SelectedIndex = -1;
            socialBox.SelectedIndex   = -1;

            //These lists hold the Semantic and Social items to highlight
            List <string> semList;
            List <string> socList;

            //Set the easy boxes, easily
            headWordBox.Text = wea.Headword;
            pOSBox.Text      = wea.Pos1;
            PronBox.Text     = wea.Pron;
            crossBox.Text    = wea.CR;

            //split strings by comma delimiters
            semList = new List <string>(wea.SemF.Split(',').ToList());
            socList = new List <string>(wea.SocU.Split(',').ToList());



            for (int i = 0; i < semanticBox.Items.Count; i++)   //For every item in semanticBox
            {
                for (int x = 0; x < semList.Count; x++)         //Compare it to the items in semList
                {
                    if (semanticBox.Items.Contains(semList[x])) //If there is a match
                    {
                        semanticBox.SelectedItem = semList[x];  //then select that item
                    }
                }
            }
            for (int i = 0; i < socialBox.Items.Count; i++)   //For every item in socialBox
            {
                for (int x = 0; x < socList.Count; x++)       //Compare it to the items in socList
                {
                    if (socialBox.Items.Contains(socList[x])) //If there is a match
                    {
                        socialBox.SelectedItem = socList[x];  //then select that item
                    }
                }
            }
        }
Exemple #9
0
    public void DetectWords(float[] wave)
    {
        float minScore = 0f;

        int         closestIndex = 0;
        WordDetails closestWord  = null;

        int size     = wave.Length;
        int halfSize = size / 2;

        for (int wordIndex = FIRST_WORD_INDEX; wordIndex < Words.Count; ++wordIndex)
        {
            WordDetails details = Words[wordIndex];

            if (null == details)
            {
                continue;
            }

            if (WordsToIgnore.Contains(details.Label))
            {
                continue;
            }

            float[] spectrum = details.SpectrumReal;
            if (null == spectrum)
            {
                //Debug.LogError(string.Format("Word profile not set: {0}", details.Label));
                details.Score = -1;
                continue;
            }
            if (null == m_spectrumReal)
            {
                details.Score = -1;
                continue;
            }
            if (spectrum.Length != halfSize ||
                m_spectrumReal.Length != halfSize)
            {
                details.Score = -1;
                continue;
            }

            float score = 0;
            for (int index = 0; index < halfSize;)
            {
                float sumSpectrum = 0f;
                float sumProfile  = 0f;
                int   nextIndex   = index + Threshold;
                for (; index < nextIndex && index < halfSize; ++index)
                {
                    sumSpectrum += Mathf.Abs(m_spectrumReal[index]);
                    sumProfile  += Mathf.Abs(spectrum[index]);
                }
                sumProfile  = sumProfile / (float)Threshold;
                sumSpectrum = sumSpectrum / (float)Threshold;
                float val = Mathf.Abs(sumSpectrum - sumProfile);
                score += Mathf.Abs(val);
            }

            details.Score = score;

#if USE_WORD_MIN_SCORE
            details.AddMinScore(score);
            score = details.GetMinScore(DateTime.Now - TimeSpan.FromSeconds(1));
#endif

            if (wordIndex == FIRST_WORD_INDEX)
            {
                closestIndex = wordIndex;
                minScore     = score;
                closestWord  = details;
            }
            else if (score < minScore)
            {
                closestIndex = wordIndex;
                minScore     = score;
                closestWord  = details;
            }
        }

        if (ClosestIndex != closestIndex)
        {
            ClosestIndex = closestIndex;
            if (null != WordDetectedEvent)
            {
                WordEventArgs args = new WordEventArgs();
                args.Details = closestWord;
                //Debug.Log(args.Details.Label);
                WordDetectedEvent.Invoke(this, args);
            }
        }
    }
Exemple #10
0
    public void DetectWords(float[] wave)
    {
        float minScore = 0f;

        int closestIndex = 0;
        WordDetails closestWord = null;

        int size = wave.Length;
        int halfSize = size / 2;
        for (int wordIndex = FIRST_WORD_INDEX; wordIndex < Words.Count; ++wordIndex)
        {
            WordDetails details = Words[wordIndex];

            if (null == details)
            {
                continue;
            }

            if (WordsToIgnore.Contains(details.Label))
            {
                continue;
            }

            float[] spectrum = details.SpectrumReal;
            if (null == spectrum)
            {
                //Debug.LogError(string.Format("Word profile not set: {0}", details.Label));
                details.Score = -1;
                continue;
            }
            if (null == m_spectrumReal)
            {
                details.Score = -1;
                continue;
            }
            if (spectrum.Length != halfSize ||
                m_spectrumReal.Length != halfSize)
            {
                details.Score = -1;
                continue;
            }

            float score = 0;
            for (int index = 0; index < halfSize;)
            {
                float sumSpectrum = 0f;
                float sumProfile = 0f;
                int nextIndex = index + Threshold;
                for (; index < nextIndex && index < halfSize; ++index)
                {
                    sumSpectrum += Mathf.Abs(m_spectrumReal[index]);
                    sumProfile += Mathf.Abs(spectrum[index]);
                }
                sumProfile = sumProfile/(float) Threshold;
                sumSpectrum = sumSpectrum/(float) Threshold;
                float val = Mathf.Abs(sumSpectrum - sumProfile);
                score += Mathf.Abs(val);
            }

            details.Score = score;

        #if USE_WORD_MIN_SCORE
                details.AddMinScore(score);
                score = details.GetMinScore(DateTime.Now - TimeSpan.FromSeconds(1));
        #endif

            if (wordIndex == FIRST_WORD_INDEX)
            {
                closestIndex = wordIndex;
                minScore = score;
                closestWord = details;
            }
            else if (score < minScore)
            {
                closestIndex = wordIndex;
                minScore = score;
                closestWord = details;
            }
        }

        if (ClosestIndex != closestIndex)
        {
            ClosestIndex = closestIndex;
            if (null != WordDetectedEvent)
            {
                WordEventArgs args = new WordEventArgs();
                args.Details = closestWord;
                //Debug.Log(args.Details.Label);
                WordDetectedEvent.Invoke(this, args);
            }
        }
    }
Exemple #11
0
 private void _testController_NextWord(object sender, WordEventArgs e)
 {
     _testString    = e.RemainingWords;
     _clearEntryBox = true;
 }
Exemple #12
0
 private void _testController_NewTest(object sender, WordEventArgs e)
 {
     _testString = e.RemainingWords;
     _UpdateTimer.Start();
 }
Exemple #13
0
 public void WordRecordHandler(object sender, WordEventArgs args)
 {
     if(args.result == false)
     {
         //Debug.LogError(string.Format("Record {0} FALSE", args.Details.Label));
         GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().ShowQuestion();
     }
     else
     {
         //Debug.LogError(string.Format("Record {0} TRUE", args.Details.Label));
         WordDetectHandler(null, args);
     }
 }
Exemple #14
0
    public void WordDetectHandler(object sender, WordEventArgs args)
    {
        if (string.IsNullOrEmpty(args.Details.Label))
        {
            return;
        }

        Debug.Log(string.Format("Detected: {0}", args.Details.Label));

        if(interact)
        {
            if (string.Compare(args.Details.Label, WORD_INTERACT) == 0) {
                GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().ToInteract();
            }
        }
        else
        {
            if (string.Compare(args.Details.Label, WORD_SITDOWN) == 0) {
                GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().SitDown();
            } else if (string.Compare(args.Details.Label, WORD_FALLDOWN) == 0) {
                GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().FallDown();
            }else if (string.Compare(args.Details.Label, WORD_STANDUP) == 0) {
                GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().StandUp();
            }else if (string.Compare(args.Details.Label, WORD_RIGHTRAWUP) == 0) {
                GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().RightRawUp();
            }else if (string.Compare(args.Details.Label, WORD_LEFTRAWUP) == 0) {
                GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().LeftRawUp();
            }else if (string.Compare(args.Details.Label, WORD_INTERACT) == 0) {
                GameObject.FindGameObjectWithTag("dog").GetComponent<DogController>().ToInteract2();
            }
        }
    }