static void SerializerTest(Corpora cops) { XmlSerializer ser = new XmlSerializer(typeof(Corpora)); string filename = cops.Language + ".xml"; TextWriter writer = new StreamWriter(filename); ser.Serialize(writer, cops); writer.Close(); }
private static void IrrigateCorporaWithBigrams(Corpora cops, List <Tuple <char, char> > bigrams) { foreach (Tuple <char, char> tuple_char_char in bigrams) { char first_char = tuple_char_char.Item1; char second_char = tuple_char_char.Item2; cops.IrrigateBigram(first_char, second_char); } }
static void CorporaIrrigationTest() { string[] arr_filenames = { @"E:\Dropbox\Codes Hub\C#\Corpus\text samples\english.txt", @"E:\Dropbox\Codes Hub\C#\Corpus\text samples\french.txt", @"E:\Dropbox\Codes Hub\C#\Corpus\text samples\italian.txt" }; foreach (string filename in arr_filenames) { Corpora cops = CorpAnalyzer.ExtractCorporaFromFile(filename); SerializerTest(cops); } }
static void DeserializerTest() { Corpora cops = new Corpora(); XmlSerializer ser = new XmlSerializer(typeof(Corpora)); string filename = "data.xml"; TextReader reader = new StreamReader(filename); cops = ser.Deserialize(reader) as Corpora; reader.Close(); }
static void SerializerTest() { string language = "test"; Corpora cops = new Corpora(); cops.Init(language); XmlSerializer ser = new XmlSerializer(typeof(Corpora)); string filename = "data.xml"; TextWriter writer = new StreamWriter(filename); ser.Serialize(writer, cops); writer.Close(); }
static List <Corpora> FuncDeserializeCorporaFiles(List <string> lst_filepaths) { List <Corpora> lst_cops = new List <Corpora>(); XmlSerializer ser = new XmlSerializer(typeof(Corpora)); foreach (string filename in lst_filepaths) { TextReader reader = new StreamReader(filename); Corpora cops = new Corpora(); cops = ser.Deserialize(reader) as Corpora; lst_cops.Add(cops); reader.Close(); } return(lst_cops); }
static List <Corpora> DeserializerTest(int any_number) { List <Corpora> lst_cops = new List <Corpora>(); XmlSerializer ser = new XmlSerializer(typeof(Corpora)); string[] arr_filenames = { @"english.xml", @"french.xml", @"italian.xml" }; foreach (string filename in arr_filenames) { TextReader reader = new StreamReader(filename); Corpora cops = new Corpora(); cops = ser.Deserialize(reader) as Corpora; lst_cops.Add(cops); reader.Close(); } return(lst_cops); }
static void FuncBuildCorporas() { OpenFileDialog openTextFileDialog = new OpenFileDialog(); openTextFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openTextFileDialog.RestoreDirectory = true; openTextFileDialog.Multiselect = true; openTextFileDialog.Title = "Please Select Text File(s)"; List <Corpora> lst_cops = new List <Corpora>(); if (openTextFileDialog.ShowDialog() == DialogResult.OK) { foreach (string str_path in openTextFileDialog.FileNames) { Corpora cops = CorpAnalyzer.ExtractCorporaFromFile(str_path); lst_cops.Add(cops); } FuncSerializeCorporaFiles(lst_cops); } }
public static Corpora ExtractCorporaFromFile(string filename) { string language = Path.GetFileName(filename).Replace(".txt", ""); Corpora cops = new Corpora(); cops.Init(language); StreamReader file = new StreamReader(filename); string line; while ((line = file.ReadLine()) != null) { string str_in_process = TrimNoneAlphabetChars(line); if (2 <= str_in_process.Length) { List <Tuple <char, char> > bigrams = BuildBigramsFromString(str_in_process); IrrigateCorporaWithBigrams(cops, bigrams); } } file.Close(); return(cops); }