예제 #1
0
        public Double CalculateScore(Advert ad, List<ParseToken> tokens)
        {
            if (tokens.Count == 0) return 1.0;

            foreach (var t in tokens)
            {
                if (t.word.termId == ad.accUID) return 1.0;
            }

            return 0.45;
        }
예제 #2
0
        public double CalculateScore(Advert ad, List<ParseToken> dateTokens)
        {
            if (dateTokens.Count == 0) return 1;
            if (ad.dateFrom.Equals(new DateTime(0)) || ad.dateTo.Equals(new DateTime(0))) return 0.8;

            ParseToken token = dateTokens[0];

            int mjesec = 0;
            string tag = token.word.parseTag;

            if ("DATE_MONTH".Equals(tag))
            {
                mjesec = Int32.Parse(Regex.Match(token.text, @"\d+").Value);
            } else {
                mjesec = Math.Min(token.termId - 1805, token.termId - 1817);
            }

            int m1 = ad.dateFrom.Month, m2 = ad.dateTo.Month;

            if (m1 <= m2) return (m1 <= mjesec && mjesec <= m2 ? 1 : 0);
            return (m1 <= mjesec || mjesec <= m2 ? 1 : 0);
        }
예제 #3
0
        public Double CalculateScore(Advert ad, List<ParseToken> capacityTokens)
        {
            if (capacityTokens.Count == 0) return 1.0;
            if (ad.capacityMin == -1 && ad.capacityMax == -1) return 0.8;

            int noofpeeps = 1;

            string tag = capacityTokens[0].word.parseTag;

            for (int i = 2; i <= 10; ++i)
            {
                if (String.Format(@"CAPACITY_{0}_PEOPLE", i).Equals(tag))
                {
                    noofpeeps = i;
                }
            }

            if ("CAPACITY_1_PERSON".Equals(capacityTokens[0].word.parseTag))
            {
                noofpeeps = 1;
            }
            else if ("CAPACITY_X_PEOPLE".Equals(capacityTokens[0].word.parseTag))
            {
                noofpeeps = Int32.Parse(Regex.Match(capacityTokens[0].text, @"\d+").Value);

            }

            if (ad.capacityMax == -1) ad.capacityMax = 10000000;

            if (ad.capacityMin <= noofpeeps && noofpeeps <= ad.capacityMax) return 1.0;

            if (noofpeeps > 3 && noofpeeps == ad.capacityMin - 1) return 0.6;

            if (noofpeeps > 3 && noofpeeps == ad.capacityMax + 1) return 0.3;

            return 0.0;
        }
