/// <summary> /// Saves the TernaryIndex to the given file path. /// Does not catch any file-related exceptions. /// </summary> /// <param name="filePath">Full path and file name for the JSON file.</param> /// <param name="index">The TernaryIndex to be saved.</param> public void SaveIndex(string filePath, TernaryIndex index) { var settings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects }; var serializer = JsonSerializer.Create(settings); using (var writer = new StreamWriter(filePath)) using (var jsonWriter = new JsonTextWriter(writer)) { serializer.Serialize(jsonWriter, index); } }
/// <summary> /// Loads the ternay index for the currently selected language. /// </summary> private void LoadTernaryIndex() { string indexPath = CommonFiles.TernaryIndex(LanguageId); var io = new IndexIO(); TernaryIndex = io.LoadIndex(indexPath); }
/// <summary> /// Performs clustering for the selected language using the current parameters. /// </summary> private void Cluster() { try { TernaryIndex = new TernaryIndex(ClusterVectorSize, ClusterVectorDensity); Parallel.ForEach(DocFiles, docFile => { string text; try { text = File.ReadAllText(Path.Combine(CommonFiles.DocsPath(LanguageId), docFile)); } catch (IOException ex) { Debug.WriteLine(ex.Message + ex.StackTrace); return; } var tokenizer = new TextTokenizer(text); var tokens = tokenizer.Tokenize(); TernaryIndex.ReadSequence(tokens, ClusterPreWindow, ClusterPostWindow); }); TernaryIndex.SimilarityIndex.AddRange(TernaryIndex.BaseWords.ToArray()); //TernaryIndex.SimilarityIndex.BuildIndex(TernaryIndex.Contexts.Cast<ITernaryVector>().ToArray()); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }