コード例 #1
0
        protected bool readTAssignFile(string tassignFile)
        {
            try
            {
                int i, j;
                var reader = new StreamReader(tassignFile);

                string line;
                z      = new List <int> [M];
                data   = new LDADataset(M);
                data.V = V;
                for (i = 0; i < M; i++)
                {
                    line = reader.ReadLine();
                    var parts = line.Split();

                    int length = parts.Length;

                    var words  = new List <int>();
                    var topics = new List <int>();

                    for (j = 0; j < length; j++)
                    {
                        var token = parts[j];

                        var tokenParts = token.Split(':');
                        if (tokenParts.Count() != 2)
                        {
                            Console.WriteLine("Invalid word-topic assignment line\n");
                            return(false);
                        }

                        words.Add(Convert.ToInt32(tokenParts[0]));
                        topics.Add(Convert.ToInt32(tokenParts[0]));
                    }//end for each topic assignment

                    //allocate and add new document to the corpus
                    Document doc = new Document(words);
                    data.SetDoc(doc, i);

                    //assign values for z
                    z[i] = new List <int>();
                    for (j = 0; j < topics.Count(); j++)
                    {
                        z[i].Add(topics[j]);
                    }
                }//end for each doc

                reader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while loading model: " + e.Message);
                return(false);
            }
            return(true);
        }
コード例 #2
0
ファイル: LDADataset.cs プロジェクト: Laib/GibbsLDA.NET
        public static LDADataset ReadDataset(string[] strings, WordDictionary dictionary)
        {
            var dataSet = new LDADataset(strings.Length, dictionary);

            for (int i = 0; i < strings.Length; i++)
            {
                dataSet.SetDoc(strings[i], i);
            }

            return(dataSet);
        }
コード例 #3
0
ファイル: LDADataset.cs プロジェクト: Laib/GibbsLDA.NET
        public static LDADataset ReadDataset(string[] strings)
        {
            var dataSet = new LDADataset(strings.Length);

            for (int i = 0; i < strings.Length; i++)
            {
                dataSet.SetDoc(strings[i], i);
            }

            return(dataSet);
        }
コード例 #4
0
ファイル: LDADataset.cs プロジェクト: Laib/GibbsLDA.NET
 public static LDADataset ReadDataset(string filename)
 {
     try
     {
         using (StreamReader reader = new StreamReader(filename))
         {
             var line    = reader.ReadLine();
             var m       = Convert.ToInt32(line);
             var dataSet = new LDADataset(m);
             for (int i = 0; i < m; i++)
             {
                 line = reader.ReadLine();
                 dataSet.SetDoc(line, i);
             }
             return(dataSet);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Failed reading dataSet :" + e.Message);
         return(null);
     }
 }