Пример #1
0
        private TreeGridItem GetCommentTree(children child)
        {
            List <string> top5 = child.GetTopNWords(5);

            TreeGridItem tgi = new TreeGridItem();

            if (top5.Count > 0)
            {
                string all5 = string.Empty;
                foreach (string s in top5)
                {
                    all5 += s + " ";
                }
                tgi.Values = new object[] { all5 };
                RichTextArea rta = new RichTextArea();
                rta.Text = WebUtility.HtmlDecode(child.text);

                tgi.Children.Add(new TreeGridItem()
                {
                    Values = new object[] { WebUtility.HtmlDecode(child.text) }
                });
                foreach (children commentchild in child.Children)
                {
                    TreeGridItem tgic = GetCommentTree(commentchild);
                    tgi.Children.Add(tgic);
                }
            }
            else
            {
                tgi.Tag = "empty";
            }
            return(tgi);
        }
Пример #2
0
        private TreeGridItem GetCommentTree(children child)
        {
            List<string> top5 = child.GetTopNWords(5);

            TreeGridItem tgi = new TreeGridItem();
            if (top5.Count > 0)
            {
                string all5 = string.Empty;
                foreach (string s in top5)
                {
                    all5 += s + " ";
                }
                tgi.Values = new object[] { all5 };
                RichTextArea rta = new RichTextArea();
                rta.Text = WebUtility.HtmlDecode(child.text);

                tgi.Children.Add(new TreeGridItem() { Values = new object[] {WebUtility.HtmlDecode(child.text) } });
                foreach (children commentchild in child.Children)
                {
                    TreeGridItem tgic = GetCommentTree(commentchild);
                    tgi.Children.Add(tgic);
                }
            }
            else
            {
                tgi.Tag = "empty";
            }
            return tgi;
        }
Пример #3
0
        public Node tinhEntropy(int c1, int c2, List <int> remainingAttribute, List <value> listData, string class1, string class2)
        {
            double max      = -1;
            int    tong     = c1 + c2;
            double Sentropy = entropyS(c1, c2);
            int    count    = listData.Count;
            Node   node     = new Node();

            node.entropy = Sentropy;
            for (int i = 0; i < remainingAttribute.Count; i++)
            {
                List <Node>     listchildren = new List <Node>();
                List <children> list         = new List <children>();

                for (int j = 0; j < listData.Count; j++)
                {
                    bool check = true;
                    foreach (var x in list)
                    {
                        if (x.name == listData[j].values[remainingAttribute[i]])
                        {
                            check = false;
                            if (listData[j].values[listData[j].values.Count - 1] == class1)
                            {
                                x.c1++;
                            }
                            if (listData[j].values[listData[j].values.Count - 1] == class2)
                            {
                                x.c2++;
                            }
                        }
                    }
                    if (check)
                    {
                        children child = new children();

                        child.name = listData[j].values[remainingAttribute[i]];
                        if (listData[j].values[listData[j].values.Count - 1] == class1)
                        {
                            child.c1 = 1;
                        }
                        else
                        {
                            child.c2 = 1;
                        }
                        list.Add(child);
                    }
                }
                double gain = Sentropy;
                foreach (var x in list)
                {
                    x.entropy = entropyS(x.c1, x.c2);
                    gain     -= x.entropy * (x.c1 + x.c2) / listData.Count;
                }
                if (gain > max)
                {
                    node.attr = remainingAttribute[i];
                    max       = gain;
                    //Console.WriteLine("chon" + i);
                    foreach (var x in list)
                    {
                        Node nodeChild = new Node();
                        nodeChild.entropy = x.entropy;
                        nodeChild.nClass1 = x.c1;
                        nodeChild.nClass2 = x.c2;
                        if (nodeChild.nClass1 == 0)
                        {
                            nodeChild.isLeaf    = true;
                            nodeChild.classCati = "No";
                        }

                        if (nodeChild.nClass2 == 0)
                        {
                            nodeChild.isLeaf    = true;
                            nodeChild.classCati = "Yes";
                        }
                        nodeChild.value = x.name;
                        nodeChild.data  = updateDataTrain(listData, remainingAttribute[i], x.name);
                        listchildren.Add(nodeChild);
                    }
                    node.children = listchildren;
                }
            }
            foreach (var i in node.children)
            {
                //Console.WriteLine("value "+i.value);
                //Console.WriteLine("data " + i.data.Count);
                //if (i.isLeaf) Console.WriteLine("kq " + i.classCati);
            }
            //Console.WriteLine(node.attr);
            //Console.WriteLine("max" + max);
            //Console.WriteLine("entrype" + Sentropy);
            return(node);
        }
