Exemplo n.º 1
0
Arquivo: App.cs Projeto: kreeben/u-sir
        private int AddDocument(string documentId, string[] input, VectorTree tree)
        {
            var docId = Hash(documentId);
            var dic   = new SortedList <double, string>();
            var count = tree.Count;

            foreach (var word in input)
            {
                if (string.IsNullOrWhiteSpace(word))
                {
                    continue;
                }

                tree.GetNode(0, 0).Add(word, docId);

                var wordvec = new VectorNode(word).TermVector;

                if (wordvec.CosAngle(tree.Find(0, 0, word).TermVector) < VectorNode.IdenticalAngle)
                {
                    throw new Exception("error");
                }

                //Console.Write("{0} [", word);
                //foreach (var c in word.Components())
                //{
                //    Console.Write("{0}:{1}, ", c.Key, c.Value);
                //}
                //Console.WriteLine("]");
            }

            return(tree.Count - count);
        }
Exemplo n.º 2
0
Arquivo: App.cs Projeto: kreeben/u-sir
        public void Analyze(string[] input, VectorTree tree)
        {
            var node = tree.Find(0, 0, string.Join(" ", input.Skip(1).ToArray()));

            if (node != null)
            {
                foreach (var x in node.TermVector)
                {
                    Console.WriteLine("{0}:{1}", x.Key, x.Value);
                }
            }
        }
Exemplo n.º 3
0
Arquivo: App.cs Projeto: kreeben/u-sir
        public void Find(string[] input, VectorTree tree)
        {
            var q      = string.Join("", input.Skip(1).ToArray());
            var result = tree.Find(0, 0, q);

            if (result == null)
            {
                Console.WriteLine("{0} not found", q);
            }
            else
            {
                Console.WriteLine("{0} {1} ", result, result.Highscore);
                var sb     = new StringBuilder();
                var cursor = result.Ancestor;
                while (cursor != null)
                {
                    Console.Write("{0} {1} ", cursor, cursor.Angle);
                    cursor = cursor.Ancestor;
                }
                Console.WriteLine();
            }
        }