Skip to content

Commit

Permalink
Added word frequency list and made new release
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Jul 8, 2017
1 parent b3e1d6a commit 06b3f67
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 7 deletions.
28 changes: 26 additions & 2 deletions EditTools/Ribbon1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions EditTools/Ribbon1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,71 @@ private void btn_AcceptFormatting_Click(object sender, RibbonControlEventArgs e)
view.ShowInsertionsAndDeletions = true;
MessageBox.Show("Formatting changes have been accepted.");
}

private void btn_WordFreq_Click(object sender, RibbonControlEventArgs e)
{
Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
Dictionary<string, uint> wordlist = new Dictionary<string, uint>();
Regex re_allnums = new Regex(@"^\d+$");

foreach (Word.Range rng in TextHelpers.GetText(doc))
{
string txt = rng.Text;

//strip punctuation
txt = TextHelpers.StripPunctuation(txt);


string[] substrs = Regex.Split(txt, @"\s+");
foreach (string word in substrs)
{
Match m = re_allnums.Match(word);
if (!m.Success)
{
if (wordlist.ContainsKey(word)) {
wordlist[word]++;
} else
{
wordlist.Add(word, 1);
}
}

}
}

//Create new document
Word.Document newdoc = Globals.ThisAddIn.Application.Documents.Add();
Word.Paragraph pgraph;

//Intro text
pgraph = newdoc.Content.Paragraphs.Add();
pgraph.set_Style(newdoc.Styles["Heading 1"]);
pgraph.Range.Text = "Word Frequency List\n";
pgraph = newdoc.Content.Paragraphs.Add();
pgraph.set_Style(newdoc.Styles["Normal"]);
pgraph.Range.Text = "Capitalization is retained as is. That means that words that appear at the beginning of a sentence will appear capitalized. Don't forget that you can sort the table!\n";

pgraph = newdoc.Content.Paragraphs.Add();
pgraph.Range.InsertBreak(Word.WdBreakType.wdSectionBreakContinuous);
Word.Section sec = newdoc.Sections[2];
sec.PageSetup.TextColumns.SetCount(3);

var words = wordlist.ToList();
words.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value));
newdoc.Tables.Add(pgraph.Range, words.Count, 2);
int row = 1;
foreach (var pair in words)
{
Word.Cell cell = newdoc.Tables[1].Cell(row, 1);
cell.Range.Text = pair.Key;
cell = newdoc.Tables[1].Cell(row, 2);
cell.Range.Text = pair.Value.ToString();
row++;
}

pgraph = newdoc.Content.Paragraphs.Add();
pgraph.Range.InsertBreak(Word.WdBreakType.wdSectionBreakContinuous);
newdoc.GrammarChecked = true;
}
}
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ These are just a couple tools I coded for use where I work.
Features include a

* one-click language applicator,
* one-click "accept formatting changes,"
* proper noun discrepancy checker,
* "singular data" finder,
* word list generator,
* "singular data" finder, and
* word frequency generator,
* proper noun discrepancy checker,
* one-click "accept formatting changes," and
* comment boilerplate manager.

The language applicator applies the language to *all* text, including notes, headers, and footers. Text boxes and frames may be skipped. I haven't done extensive testing around those.
Expand Down
4 changes: 2 additions & 2 deletions deploy/make-installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
; The version number. It is suggested to use the semantic versionin
; scheme (http://semver.org), but this is not a must. This version
; information may contain text.
#define SEMANTIC_VERSION "1.1.0"
#define SEMANTIC_VERSION "1.2.0"

; The version in four-number format
#define FOUR_NUMBER_VERSION "1.1.0.0"
#define FOUR_NUMBER_VERSION "1.2.0.0"

; The year(s) of publication (e.g., "2014-2017")
#define PUB_YEARS "2017"
Expand Down
Binary file modified screen-capture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06b3f67

Please sign in to comment.