Пример #4
0
 void GetCommentDictionary(children childlist, ref Dictionary<int, string> dict)
 {
     foreach (children child in childlist.Children)
     {
         dict[child.id] = child.text;
         GetCommentDictionary(child, ref dict);
     }
 }
Пример #5
0
 protected virtual void Bind()
 {
     c = gameObject.AddComponent <children>();
     c.AutoFillAll();
 }
Пример #6
0
 private void PopulateNodeList(children child)
 {
     NodeList.Add(child);
     foreach (children childnode in child.Children)
     {
         PopulateNodeList(childnode);
     }
 }
Пример #7
0
 public int GetChildCount(children childrenlist)
 {
     int counter = string.IsNullOrWhiteSpace(childrenlist.text)?0:1;
     foreach (children child in childrenlist.Children)
     {
         counter += GetChildCount(child);
     }
     return counter;
 }
Пример #8
0
 private HashSet<int> GetChildIDs(children childnode)
 {
     HashSet<int> childIDs = new HashSet<int>();
     childIDs.Add(childnode.id);
     foreach (children child in childnode.Children)
     {
         childIDs.Add(child.id);
         childIDs.UnionWith(GetChildIDs(child));
     }
     return childIDs;
 }
Пример #9
0
 private void GetChildIDHashSetList(children node)
 {
     node.ChildIDList = GetChildIDList(node);
     foreach (children child in node.Children)
     {
         GetChildIDHashSetList(child);
     }
 }
Пример #10
0
 private List<HashSet<int>> GetChildIDList(children node)
 {
     List<HashSet<int>> myChildren = new List<HashSet<int>>();
     foreach (children child in node.Children)
     {
         HashSet<int> idList = GetChildIDs(child);
         myChildren.Add(idList);
     }
     return myChildren;
 }
Пример #11
0
        public TagCloudNode GetTagCloudTreeString(children children)
        {
            Dictionary<string, int> topNWordsRoot = children.GetTopNWordsDictionary(10);
            string topNWords = GetTagCloudFromDictionary(topNWordsRoot);
            TagCloudNode tgnRoot = new TagCloudNode();
            tgnRoot.id = children.id;
            tgnRoot.key = children.key;
            tgnRoot.text = topNWords;
            tgnRoot.title = topNWords;

            tgnRoot.children = new List<TagCloudNode>();
            children.Children = children.Children.OrderByDescending(x => x.created_at).ToList();
            foreach (children child in children.Children)
            {
                if (!string.IsNullOrWhiteSpace(child.SubtreeText))
                {
                    TagCloudNode tgnChild = GetTagCloudTreeString(child);
                    tgnRoot.children.Add(tgnChild);
                }
            }
            return tgnRoot;
        }
