KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: How to convert selected text to uppercase, lowercase, or title case?
Topic Summary:
Created On: 01/06/2021 11:07 AM
Status: Post and Reply
Linear : Threading : Single : Branch
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/06/2021 11:07 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - Edgar - 01/06/2021 11:20 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/07/2021 11:03 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - Alan Cantor - 01/06/2021 12:07 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/07/2021 11:02 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - Lunis Orcutt - 01/06/2021 01:51 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/07/2021 11:02 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - Alan Cantor - 01/07/2021 12:05 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - Alan Cantor - 01/07/2021 04:01 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - Lunis Orcutt - 01/07/2021 04:35 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/08/2021 02:06 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/08/2021 02:22 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - Alan Cantor - 01/08/2021 02:49 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/08/2021 07:40 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - Alan Cantor - 01/08/2021 10:29 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - Edgar - 01/09/2021 09:59 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - wristofdoom - 01/09/2021 10:45 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - kkkwj - 01/10/2021 02:46 AM  
 How to convert selected text to uppercase, lowercase, or title case?   - Alan Cantor - 01/10/2021 01:32 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - Edgar - 01/10/2021 02:40 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - kkkwj - 01/20/2021 08:43 PM  
 How to convert selected text to uppercase, lowercase, or title case?   - dilligence - 01/20/2021 09:53 PM  
Keyword
 01/06/2021 11:07 AM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

In apps with full Dragon Select-and-Say support, I can say "all caps that" to convert the selected text to uppercase.

 

I want to create a custom command that will force that same behavior in apps that do not have full Dragon support.

 

I have an autohotkey script that currently does this same behavior; for example, a press control, shift, and 1, and the selected text is converted to uppercase. but triggering the Autohotkey script via a Dragon command is not working too well. So I'd like to know how to do this entirely within Dragon.

 

I don't know the syntax, but here's how I would approach it:

 

oldClipboard = { current value of the clipboard } ' I want to do is create a variable called "oldclipboard" and store the current clipboard value in that variable

SendKeys "^c"  ' this is to copy the selected text to my clipboard

SendKeys ucase clipboard 'now I want to send the value of the new "clipboard" but converted uppercase

clipboard = oldclipboard ' finally, I want to restore the value of the clipboard to the original value that was in there before the command began

 

Assuming that this would be the best way to approach it, I am having trouble finding the syntax that would allow me to express this behavior.

Or maybe there is a better way to execute the same command, and force selected text to change case while also retaining whatever is in my clipboard before the command begins?

If I get this working, the my next steps would be to apply the same behavior to lowercase and to title case.

Thank you



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 01/06/2021 11:20 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1036
Joined: 04/03/2009

