public static Dictionary <string, int> WordFreqSingle(string StrDirectory) { var StrEnumFiles = Directory.EnumerateFiles(StrDirectory, "*.txt"); var DicWordsFreq = new Dictionary <string, int>(); String[] wordsArray; string FileText; foreach (var file in StrEnumFiles) { Char[] separators = { ' ', ',', '-', '.', '!', '?', '\"', '\n', '\r' }; FileText = File.ReadAllText(file, System.Text.Encoding.Default); wordsArray = FileText.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (var word in wordsArray) { String lowerWord = word.ToLower(); if (!DicWordsFreq.ContainsKey(lowerWord)) { DicWordsFreq.Add(lowerWord, 1); } else { DicWordsFreq[lowerWord] += 1; } } } Console.WriteLine("Количество слов" + DicWordsFreq.Values.Sum()); // DicWordsFreq.Clear(); return(DicWordsFreq); }
private void tvGitTree_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node?.Tag is GitItem gitItem) { switch (gitItem.ObjectType) { case GitObjectType.Blob: { FileText.ViewGitItemAsync(gitItem.FileName, gitItem.Guid); break; } case GitObjectType.Commit: { FileText.ViewTextAsync(gitItem.FileName, LocalizationHelpers.GetSubmoduleText(Module, gitItem.FileName, gitItem.Guid)); break; } default: { FileText.ViewTextAsync("", ""); break; } } } }
private void tvGitTree_AfterSelect(object sender, TreeViewEventArgs e) { ThreadHelper.JoinableTaskFactory.RunAsync(ViewItem); Task ViewItem() { return(e.Node?.Tag is GitItem gitItem ? ViewGitItemAsync(gitItem) : Task.CompletedTask); } Task ViewGitItemAsync(GitItem gitItem) { switch (gitItem.ObjectType) { case GitObjectType.Blob: { return(FileText.ViewGitItemAsync(gitItem.FileName, gitItem.ObjectId)); } case GitObjectType.Commit: { return(FileText.ViewTextAsync(gitItem.FileName, LocalizationHelpers.GetSubmoduleText(Module, gitItem.FileName, gitItem.Guid))); } default: { return(FileText.ViewTextAsync("", "")); } } } }
private void tvGitTree_AfterSelect(object sender, TreeViewEventArgs e) { var gitItem = e.Node?.Tag as GitItem; if (gitItem == null) { return; } switch (gitItem.ObjectType) { case GitObjectType.Blob: { FileText.ViewGitItem(gitItem.FileName, gitItem.Guid); break; } case GitObjectType.Commit: { FileText.ViewText(gitItem.FileName, LocalizationHelpers.GetSubmoduleText(Module, gitItem.FileName, gitItem.Guid)); break; } default: { FileText.ViewText("", ""); break; } } }
public T GetModel() { int startIndex = FileText.IndexOf('{'); int endIndex; int braceCount = 1; for (endIndex = startIndex + 1; braceCount > 0; endIndex++) { if (FileText[endIndex] == '{') { braceCount++; } else if (FileText[endIndex] == '}') { braceCount--; } } string meta = FileText.Substring(startIndex, endIndex - startIndex); var model = JsonSerializer.Deserialize <T>(meta); model.FileName = _name; model.HtmlContent = MarkdownParser.ToHtml(FileText.Substring(endIndex)); return(model); }
static int CountWords(string fileName) { Console.WriteLine("3. Count number of words in the file."); if (fileName == null) { Console.WriteLine("You haven't selected file yet!! Do it now!"); return(1); } string FileText; try { FileText = File.ReadAllText(fileName); } catch (FileNotFoundException) { Console.WriteLine("Could not find file " + fileName); return(1); } string[] Words = FileText.Split(' '); int WordsQty = 0; foreach (string word in Words) { if (word.Length == 1) { continue; } WordsQty++; } Console.WriteLine("REMINDER: Single letters are not counted towards number of words!"); Console.WriteLine("Number of words is: " + WordsQty); return(0); }
/// <summary> /// Create one token if one textTokenList matches. /// </summary> /// <param name="owner">Owner of new token to create.</param> /// <param name="reference">Character to start match.</param> /// <param name="createToken">Call back method to create one token.</param> /// <param name="textTokenList">One of these tokens has to match.</param> public static void CreateToken(FileText owner, Storage.Character reference, Action <FileText, string, Storage.Character, Storage.Character> createToken, params string[] textTokenList) { foreach (var textToken in textTokenList) { if (reference.Owner.Text.Length > reference.TextIndex + textToken.Length - 1) { if (reference.Owner.Text.Substring(reference.TextIndex, textToken.Length) == textToken) { var referenceEnd = (Storage.Character)reference.Owner.List[reference.TextIndex + textToken.Length - 1]; // Create before int length = owner.List.Count; // Create createToken(owner, textToken, reference, referenceEnd); // Create after int lengthNew = owner.List.Count; // Create validate UtilFramework.Assert(lengthNew - length == 1); // Created one token UtilFramework.Assert(owner.Last is Token); // Create of type token break; } } } }
public override void CreateSyntax(FileText owner, Storage.Character reference, CreateSyntaxResult result) { if (reference.Text == '*') { new Bullet(owner, reference); } }
public static ConcurrentDictionary <int, int> WordsDistributionParallel(string StrDirectory) { var StrEnumFiles = Directory.EnumerateFiles(StrDirectory, "*.txt"); var DicWordsFreq = new ConcurrentDictionary <string, int>(); var DicWordsDistrib = new ConcurrentDictionary <int, int>(); String[] StrArrWords; string FileText; Parallel.ForEach(StrEnumFiles, (file) => { Char[] separators = { ' ', ',', '-', '.', '!', '?', '\"', '\n', '\r' }; FileText = File.ReadAllText(file, System.Text.Encoding.Default); StrArrWords = FileText.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (var word in StrArrWords) { String lowerWord = word.ToLower(); DicWordsFreq.AddOrUpdate(lowerWord, 1, (sKey, oldValue) => oldValue + 1); } }); Parallel.ForEach(DicWordsFreq, (word) => { DicWordsDistrib.AddOrUpdate(word.Value, 1, (sKey, oldValue) => oldValue + 1); }); return(DicWordsDistrib); }
public IActionResult PostFileTxt([FromForm] FileText info) { if (info == null) { return(BadRequest()); } info.Date = DateTime.Now; _log.Add(info).Wait(); ProcessFile processFile = new ProcessFile(new ProcessFileTxt()); try { Response.Headers.Add("Access-Control-Allow-Origin", new[] { (string)Request.Headers["Origin"] }); MemoryStream fileProcessed = processFile.FileProcess(info.File); return(File(fileProcessed, "text/plain", textFileOutput)); } catch (OutOfMemoryException) { return(BadRequest()); } catch (Exception) { return(BadRequest()); } }
public void ReloadHotkeys() { Hotkeys = HotkeySettingsManager.LoadHotkeys(HotkeySettingsName); fileHistoryToolStripMenuItem.ShortcutKeyDisplayString = GetShortcutKeyDisplayString(Command.ShowHistory); blameToolStripMenuItem1.ShortcutKeyDisplayString = GetShortcutKeyDisplayString(Command.Blame); openWithDifftoolToolStripMenuItem.ShortcutKeyDisplayString = GetShortcutKeyDisplayString(Command.OpenWithDifftool); FileText.ReloadHotkeys(); }
public override void CreateSyntax(Tree.Component owner, Tree.Syntax reference, CreateSyntaxResult result) { if (reference is Storage.FileText referenceFileText) { var fileText = new FileText((Document)owner, referenceFileText); result.CreateSyntaxTree(fileText, reference.NextAll); } }
/// <summary> /// Creates the process settings. /// </summary> /// <returns></returns> public CubeSummationConfigurationSettings CreateProcessSettings() { var settings = new CubeSummationConfigurationSettings() { PathFile = FileText.GetPathFile(), GenerateInputFormatValidation = new GenerateInputFormatValidation() }; return(settings); }
public JsonResult GhiLog() { FileText ft = new FileText(); ft.FileName = @"C:\Users\Thien\source\repos\WebCuocDT-master\Log.txt"; ft.WriteData(); return(Json(new { status = true })); }
public void SwitchFocus(bool alreadyContainedFocus) { if (alreadyContainedFocus && tvGitTree.Focused) { FileText.Focus(); } else { tvGitTree.Focus(); } }
public override string JSON() { string strReturn = ""; strReturn += "{"; strReturn += "\"type\": \"writeFile\","; strReturn += "\"fileName\": \"" + FileName.Replace("\\", "\\\\") + "\","; strReturn += "\"appendFile\": " + (AppendFile ? "true" : "false") + ","; strReturn += "\"text\": \"" + FileText.Replace("\"", "\\\"") + "\""; strReturn += "}"; return(strReturn); }
public override void CreateSyntax(FileText owner, Storage.Character reference, CreateSyntaxResult result) { if (owner.Last is Content content) { content.Remove(); new Content((FileText)owner, content.ReferenceBegin, reference); } else { new Content((FileText)owner, reference, reference); } }
static void InputFunction() { while (true) { MenuInputStudent(); TotalStudent ts = new TotalStudent(Students.Count); switch (Convert.ToInt32(Console.ReadLine())) { case 1: ts.NumStudentChanged += OnNumberOfStudentChanged; Students.Add(inputStudent(s)); ts.TotalStudents = Students.Count; FileText.WriteData(ConfigurationManager.AppSettings["FileName"].ToString(), "1 | " + s.ToString()); Console.WriteLine("Add student successfully!"); break; case 2: ts.NumStudentChanged += OnNumberOfStudentChanged; Students.Add(inputStudent(s1)); ts.TotalStudents = Students.Count; FileText.WriteData(ConfigurationManager.AppSettings["FileName"].ToString(), "2 | " + s1.ToString()); Console.WriteLine("Add Foreign student successfully!"); break; case 3: ts.NumStudentChanged += OnNumberOfStudentChanged; Students.Add(inputStudent(s2)); ts.TotalStudents = Students.Count; FileText.WriteData(ConfigurationManager.AppSettings["FileName"].ToString(), "3 | " + s2.ToString()); Console.WriteLine("Add VN sutdent successfully!"); break; case 4: ts.NumStudentChanged += OnNumberOfStudentChanged; InitStudent(); ts.TotalStudents = Students.Count; //ft.UpdateListData(Students); Console.WriteLine("Init successfully!"); break; case 5: ts.NumStudentChanged += OnNumberOfStudentChanged; Students = convertFileToListStudents(ConfigurationManager.AppSettings["FileName"].ToString()); ts.TotalStudents = Students.Count; Console.WriteLine(); break; case 6: return; } } }
private void RedoToolStripMenuItem_Click(object sender, EventArgs e) { if (haveChangesText == -1) { pastText = FileText.Text; FileText.Text = nextText; haveChangesText = 1; } else { FileText.Redo(); } }
public static string[] TopTenWordsSingle(string StrDirectory) { var StrEnumFiles = Directory.EnumerateFiles(StrDirectory, "*.txt"); var DicWordsFreq = new Dictionary <string, int>(); String[] StrArrWords; string FileText; string MaxWord = ""; int MaxWordFreq = 0; foreach (var file in StrEnumFiles) { Char[] separators = { ' ', ',', '-', '.', '!', '?', '\"', '\n', '\r' }; FileText = File.ReadAllText(file, System.Text.Encoding.Default); StrArrWords = FileText.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (var word in StrArrWords) { String lowerWord = word.ToLower(); if (!DicWordsFreq.ContainsKey(lowerWord)) { DicWordsFreq.Add(lowerWord, 1); } else { DicWordsFreq[lowerWord] += 1; } } } string[] StrArrTopTenWords = new string[10]; for (int i = 0; i < StrArrTopTenWords.Length; i++) { foreach (var word in DicWordsFreq) { if (word.Value > MaxWordFreq) { MaxWordFreq = word.Value; MaxWord = word.Key; } } StrArrTopTenWords[i] = MaxWord; DicWordsFreq.Remove(MaxWord); MaxWord = ""; MaxWordFreq = 0; } // DicWordsFreq.Clear(); return(StrArrTopTenWords); }
private void TimeToolStripMenuItem_Click(object sender, EventArgs e) { try { string bufferText = Clipboard.GetText(); Clipboard.SetText(Convert.ToString(System.DateTime.Now)); FileText.Paste(); Clipboard.SetText(bufferText); } catch { Clipboard.SetText(Convert.ToString(System.DateTime.Now)); FileText.Paste(); } }
public static Dictionary <int, int> WordsDistributionSingle(string StrDirectory) { var StrEnumFiles = Directory.EnumerateFiles(StrDirectory, "*.txt"); var DicWordsFreq = new Dictionary <string, int>(); var DicWordsDistrib = new Dictionary <int, int>(); String[] StrArrWords; string FileText; foreach (var file in StrEnumFiles) { Char[] separators = { ' ', ',', '-', '.', '!', '?', '\"', '\n', '\r' }; FileText = File.ReadAllText(file, System.Text.Encoding.Default); StrArrWords = FileText.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (var word in StrArrWords) { String lowerWord = word.ToLower(); if (!DicWordsFreq.ContainsKey(lowerWord)) { DicWordsFreq.Add(lowerWord, 1); } else { DicWordsFreq[lowerWord] += 1; } } } foreach (var word in DicWordsFreq) { if (!DicWordsDistrib.ContainsKey(word.Value)) { DicWordsDistrib.Add(word.Value, 1); } else { DicWordsDistrib[word.Value] += 1; } } return(DicWordsDistrib); }
public override void CreateSyntax(FileText owner, Storage.Character reference, CreateSyntaxResult result) { var character = reference; if (character.Text == ' ') { if (owner.Last is Space space) { space.Remove(); new Space(owner, space.ReferenceBegin, reference); } else { new Space(owner, reference, reference); } } }
private void PrintFile(string path) { if (InvokeRequired) { Invoke(_addMessage, path); return; } string file = string.Empty; using (StreamReader sr = new StreamReader(path)) { file = sr.ReadToEnd(); } FileText.Clear(); FileText.SelectionStart = FileText.TextLength; FileText.SelectionLength = file.Length; FileText.AppendText(file + Environment.NewLine); }
public static string[] TopTenWordsParallel(string StrDirectory) { var StrEnumFiles = Directory.EnumerateFiles(StrDirectory, "*.txt"); var DicWordsFreq = new ConcurrentDictionary <string, int>(); String[] StrArrWords; string FileText; string MaxWord = ""; int MaxWordFreq = 0; Char[] separators = { ' ', ',', '-', '.', '!', '?', '\"', '\n', '\r' }; Parallel.ForEach(StrEnumFiles, (file) => { FileText = File.ReadAllText(file, System.Text.Encoding.Default); StrArrWords = FileText.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (var word in StrArrWords) { String lowerWord = word.ToLower(); DicWordsFreq.AddOrUpdate(lowerWord, 1, (sKey, oldValue) => oldValue + 1); } }); string[] StrArrTopTenWords = new string[10]; for (int i = 0; i < StrArrTopTenWords.Length; i++) { foreach (var word in DicWordsFreq) { if (word.Value > MaxWordFreq) { MaxWordFreq = word.Value; MaxWord = word.Key; } } StrArrTopTenWords[i] = MaxWord; DicWordsFreq.TryRemove(MaxWord, out MaxWordFreq); MaxWord = ""; MaxWordFreq = 0; } // DicWordsFreq.Clear(); return(StrArrTopTenWords); }
private void GitTree_AfterSelect(object sender, TreeViewEventArgs e) { var item = e.Node.Tag as GitItem; if (item == null) { return; } if (item.IsBlob) { FileText.ViewGitItem(item.FileName, item.Guid); } else if (item.IsCommit) { FileText.ViewText(item.FileName, LocalizationHelpers.GetSubmoduleText(Module, item.FileName, item.Guid)); } else { FileText.ViewText("", ""); } }
public static ConcurrentDictionary <string, int> WordFreqParallel(string StrDirectory) { var StrEnumFiles = Directory.EnumerateFiles(StrDirectory, "*.txt"); var DicWordsFreq = new ConcurrentDictionary <string, int>(); String[] wordsArray; string FileText; Char[] separators = { ' ', ',', '-', '.', '!', '?', '\"', '\n', '\r' }; Parallel.ForEach(StrEnumFiles, (file) => { FileText = File.ReadAllText(file, System.Text.Encoding.Default); wordsArray = FileText.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (var word in wordsArray) { String lowerWord = word.ToLower(); DicWordsFreq.AddOrUpdate(lowerWord, 1, (sKey, oldValue) => oldValue + 1); } }); Console.WriteLine("Количество слов" + DicWordsFreq.Values.Sum()); // DicWordsFreq.Clear(); return(DicWordsFreq); }
private void tvGitTree_AfterSelect(object sender, TreeViewEventArgs e) { ThreadHelper.JoinableTaskFactory.RunAsync(ViewItem); Task ViewItem() { return(e.Node?.Tag is GitItem gitItem ? ViewGitItemAsync(gitItem) : Task.CompletedTask); } Task ViewGitItemAsync(GitItem gitItem) { switch (gitItem.ObjectType) { case GitObjectType.Blob: case GitObjectType.Commit: { var file = new GitItemStatus { IsTracked = true, Name = gitItem.Name, TreeGuid = gitItem.ObjectId, IsSubmodule = gitItem.ObjectType == GitObjectType.Commit }; return(FileText.ViewGitItemAsync(file)); } default: { return(FileText.ViewTextAsync("", "")); } } } }
static int CountSentence() { Console.WriteLine("5. Count number of sentences in the file."); string FileText; try { FileText = File.ReadAllText("3.txt"); } catch (FileNotFoundException) { Console.WriteLine("Could not find file 3.txt"); return(1); } string[] Words = FileText.Split('.', '?', ';', '!'); int SentenceQty = 0; foreach (string word in Words) { SentenceQty++; } Console.WriteLine("Number of sentences is: " + SentenceQty); return(0); }
static int CountWords() { Console.WriteLine("3. Count number of words in the file."); string FileText; try { FileText = File.ReadAllText("3.txt"); } catch (FileNotFoundException) { Console.WriteLine("Could not find file 3.txt"); return(1); } string[] Words = FileText.Split(' '); int WordsQty = 0; foreach (string word in Words) { WordsQty++; } Console.WriteLine("Number of words is: " + WordsQty); return(0); }
static void Main(string[] args) { FileText ft = new FileText(); ft.Filename = System.IO.Directory.GetCurrentDirectory() + @"\11.db.txt"; Sinhvien sv = new Sinhvien(); ft.ResetData(); string[] CSDL = File.ReadAllLines(System.IO.Directory.GetCurrentDirectory() + @"\Csdl-bk.txt"); string[] Nguyenvong = File.ReadAllLines(System.IO.Directory.GetCurrentDirectory() + @"\dknguyenvong.txt"); for (int k = 1100; k < 1200; k++) { string[] str = CSDL[k].Split(); foreach (string st in str) { st.Trim(); } sv.sbd = str[0]; sv.ten = str[1]+str[2]+str[3]; sv.ngaysinh = str[4]; sv.khuvuc = str[5]; sv.doituong = str[6]; sv.uutien = str[7]; for (int i = 0; i < 13; i++) { if (str[i + 8] == "NA") sv.diemthi[i] = -1; else sv.diemthi[i] = Double.Parse(str[i+8].ToString()); } //toan=0, van=1, ly=2, hoa=3, sinh=4, su=5, dia=6, anh=7, nga=8, phap=9, trung=10, duc=11, nhat=12 str = Nguyenvong[k].Split(); foreach (string st in str) { st.Trim(); } int dem=1; for(int i=0;i<4;i++) for (int j = 0; j < 2; j++) { if (str[dem] == "NA") sv.nguyenvong[i,j] = null; else sv.nguyenvong[i,j] = str[dem]; dem++; } for (int i = 0; i < 4; i++) { if (sv.nguyenvong[i, 0] != null) { double d; sv.ketqua[0] = sv.sbd; sv.ketqua[1] = (i+1).ToString(); sv.ketqua[2] = sv.nguyenvong[i, 0]; string[] s = sv.nguyenvong[i, 1].Split(','); if (s[3] == "1") d = (sv.diemcacmon(s[0]) * 2 + sv.diemcacmon(s[1]) + sv.diemcacmon(s[2])) / 4 + sv.diemkhuvuc(sv.khuvuc) / 3 + sv.diemuutien(sv.uutien); else d = (sv.diemcacmon(s[0]) + sv.diemcacmon(s[1]) + sv.diemcacmon(s[2])) / 3 + sv.diemkhuvuc(sv.khuvuc) / 3 + sv.diemuutien(sv.uutien); sv.ketqua[3] = d.ToString(); string ketqua = sv.ketqua[0] + " " + sv.ketqua[1] + " " + sv.ketqua[2] + " " + sv.ketqua[3]; ft.WriteData(ketqua); } } } Console.WriteLine("Thuc hien thanh cong! Xem ket qua tai file text 11.db.txt trong thu muc debug cua project"); Console.ReadKey(); }