示例#1
0
        public void build(string fileName)
        {
            var text = File.ReadAllText(fileName);

            if (String.IsNullOrEmpty(text))
            {
                return;
            }

            int i = 0;

            foreach (var abz in Regex.Split(text, "\r\n\r\n"))
            {
                prepareData(abz.Replace("\r\n", " "), i++);
            }

            freq = clearObject().OrderByDescending(t => t.Value).Take(100).ToDictionary(t => t.Key, t => t.Value);

            List <Clust> clust = new List <Clust>();

            foreach (var s in freq)
            {
                Clust c = new Clust();
                foreach (var t in source[s.Key])
                {
                    c.sources.Add(t, 1);
                }
                c.words.Add(s.Key, 1);
                clust.Add(c);
            }

            clust = clustering(clust);
            Word root = new Word
            {
                key    = "root",
                parent = null,
                lev    = 0,
                name   = "root"
            };

            mapping(root, clust);

            string res = "<map version=\"1.0.1\">\r\n" + printMM(root, "") + "\r\n</map>";

            File.WriteAllText(Path.ChangeExtension(fileName, "mm"), res);
            File.WriteAllText(Path.ChangeExtension(fileName, "xml"), res);
        }
示例#2
0
        private static void mapping(Word parent, List <Clust> clust)
        {
            if (parent.lev > 3)
            {
                return;
            }

            foreach (var c in clust)
            {
                if (c.words.Count <= 2) //Если осталось меньше трех элементов
                {
                    foreach (var a in c.words)
                    {
                        Word root = new Word
                        {
                            key    = a.Key,
                            name   = dicNames[a.Key].First(),
                            parent = parent,
                            lev    = parent.lev + 1
                        };
                        words.Add(root);
                    }
                }
                else
                {
                    var sel = from w in c.words
                              join f in freq on w.Key equals f.Key
                              orderby f.Value descending //w.Value * 10000 +
                              select w.Key;


                    Word root = new Word
                    {
                        key    = sel.First(),
                        name   = dicNames[sel.First()].First(),
                        parent = parent,
                        lev    = parent.lev + 1
                    };
                    words.Add(root);

                    List <Clust> new_clust = new List <Clust>();
                    foreach (var a in c.words)
                    {
                        if (a.Key == root.key)
                        {
                            continue;
                        }

                        Clust n = new Clust();
                        foreach (var t in source[a.Key])
                        {
                            n.sources.Add(t, 1);
                        }
                        n.words.Add(a.Key, 1);
                        new_clust.Add(n);
                    }

                    new_clust = clustering(new_clust);
                    mapping(root, new_clust);
                }
            }
        }