Пример #12
0
 public Dictionary<string, List<CommentObj>> GetNamedObjects(int N)
 {
     StringBuilder sbAllWords = new StringBuilder();
     foreach (children child in children)
     {
         sbAllWords.Append(child.SubtreeText);
         sbAllWords.Append(" ");
     }
     string[] allWords = GetAllWords(sbAllWords.ToString());
     Dictionary<string, string> stemParentDictionary = GetStemParentDictionary(allWords);
     List<string> namedObjects = new List<string>();
     children rootNode = new children();
     List<HashSet<int>> rootChildIDs = new List<HashSet<int>>();
     foreach (children child in children)
     {
         GetChildIDHashSetList(child);
         HashSet<int> currChildIDs = new HashSet<int>();
         currChildIDs.Add(child.id);
         foreach (var item in child.ChildIDList)
         {
             currChildIDs.UnionWith(item);
         }
         rootChildIDs.Add(currChildIDs);
     }
     rootNode.ChildIDList = rootChildIDs;
     NodeList = new List<children>();
     NodeList.Add(rootNode);
     foreach (children child in children)
     {
         PopulateNodeList(child);
     }
     Dictionary<string, HashSet<int>> wordIDMapping = GetWordIDMapping();
     //Dictionary<string, double> WordTreeScore = new Dictionary<string, double>();
     Dictionary<string, List<children>> WordLCAList = new Dictionary<string, List<children>>();
     foreach (var kvp in wordIDMapping)
     {
         List<children> currLCAList = new List<children>();
         int numLCAs = 0;
         foreach (children node in NodeList)
         {
             int numBranchesWithWord = 0;
             foreach (var childIDBranch in node.ChildIDList)
             {
                 if (childIDBranch.Intersect(kvp.Value).Count() > 0)
                 {
                     numBranchesWithWord += 1;
                 }
             }
             if ((numBranchesWithWord == 1 && node.ChildIDList.Count == 1) || numBranchesWithWord > 1)
             {
                 currLCAList.Add(node);
             }
         }
         WordLCAList[stemParentDictionary.ContainsKey(kvp.Key) ? stemParentDictionary[kvp.Key] : kvp.Key] = currLCAList;
     }
     namedObjects = WordLCAList
         .OrderByDescending(x => x.Value.Count)
         .Select(x => x.Key)
         .Where(y => CommonWords.GetFrequency(y) < 1)
         .Where(a=>char.IsUpper(a[0]))
         .Where(b => b.Length>1)
         .Where(z => !(z.EndsWith("n't") || z.EndsWith("'m") || (z.EndsWith("'ll")) || (z.EndsWith("'d")) || z.EndsWith("'ve") || z.EndsWith("'re") || z.EndsWith("'s")))
         .Take(N)
         .ToList();
     //namedObjects.Sort();
     Dictionary<string,List<CommentObj>> namedObjectDictionary = new Dictionary<string, List<CommentObj>>();
     foreach (string namedObject in namedObjects)
     {
         List<CommentObj> commentObjsForWord = new List<CommentObj>();
         string stem = Stemmer.GetStem(namedObject);
         HashSet<int> idsWithWord = wordIDMapping[stem];
         foreach (int id in idsWithWord)
         {
             children child = GetNodeById(id);
             CommentObj commentObj = new CommentObj(){Id = id,Text = child.text};
             commentObjsForWord.Add(commentObj);
         }
         namedObjectDictionary[namedObject] = commentObjsForWord;
     }
     var ordered = namedObjectDictionary.Keys.OrderByDescending(x => namedObjectDictionary[x].Count).ToList().ToDictionary(x=>x,x=>namedObjectDictionary[x]);
     return ordered;
 }
Пример #13
0
 public TagCloudNode GetCommentTreeString(children children)
 {
     Dictionary<string, int> topNWordsRoot = children.GetTopNWordsDictionary(10);
     TagCloudNode tgnRoot = new TagCloudNode();
     tgnRoot.id = children.id;
     tgnRoot.key = children.key;
     tgnRoot.text = children.text;
     bool isOP = author == children.author;
     string citePre = isOP ? "<cite class='op'>" : "<cite>";
     string citePost = ":</cite>";
     tgnRoot.title = citePre+children.author+ citePost+children.text;
     GetTagCloudFromDictionary(topNWordsRoot);
     tgnRoot.children = new List<TagCloudNode>();
     children.Children = children.Children.OrderByDescending(x => x.created_at).ToList();
     foreach (children child in children.Children)
     {
         if (!string.IsNullOrWhiteSpace(child.SubtreeText))
         {
             TagCloudNode tgnChild = GetCommentTreeString(child);
             tgnRoot.children.Add(tgnChild);
         }
     }
     return tgnRoot;
 }
Пример #14
0
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        Dictionary <string, Person> persons = new Dictionary <string, Person>();

        while (input[0] != "End")
        {
            if (!persons.ContainsKey(input[0]))
            {
                Person current = new Person();
                current.name = input[0];
                persons.Add(input[0], current);
            }
            switch (input[1])
            {
            case "company":
                company comp = new company();
                comp.name                 = input[2];
                comp.department           = input[3];
                comp.salary               = double.Parse(input[4]);
                persons[input[0]].Company = comp;
                break;

            case "pokemon":
                pokemon poke = new pokemon();
                poke.name = input[2];
                poke.type = input[3];
                persons[input[0]].Pokemons.Add(poke);
                break;

            case "parents":
                parents parent = new parents();
                parent.name     = input[2];
                parent.birthday = input[3];
                persons[input[0]].Parents.Add(parent);
                break;

            case "children":
                children child = new children();
                child.name     = input[2];
                child.birthday = input[3];
                persons[input[0]].Children.Add(child);
                break;

            case "car":
                car car = new car();
                car.model             = input[2];
                car.speed             = input[3];
                persons[input[0]].Car = car;
                break;
            }
            input = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
        string person = Console.ReadLine();
        var    pers   = persons.Where(x => x.Key == person).ToList();

        foreach (var one in pers)
        {
            Console.WriteLine(one.Value.name);
            Console.WriteLine("Company:");
            if (one.Value.Company != null)
            {
                Console.WriteLine($"{one.Value.Company.name} {one.Value.Company.department} {one.Value.Company.salary:f2}");
            }
            Console.WriteLine("Car:");
            if (one.Value.Car != null)
            {
                Console.WriteLine($"{one.Value.Car.model} {one.Value.Car.speed}");
            }
            Console.WriteLine("Pokemon:");
            if (one.Value.Pokemons != null)
            {
                foreach (var pokemon in one.Value.Pokemons)
                {
                    Console.WriteLine($"{pokemon.name} {pokemon.type}");
                }
            }
            Console.WriteLine("Parents:");
            if (one.Value.Parents != null)
            {
                foreach (var parent in one.Value.Parents)
                {
                    Console.WriteLine($"{parent.name} {parent.birthday}");
                }
            }
            Console.WriteLine("Children:");
            if (one.Value.Children != null)
            {
                foreach (var child in one.Value.Children)
                {
                    Console.WriteLine($"{child.name} {child.birthday}");
                }
            }
        }
    }
