コード例 #1
0
 public void ExceptInitialOccurence()
 {
     if (InitialOccurence != Guid.Empty &&
         Occurences.ContainsKey(InitialOccurence))
     {
         Occurences.Remove(InitialOccurence);
     }
 }
コード例 #2
0
        public void AddKind(ExpressionKind kind)
        {
            Occurences[Guid.NewGuid()] = kind;

            if (Occurences.Count == 1)
            {
                InitialOccurence = Occurences.Single().Key;
            }
        }
コード例 #3
0
        public SearchEnginesServiceTests()
        {
            occurences = new Occurences
            {
                Keywords      = new[] { "e-settlements" },
                SearchEngines = new[] { "google.com" },
            };

            service = new SearchEnginesService(occurences);
            html    = File.ReadAllText(@"Expected\html.xml");
        }
コード例 #4
0
        public Dictionary <string, Occurences> GetWordsWithOccurences(IEnumerable <string> documentIds, IEnumerable <string> textFields, int ngramCount)
        {
            var wordsDic = new Dictionary <string, Occurences>();

            if (!documentIds.Any())
            {
                return(wordsDic);
            }

            var documentIdsList = documentIds.ToList();
            var fields          = textFields.Select(f => $"{f}.{ngramCount}").ToArray();

            var wordTotalTermFreq = new Dictionary <string, Dictionary <string, int> >();
            var wordTermFreq      = new Dictionary <string, Dictionary <string, int> >();

            foreach (var field in fields)
            {
                wordTotalTermFreq.Add(field, new Dictionary <string, int>());
                wordTermFreq.Add(field, new Dictionary <string, int>());
            }

            var noChance  = false;
            var batchSize = SiteConfig.Resources.MaxIndexBulkCount;
            IMultiTermVectorsResponse elasticResponse = null;

            do
            {
                try
                {
                    var actualBatch = documentIdsList.Count > batchSize?documentIdsList.Take(batchSize) : documentIdsList;

                    elasticResponse = Client.MultiTermVectors(mtv => mtv
                                                              .Fields(fields)
                                                              .GetMany <DocumentElastic>(actualBatch)
                                                              .TermStatistics(true)
                                                              );
                    ResponseValidator(elasticResponse);

                    var idsDic = actualBatch.ToDictionary(id => id, id => id);
                    documentIdsList.RemoveAll(id => idsDic.ContainsKey(id));

                    if (!elasticResponse.Documents.Any())
                    {
                        continue;
                    }

                    foreach (var field in fields)
                    {
                        var termVectors = elasticResponse.Documents
                                          .Where(d => d.TermVectors.ContainsKey(field))
                                          .Select(d => d.TermVectors[field])
                                          .SelectMany(tv => tv.Terms)
                                          .ToList();

                        foreach (var termVector in termVectors)
                        {
                            if (!wordTotalTermFreq[field].ContainsKey(termVector.Key))
                            {
                                wordTotalTermFreq[field].Add(termVector.Key, termVector.Value.TotalTermFrequency);
                            }

                            if (!wordTermFreq[field].ContainsKey(termVector.Key))
                            {
                                wordTermFreq[field].Add(termVector.Key, termVector.Value.TermFrequency);
                            }
                            else
                            {
                                wordTermFreq[field][termVector.Key] = wordTermFreq[field][termVector.Key] + termVector.Value.TermFrequency;
                            }
                        }
                    }
                }
                catch (Exception ex)
                    when(ex is UnexpectedElasticsearchClientException ||
                         ex is ElasticSearchException)
                    {
                        if (ex is UnexpectedElasticsearchClientException ||
                            elasticResponse.ServerError?.Status == 503 ||
                            elasticResponse.ServerError?.Status == 429)
                        {
                            if (batchSize == 1)
                            {
                                noChance = true;
                            }
                            else
                            {
                                batchSize = Math.Max((Convert.ToInt32((double)batchSize / 2)), 1);
                                System.Threading.Thread.Sleep(5000);
                            }
                        }
                        else
                        {
                            throw ex;
                        }
                    }
            }while (documentIdsList.Any() || noChance);

            if (noChance)
            {
                throw new OutOfResourceException("The server doesn't have enough resource to complete the request!");
            }

            var allWordsList = wordTotalTermFreq.SelectMany(w => w.Value.Keys).Distinct().ToList();

            foreach (var word in allWordsList)
            {
                var wwo = new Occurences();
                foreach (var field in fields)
                {
                    if (wordTotalTermFreq[field].ContainsKey(word))
                    {
                        wwo.Corpus += wordTotalTermFreq[field][word];
                    }
                    if (wordTermFreq[field].ContainsKey(word))
                    {
                        wwo.Tag += wordTermFreq[field][word];
                    }
                }
                wordsDic.Add(word, wwo);
            }
            // because of the conat string in text field
            if (wordsDic.ContainsKey(""))
            {
                wordsDic.Remove("");
            }
            return(wordsDic);
        }
