Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Multi choice text and grammar correction


  • Please log in to reply
33 replies to this topic
stephenmika
  • Members
  • 19 posts
  • Last active: Mar 16 2011 05:39 PM
  • Joined: 09 Apr 2009
I am new to AutoHotkey and whilst I don't want a finished scrip, I would like some guidance as to programming approach I should consider in order to write the Hotkey script to perform the following -

I have over 900 standard phrases many of which have multi-choice options. Firstly there are standard parts of the phrase (preceeded by [*] in the example below) which would always be generated whenever the phrase number Hotkey is entered. Then there are the options (preceeded by letters in brackets [A] to [H] in the example below). If these letters were appended to the phrase number Hotkey then the completed phrase would be produced. Whilst this appears not to difficult, what I also need is some automatic grammer correction.

Firslty, in the example below, if C and D are appended to the phrase number Hotkey, an automatic 'and' is inserted between the two text strings. If C, D and E are inputted, a comma is inserted between C text string and D text string and an 'and' is inserted between D text string and E text string.

Secondly, if F or H is appended to the phrase number Hotkey, an input box automatically pops up, in sequence, ie F first and then H, for freetext to be inserted.

Finally, in some phrases I need to have seperate selectable options for singular and plural choice. In these phrases, it would be great to automatically change the 'is' to an 'are' if more than one option is selected.

Example phrase -

54 [*] There is a [A] covered [B] open air [C] swimming pool [D] tennis court [E] leisure complex [F] ... [G] in the <INSERT TEXT> garden. [H] at the <INSERT TEXT> of the property. [*] No comments can be made on condition.

I am not expecting a finished script in response, but being a newbie, any suggestion as to what programming approach I should follow would be most appreciated.

regards

Steve Mika

_________________
Many thanks

Stephen Mika
University of Reading

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Is this more or less what you want? This is just an example, but if you create a function and place all the sentences in a text file it should
be doable.
; 54 [*] There is a [A] covered [B] open air [C] swimming pool [D] tennis court [E] leisure complex [F] ... [G] in the <INSERT TEXT> garden. [H] at the <INSERT TEXT> of the property. [*] No comments can be made on condition. 

