KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Command to consolidate spaces
Topic Summary:
Created On: 04/08/2022 01:26 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Command to consolidate spaces   - wristofdoom - 04/08/2022 01:26 PM  
 Command to consolidate spaces   - ax - 04/08/2022 02:33 PM  
 Command to consolidate spaces   - R. Wilke - 04/08/2022 04:17 PM  
 Command to consolidate spaces   - dilligence - 04/10/2022 09:28 AM  
 Command to consolidate spaces   - wristofdoom - 04/11/2022 05:36 PM  
 Command to consolidate spaces   - Edgar - 04/10/2022 10:24 AM  
 Command to consolidate spaces   - ax - 04/11/2022 07:21 PM  
 Command to consolidate spaces   - R. Wilke - 04/12/2022 01:11 PM  
 Command to consolidate spaces   - PG LTU - 04/12/2022 12:34 PM  
 Command to consolidate spaces   - ax - 04/12/2022 08:16 PM  
 Command to consolidate spaces   - Lunis Orcutt - 04/13/2022 11:48 AM  
 Command to consolidate spaces   - PG LTU - 04/13/2022 04:46 PM  
 Command to consolidate spaces   - Matt_Chambers - 04/13/2022 05:49 PM  
 Command to consolidate spaces   - R. Wilke - 04/13/2022 08:06 PM  
Keyword
 04/08/2022 01:26 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Top-Tier Member

Posts: 321
Joined: 09/03/2020

I have a command called "consolidate that" that I use to get rid of extra spaces and linebreaks that are in the current selected text.

 

For example, if I had "this   example   text", I can select the text, under the command "consolidate that", and then the text becomes "this example text"

 

My current script:

 

https://pastebin.com/PUYa8QXu

 

The script that I have works but it is not very smart. Right now, I just search for instances of 4 back to back spaces, 3 spaces, 2 spaces, and consolidate all of that into a single space.

 

This works for almost all may use cases, but it won't work if I ever have a block of text with a                              lot                       of                                             spaces.

 

What I want to do is replace all instances of Space(x) where X = any number > 1, but I don't know how to express that in Visual Basic.

 

Any tips?

 



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

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



 04/08/2022 02:33 PM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

I suppose you could use a loop of some sort, looping around to check to see if you have gotten rid of any 2-space blocks, recursively.

Then there is "regular expression".  Definitely no fun to use.  But you do it when you have to, like chopping wood.

Tools that can do regex are a dime a dozen.  Using AHK just as an example, you'd have something along the line of the following :

Clipboard := RegExReplace(Clipboard, "([[:blank:]]+)([,;:.!?')/])", "$2")     ;Remove any space between words and punctuations.

Clipboard := RegExReplace(Clipboard, "([,;:.!?)])([[:blank:]]*)([a-zA-Z])", "$1 $3")      ;Alter zero or more spaces after punctuations to one.

Clipboard := RegExReplace(Clipboard, "(\w*)([[:blank:]]+)(\w*)", "$1 $3")     ;Shrink multiple spaces between alphanumeric words to one, and need to use [[:blank:]] due to \s matching newline characters.

Above are just 3 out a multi-line "post-processing" script I use to "clean up" paragraphs - in non-Select-And-Say situations.  Second and third lines can be combined.  But leaving them separate is more flexible and easier to maintain.   Anyhow, just to give an idea.


And there are always multiple ways to attack something with regular expression.

It's as "fun" as sudoko or word puzzles (neither of which I personally go near ... but they tickle some folks' fancy).

Finally, for VB RegEx, there is a tutorial here:

https://www.tutlane.com/tutorial/visual-basic/vb-regex-regular-expression

 

Or here:

 

https://www.vbforums.com/showthread.php?830065-RESOLVED-Remove-All-Whitespace



 04/08/2022 04:17 PM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7840
Joined: 03/04/2007

It's as "fun" as sudoko or word puzzles (neither of which I personally go near ... but they tickle some folks' fancy).


Now that you are mentioning it, I love sudoku, and this is what I always do whenever I take a break from my day job as a loss adjuster. While having a cigarette.

As regards handling white spaces programmatically, using regular expressions may be the first thing springing to mind, but your options will always be limited which you will realise sooner or later.

The ultimate way to go is using CFG parsing, but that would be even more above the head of the original poster than regular expressions.

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



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 04/10/2022 09:28 AM
User is offline View Users Profile Print this message

Author Icon
dilligence
Top-Tier Member

Posts: 1526
Joined: 08/16/2010

Originally posted by: R. Wilke  Now that you are mentioning it, I love sudoku, and this is what I always do whenever I take a break from my day job as a loss adjuster. While having a cigarette. 