コード例 #5
0
 public void Add(Occurence occurence)
 {
     occurence.Id = Occurences.GetNewId();
     Occurences.Add(occurence);
     SortOccurences();
 }
コード例 #6
0
 public TableInMemory(int length, int offset, Occurences max)
     : base(-1, offset)
 {
     MaxOccurences = max;
     UnitLength    = length;
 }
コード例 #7
0
 public OccurencesController(Occurences occurrences)
 {
     this.occurrences = occurrences;
 }
コード例 #8
0
        public static void convertCsvToDictionary(List <dynamic> LocationList, string type)
        {
            foreach (var lcsv in LocationList)
            {
                var    dict     = (IDictionary <string, object>)lcsv;
                string Country  = lcsv.countryregion.ToLower();
                string Province = lcsv.provincestate.ToLower();


                if (!String.IsNullOrEmpty(Country))
                {
                    CountryRegions.Add(Country.ToLower());
                }
                if (!String.IsNullOrEmpty(Province))
                {
                    ProvinceStates.Add(Province.ToLower());
                    LocationKey lk = new LocationKey(Country, Province);
                    if (!CountryProvinces.ContainsKey(Country))
                    {
                        CountryProvinces.Add(Country, new Country());
                    }
                    //CountryProvinces.Add(lk, new Location(Country, Province, new Coordinates(lcsv.Lat, lcsv.Long)));
                    else
                    {
                        if (!CountryProvinces[Country].Provinces.Contains(Province))
                        {
                            CountryProvinces[Country].Provinces.Add(Province);
                        }
                    }
                }



                DateTime firstDate     = DateTime.Parse("1/1/2020");
                DateTime endDate       = DateTime.Now;
                int      daysToAttempt = (endDate - firstDate).Days + 10;


                for (int i = 0; i < daysToAttempt; i++)
                {
                    StatusCount statusCount   = new StatusCount();
                    DateTime    dateToAttempt = firstDate.AddDays(i);
                    string      targetDay     = dateToAttempt.ToString("Mdyy");

                    if (dict.TryGetValue(targetDay, out var count) && !String.IsNullOrEmpty(count.ToString()))
                    {
                        int intcount = int.Parse(count.ToString());
                        if (type == "Confirmed")
                        {
                            statusCount.Confirmed = intcount;
                        }
                        else if (type == "Deaths")
                        {
                            statusCount.Deaths = intcount;
                        }
                        else if (type == "Recovered")
                        {
                            statusCount.Recovered = intcount;
                        }

                        Occurences occurences = new Occurences();
                        occurences.DateOccurrences.Add(dateToAttempt, statusCount);

                        LocationKey location = new LocationKey(Country.ToLower(), Province.ToLower());

                        if (!LocationOccurrences.ContainsKey(location))
                        {
                            LocationOccurrences.Add(location, occurences);
                        }


                        if (!LocationOccurrences[location].DateOccurrences.ContainsKey(dateToAttempt))
                        {
                            LocationOccurrences[location].DateOccurrences[dateToAttempt] = new StatusCount();
                        }

                        if (type == "Confirmed")
                        {
                            LocationOccurrences[location].DateOccurrences[dateToAttempt].Confirmed = statusCount.Confirmed;
                        }
                        else if (type == "Deaths")
                        {
                            LocationOccurrences[location].DateOccurrences[dateToAttempt].Deaths = statusCount.Deaths;
                        }
                        else if (type == "Recovered")
                        {
                            LocationOccurrences[location].DateOccurrences[dateToAttempt].Recovered = statusCount.Recovered;
                        }
                    }
                }
            }
        }
コード例 #9
0
 public Measure(string measureName, string measureDesc, List <Occurence> occurences) : this(measureName, measureDesc)
 {
     Occurences.AddRange(occurences);
 }
コード例 #10
0
 public Measure(string measureName, string measureDesc, Occurence occurence) : this(measureName, measureDesc)
 {
     Occurences.Add(occurence);
 }
コード例 #11
0
 public ReoccuringFixedPriceFee(decimal price, Occurences occurence)
 {
     Price     = price;
     Occurence = occurence;
 }
