Getting the cursor context in Dragon NaturallySpeaking's advanced scripting - naturallyspeaking

I wonder whether it is possible to get the cursor context in Dragon NaturallySpeaking's advanced scripting.
By cursor context, I mean the surrounding characters. For example, I sometimes want to condition some steps of a voice command on whether the character preceding the cursor is a space.

Best I could come up with is my CheckNewPara function shown here: http://knowbrainer.com/forums/forum/messageview.cfm?catid=4&threadid=2739&discTab=true&messid=11427&parentid=11409&FTVAR_FORUMVIEWTMP=Single
Function CheckNewPara()
Clipboard$()
SendKeys "+{Left}^c", True ' copy previous character
Select Case Clipboard$()
Case "" ' if the prior character is nothing
CheckNewPara = "" ' add no space
Case Chr(13)&Chr(10), Chr(9), ")" ' if the prior character is a Lf-CR, tab or )
SendKeys "{Right}", True
CheckNewPara = "" ' add no space
Case "." ' if the prior character is a period
SendKeys "{Right}", True
Clipboard$() ' check for No.
SendKeys "+{Left 3}^c", True ' copy prior three characters
SendKeys "{Right}", True
If Clipboard$() = "No." Then
CheckNewPara = " " ' add one space after No.
Else
CheckNewPara = " " ' add two spaces after period
End If
Case "?", "!"
SendKeys "{Right}", True
CheckNewPara = " " ' add two spaces after other ends of sentence
Case Else
SendKeys "{Right}", True
CheckNewPara = " " ' add one space in the usual case
End Select
Clipboard$()
End Function
You should look at the complete topic at http://knowbrainer.com/forums/forum/messageview.cfm?FTVAR_FORUMVIEWTMP=Linear&catid=4&threadid=2739&discTab=true to get all the context, but the code in the post I pointed to should get you started.
My newest version of the function actually calls an AutoHotKey script which looks at both the prior three characters (or as many as there are, if there are any) and the next two characters (or how ever many there are, if there are any) and returns either a space, two spaces, or nothing depending on the context. The context could be a terminal punctuation (requiring two spaces) or a pound/hash # symbol or close paren bracket or brace ) ] } all requiring no spaces, or else by default one space. I also have it so I can call it before and/or after typing in the results of a Dragon command.
HTH, YMMV,

Related

How to match exact string in perl