String=54 [*] There is a [A] covered [B] open air [C] swimming pool [D] tennis court [E] leisure complex [F] ... [G] in the <INSERT TEXT> garden. [H] at the <INSERT TEXT> of the property. [*] No comments can be made on condition. 
StringSplit, Section, String, [ ; split string into sections (array)
Loop, % Section0 ; add a checkbox for each section of the string, so loop it 
	{
	  Text:= "[" Section%A_Index% ; append [ we removed
	  If (A_Index = 1) ; first one doesn't have ] so remove it again
		StringTrimLeft, Text, Text, 1
	  Gui, Add, Checkbox, x20 yp+25 vC%A_Index%, &%A_Index% - %Text%
	}
GuiControl, , Button1, 1 ; always include
GuiControl, , Button2, 1 ; always include
Gui, Add, Button, w200 default, &OK
Gui, Show, w600 h400
Return

ButtonOK:
Gui, Submit, NoHide
Loop, % Section0
	{
	If (C%A_Index% = 1)
		{
		StringTrimLeft, Append, Section%A_Index%, 3 ; remove "letter]"
		IfInString, Append, <insert text>
			{
			InputBox, InsertText, Insert Text, %Append%
			StringReplace, Append, Append, <insert text>, %InsertText%, All
			}
		NewString .= Append
		Append=
		}
	}
MsgBox % NewString
NewString=
Return

GuiClose:	
Esc::
ExitApp


stephenmika
  • Members
  • 19 posts
  • Last active: Mar 16 2011 05:39 PM
  • Joined: 09 Apr 2009
Hugo, immense thanks for your time in programming and showing a GUI approach. Unfortunately, the GUI interface would be slower and I would prefer just to type in the phrase number and letters (as a Hotkey) and after pressing return, the text would then be placed in whatever word document I have open. Perhaps I missled you by using the term multi-choice :oops:

Any pointers for the Hotkey approach of am I missing something :oops:

Kind regards

PS :oops: The automatic 'ands' did not appear as did not the last bit of the text preceeded by the [*] in the example. Nvertheless, the insert feature worked perfectly and in sequence.

sinkfaze
  • Moderators
  • 6365 posts
  • Last active:
  • Joined: 18 Mar 2008
Not to detract from your vision of how you want this work, but have you considered hotstrings as a possible aid to accomplishing this? I think you need to look at your phrase templates as one thing and the modifying characteristics that go in the templates as another, which is where a hotstring(s) would come into play.

Say you've used something to insert the following phrase template into a Word doc you're typing:

There is in the rear garden.


Now in a script you have some shorthand hotstrings that will automatically type in the modifying characteristics you need. For example:

#HotString EndChars /
::cvd::covered
::opn::open air
::swm::swimming pool
::ten::tennis court
::lcx::leisure complex

So now when you go back into your template and type this:

There is an opn/ swm/ in the rear garden.


You get this:

There is an open air swimming pool in the rear garden.


The phrase templates could also be input via a hotstring or they could be saved to an ini file and made viewable from a GUI so you can see what you're selecting before you input the phrase.

I understand you're probably looking for an all-encompassing solution but the problem with typing is that there's only so much time you can save over just typing in what you wanted in the first place.

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
I never attended uni you see, catches up with me sometimes :wink:

I see, so you want to type

4bcdeh

which would become

There is a open air swimming pool and tennis court at the back of the property. No comments can be made on condition.

where back was done via an inputbox?

It might be possible using Input but I'm on win98 so I can't test (input doesnt work there) so I made an inputbox where you can type your shorthand, the

in this example you have to type 4cdefgh to see the full text

All I hope is that all your 900 sentence have the same structure otherwise ... good luck

edit: type windowskey & z to start the script
removed code didn't work

stephenmika
  • Members
  • 19 posts
  • Last active: Mar 16 2011 05:39 PM
  • Joined: 09 Apr 2009
Thanks Sinkfaze, I appreciate the shortform of writing out the full text string but with over 900 phrases, many with up to a dozen choices or more, typing in shorthand hotstrings would be tiresome. typing in a number and a series of letters would be quicker. The phrase are produced in short form on a pad and I circle the number and letters of each phrase I want to use and so it is easier to copy type the numbers and letters. I do know of a DOS based program which works in this way.

Now what about this approach -
Use a hotkey to run a standard routine (say the asterisk key), followed by the phrase number and option letters.

The routine would search for the relevant phrase in say a text file (I would prefer to incorporate the whole phrase text file in the program, rather than use a separate ini file. The current one is some 256Kb long).

The routine would parse all inclusive text which would be tagged in some way, currently [*] as in the sample phrase. The options which need grammer improvement (the automatic ands) would also be tagged. In the DOS version, the text was tagged with a backslash and comma which was removed when the final text was produced. This tagging would enable the routine to recognise the need or otherwise to include a 'comma' or 'and' between the selected options.

Is this possible?

Kind regards

stephenmika
  • Members
  • 19 posts
  • Last active: Mar 16 2011 05:39 PM
  • Joined: 09 Apr 2009
Hugo, thanks once again for your efforts. Please have a look at my preceeding posting which refers to an old DOS (I miss this OS) program that did a similar thing.

Your script is on the right lines although there are a few niggles, like some extra full stops and some wide spacing between text strings when different options are selected, (perhaps some form of multiple space stripper might resolve this).

In my preceeding reply, I mentioned the purpose of having one routine which will obviate the need to create your routine for each phrase. It would also obviate the need for one huge array of all possible sentences.
As each phrase is structured in the same way, one routine would work on all phrases.

What about my suggestion of using some string tags to identify the three main types of text - ie 1) text strings that should always be included in a phrase, 2) text strings (choices) that may or may not need a 'comma' or and 'and' following the text and 3), insert text strings that need a gui interface.

By the way I left school at 15 and only after long periods of evening and postal study did I become a lecturer. Judging by the complexity of your solution, missing University may not have done you any harm.

Kind regards

sinkfaze
  • Moderators
  • 6365 posts
  • Last active:
  • Joined: 18 Mar 2008
Just to make sure I understand you correctly, when discussing this input code for example:

54aghc


Are the values for a-z universal to all 900 phrases? Or do a-z have specific assignments with regards to each individual phrase, wherein the previous input code would create a different result for aghc than:

78aghc



stephenmika
  • Members
  • 19 posts
  • Last active: Mar 16 2011 05:39 PM
  • Joined: 09 Apr 2009
Dear Sinkfaze, the values a -z are not universal. The number of options in each phrase are not uniform, please see some of the phrases below . Please note the use of tags for the DOS version - backslash and comma \, to identify those options which if selected togther would need automtaic 'ands'. The three full stops ... would indicate the need to insert freetext and would require a GUI.

25 [*] The front of the building faces approximately [A] north [B] north east [C] east [D] south east [E] south [F] south west [G] west [H] north west [-] and all directions in this report are given as if viewing the property from the front. [I] The main entrance is on the ... of the property.

65 [*] Access will be difficult [A] owing to the proximity of the main road [B] because of the restricted visibility\, [C] during severe weather as the drive is very steep\, [-] and great care must be taken with vehicles when entering or leaving the property. [D] As this could affect future saleability, we would refer you to our comments in Section F3.