Пример #15
0
        Dictionary<string, HashSet<int>> GetWordIDMapping(children child)
        {
            Dictionary<string, HashSet<int>> wordIDMapping = new Dictionary<string, HashSet<int>>();
            string[] allWords = GetAllWords(child.text);

            foreach (string word in allWords)
            {
                if(stopWords.Contains(word.ToLower())) continue;
                if (word.Length < 3 && word.Any(c=>char.IsLower(c))) continue;
                string stem = Stemmer.GetStem(word);
                if (!wordIDMapping.ContainsKey(stem))
                {
                    wordIDMapping[stem] = new HashSet<int>();
                }
                wordIDMapping[stem].Add(child.id);
            }
            foreach (children childitem in child.Children)
            {
                Dictionary<string, HashSet<int>> mapping = GetWordIDMapping(childitem);
                foreach (var kvp in mapping)
                {
                    if (wordIDMapping.ContainsKey(kvp.Key))
                    {
                        wordIDMapping[kvp.Key].UnionWith(kvp.Value);
                    }
                    else
                    {
                        wordIDMapping[kvp.Key] = kvp.Value;
                    }
                }
            }
            return wordIDMapping;
        }
Пример #16
0
        /// <summary>
        ///  Create Caterory Combobox
        /// </summary>
        /// <returns>List json</returns>
        public static List <_text> CateroryCombobox()
        {
            List <_text> list          = new List <_text>();
            var          category_root = (from cate in db.Categories
                                          where cate.ParentId == 1
                                          select cate).ToList();

            for (int i = 0; i < category_root.Count; i++)
            {
                _text temp = new _text();
                temp.children = new List <children>();
                temp.text     = category_root[i].Name;
                int cateid         = category_root[i].CategoryId;
                var category_child = (from _cate in db.Categories
                                      where _cate.ParentId == cateid
                                      select _cate).ToList();
                for (int j = 0; j < category_child.Count; j++)
                {
                    children child = new children();
                    child.id   = category_child[j].CategoryId;
                    child.text = category_child[j].Name;
                    temp.children.Add(child);
                }
                list.Add(temp);
            }
            return(list);


            /*
             * string json = "[{";
             * var category_root = (from cate in db.Categories
             *                   where cate.ParentId == 1
             *                   select cate).ToList();
             *
             * for (int i = 0; i < category_root.Count; i++)
             * {
             *  json += "text : " + category_root[i].Name + ",children : [";
             *  int cateid= category_root[i].CategoryId;
             *  var category_child = (from _cate in db.Categories
             *                          where _cate.ParentId == cateid
             *                          select _cate).ToList();
             *  for (int j = 0; j < category_child.Count; j++)
             *  {
             *      json += "{ id : " + category_child[i].CategoryId + ",text:" + category_child[i].Name + "}";
             *      if (j != category_child.Count - 1)
             *      {
             *          json += ",";
             *      }
             *  }
             *  json += "]}";
             *  if (i != category_root.Count - 1)
             *  {
             *      json += ",";
             *  }
             * }
             * json += "]}";
             */



            // return json;
        }
Пример #17
0
 void LoadUserComments(children child)
 {
     if (!string.IsNullOrWhiteSpace(child.author))
     {
         if (!UserComments.ContainsKey(child.author))
         {
             UserComments[child.author] = new List<CommentObj>();
         }
         UserComments[child.author].Add(new CommentObj() { Id = child.id, Text = child.text });
     }
     foreach (children childNode in child.Children)
     {
         LoadUserComments(childNode);
     }
 }
