Exemplo n.º 1
0
        public double EuclDW(Item item)
        {
            int nCount = 0;
            int iIndex = 0; double nDistance = 0;

            // Iterating through the array of attributes and for each pair of either users or items
            // attributes computing the distance between those attributes. Then, each distance values
            // is added to the nDistance variable. During the computation we're also obtaining the
            // value of releavance between the lexicographical representations of those attributes
            while (iIndex < item.AttribList.Count() && iIndex < AttribList.Count())
            {
                // Compute the relevance between names of the pair of attributes
                double nRel = Relevance(item.AttribList[iIndex].Name, AttribList[iIndex].Name);
                if (nRel == 1)
                {
                    nCount++;
                }

                // Computing the Eucledean distance between the pair of current attributes
                nDistance += Math.Pow(item.AttribList[iIndex].Value - AttribList[iIndex].Value, 2.0) *
                             ((double)((nRel > 0) ? nRel : 1));

                iIndex++;
            }

            // Returning the value of the distance between two vectors of attributes
            return(Math.Sqrt(nDistance) * ((double)1 / ((nCount > 0) ? nCount : 0.01)));
        }
Exemplo n.º 2
0
        public void AppendTag(string tagname, AttribList attribs, Action cb)
        {
            int curlevel = m_indcnt;

            BeginTag(tagname, attribs, (cb == null));
            if (cb != null)
            {
                if (m_doindent)
                {
                    m_buf.Append("\n");
                }
                cb();
                if (m_doindent)
                {
                    WriteIndent(curlevel);
                }
                EndTag(tagname);
            }
        }
Exemplo n.º 3
0
 private void BeginTag(string tagname, AttribList attribs, bool isempty = false)
 {
     BeginIndent();
     m_buf.AppendFormat("<{0}", tagname);
     WriteAttribs(attribs);
     if (isempty)
     {
         m_buf.Append(" />");
         if (m_doindent)
         {
             m_buf.Append("\n");
         }
         EndIndent();
     }
     else
     {
         m_buf.Append(">");
     }
 }
Exemplo n.º 4
0
        private void WriteAttribs(AttribList attribs)
        {
            int  icount = attribs.Count;
            bool islast = false;

            if (attribs.Count > 0)
            {
                m_buf.Append(" ");
                foreach (var kvp in attribs)
                {
                    icount--;
                    islast = (icount == 0);
                    m_buf.AppendFormat("{0}=\"{1}\"", kvp.Key, kvp.Value);
                    if (!islast)
                    {
                        m_buf.Append(" ");
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void AppendTag(string tagname, AttribList attribs, string content)
        {
            int  curlevel    = m_indcnt;
            bool isempty     = (String.IsNullOrEmpty(content));
            bool needsindent = (m_doindent && (content.IndexOf("\n") > -1));

            BeginTag(tagname, attribs, isempty);
            if (isempty == false)
            {
                if (needsindent)
                {
                    int i;
                    var lines = content.Replace("\r", "").Trim().Split('\n');
                    for (i = 0; i < lines.Length; i++)
                    {
                        var line = lines[i].Trim();
                        WriteIndent(m_indcnt);
                        m_buf.Append(line);
                        if ((i + 1) != lines.Length)
                        {
                            m_buf.Append("\n");
                        }
                    }
                    m_buf.Append("\n");
                }
                else
                {
                    m_buf.Append(content.Trim());
                }
                if (m_doindent)
                {
                    if (needsindent)
                    {
                        WriteIndent(curlevel);
                    }
                }
                EndTag(tagname);
            }
        }
Exemplo n.º 6
0
 public void t(string tagname, AttribList attribs, string content)
 {
     AppendTag(tagname, attribs, content);
 }
Exemplo n.º 7
0
 public void t(string tagname, AttribList attribs)
 {
     AppendTag(tagname, attribs);
 }
Exemplo n.º 8
0
 public void t(string tagname, AttribList attribs, Action cb)
 {
     AppendTag(tagname, attribs, cb);
 }
Exemplo n.º 9
0
 public void AppendTag(string tagname, AttribList attribs)
 {
     AppendTag(tagname, attribs, (Action)null);
 }