/// <summary> /// /// </summary> /// <param name="fileAndContent"></param> /// <param name="maxClusterSize"></param> /// <returns></returns> public static TextFileClassifier GetInstance( IDictionary <string, string> fileAndContent, int maxClusterSize = -1) { Queue <Task <Point> > tasks = new Queue <Task <Point> >(); foreach (KeyValuePair <string, string> kvp in fileAndContent) { tasks.Enqueue( new Task <Point>( () => { return(new Text(kvp.Value, kvp.Key)); } ) ); } QueueBasedTaskRunner <Point> runner = new QueueBasedTaskRunner <Point>(tasks); runner.RunParallel(); TextFileClassifier TheInstance = new TextFileClassifier(); TheInstance.ClusterIdentifier = new KMinSpanningTree(runner.GetResult().ToArray(), maxClusterSize); return(TheInstance); }
/// <summary> /// Get the instance prividing the directory containing the text files you want to classfiy /// </summary> /// <param name="directory"> /// A string that points to the directory of targeted files. /// </param> /// <param name="maxClusterSize"> /// The maximum size you of the clusters you want to set. /// </param> /// <returns> /// An instacne of TextFileClassifier. /// </returns> public static TextFileClassifier GetInstance(string directory, int maxClusterSize = -1) { DirectoryInfo dinfo = new DirectoryInfo(directory); if (!dinfo.Exists) { throw new ArgumentException("Directory doesn't exist."); } IDictionary <string, string> FilesAndContent = Basic.GetContentForAllFiles( directory, SettingsManager.FileSearchRecursive, "txt"); TextFileClassifier TheInstance = GetInstance(FilesAndContent, maxClusterSize); TheInstance.Directory = directory; return(TheInstance); }