The ultimate way to go is using CFG parsing, but that would be even more above the head of the original poster than regular expressions.

 

I don't like sudoku and I don't smoke (anymore), but I do like to respond to original forum posters in a decent manner, trying to offer something that is useful.

 

wristofdoom may be interested in the "Remove Unnecessary Spaces" feature in SP 7 Standard's Zen Editor© and DB Advanced©). This removes any number of spaces > 1.



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

https://speechproductivity.eu


Turbocharge your Dragon® productivity with 40 Power Addons



 04/11/2022 05:36 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Top-Tier Member

Posts: 321
Joined: 09/03/2020

The ultimate way to go is using CFG parsing, but that would be even more above the head of the original poster than regular expressions.

 

I use regex regularly and for my needs it's usually not too far above or below the level of my head. However, I haven't seen a VBA script using regex in the context of a Dragon script. 

 

An example would be helpful.



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

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

 04/10/2022 10:24 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1265
Joined: 04/03/2009

Don't forget, white space can include tabs. Sometimes the combination of spaces and tabs together needs to be consolidated. Generally, multiple back-to-back tabs are intentional. Something that looks like: "space tab" or "tab space" typically wants to be reduced to just "tab". Something like "tab space space tab" might best look as "tab tab". There are no hard and fast rules here. This problem really requires multiple solutions.

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

-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

 04/11/2022 07:21 PM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

Originally posted by: wristofdoom

I use regex regularly and for my needs it's usually not too far above or below the level of my head. However, I haven't seen a VBA script using regex in the context of a Dragon script.


An example would be helpful.

 

 

Indeed regex is not necessarily difficult, just generally "unpleasant", at least to me.  Apparently you will need to use your Knowbrainer to pull it off in Dragon scripting indirectly.

https://www.knowbrainer.com/forums/forum/messageview.cfm?catid=12&threadid=32938&

https://www.knowbrainer.com/forums/forum/messageview.cfm?catid=12&threadid=33051&



 04/12/2022 01:11 PM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7840
Joined: 03/04/2007

We do that

Originally posted by: ax
Originally posted by: wristofdoom I use regex regularly and for my needs it's usually not too far above or below the level of my head. However, I haven't seen a VBA script using regex in the context of a Dragon script. An example would be helpful.

 

 

 

 

 

Indeed regex is not necessarily difficult, just generally "unpleasant", at least to me.  Apparently you will need to use your Knowbrainer to pull it off in Dragon scripting indirectly. https://www.knowbrainer.com/forums/forum/messageview.cfm?catid=12&threadid=32938& https://www.knowbrainer.com/forums/forum/messageview.cfm?catid=12&threadid=33051&



AX,

It is very kind of you to jump in and try to help out anyone getting lost in confusion in this place, which admittedly happens ever so often, but in the case of "wrist of doom", he only appears to be like the kid posting on programmers forums asking questions such as "hey, I need to get my homework done by tomorrow, anyone give me the code?"

And for sure, in places such as "stackoverflow", my initial response to him would have been judged as quite politely rather. (As opposed to what the less than up to the task competitor from the Netherlands tried harping on.)

Anyway, anyone should get happy with using regular expressions as long as they can to sort it out, would be my advice.



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



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 04/12/2022 12:34 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2202
Joined: 03/21/2007

Everything you need to know is right here in the forum, real easy.

Just, put your text in where it asks for it, or more generally, grab it from the clipboard, type in a single space for the replacement text, and use \s+ for the replacement pattern (handles tabs and other white space).

Hth,



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




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 04/12/2022 08:16 PM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

^^^ Let 's not sell ourselves short, RW! I don't think any regular to this forum would seriously dispute that next to Lunis, who may be said to have a "proprietor's" interest in answering questions, you have helped more folks on this forum, cumulatively over the years and counting, than several others combined.

However, sometimes the "colour of personality" gets ahead of the messages. Granted, can't count on everyone to be as even-keeled as Lindsay, PG, Matt, Alan, or Edgar, etc and et al ... Sometimes, even "placid me" wouldn't pass up an opportunity to vent a little, hiding behind an online veneer.

And like most, I will only venture a thought or 2 on the subjects that particularly interest me, when I feel I can spare a moment and have something to say.

But what really attracts me to this place are the following;

