Spread the love

Today we step back into work on NaNoE for ourselves. There are simple things we are doing for our strategy here, it should help with converting our novels written in NaNoE in the future.

Firstly, with the latest Windows 10 update, and my Visual Studio 2019 up to date, I have to enable developer mode. I have never needed to do that in the past, so technically, I have no idea if people will be able to even use NaNoE, and helpers, on their computers unless they unlock developer mode? My main question is “Why?” I have no idea why it looks this way.

New Helper: DocToNne

Considering the fact that we can generate DocX files through NaNoE it would make sense to finally have a way to go the other way. Firstly, let us open an existing word document file:

            OpenFileDialog openFileDialogue = new OpenFileDialog();
            openFileDialogue.Filter = "Word Documents|*.doc; *.docx";

            if (openFileDialogue.ShowDialog() == DialogResult.OK)
            {

            }

Now, let us assume we only have chapter numbers, followed by the text in our document. I used Word 2013‘s table of contents, remove all of that so that we can start at the first Chapter:

Ch. 1 – [9]

Chapter Headings

Take note, I want the Chapter heading in a way that can be easy to understand. I personally made it Ch. 1 for the chapters, then added extra on in the square brackets afterward. That is the page count, this is personally since I need to reorganize my chapters.

So, first off, let us start creating the nne file for ourselves. So, from nuget in VS we need Microsoft.Office.Interop.Word. With this, we can start with the first paragraph, as in the first line, with the title:

            OpenFileDialog openFileDialogue = new OpenFileDialog();
            openFileDialogue.Filter = "Word Documents|*.doc; *.docx";

            if (openFileDialogue.ShowDialog() == DialogResult.OK)
            {
                Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
                var path = openFileDialogue.FileName;
                var miss = System.Type.Missing;
                Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(path,
                    miss, miss, miss, miss,
                    miss, miss, miss, miss,
                    miss, miss, miss, miss,
                    miss, miss, miss);
                
                using (FileStream fileStream = new FileStream("output.nne", FileMode.Create))
                {
                    using (StreamWriter fileWriter = new StreamWriter(fileStream))
                    {
                        fileWriter.WriteLine("hNone\r\nHNo Doc Data\r\npNone\r\nPNo Doc Data");

                        foreach (Paragraph p in wordDoc.Paragraphs)
                        {
                            var line = p.Range.Text.Trim();
                            if (line.IndexOf("Ch. ") == 0)
                            {
                                fileWriter.WriteLine("p" + line);
                            }
                            else
                            {
                                fileWriter.WriteLine("P" + line);
                            }
                        }
                    }
                }

As you can see, this is a very simplified reader for these documents. On my PC, it is quite quick, just wait for what we add below then you can move forward. If you have the word document open it will be slower, and you must keep the word documents open.

Taking the output.nne you can move it to your NaNoE use directory, rename it, then you have it in the nne format again. This should work for Doc and Docx files now.

You will see on GitHub before moving on I added a single check, and further in the code added a notification:

                if (File.Exists("output.nne"))
                {
                    File.Delete("output.nne");
                }
//              ---
                MessageBox.Show("Complete", "File converted to 'output.nne'", MessageBoxButtons.OK, MessageBoxIcon.Information);
This is Accidental Distances converted back!

Updates the NaNoE Edit

First, I found a major flaw in NaNoE, the Edit function has several flaws. The words.txt seems to not allow “cab” with how we use it. Yet, on line 3448 it has the word “cab”. I figure I probably have logic errors in the code we used before.

I figure I will find a nuget package to use. I finally get PlatformSpellCheck by bbowyersmyth to work for us. You can take a look at it on GitHub.

The changes were quite simple, and it seems to work perfectly as is:

        private static SpellChecker spellChecker = new PlatformSpellCheck.SpellChecker();

        /// <summary>
        /// Load the file, generate the array, remove the file itself from memory
        /// </summary>
        public static void Init()
        {

        }
//      ---
        public static List<string> Process(string para)
        {
//      ---
            var speller = RunLongSpellCheck(para);
            if (speller != null)
            {
                ans.Add("Spelling? " + speller);
            }

            // Debug
            //ans.Add("This isnt a problem. Just a test.");
            // =========================================================
            // = End Checks                                            =
            // =========================================================
            return ans;
        }
//     ---
        /// <summary>
        /// Spellcheck entire novel
        /// </summary>
        /// <param name="ling">Line to check</param>
        internal static string RunLongSpellCheck(string ling)
        {
            string spellErrors = "";
            var words = ling.Split(' ');
            for (int i = 0; i < words.Count(); i++)
            {
                var truncated = words[i].Replace('.', ' ')
                        .Replace('"', ' ')
                        .Replace(',', ' ')
                        .Replace(';', ' ')
                        .Replace(" ", "");
                if (spellChecker.Check(truncated).Count() > 0)
                {
                    if (spellChecker.Check(truncated.ToUpper()).Count() > 0)
                    {
                        spellErrors += truncated + ", ";
                    }
                }
            }
            if (spellErrors.Length > 0)
            {
                return spellErrors;
            }
            return null;
        }

So we check every word separately, removing some of the spacing, such as commas and full stops, then if there is a spelling error try to make sure it isn’t something that should be capitalized.

The capitalization? This showed “I” as a spelling error in lowercase, similarly, it also came out for “NASA”. This also adds a caveat here, you could have “nasa” in lower case… Though, I figure that can come in the word document edits.

I also know I could write it with a single Replace(…) less, I just figure it doesn’t make a big enough impact to worry about it now.

So, we should have proper spellchecking in NaNoE from now on, hopefully with no major bugs.

I added the position number in front of the Spelling suggestions for us as well. Seen in the repo, not above.

Yes, as you could see above, I named it ling by accident, I will fix that one day in the future. I would rather just fix code at a later stage.

Let’s Add Tenses

So, we should try to make sure our tenses are correct in our writing. Not accidentally going past, present, and future. We can do different tenses in our writing, it is just adding checks for what we should be careful of. It would be simplest to add using a dictionary:

        private static Dictionary<string, string> tenseDict = new Dictionary<string, string>();

        /// <summary>
        /// Load the file, generate the array, remove the file itself from memory
        /// </summary>
        public static void Init()
        {
            var tenses = File.OpenRead("grammarhelp.txt");
            using (StreamReader tensesReader = new StreamReader(tenses))
            {
                string line = null;
                while ((line = tensesReader.ReadLine()) != null)
                {
                    var tenseSplit = line.Split(',');
                    tenseDict.Add(tenseSplit[1], tenseSplit[0]);
                }
            }

            tenses.Close();
        }

You will see I added a text file with comma-separated values to the project. Since the spacing is a key aspect, we use a different method for this dictionary key search:

            // Tenses
            var spacedpara = para.Replace('.', ' ')
                        .Replace('"', ' ')
                        .Replace(',', ' ')
                        .Replace(';', ' ');
            foreach (var k in tenseDict.Keys)
            {
                if (spacedpara.Contains(k))
                {
                    ans.Add("Tense Check: " + k);
                }
            }

As you can tell, this technically doesn’t do the work for you. It doesn’t show where the word that might be in the incorrect tense is, it just lets you know it is somewhere you should double-check past tense words.

Two years after we had people starting to occupy the moon; we got near 24 thousand people up there.

Got

He is an example of Accidental Distances. This is in Paragraph 6 in the first chapter. Technically? This isn’t too bad, it just serves as an example.

Two years after we had people starting to occupy the moon; we’ve managed to get near 24 thousand people up there.

Without Got

It is just slight adjustments you may want to make in your plot so that the timing of the story makes sense. This should be all the editing to NaNoE we need currently.

The Next Adjustments

I’ve spent the time to update NaNoEdit, just so that we can have more of an idea of what we can change in the edit. More descriptive with more explanations.

Similarly, I adjusted the output to a Word document so that it can have the chapters titled with “Ch. <num>”. This is such a tiny adjustment, yet, it is personal preference.

Please note, I cannot run it under Release mode. I have to stick to Debug, the exception doesn’t share details…

Tiny little adjustments in the main project, so there isn’t any reason to share them here…

The Grind

Yes, technically this is “a grind.” The first part of the grind happens to be using NaNoE to make the entire novel better using the edit suggestions in it. There are 1668 paragraphs to go through. From 1 to 43 it took 2 hours odd for me. It is a slow process for me.

That would mean roughly 39 hours of work incoming. Though, that does not mean every paragraph would need the editing. Similarly, I will get quicker at it over time. It is still a lot considering over 5 days that would be 7 hours a day. We can just hope it only takes two or three days.