예제 #4
0
        public void InitFromDB()
        {
            try
            {
                SqlConnection conn = Utility.GetDefaultConnection();
                conn.Open();

                String strcmd = @"SELECT a.Id, a.Price, a.PriceTo, a.CurrencyId, a.DateFrom, a.DateTo, a.CapacityMin,
                                        a.CapacityMax, a.LanguageId, i.AccommodationTermId AccTypeId, i.GeoplaceId GeoplaceId
                                    FROM Advert a LEFT JOIN SearchAdvertInfo i ON a.Id = i.AdvertId
                                    WHERE (Country LIKE 'Hrvatska' OR Country LIKE 'Croatia')
                                        AND LanguageId IN (1, 2)";
                //                                        , AccommodationType, Title, Description, Country, Region, Island, City

                SqlCommand sqlcmd = new SqlCommand(strcmd, conn);
                SqlDataReader reader = sqlcmd.ExecuteReader();

                while (reader.Read())
                {
                    Advert advert = new Advert();

                    advert.id = Int32.Parse(reader["Id"].ToString());

                    advert.geoUID = MyTryParseInt(reader["GeoplaceId"].ToString());
                    advert.accUID = MyTryParseInt(reader["AccTypeId"].ToString());

                    advert.priceFrom = MyTryParseDouble(reader["Price"].ToString());
                    advert.priceTo = MyTryParseDouble(reader["PriceTo"].ToString());
                    advert.currencyId = MyTryParseInt(reader["CurrencyId"].ToString());

                    advert.dateFrom = MyTryParseDateTime(reader["DateFrom"].ToString());
                    advert.dateTo = MyTryParseDateTime(reader["DateTo"].ToString());

                    advert.capacityMin = MyTryParseInt(reader["CapacityMin"].ToString());
                    advert.capacityMax = MyTryParseInt(reader["CapacityMax"].ToString());

                    advert.languageId = MyTryParseInt(reader["LanguageId"].ToString());

                    adverts[advert.id] = advert;

                    //if (advert.id == 97044)
                    //{
                    //    Console.WriteLine("bam");
                    //}

                    // *** FOLLOWING IS NOT NECESSARY FOR SEARCHING ***
                    // Some of it actualy updates the database and should be moved somewhere (where batch-like code is).

                    //advert.accommodation = reader["AccommodationType"].ToString();
                    //advert.title = reader["Title"].ToString();
                    //advert.description = reader["Description"].ToString();
                    //advert.country = reader["Country"].ToString();
                    //advert.region = reader["Region"].ToString();
                    //advert.island = reader["Island"].ToString();
                    //advert.city = reader["City"].ToString();
                }

                conn.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #5
0
        public Double CalculateScore(Advert ad, List<ParseToken> priceTokens)
        {
            double l = ad.priceFrom, h = ad.priceTo;

            if (priceTokens.Count == 0) return 1.0;
            if (l == -1 && h == -1) return 0.8;

            if (l == -1) l = 0;
            if (h == -1) h = MAX;

            double lq = 0.0, hq = MAX;

            foreach (ParseToken token in priceTokens)
            {
                string tag = token.word.parseTag;

                if ("PRICE_MIN_X".Equals(tag))
                {
                    lq = ParseAndAdjustCurrency(token.text, ad.currencyId);
                }
                else if ("PRICE_MAX_X".Equals(tag))
                {
                    hq = ParseAndAdjustCurrency(token.text, ad.currencyId);
                }
                else if ("PRICE_MIN_X_MAX_Y".Equals(tag))
                {
                    string levi = "", desni = "";

                    int bio = 0;
                    for (int i = 0; i < token.text.Length; ++i)
                    {
                        if (Char.IsDigit(token.text[i])) bio = 1;
                        if (bio == 1 && !char.IsDigit(token.text[i])) {
                            levi = token.text.Substring(0, i);
                            desni = token.text.Substring(i);
                            break;
                        }
                    }

                    if ("".Equals(levi) || "".Equals(desni)) continue;

                    String zz = Regex.Match(levi, @"[1-9][0-9]*([.,][0-9][0-9])?").Value;
                    zz.Replace(',', '.');
                    lq = Double.Parse(zz);

                    zz = Regex.Match(desni, @"[1-9][0-9]*([.,][0-9][0-9])?").Value;
                    zz.Replace(',', '.');
                    hq = Double.Parse(zz);

                    int cid = ad.currencyId;
                    int cid2 = 2;

                    if (Regex.IsMatch(desni, @"kun|hr?\skn|kn")) cid2 = 1;

                    if (cid == 1 && cid2 == 2)
                    {
                        lq *= 7.5;
                        hq *= 7.5;
                    }
                    else if (cid == 2 && cid2 == 1)
                    {
                        lq /= 7.5;
                        hq /= 7.5;
                    }
                }
            }

            return HardBoundScore(l, h, lq, hq);
        }
예제 #6
0
        private Double CalculateGeoScore(Advert ad, List<ParseToken> geoTokens)
        {
            if (geoTokens.Count == 0) return 0.9;

            if (ad.geoUID == -1) return 0.0;

            int count = 0;
            double sum = 0;
            foreach (ParseToken gt in geoTokens)
            {
                double ts = geoSimilarity.GetDistance(ad.geoUID, words[gt.termId].geoplaceId);
                if (ts > 1e-9)
                {
                    count++;
                    sum += ts;
                }
            }

            return (count == 0 ? 0.0 : sum / count);
        }