Both uppercase and lowercase are going to be very easy but title case is a can of worms! There are a few different definitions of "title case": "This is Title Case", "This Is Title Case"," This is also Title Case" and "This is Also Title Case". The most common definition of "title case" is: ALWAYS capitalize the first letter of the first word, OBVIOUSLY, capitalize the first letter of any proper noun, with a few exceptions (and this exception list varies from governing body to governing body) NEVER capitalize three letter words and RARELY capitalize four letter words. To make matters worse, while Dragon has both all uppercase and all lowercase commands built in, it has no built-in title case; for that you will need third-party help (I use C#, but AutoIT or AutoHotKey might also have a "title case" command built-in). Your proposed solution above should work just fine with a little fine tuning - post your code if you get into problems.

-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 01/07/2021 11:03 AM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

My script is working except for the part that retains the original clipboard. Here's what I have currently:

Sub Main
oldClipboard = Clipboard ' I want to save the current/hold value of the clip board in a variable
Wait 0.2
SendKeys "^c"
Wait 0.2
SendKeys UCase Clipboard
Wait 0.2
Clipboard = oldclipboard ' I want to restore the clipboard to the original value that was in there before the command began
End Sub

it says the syntax is incorrect when I try to save the command. However, the script works as I would expect if I remove the first line and the last line. So there is something wrong with the custom variable.

What's the correct syntax for declaring variables and reassigning their values?



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 01/06/2021 12:07 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 3987
Joined: 12/08/2007

If you have an AutoHotkey script that you like that is triggered by Shift + Ctrl + 1, you can make a Dragon command that outputs this key combination.

Create a new command in the Command Browser. Set the "Command Type" to "Step-by-Step" and click the "Insert" button in the lower-right corner. You will be prompted to press a key combination. Shift + Ctrl + 1 is valid.

I've looked at many AutoHotkey scripts that rotate through three case states: ALL CAPS, all lower case, and Title Case Everything. The challenge is that different applications require different coding approaches. For example, what works in Notepad may fail occasionally in WordPad.
 01/07/2021 11:02 AM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

If you have an AutoHotkey script that you like that is triggered by Shift + Ctrl + 1, you can make a Dragon command that outputs this key combination.

 

I currently do have a Dragon command set up like that to trigger the autohotkey script, but its behavior is very inconsistent. It does not trigger the command as reliably as the actual Autohotkey script when I press the buttons on the keyboard. And that's in addition to the other issues that you mentioned.



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.



 01/06/2021 01:51 PM
User is offline View Users Profile Print this message

Author Icon
Lunis Orcutt
Top-Tier Member

Posts: 38491
Joined: 10/01/2006

You already have an alternative solution in your KnowBrainer commands utility. If you pause before and after your dictation you can apply the following 3 KnowBrainer commands:

 

Lower <dictation> applies lowercase to to your following dictation
Example: “the liberal dems took the senate”

 

Print <dictation> same as Lower <dictation> but additionally adds a space to the end of your phrase

 

Title <dictation> applies Title Case to your following dictation
Example: “The liberal Dems Took the Senate”

Upper <dictation> applies ALL CAPS to your following dictation
Example: “THE LIBERAL DEMS TOOK THE SENATE”



-------------------------

Forum Mission Statement
Trial Downloads
Dragon/Sales@KnowBrainer.com 
(615) 884-4558 ext 1

 01/07/2021 11:02 AM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

I use these commands currently when I am writing new text, but I'm frequently in a situation where I need to change capitalization of something after it's already been written. So what I am looking for here is different.



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 01/07/2021 12:05 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 3987
Joined: 12/08/2007

You're so close. Delete the equal sign from the second last line of the script and you should be good to go.
 01/07/2021 04:01 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 3987
Joined: 12/08/2007

When it comes time to write a script to convert the selection to title case, you'll find several examples in this 2013 thread:

https://www.knowbrainer.com/pubforum/messageview.cfm?catid=4&threadid=16949



 01/07/2021 04:35 PM
User is offline View Users Profile Print this message

Author Icon
Lunis Orcutt
Top-Tier Member

Posts: 38491
Joined: 10/01/2006

KnowBrainer 2017 (w/2020 AI Commands) end users can now enjoy the following new commands which can be applied to selected text:

 

UPPER THAT = ALL CAPS

Title That = Initial Capitalization

lower that = lowercase



-------------------------

Forum Mission Statement
Trial Downloads
Dragon/Sales@KnowBrainer.com 
(615) 884-4558 ext 1

 01/08/2021 02:06 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

Thanks, I did not realize there was a new version of the Knowbrainer commands.

I updated and I see that the UPPER THAT and similar commands have the same issue I'm trying to get around-- the clipboard text gets overwritten.

Is there a update log that shows what new commands have been added or improved in the new Knowbrainer version?



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 01/08/2021 02:22 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

Thanks for your help.

 

Using a modified version of the final script in that thread, I have created commands which are working well for me in Dragon NaturallySpeaking.

 

Convert the selected text to ALL CAPS:

 

Sub Main
oldClipboard = Clipboard
Wait 0.1
SendKeys "^c"
Wait 0.1
SendKeys UCase Clipboard
Wait 0.1
Clipboard oldclipboard
End Sub

Convert the selected text to lowercase:

 

Sub Main
oldClipboard = Clipboard
Wait 0.1
SendKeys "^c"
Wait 0.1
SendKeys LCase Clipboard
Wait 0.1
Clipboard oldclipboard
End Sub
 

 

Convert the selected text to Title Case:

 

'Script by Lindsay Adam www.pcbyvoice.com
' modified by Alan Cantor to capitalize the first letter of a paragraph
' and the first letter after a tab
'modified by edgar to start with the first word's letter
' and to make sure that the first letter after both an
' open parentheses ( and open square bracket [ get capitalized
' Also made the single holdout variable camelCase

' Wristofdoom 01/08/2021 update: preserves original clipboard

Sub Main
Dim capNext As Boolean
Dim myText As String
Dim characterToChange As String
Dim precedingCharacter As String

oldClipboard = Clipboard 'wristofdoom: save the current/hold value of the clip board in a variable
capNext = True
myText = ""
characterToChange = "
precedingCharacter = a

SendKeys"^c"
Wait 0.1
For i = 1 To Len (Clipboard)
characterToChange = Mid(Clipboard, i, 1)
If i > 1 Then
precedingCharacter = Mid(Clipboard, i - 1, 1)
If precedingCharacter = "(" Then
capNext = True
ElseIf precedingCharacter = "[" Then
capNext = True
End If
End If
If capNext And (characterToChange >= "a" Or characterToChange <= "z") Then
myText = myText & UCase (characterToChange)
capNext = False
Else
myText = myText & characterToChange
End If
If characterToChange= " " Or characterToChange= Chr$(9) Or characterToChange= Chr$(10) Or characterToChange= Chr$(13) Then
capNext = True
End If
Next
Clipboard myText
SendKeys"^v"
Wait 0.1
Clipboard oldClipboard ' wristofdoom: restore clipboard to the original clipboard
End Sub

 



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 01/08/2021 02:49 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 3987
Joined: 12/08/2007

The Windows clipboard is flaky. There is often a "penalty" to pay to preserve the clipboard in custom Dragon commands. Commands that use and reuse the clipboard run more slowly, can be less reliable, and may give inconsistent results.

Scripts that manipulate the clipboard two or more times are, in my experience, slightly unreliable. Inserting pauses between steps helps -- but not always. If my Dragon commands that repeatedly act on the clipboard work 99% of the time, I pat myself on the back for a job well done. But I recognize that these scripts will occasionally fail.

Other scripting languages do a better job of managing the clipboard than Dragon Advanced Scripting. In VBA (the macro language for Office applications) it's possible to act on a selected region without even recruiting the clipboard. This works much better than copying or cutting, assigning the clipboard to a variable, and later assigning the variable to the clipboard. So when I'm writing Dragon commands for Microsoft Word (and other Office products), I try to use VBA. AutoHotkey offers a "ClipWait" instruction that waits until the (empty) clipboard is populated. But it doesn't always work: I think the reason is the inherent flakiness of the Windows clipboard.
 01/08/2021 07:40 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

Built-in commands for changing capitalization work fine for the Microsoft applications, so in this particular case using VBA isn't useful. I need to be able to convert case and hang onto my clipboard in other apps that do not have Select-and-Say functionality.


That being said, very interesting and good to know. Thanks for the help.



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 01/08/2021 10:29 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 3987
Joined: 12/08/2007

Nice script. Given that this script manipulates the clipboard as much as it does, it runs reasonably quickly. Congratulations on developing a working prototype for a really useful task. I just might "borrow" it!

If you enjoy these kinds of challenges, at least two refinements are possible:

1. If the character to the immediate left is an open quote, the script misses it. E.g., "hello" stays "hello" instead of becoming "Hello"

2. It looks like the script might not transform selected text to Title Case if the text is in ALL CAPS to start. This may not be an issue; it depends on how you want the script to work.
 01/09/2021 09:59 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1036
Joined: 04/03/2009

Here's the way I modified Lindsay’s script (does not preserve clipboard):


'WinWrap Basic by Lindsay Adam www.pcbyvoice.com

' modified by Alan Cantor to capitalize the first letter of a paragraph

'    and the first letter after a tab

'modified by edgar to start with the first word's letter

'    and to make sure that the first letter after an:

'    open parentheses ( , open square bracket [ , an open quote " ,

'    an open curly quote “, a dash – , a bullet point ? , or a hyphen -

'    get capitalized

'    Also made the single holdout variable camelCase


   Dim capNext As Boolean

   Dim clip, internalText, characterToChange, precedingCharacter As String

   Dim length As Integer

   capNext = True

   internalText = ""

   characterToChange = ""

   precedingCharacter = "a"


   SendKeys "^c", 1

   Wait 0.3

   clip = Clipboard

   Wait 0.3


   length = Len (clip)

   For iteration = 1 To length

      characterToChange = Mid(clip, iteration, 1)

      If iteration > 1 Then

         precedingCharacter = Mid(clip, iteration - 1, 1)

         If precedingCharacter = "(" Then

            capNext = True

         ElseIf precedingCharacter = "[" Then

            capNext = True

         ElseIf precedingCharacter = "¿" Then

            capNext = True

         ElseIf precedingCharacter = "…" Then

            capNext = True

         ElseIf precedingCharacter = Chr$(149) Then 'bullet point

            capNext = True

         ElseIf precedingCharacter = Chr$(147) Then 'open curly quote “

            capNext = True

         ElseIf precedingCharacter = Chr$(34) Then 'open regular quote "

            capNext = True

         ElseIf precedingCharacter = "-" Then

            capNext = True

         ElseIf precedingCharacter = Chr$(150) Then 'dash –

            capNext = True

         ElseIf precedingCharacter = Chr$(161) Then 'inverted exclamation mark ¡

            capNext = True

         End If

      End If

      If capNext And (characterToChange >= "a" Or characterToChange <= "z") Then

         internalText = internalText & UCase (characterToChange)

         capNext = False

      Else

         internalText = internalText & characterToChange

      End If

      If characterToChange = " " Or characterToChange = Chr$(9) Or _

      characterToChange = Chr$(10) Or characterToChange = Chr$(13) Or _

      characterToChange = Chr$(34) Then

         capNext = True

      End If

   Next iteration

   Replace (internalText, "'", Chr$(130))


   Wait 0.3

   Clipboard internalText

   Wait 0.3



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 01/09/2021 10:45 AM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 105
Joined: 09/03/2020

I stole Edgar's script to address issue number one, and added in the clipboard preservation functionality, and also reduced the pause time from 0.3 to 0.2.

I modified Edgar's script to address issue number two by converting the selected text to lowercase before saving it in the variable.

This is working for me so far:

 

"Force title case"

 

'WinWrap Basic by Lindsay Adam www.pcbyvoice.com
' modified by Alan Cantor to capitalize the first letter of a paragraph
'    and the first letter after a tab
'modified by edgar to start with the first word's letter
'    and to make sure that the first letter after an:
'    open parentheses ( , open square bracket [ , an open quote " ,
'    an open curly quote ", a dash  -  , a bullet point ? , or a hyphen -
'    get capitalized
'    Also made the single holdout variable camelCase
' Wristofdoom 01/09/2021 update: preserves original clipboard and makes it work for tax that's already in all caps

Sub Main
   oldClipboard = Clipboard 'wristofdoom: save the current/hold value of the clip board in a variable
   Dim capNext As Boolean
   Dim clip, internalText, characterToChange, precedingCharacter As String
   Dim length As Integer
   capNext = True
   internalText = ""
   characterToChange = ""
   precedingCharacter = "a"

   SendKeys "^c", 1
   Wait 0.2
   clip = LCase Clipboard 'wristofdoom: convert clipboard to lowercase ensures the command works on text that is in all caps
   Wait 0.2

   length = Len (clip)
   For iteration = 1 To length
      characterToChange = Mid(clip, iteration, 1)
      If iteration > 1 Then
         precedingCharacter = Mid(clip, iteration - 1, 1)
         If precedingCharacter = "(" Then
            capNext = True
         ElseIf precedingCharacter = "[" Then
            capNext = True
         ElseIf precedingCharacter = "¿" Then
            capNext = True
         ElseIf precedingCharacter = "..." Then
            capNext = True
         ElseIf precedingCharacter = Chr$(149) Then 'bullet point
            capNext = True
         ElseIf precedingCharacter = Chr$(147) Then 'open curly quote "
            capNext = True
         ElseIf precedingCharacter = Chr$(34) Then 'open regular quote "
            capNext = True
         ElseIf precedingCharacter = "-" Then
            capNext = True
         ElseIf precedingCharacter = Chr$(150) Then 'dash  - 
            capNext = True
         ElseIf precedingCharacter = Chr$(161) Then 'inverted exclamation mark ¡
            capNext = True
         End If
      End If
      If capNext And (characterToChange >= "a" Or characterToChange <= "z") Then
         internalText = internalText & UCase (characterToChange)
         capNext = False
      Else
         internalText = internalText & characterToChange
      End If
      If characterToChange = " " Or characterToChange = Chr$(9) Or _
      characterToChange = Chr$(10) Or characterToChange = Chr$(13) Or _
      characterToChange = Chr$(34) Then
         capNext = True
      End If
   Next iteration
   Replace (internalText, "'", Chr$(130))
   Wait 0.2
   Clipboard internalText
   Wait 0.2
   SendKeys "^v"
   Wait 0.2
   Clipboard oldClipboard ' wristofdoom: restore clipboard to the original clipboard
End Sub





-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 01/10/2021 02:46 AM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 645
Joined: 11/05/2015

As Edgar said, defining and implementing title case is a can of worms. Depending on your definition, folding everything to lowercase is not a general solution. Try doing title case on "IBM announces new PC computer," for example. Or, "AFAIK, title case requires two separate lists of keywords to capitalize or ignore." Good luck!

-------------------------

Win10/x64, AMD Ryzen 7 3700X, 64GB RAM, Dragon 15.61, SP 6 PRO, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 01/10/2021 01:32 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 3987
Joined: 12/08/2007

Since we've taken this script this far, here's a possible enhancement. In the rules for title-case that I use, "a" and all non-acronym words that contain two and three letters are supposed to be lowercase.

Online, I found a list of frequently-used two and three letter words. I incorporated about 64 into the script.

This brute force solution cannot handle every situation. But this script could be made more "bulletproof" if one is inclined: only about 1000 three-letter words appear in the Scrabble dictionary, so expanding this script to handle more words is within reach.

Sub Main
' Collaboratively developed and improved by Lindsay Adams, Edgar, wristofdoom, and Alan Cantor
Dim capNext As Boolean
Dim oldClipboard, clip, internalText, characterToChange, precedingCharacter As String
Dim length As Integer

oldClipboard = Clipboard
capNext = True
internalText = ""
characterToChange = ""
precedingCharacter = "a"

SendKeys "^c", 1
Wait 0.2
clip = LCase (Clipboard)
Wait 0.2

length = Len (clip)
For iteration = 1 To length
characterToChange = Mid(clip, iteration, 1)
If iteration > 1 Then
precedingCharacter = Mid(clip, iteration - 1, 1)
If precedingCharacter = "(" Then
capNext = True
ElseIf precedingCharacter = "[" Then
capNext = True
ElseIf precedingCharacter = "¿" Then
capNext = True
ElseIf precedingCharacter = "..." Then
capNext = True
ElseIf precedingCharacter = Chr$(149) Then 'bullet point
capNext = True
ElseIf precedingCharacter = Chr$(147) Then 'open curly quote "
capNext = True
ElseIf precedingCharacter = Chr$(34) Then 'open regular quote "
capNext = True
ElseIf precedingCharacter = "-" Then
capNext = True
ElseIf precedingCharacter = Chr$(150) Then 'dash -
capNext = True
ElseIf precedingCharacter = Chr$(161) Then 'inverted exclamation mark ¡
capNext = True
End If
End If
If capNext And (characterToChange >= "a" Or characterToChange <= "z") Then
internalText = internalText & UCase (characterToChange)
capNext = False
Else
internalText = internalText & characterToChange
End If
If characterToChange = " " Or characterToChange = Chr$(9) Or _
characterToChange = Chr$(10) Or characterToChange = Chr$(13) Or _
characterToChange = Chr$(34) Then
capNext = True
End If
Next iteration

Replace (internalText, "'", Chr$(130))
' Fix title case for 64 common one-, two- and three-letter words
Let internalText = Replace (internalText, " A ", " a ")
Let internalText = Replace (internalText, " Of ", " of ")
Let internalText = Replace (internalText, " To ", " to ")
Let internalText = Replace (internalText, " In ", " in ")
Let internalText = Replace (internalText, " It ", " it ")
Let internalText = Replace (internalText, " Is ", " is ")
Let internalText = Replace (internalText, " Be ", " be ")
Let internalText = Replace (internalText, " As ", " as ")
Let internalText = Replace (internalText, " At ", " at ")
Let internalText = Replace (internalText, " So ", " so ")
Let internalText = Replace (internalText, " We ", " we ")
Let internalText = Replace (internalText, " He ", " he ")
Let internalText = Replace (internalText, " By ", " by ")
Let internalText = Replace (internalText, " Or ", " or ")
Let internalText = Replace (internalText, " On ", " on ")
Let internalText = Replace (internalText, " Do ", " do ")
Let internalText = Replace (internalText, " If ", " if ")
Let internalText = Replace (internalText, " Me ", " me ")
Let internalText = Replace (internalText, " My ", " my ")
Let internalText = Replace (internalText, " Up ", " up ")
Let internalText = Replace (internalText, " An ", " an ")
Let internalText = Replace (internalText, " Go ", " go ")
Let internalText = Replace (internalText, " No ", " no ")
Let internalText = Replace (internalText, " Us ", " us ")
Let internalText = Replace (internalText, " Am ", " am ")
Let internalText = Replace (internalText, " The ", " the ")
Let internalText = Replace (internalText, " And ", " and ")
Let internalText = Replace (internalText, " For ", " for ")
Let internalText = Replace (internalText, " Are ", " are ")
Let internalText = Replace (internalText, " But ", " but ")
Let internalText = Replace (internalText, " Not ", " not ")
Let internalText = Replace (internalText, " You ", " you ")
Let internalText = Replace (internalText, " All ", " all ")
Let internalText = Replace (internalText, " Any ", " any ")
Let internalText = Replace (internalText, " Can ", " can ")
Let internalText = Replace (internalText, " Had ", " had ")
Let internalText = Replace (internalText, " Her ", " her ")
Let internalText = Replace (internalText, " Was ", " was ")
Let internalText = Replace (internalText, " One ", " one ")
Let internalText = Replace (internalText, " Our ", " our ")
Let internalText = Replace (internalText, " Out ", " out ")
Let internalText = Replace (internalText, " Day ", " day ")
Let internalText = Replace (internalText, " Get ", " get ")
Let internalText = Replace (internalText, " Has ", " has ")
Let internalText = Replace (internalText, " Him ", " him ")
Let internalText = Replace (internalText, " His ", " his ")
Let internalText = Replace (internalText, " How ", " how ")
Let internalText = Replace (internalText, " Man ", " man ")
Let internalText = Replace (internalText, " New ", " new ")
Let internalText = Replace (internalText, " Now ", " now ")
Let internalText = Replace (internalText, " Old ", " old ")
Let internalText = Replace (internalText, " See ", " see ")
Let internalText = Replace (internalText, " Two ", " two ")
Let internalText = Replace (internalText, " Way ", " way ")
Let internalText = Replace (internalText, " Who ", " who ")
Let internalText = Replace (internalText, " Boy ", " boy ")
Let internalText = Replace (internalText, " Did ", " did ")
Let internalText = Replace (internalText, " Its ", " its ")
Let internalText = Replace (internalText, " Let ", " let ")
Let internalText = Replace (internalText, " Put ", " put ")
Let internalText = Replace (internalText, " Say ", " say ")
Let internalText = Replace (internalText, " She ", " she ")
Let internalText = Replace (internalText, " Too ", " too ")
Let internalText = Replace (internalText, " Use ", " use ")
Wait 0.2
Clipboard internalText
Wait 0.2
SendKeys "^v"
Wait 0.2
Clipboard oldClipboard
End Sub
 01/10/2021 02:40 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1036
Joined: 04/03/2009

Originally posted by: Alan Cantor Since we've taken this script this far

Alan’s proposal for 3 letter words makes me think…

Break the long string down into an array of strings:

   dictationAsString = ListVar#' change to which ever ListVar it actually is
   dictationArray = Split (dictationAsString, " ", -1)
   arrayLength = UBound(dictationArray)

This gives us an array of arrayLength items - one for each "word" in the original dictation (split on the space character). Now process these items: 

no matter what always capitalize the first item;

on items 2 to the end look for all items whose length is 4 or less, if length is 4 AND the final character is punctuation, treated as a 3 letter word, then make all 1-3 letter words lowercase, look at every 1-3 letter word and compare against a list of words to force capitalization (Bo, Ann etc. - I have a list of proper nouns sorted by length);

on items 2 on, look at the last character of the preceding item and decide if you want to force capitalization based on punctuation;

on items 2 on, look at the first character of the item to see if you want to force capitalization of the second character (opening quotation marks, inverted question and exclamation marks etc.).

Finally, put the array together as a single string. Little more work would create two identical arrays originally, keeping one as a reference and only operating on the other. After all the above is done, one could go through the original reference looking for words that were (excluding leading and trailing punctuation as necessary) ALL CAPS and determine if any of them are acronyms (I have a list of thousands) which should remain ALL CAPPED. Obviously, this would probably be better done in some language other than Verbal Basic. I have done so in C++ and my application has a GUI dialog which allows the user to enter and store words which must never be capitalized (after the three letters or less rule is applied) and another dialog for words which must always be capitalized regardless. Unfortunately, it does not currently consider acronyms - so much to do, so little time! It also starts out using Microsoft® Visual Studio’s built-in title case function.



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 01/20/2021 08:43 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 645
Joined: 11/05/2015

For those who have title case scripts running, here's one I ran across from an APA-style-related article:

Writing New Media, There Is Nothing Left to Lose


That's the correct capitalization according to APA rules. Maybe try it out and see if your code does the right thing. (APA capitalizes 4-character words and above; most others that I checked capitalize after 3-characters or longer).


Beauty And The Beast (Most others)
Beauty and the Beast (APA)


-------------------------

Win10/x64, AMD Ryzen 7 3700X, 64GB RAM, Dragon 15.61, SP 6 PRO, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 01/20/2021 09:53 PM
User is offline View Users Profile Print this message

Author Icon
dilligence
Top-Tier Member

Posts: 1262
Joined: 08/16/2010

You may be interested in SP Text Tools which can quickly convert either selected text or all text to UPPERCASE, lowercase, PascalCase, snake_case, SCREAMING_SNAKE, camelCase or kebab-case (I just realize we forgot to include Title Case :-(). Will add that soon.

 

But it can do a whole lot more: Alphabetizing, Sorting, Removing, Replacing, Correcting, Quoting.

 

It is developed to work in speech unfriendly applications (directly, without the intervention of a dictation box) but it also works in speech friendly applications.

 

I attached the Text Tools section of the SP 6 PRO Command List.

 

Of course the AIO DB also supports these casings.






-------------------------

www.speechproductivity.eu 


Auto Box - SP Editor - HyperNotes - Hotkeys for Dragon - Quick Correct - Press Utility - Easy Guide to Dragon Scripting



Statistics
31935 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 2 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 537 guests browsing this forum, which makes a total of 539 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2021 FuseTalk™ Inc. All rights reserved.