Exemplo n.º 1
0
        public static InvertedIndex CreateIndex(string[] files)
        {
            var result = new InvertedIndex();

            for (var i = 0; i < files.Length; i++)
            {
                var extracted = _cut.Extract(files[i]);

                var tokens = DefaultAnalyzer.Analyzer(extracted.Text.Split());

                foreach (var token in tokens)
                {
                    result.append(token, files[i]);
                }
            }

            foreach (KeyValuePair <string, Dictionary <string, int> > kvp in result.data)
            {
                Console.Write("Term = {0}", kvp.Key);

                foreach (KeyValuePair <string, int> res in kvp.Value)
                {
                    Console.Write("  Posting-List = {0},  Frequency = {1}", res.Key, res.Value);
                }

                Console.WriteLine();
            }


            return(result);
        }
Exemplo n.º 2
0
        public static Dictionary <string, double> convertQuery(string term)
        {
            Dictionary <string, double> weightedQuery = new Dictionary <string, double>();

            string[] x = DefaultAnalyzer.Analyzer(term.Split());

            foreach (string word in x)
            {
                if (weightedQuery.ContainsKey(word))
                {
                    weightedQuery[word] += 1;
                }
                else
                {
                    weightedQuery.Add(word, 1);
                }
            }

            return(weightedQuery);
        }