I am trying to parse all the files and verify if any of the file content has strings TESTDIR or TEST_DIR
Files contents might look something like:-
TESTDIR = foo
include $(TESTDIR)/chop.mk
...
TEST_DIR := goldimage
MAKE_TESTDIR = var_make
NEW_TEST_DIR = tesing_var
Actually I am only interested in TESTDIR ,$(TESTDIR),TEST_DIR but in my case last two lines should be ignored. I am new to perl , Can anyone help me out with re-rex.
/\bTEST_?DIR\b/
\b means a "word boundary", i.e. the place between a word character and a non-word character. "Word" here has the Perl meaning: it contains characters, numbers, and underscores.
_? means "nothing or an underscore"
Look at "characterset".
Only (space) surrounding allowed:
/^(.* )?TEST_?DIR /
^ beginning of the line
(.* )? There may be some content .* but if, its must be followed by a space
at the and says that a whitespace must be there. Otherwise use ( .*)?$ at the end.
One of a given characterset is allowed:
Should the be other characters then a space be possible you can use a character class []:
/^(.*[ \t(])?TEST_?DIR[) :=]/
(.*[ \t(])? in front of TEST_?DIR may be a (space) or a \t (tab) or ( or nothing if the line starts with itself.
afterwards there must be one of (space) or : or = or ). Followd by anything (to "anything" belongs the "=" of ":=" ...).
One of a given group is allowed:
So you need groups within () each possible group in there devided by a |:
/^(.*( |\t))?TEST_?DIR( | := | = )/
In this case, at the beginning is no change to [ \t] because each group holds only one character and \t.
At the end, there must be (single space) or := (':=' surrounded by spaces) or = ('=' surrounded by spaces), following by anything...
You can use any combination...
/^(.*[ \t(])?TEST_?DIR([) =:]| :=| =|)/
Test it on Debuggex.com. (Use 'PCRE')

Using regexp_replace how do t replace a string with an exception

How do I replace all occurrences of ' sub.*' with the exception of ' substation.*'?
regexp_replace("CleanString",' sub.*',' ', 'ig')
I have tried using various combinations of groupings () but still not getting it.
Using postgres regexp_replace()
A regular expression normally matches only things that are there, not things that are not there - you cannot simply put an "if-then-else" in there.
However, Postgres's regex support, the manual page for which is here includes "lookahead" and "lookbehind" expressions.
In your case, you want a *negative lookahead":
(?!re) negative lookahead matches at any point where no substring matching re begins (AREs only)
It's important to note the phrase "at any point" - lookarounds are "zero width", so (?!station) doesn't mean "something other than station", it means "a position in the string where station isn't coming next".
You can therefore construct your query like this:
' sub(?!station).*'
That will match any of "sub", "foo sub", " subbar", or "foo subbar", but not any of "substation", "foo substation", " substationbar", or "foo substationbar". Since the (?!station) is zero-width, and the next token is .*, it's fine for nothing to come after " sub".
If you want there to be something after the "sub", you could instead write:
' sub(?!station).+'
The .+ means "at least one of something", so it will still match " subbar" and "foo subbar", but will no longer match " sub" or "foo sub".

Issue with eval_in_page - Trying to interpolate an array

my #para_text = $mech->xpath('/html/body/form/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/table/tbody/tr[3]/td/div/div/div', type => $mech->xpathResult('STRING_TYPE'));
#BELOW IS JUST TO MAKE SURE THE ABOVE CAPTURED THE CORRECT TEXT
print "Look here: #para_text";
$mech->click_button( id => "lnkHdrreplyall");
$mech->eval_in_page('document.getElementsByName("txtbdy")[0].value = "#para_text"');
In the last line of my code I need to put the contents of the #para_text array as the text to output into a text box on a website however from the "document" till the end of the line it needs to be surrounded by ' ' to work. Obviously this doesnt allow interpolation as that would require " " Any ideas on what to do?
To define a string that itself contains double quotes as well as interpolating variable values, you may use the alternative form of the double quote qq/ ... /, where you can choose the delimiter yourself and prevent the double quote " from being special
So you can write
$mech->eval_in_page(qq/document.getElementsByName("txtbdy")[0].value = "#para_text"/)

Matlab: How to print " ' " character

I am trying to create the following string:
javaaddpath ('C:\MatlabUserLib\ParforProgMonv2')
However, I could only do the following
command = sprintf('%s ', varargin{1}, '(', varargin{2}, ')');
and that gives me:
javaaddpath ( C:\MatlabUserLib\ParforProgMonv2 )
UPDATE:
Based on Dan's suggestion, I used the following:
command = sprintf('%s', varargin{1}, '(', '''', varargin{2}, '''', ')')
Use two single quotation marks. See the docs for formatting strings, btw this concept is known as an escape character (to help you google such things in the future).
command = sprintf('%s ', varargin{1}, '(''', varargin{2}, ''')')
Although I think you might prefer
command = sprintf('%s (''%s'')', varargin{1}, varargin{2})
or if you have no other varargins (which I guess is very unlikely but anyway)
command = sprintf('%s (''%s'')', varargin{:})
There are a couple of ways around this. First you could declare your path as a string variable then pass the string to your command, eg,
path = 'my/path'
javaaddpath (path)
Or you can use special characters to insert things like a single quote or a new line character, so for a single quote,
EDIT: wrong display command as pointed out by Dan below
myString = '" Hi there! "'
disp(myString)

MSWord macro: search and highlight formatted text patterns

I'm trying to write a MSWord macro that will find, and then highlight (in yellow), certain kinds of text strings in a MSWord file.
For example:
1) An italicized comma, followed by whitespace, and then a non-italicized text. Thus, for example:
The second comma in this sentence, which is italicized, should be highlighted by the desired macro. But the comma in this sentence should not be highlighted, because the entire sentence is in italics.
2) A bolded character (of any kind, even whitespace), both preceded and followed by non-bolded characters. Thus, for example:
This sentence ends in a bolded punctuation mark. That first period should be highlighted.
I know that first period might look normal, but it's not. It's bold.
3) Any word that is in SmallCaps, and is >4 letters long, but is not capitalized. I don't know how to do smallcaps in markdown... but imagine for a moment that the following text is in smallcaps in MSWord:
Imagine All of This Is in Small Caps. . . the Word "under" Should Be Highlighted Because It Is More Than Four Characters Long but is not Capitalized
Does anyone know whether this is possible? I know it's quite easy to find text-patterns using regular expressions, but adding changes in formatting to those patterns seems to be tricky.
run cmd,
cscript //Nologo regexp02.vbs
regexp02.vbs:
Dim objRegExp : Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Global = True
Dim input
input="Imagine All of This Is in Small Caps. . . the Word under Should Be Highlighted Because It Is More Than Four Characters Long but is not Capitalized"
WScript.Echo input
WScript.Echo
Dim Pattern1 : Pattern1 = "\b[a-z]{5,}\s"
WScript.Echo "Pattern1 : " & Pattern1
WScript.Echo
objRegExp.Pattern = Pattern1
Set objMatches = objRegExp.Execute(input)
For i=0 To objMatches.Count-1
Set objMatch = objMatches.Item(i)
WScript.Echo objMatch.Value
Next
WScript.Echo
Dim Pattern2 : Pattern2 = "\b[A-Z]([a-z]{4,})\s"
WScript.Echo "Pattern2 : " & Pattern2
WScript.Echo
objRegExp.Pattern = Pattern2
Set objMatches = objRegExp.Execute(input)
For i=0 To objMatches.Count-1
Set objMatch = objMatches.Item(i)
WScript.Echo objMatch.Value
WScript.Echo Left(objMatch.Value, 1)
'TODO test bold sumbol Left(objMatch.Value, 1)
'
' TODO Highlight Code
'
Next
Output:
Imagine All of This Is in Small Caps. . . the Word under Should Be Highlighted Because It Is More Than Four Characters Long but is not Capitalized
Pattern1 : \b[a-z]{5,}\s
under
Pattern2 : \b[A-Z]([a-z]{4,})\s
Imagine
I
Small
S
Should
S
Highlighted
H
Because
B
Characters
C
Regex at VBA:
Open reference
Select COM-server Microsoft VBScript Regular Expressions 5.5
VBA code:
Dim objRegExp As New VBScript_RegExp_55.RegExp
objRegExp.IgnoreCase = False
objRegExp.Global = True
objRegExp.Pattern = Pattern1
Record macro
Press Ctrl+F, open search dialog
select font property
select font style
Press Find Next
Stop macro record, open VBA editor
Edit macro SearchItalic
Run macro SearchItalic
Search italic text:
Sub SearchItalic()
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
With Selection.Find
.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
End Sub