1. This forum is handy - not just as a "Dragon fountain", but also as an "assistive computing" wellspring. Sooner or later I will develop some back/neck/arm/wrist/vision problems (not that they haven't creeped up to various degrees already). This site is simply useful, in all sorts of ways.

2. This place is inspiring (indeed the right adjective without quotes). Work for many of us is a slog these days (yes I consider myself privileged but a privileged slog is still slog). Visiting this forum nevertheless reminds me that there are those with what I might otherwise consider physical disabilities, who not only haven't thrown in the towel, but are still making the most out of fighting the good fight, with "assistive computing". As much as this will come across as a daft "chicken-soup-for-the-soul" sentiment - I won't hesitate to say that "I feel inspired".

3. The level of technical discussion here is still relatively accessible, at least for me. For "real" programming shop talk, whether on AHK forum or indepth JavaScript sites, I'd get lost fast. But programming is not my day job nor do I wish it to be. As matters of general "edification", the bits and pieces on this forum are practical and "edifying" enough.

4. Live-and-let-live. If I feel someone's question is akin to "you-do-my-homework", I will simply boycott the Reply button. Perhaps a "purist" would feel the "righteous indignation" to say something ... even if tangentially. But I personally prefer a little more live-and-let-live, which is in short supply these days. Frankly, I don't particularly care for Rob's style of "direct marketing", either. But he certainly isn't shy to help others. Incidentally, even in a country like Canada, live-and-let-live is getting scarcer (thankfully neither Corona, nor Truckers, nor Pootin, have yet succeeded in blasting it away altogether. But let it be said that forces are increasingly arrayed against "live-and-let-live", even in "the Shire").



P.S., The forum software really could use an upgrade. Maybe through fundraising? Many useful posts (such as the one PG linked) could benefit from a tag system or some other indexing methods perhaps. Anyway, another digression.

 04/13/2022 11:48 AM
User is offline View Users Profile Print this message

Author Icon
Lunis Orcutt
Top-Tier Member

Posts: 39831
Joined: 10/01/2006

This forum could use some serious upgrading. We chose this particular forum because it was used at Dell, permitted embedded hyperlinks and was the most expensive forum on earth. In other words, we were hedging our bets but we lost. The manufacturer of this forum went out of business well over a decade ago so we can no longer edit or add amenities; like the ability to scroll left and right



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

Change "No" to "Know" w/KnowBrainer 2020
Trial Downloads
Dragon/Sales@KnowBrainer.com 
(615) 884-4558 ex 1



 04/13/2022 04:46 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2202
Joined: 03/21/2007

Getting back to the original @wristofdoom post, no need to purchase any "Remove Unnecessary Spaces" product, using my function from the post I linked above, a simple two line command suffices to consolidate any amount of white space (including tabs and blank characters) in a highlighted selection (which can span paragraphs, ymmv):


Sub Main
    SendKeys "^c",1
    SendKeys RegExReturn( Clipboard , " ", "\s+")
End Sub



And yes, I know, as the wise elder from the past, Tom (Gauss) Perry told me, this kind of stuff sometimes finds its way into some aftermarket products, which I mostly don't mind (and when I'm asked for the permission I require for commercial use, I usually give it without much more than asking for a free copy of the result).

 

[[Edited:

Removed potentially inflammatory remark (though I'm not sure why it created such offense). I only provide the full detail (beyond my earlier proof-of-concept, which I linked to above) because the earlier answers here are either for a commercial product (not Lunis' KnowBrainer, Lunis never shys away from providing the actual code from his product that can show a poster how to do something), as well as the suggestions that RegEx might be too complicated for Dragon users, which I hope to have dispelled.  After all, wristofdoom admitted regex wasn't beyond his or her or their ability so I'm sure the P-O-C was already enough, nonetheless, for others who stumble upon this post who think their only hope is to buy something, well, here it is for free and spoon-fed.]]



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




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 04/13/2022 05:49 PM
User is offline View Users Profile Print this message

Author Icon
Matt_Chambers
Top-Tier Member

Posts: 569
Joined: 08/09/2018

Excellent Tom Perry reference!

That is all.

 04/13/2022 08:06 PM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7840
Joined: 03/04/2007

Originally posted by: Matt_Chambers Excellent Tom Perry reference!

 

That is all.

 



As far as programming, the best teachers I have met on the Internet are those who don't give their wisdom away so easily, but instead, put up some barrier which you will have to climb first before getting the knack of it, and realise the value in getting the concept yourself. PG, as an example, sometimes meets this criteria, although not always.

For everything else, there will always be the documentation, and thanks to the Internet, Google will always be your friend, but kids who grew up with everything being readily available right away probably don't know what to do with it.

At any event, you will never learn anything from just copying snippets of code without understanding the basics of the underlying structure, and everyone is wasting their time in this game, those who ask question after question, and those who answer.



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



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage



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

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