Пример #18
0
    public static String MontaSalaTerapeuta(String cod_filial, String cod_terapeuta)
    {
        List <resources> resources = new List <resources>();

        String        conexao = ConfigurationManager.ConnectionStrings["conexao"].ConnectionString;
        SqlConnection con     = new SqlConnection();

        con.ConnectionString = conexao.ToString();

        SqlCommand cmd = new SqlCommand();

        String ssql = "";

        ssql = @"  select ds_sala,cod_sala,fil.ds_filial from tb_sala s
                              inner join tb_filial fil on fil.cod_filial = s.cod_filial
                               where 1=1";
        if (cod_filial != "0")
        {
            ssql += "  and fil.cod_filial =" + cod_filial;
        }
        ssql += "    order by fil.ds_filial,s.ds_sala ";

        cmd.CommandText = ssql;
        cmd.Connection  = con;
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            resources r = new resources();
            r.id       = Convert.ToInt32(dr["cod_sala"]);
            r.title    = "SALA " + dr["ds_sala"].ToString();
            r.building = dr["ds_filial"].ToString();
            List <children> childrens = new List <children>();

            SqlConnection conTerapeuta = new SqlConnection();
            conTerapeuta.ConnectionString = conexao.ToString();

            SqlCommand cmdTerapeuta  = new SqlCommand();
            String     ssqlTerepeuta = "";
            ssqlTerepeuta = @"select cod_terapeuta, nm_terapeuta from tb_terapeuta
                                        where 1=1 ";

            if (cod_terapeuta != "0")
            {
                ssqlTerepeuta += " and cod_terapeuta=" + cod_terapeuta;
            }

            cmdTerapeuta.CommandText = ssqlTerepeuta;
            cmdTerapeuta.Connection  = conTerapeuta;
            conTerapeuta.Open();
            SqlDataReader drTerapeuta = cmdTerapeuta.ExecuteReader();
            while (drTerapeuta.Read())
            {
                children c = new children();
                c.id    = Convert.ToInt32(drTerapeuta["cod_terapeuta"]);
                c.title = drTerapeuta["nm_terapeuta"].ToString();
                childrens.Add(c);
            }
            drTerapeuta.Close();
            conTerapeuta.Close();

            r.children = childrens;
            resources.Add(r);
        }



        con.Close();
        return(Newtonsoft.Json.JsonConvert.SerializeObject(resources));
    }
Пример #19
0
        public List<string> GetAnchorWords(children root, int N)
        {
            List<string> anchorWords = new List<string>();
            string[] allWords = GetAllWords(root.SubtreeText);
            Dictionary<string, string> stemParentDictionary = GetStemParentDictionary(allWords);
            children rootNode = new children();
            List<HashSet<int>> rootChildIDs = new List<HashSet<int>>();
            foreach (children child in root.Children)
            {
                GetChildIDHashSetList(child);
                HashSet<int> currChildIDs = new HashSet<int>();
                currChildIDs.Add(child.id);
                foreach (var item in child.ChildIDList)
                {
                    currChildIDs.UnionWith(item);
                }
                rootChildIDs.Add(currChildIDs);
            }
            rootNode.ChildIDList = rootChildIDs;
            NodeList = new List<children>();
            NodeList.Add(rootNode);
            foreach (children child in root.Children)
            {
                PopulateNodeList(child);
            }
            Dictionary<string, HashSet<int>> wordIDMapping = GetWordIDMapping();
            //Dictionary<string, double> WordTreeScore = new Dictionary<string, double>();
            Dictionary<string, List<children>> WordLCAList = new Dictionary<string, List<children>>();
            foreach (var kvp in wordIDMapping)
            {
                List<children> currLCAList = new List<children>();
                int numLCAs = 0;
                foreach (children node in NodeList)
                {

                    int numBranchesWithWord = 0;
                    foreach (var childIDBranch in node.ChildIDList)
                    {
                        if (childIDBranch.Intersect(kvp.Value).Count() > 0)
                        {
                            numBranchesWithWord += 1;
                        }
                    }
                    if ((numBranchesWithWord == 1 && node.ChildIDList.Count == 1) || numBranchesWithWord > 1)
                    {
                        currLCAList.Add(node);
                    }
                }
                WordLCAList[stemParentDictionary.ContainsKey(kvp.Key) ? stemParentDictionary[kvp.Key] : kvp.Key] = currLCAList;
            }
            anchorWords = WordLCAList.OrderByDescending(x => x.Value.Count).Select(x => x.Key).Where(y=>CommonWords.GetFrequency(y)<20).Take(N).ToList();
            return anchorWords;
        }