Ejemplo n.º 1
0
        // Methods
        public StaticRank(XmlNode xmlFeature, XmlNode xmlRankingModel, XmlNode xmlRankingModelFeature) : base("Static")
        {
            base.SetFeatureValue(xmlFeature, xmlRankingModel, xmlRankingModelFeature);
            if (xmlRankingModelFeature.Attributes["pid"] != null)
            {
                this._pid = new Pid(int.Parse(xmlRankingModelFeature.Attributes["pid"].Value));
            }
            else if (xmlFeature.Attributes["property_name"] != null)
            {
                this._pid = new Pid(xmlFeature.Attributes["property_name"].Value);
            }
            foreach (XmlAttribute attribute in xmlFeature.Attributes)
            {
                string name = attribute.Name;
                if (name != null)
                {
                    if (!(name == "raw_value"))
                    {
                        if (name == "transformed")
                        {
                            goto Label_00F2;
                        }
                        if (name == "normalized")
                        {
                            goto Label_0105;
                        }
                        if (name == "raw_value_transformed")
                        {
                            goto Label_0118;
                        }
                    }
                    else
                    {
                        this._val = float.Parse(attribute.Value);
                    }
                }
                continue;
Label_00F2:
                this._valT = float.Parse(attribute.Value);
                continue;
Label_0105:
                this._valN = float.Parse(attribute.Value);
                continue;
Label_0118:
                this._valRT = double.Parse(attribute.Value);
            }
        }
Ejemplo n.º 2
0
        // Methods
        public BM25(XmlNode xmlBM25, XmlNode xmlRankingModel, XmlNode xmlRankingModelBM25) : base("BM25")
        {
            var         dictionary = new Dictionary <int, PropertyContext>();
            XmlNodeList list       = xmlBM25.SelectNodes("query_term");
            XmlNode     node       = xmlBM25["schema"];
            XmlNode     xmlFeature = xmlBM25["final"];
            string      str        = node.Attributes["pid_mapping"].Value;
            var         separator  = new[] { '[', ']', ':' };

            string[] strArray = str.Split(separator);
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].Trim().Length != 0)
                {
                    int num2 = int.Parse(strArray[i]);
                    i += 3;
                    int key = int.Parse(strArray[i]);
                    i++;
                    string strUpdateGroup = strArray[i];
                    if (!dictionary.ContainsKey(key))
                    {
                        dictionary.Add(key, new PropertyContext(key, num2, strUpdateGroup));
                    }
                    else if (dictionary[key].Pid > num2)
                    {
                        dictionary.Remove(key);
                        dictionary.Add(key, new PropertyContext(key, num2, strUpdateGroup));
                    }
                }
            }
            base.SetFeatureValue(xmlFeature, xmlRankingModel, xmlRankingModelBM25);
            var dictionary2 = new Dictionary <int, Bm25PropertyWeights>();

            foreach (XmlNode node3 in xmlRankingModelBM25.SelectNodes("property"))
            {
                int   num4 = int.Parse(node3.Attributes["pid"].Value);
                float w    = float.Parse(node3.Attributes["w"].Value);
                float b    = float.Parse(node3.Attributes["b"].Value);
                dictionary2.Add(num4, new Bm25PropertyWeights(w, b));
            }
            if (list.Count == 0)
            {
                base.SetFeatureValue(null, null, null);
            }
            _Score = float.Parse(xmlBM25["final"].Attributes["score"].Value);
            _Terms = new List <QueryTerm>();
            foreach (XmlNode node4 in list)
            {
                XmlNode node5   = node4["rank"];
                string  strTerm = node4.Attributes["term"].Value;
                float   score   = float.Parse(node5.Attributes["score"].Value);
                XmlNode node6   = node4["index"];
                if (node6 == null)
                {
                    continue;
                }
                int   n    = int.Parse(node6.Attributes["n"].Value);
                int   num9 = int.Parse(node6.Attributes["N"].Value);
                float rW   = float.Parse(node5.Attributes["term_weight"].Value);
                var   item = new QueryTerm(strTerm, score, n, num9, rW);
                Terms.Add(item);
                var      chArray2  = new[] { ' ' };
                float    num11     = 0f;
                string[] strArray2 = node6.Attributes["avdl"].Value.Trim().Split(chArray2);
                foreach (XmlNode node7 in node6.SelectNodes("group"))
                {
                    if (node7.Attributes["ext_doc_id"] != null)
                    {
                        _iExternalDocId = long.Parse(node7.Attributes["ext_doc_id"].Value);
                    }
                    if (node7.Attributes["int_doc_id"] != null)
                    {
                        _iInternalDocId = long.Parse(node7.Attributes["int_doc_id"].Value);
                    }
                    if (node7.Attributes["tf_prime"] != null)
                    {
                        float    num12     = float.Parse(node7.Attributes["tf_prime"].Value);
                        string[] strArray3 = node7.Attributes["tf"].Value.Trim().Split(chArray2);
                        string[] strArray4 = node7.Attributes["dl"].Value.Trim().Split(chArray2);
                        num11 += num12;
                        foreach (int num13 in dictionary.Keys)
                        {
                            float tf = float.Parse(strArray3[num13]);
                            if (tf != 0f)
                            {
                                int   num15  = dictionary[num13].Pid;
                                float weight = dictionary2[num15].W;
                                float tfw    = tf * weight;
                                float dl     = float.Parse(strArray4[num13]);
                                float avdl   = float.Parse(strArray2[num13]);
                                float dlavdl = dl / avdl;
                                float num21  = dictionary2[num15].B;
                                float dlnorm = (1f - num21) + (num21 * dlavdl);
                                float tfnorm = tf / dlnorm;
                                var   pid    = new Pid(num15, weight, tf, tfw, dl, avdl, dlavdl, dlnorm, tfnorm, num21);
                                item.AddPid(pid);
                            }
                        }
                    }
                }
                item.TFW = num11;
            }
        }
