Esempio n. 1
0
        public void Init(Dictionary<string, int> syllables)
        {
            if (syllables.Count == 0) return;
            foreach (KeyValuePair<string, int> keyValuePair in syllables)
            {
                _syllables.Add(new Tuple<string, int>(keyValuePair.Key, keyValuePair.Value));
            }
            _init = true;

            int countAll = 0;
            foreach (var keyValuePair in _syllables)
            {
                countAll += keyValuePair.Item2;
            }
            List<double> pr = new List<double>();
            foreach (var keyValuePair in _syllables)
            {
                pr.Add(keyValuePair.Item2 / (double)countAll);
            }
            _probability.Add(pr[0]);
            for(int i = 1; i < pr.Count; i++)
            {
                _probability.Add(pr[i] + _probability[i-1]);
            }
            _probability[_probability.Count - 1] = 1;
        }
Esempio n. 2
0
 /// <summary>
 /// Подсчитывает частоту появления слогов
 /// </summary>
 public Dictionary<string, int> MakeStatistics(List<string> words)
 {
     Dictionary<string, int> stat = new Dictionary<string, int>();
     foreach (string word in words)
     {
         List<string> syllables = SeparateSyllable(word);
         foreach (string syllable in syllables)
         {
             if (stat.ContainsKey(syllable))
             {
                 stat[syllable]++;
             }
             else
             {
                 stat.Add(syllable, 1);
             }
         }
     }
     return stat;
 }
Esempio n. 3
0
        public RunForm(SequenceData sequenceToRun)
        {
            this.runningSequence = sequenceToRun;
            if (WordGenerator.MainClientForm.instance.studentEdition)
            {
                MessageBox.Show("Your Cicero Professional Edition (C) License expired on March 31. You are now running a temporary 24 hour STUDENT EDITION license. Please see http://web.mit.edu/~akeshet/www/Cicero/apr1.html for license renewal information.", "License expired -- temporary STUDENT EDITION license.");
            }

            IPAddress lclhst = null;
            IPEndPoint ipe = null;
            CameraPCsSocketList = new List<Socket>();
            connectedPCs = new List<SettingsData.IPAdresses>();
            bool errorOccured = false;
            foreach (SettingsData.IPAdresses ipAdress in Storage.settingsData.CameraPCs)
            {
                errorOccured = false;
                if (ipAdress.inUse)
                {
                    try
                    {

                        lclhst = Dns.GetHostEntry(ipAdress.pcAddress).AddressList[0];
                        ipe = new IPEndPoint(lclhst, ipAdress.Port);
                        CameraPCsSocketList.Add(new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp));

                        CameraPCsSocketList[CameraPCsSocketList.Count - 1].Blocking = false;
                        CameraPCsSocketList[CameraPCsSocketList.Count - 1].SendTimeout = 100;
                        CameraPCsSocketList[CameraPCsSocketList.Count - 1].ReceiveTimeout = 100;

                    }
                    catch
                    {
                        errorOccured = true;
                    }
                    if (errorOccured)
                        continue;
                    else
                    {
                        connectedPCs.Add(ipAdress);
                        try
                        {
                            CameraPCsSocketList[CameraPCsSocketList.Count - 1].Connect(ipe);
                        }
                        catch { }
                    }
                }
            }

            if (Storage.settingsData.CameraPCs.Count != 0)
            {
                getConfirmationThread = new Thread(new ThreadStart(getConfirmationEntryPoint));
                getConfirmationThread.Start();
            }
            // Supress hotkeys in main form when this form is runnings. This will be cleared when the run form closes.
            WordGenerator.MainClientForm.instance.suppressHotkeys = true;

            InitializeComponent();
            runFormStatus = RunFormStatus.Inactive;
            formCreationTime = DateTime.Now;

            // hotkey registration
            hotkeyButtons = new Dictionary<int, Button>();

            // fortune cookie
            if (WordGenerator.MainClientForm.instance.fortunes != null)
            {
                List<string> forts = WordGenerator.MainClientForm.instance.fortunes;
                Random rand = new Random();
                fortuneCookieLabel.Text = forts[rand.Next(forts.Count - 1)];
            }
        }