86 [*] Within the [A] ... [-] roof space [B] stored household goods\, [C] insulation\, [D] timber boarding\, [E] dust/debris\, [F] a layer of polythene under the rafters\, [G] ... [H] also [I] severely [-] obstructed our inspection of the interior.

114 [*] The [A] solid [B] suspended timber [-] floor [C] in the ... [D] moves underfoot\, [E] slopes\, [F] is cracked\, [G] has lifted\, [-] which, [H] together with the nature of the site and the construction of the property, [-] leads us to suspect the quality of the [I] sub-floor construction. [J] supporting structure. [K] Therefore, a more detailed investigation should be carried out. [L] We would refer you to our advice in Section C2 in respect of the timber decay, which may be present under the floor.

824 [A] improve ventilation to the ...\, [B] ventilate the sealed [C] fireplace\, [D] fireplaces\, [E] improve insulation of the ...\,

I hope this clarifies the phrase structure.

Kind regards

engunneer
  • Moderators
  • 9162 posts
  • Last active: Jul 15 2014 12:00 AM
  • Joined: 30 Aug 2005
This is a pretty interesting script idea.

what does [-] denote?

I think this is pretty doable. If you wanted to reuse the existing text format from dos, you might be best to learn about regex.

for how to trigger something like this, see my post regarding a wiki prompt

sinkfaze
  • Moderators
  • 6365 posts
  • Last active:
  • Joined: 18 Mar 2008

what does [-] denote?


It denotes text that will be present in the template phrase, as opposed to the optional text(s) that precedes it.

stephenmika
  • Members
  • 19 posts
  • Last active: Mar 16 2011 05:39 PM
  • Joined: 09 Apr 2009
Engunneer, as sinkfaze says, it denotes the standard text strings which would be created by inputting the phrase number alone. In the DOS version, the [*] and [-] actually does the same thing.

The use of tags in the DOS version of laying out the phrases seems to suggest an approach similar to that using Regular Expressions (RegEx).

I do not have the code for the DOS version, thus the reason for using Autohotkey. Please could you give me an example of using RegEx for searching for and replacing text with such tags so that I could use it as a master to create the expressions I need to invoke the grammer rules.

Kind regards

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
mmm I don't see a regexp solution that would fix the grammar issue,
below another attempt at simply parsing the string.

The main goal of the script below is simply to get the entire sentence,
but not yet focus on the grammar of the "and" & "," It also includes
the [-] sections.

In your first example the "," and "and" was always between "cde"
but with your other sentences it seems this is not always the case.

(You can however use regexp to "fix" some grammar issues if there
is a pattern to find.)

edit: removed code didn't work

If the above at least makes your sentences work, you can focus
on the "and" and "," but it won't be that easy I think.

Other suggestion:

a) why not use something like the above but mark the positions for possible changes? You could then type your shorthand, and use
another shortcut to quickly jump (using the find function in your editor)
and simple remove "," or type and it would save you the trouble
of navigating the sentence by cursor (slow) and removing a "," is
only one key press and adding "and" isn't that much work ...

B) If your DOS program still works as it should, you could try to call
the program from AHK using Run or another method via CMDRT
which can read out from (hidden) DOS programs. (But you may
have problems with the ... sections??)

stephenmika
  • Members
  • 19 posts
  • Last active: Mar 16 2011 05:39 PM
  • Joined: 09 Apr 2009
Hugo, thanks once again. I think your solution is defintely the right approach. What about using Regex to parse the final text 'Fulltext' formed from your program. If the final text string 'Fulltext' contains the \, tags these could then be parsed and replaced as follows-

if one instance of \, is found, it is removed,
if two instances are found, the first is replaced with an 'and' and the second one removed,
if three or more of the instances are found, the last but one is replaced with an 'and' and the other \, tags are replaced with commas;

With respect to running the DOS program, frankly, it is an old program and it does not run well in a windows environment. I have tried running it in DOS in a box but again, too many windows open. I believe the solution is Autohotkey. As you have shown, it is fast and can run clean without registry issues and clashes with other programmes.

Can I beg your indulgance once more and raise some points on your excellent programming-

1) a space is created at the begining and at the end of the Fulltext which will mean a double space is always created when the phrases follow on from each other. Could the Fulltext have only one space, that is at the end of the completed phrase. This will create just one space between each phrase.
2) If a phrase contains more then one sentance, your solution only seems to pick up the first sentance options. for example in phrase 1, option [I] cannot be produced, similarly for phrase 4 which has three sentances.

Once again, thanks for your help. I am no programmer but your ideas are helping.

Kind regards

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Give this a spin

edit: removed code, see updated version later in the thread