Ejemplo n.º 3
0
 public void AddPid(Pid pid)
 {
     this._PropHits.Add(pid);
 }
Ejemplo n.º 4
0
 public bool MatchPid(Pid target)
 {
     return(target.Name == this._strName);
 }
Ejemplo n.º 5
0
 // Methods
 public MinSpan(XmlNode xmlFeature, XmlNode xmlRankingModel, XmlNode xmlRankingModelFeature)
     : base("MinSpan")
 {
     base.SetFeatureValue(xmlFeature, xmlRankingModel, xmlRankingModelFeature);
     if (xmlFeature.Attributes["raw_value"] != null)
     {
         this._fValue = float.Parse(xmlFeature.Attributes["raw_value"].Value);
     }
     else
     {
         this._fValue = 0f;
     }
     if (xmlFeature.Attributes["transformed"] != null)
     {
         this._fTransformed = float.Parse(xmlFeature.Attributes["transformed"].Value);
     }
     else
     {
         this._fTransformed = 0f;
     }
     if (xmlFeature.Attributes["normalized"] != null)
     {
         this._fNormalized = float.Parse(xmlFeature.Attributes["normalized"].Value);
     }
     else
     {
         this._fNormalized = 0f;
     }
     if (xmlFeature.Attributes["best_min_span"] != null)
     {
         this._iBestMinSpan = int.Parse(xmlFeature.Attributes["best_min_span"].Value);
     }
     else
     {
         this._iBestMinSpan = 0;
     }
     if (xmlFeature.Attributes["best_span_count"] != null)
     {
         this._iBestSpanCount = int.Parse(xmlFeature.Attributes["best_span_count"].Value);
     }
     else
     {
         this._iBestSpanCount = 0;
     }
     if (xmlFeature.Attributes["best_diff_terms_count"] != null)
     {
         this._iBestDiffTerms = int.Parse(xmlFeature.Attributes["best_diff_terms_count"].Value);
     }
     else
     {
         this._iBestDiffTerms = 1;
     }
     if (xmlFeature.Attributes["min_term_count"] != null)
     {
         this._iRarestTermCount = int.Parse(xmlFeature.Attributes["min_term_count"].Value);
     }
     else
     {
         this._iRarestTermCount = 1;
     }
     this._type = xmlFeature.Attributes["proximity_type"].Value;
     this._pid  = new Pid(int.Parse(xmlRankingModelFeature.Attributes["pid"].Value));
 }