コード例 #12
0
        public string checkDrawForWarnings(int drawRoundNumber)
        {
            m_drawRoundNumber = drawRoundNumber;
            string message = "";
            Dictionary <int, Occurences> occurences = new Dictionary <int, Occurences>();
            Occurences byeOccurence;

            byeOccurence.count          = 0;
            byeOccurence.team1Occurence = new List <int>();
            byeOccurence.team2Occurence = new List <int>();
            occurences.Add(0, byeOccurence);
            foreach (DataRow dRow in m_namesTable.Rows)
            {
                int        teamNumber = getIntValue(dRow, "Team_Number");
                Occurences occurence;
                occurence.count          = 0;
                occurence.team1Occurence = new List <int>();
                occurence.team2Occurence = new List <int>();
                occurences.Add(teamNumber, occurence);
            }
            string filterExpression = "Round_Number = " + m_drawRoundNumber;
            string sort             = "Table_Number ASC";

            m_dataRows = m_scoresTable.Select(filterExpression, sort);
            foreach (DataRow dRow in m_dataRows)
            {
                int team1Number = getIntValue(dRow, "Team_1_Number");
                int team2Number = getIntValue(dRow, "Team_2_Number");
                int tableNumber = getIntValue(dRow, "Table_Number");
                if (team1Number != -1 && team2Number != -1)
                {
                    int previousRound = doesMatchExist(m_drawRoundNumber, team1Number, team2Number);
                    if (previousRound != -1)
                    {
                        message += Environment.NewLine + team1Number + " and " + team2Number + " have already played in round " + previousRound + " and are matched in this round at Table Number " + tableNumber;
                    }
                    if (!occurences.ContainsKey(team1Number))
                    {
                        message += Environment.NewLine + "Team 1 : " + team1Number + " at Table Number " + tableNumber + " is not a valid team number";
                    }
                    else
                    {
                        Occurences value = occurences[team1Number];
                        value.count++;
                        value.team1Occurence.Add(tableNumber);
                        occurences[team1Number] = value;
                    }
                    if (!occurences.ContainsKey(team2Number))
                    {
                        message += Environment.NewLine + "Team 2 : " + team2Number + " at Table Number " + tableNumber + " is not a valid team number";
                    }
                    else
                    {
                        Occurences value = occurences[team2Number];
                        value.count++;
                        value.team2Occurence.Add(tableNumber);
                        occurences[team2Number] = value;
                    }
                }
            }
            filterExpression = "Withdraw_Round is null OR WithDraw_Round > " + drawRoundNumber;
            sort             = "Team_Number ASC";
            foreach (DataRow dRow in m_namesTable.Select(filterExpression, sort))
            {
                int i = getIntValue(dRow, "Team_Number");
                if (occurences[i].count == 0)
                {
                    message += Environment.NewLine + "Team Number " + i + " is not included in the draw.";
                }
                else if (occurences[i].count > 1)
                {
                    message += Environment.NewLine + "Team Number " + i + " appears more than once in draw (as Team 1 in Rows : ";
                    foreach (int number in occurences[i].team1Occurence)
                    {
                        message += "" + (number) + " ";
                    }
                    message += " as Team 2 in Rows : ";
                    foreach (int number in occurences[i].team2Occurence)
                    {
                        message += "" + (number) + " ";
                    }
                    message += ")";
                }
            }
            if (m_numberOfTeamsLeft % 2 != 0)
            {
                int i = 0;
                if (occurences[i].count == 0)
                {
                    message += Environment.NewLine + "No team has a bye even though there are an odd number of teams left.";
                }
                else if (occurences[i].count > 1)
                {
                    message += Environment.NewLine + "Bye has been specified more than once in draw (as Team 1 in Rows : ";
                    foreach (int number in occurences[i].team1Occurence)
                    {
                        message += "" + (number) + " ";
                    }
                    message += " as Team 2 in Rows : ";
                    foreach (int number in occurences[i].team2Occurence)
                    {
                        message += "" + (number) + " ";
                    }
                    message += ")";
                }
            }
            else
            {
                int i = 0;
                if (occurences[i].count > 0)
                {
                    message += Environment.NewLine + "Bye has been specified even though there are even number of teams left. Bye is specified as (as Team 1 in Rows : ";
                    foreach (int number in occurences[i].team1Occurence)
                    {
                        message += "" + (number) + " ";
                    }
                    message += " as Team 2 in Rows : ";
                    foreach (int number in occurences[i].team2Occurence)
                    {
                        message += "" + (number) + " ";
                    }
                    message += ")";
                }
            }
            return(message);
        }
コード例 #13
0
 public SearchEnginesService(Occurences occurences)
 {
     timer           = new Timer(CallSearchEngines);
     this.occurences = occurences;
 }