Disable copy source to use a macro
Thread poster: Evelien Snel
Evelien Snel
Evelien Snel  Identity Verified
Netherlands
Local time: 02:31
English to Dutch
+ ...
Dec 7, 2011

Hi guys,

I am trying to use a macro based MT in WordFast classic, but the output from my macro is overwritten by WordFast copying the source text to the target segment. I have managed to PROVE my macro is actually called and it is working, just the output gets overwritten.
How can I prevent WordFast doing this?
(Pandora's box is OFF, that is not the answer...)

Best regards,
Evelien


 
John Fossey
John Fossey  Identity Verified
Canada
Local time: 21:31
Member (2008)
French to English
+ ...
Delay output? Dec 8, 2011

I'm not sure if you can. I tried it and in the end sent the output to an external program for displaying in a separate window. It's a question of timing - maybe you can build in a small delay so that your macro overwrites WF and not the other way around?

 
Daniel Grau
Daniel Grau  Identity Verified
Argentina
Member (2008)
English to Spanish
This is what I'd do Dec 8, 2011

1) Run WF's Next Segment

Application.Run MacroName:="WfNextSegment"

At this point, your macro continues with the segment in an opened state (source and target in separate lines).


2) Decide based on the match percentage
If it's high (97-100), don't bother changing the proposed segment.
In older versions, there was a bookmark you could test like this:

2a) If (ActiveDocument.Bookmarks("WfPC").Range.Text L
... See more
1) Run WF's Next Segment

Application.Run MacroName:="WfNextSegment"

At this point, your macro continues with the segment in an opened state (source and target in separate lines).


2) Decide based on the match percentage
If it's high (97-100), don't bother changing the proposed segment.
In older versions, there was a bookmark you could test like this:

2a) If (ActiveDocument.Bookmarks("WfPC").Range.Text Like "<}9[789]{>") Then ...

2b) If Mid(ActiveDocument.Bookmarks("WfPC").Range.Text, 3, 3) = "100" Then ...

2c) If Mid(ActiveDocument.Bookmarks("WfPC").Range.Text, 3, 2) = "99" Then ...

In the newer versions, this bookmark is no longer used, and you need to define the location of the match percentage based on the two other WF bookmarks:

Set PercentMatch = ActiveDocument.Range(ActiveDocument.Bookmarks("WfSource").Range.End, ActiveDocument.Bookmarks("WfTarget").Range.Start - 1)

and then use something like this (depending on what you want to test):

2d) If (PercentMatch.Text Like "<}9[789]{>") Then ...

2e) If (PercentMatch.Text Like "<}[567][0-9]{>") Then ...

2f) If Mid(PercentMatch.Text, 3, 3) <= "100" Then ...


3) Identify zero matches
For zero matches in older versions, use the percent match:

If (ActiveDocument.Bookmarks("WfPC").Range.Text Like "<}0{>") ... Then

For newer versions:

If (PercentMatch.Text Like "<}0{>") And (Len(ActiveDocument.Bookmarks("WfTarget").Range.Text) = 1) Then...

And in both you can use the segment length (empty):

If (Len(ActiveDocument.Bookmarks("WfTarget").Range.Text) = 1) Then ...


4)Select the source text
Based on the results of the previous tests, you'll need to select the source text and reduce the selection by 1 (the ever-present Carriage Return) and then MT-translate:

ActiveDocument.Bookmarks("WfSource").Select
Selection.MoveEnd UNIT:=wdCharacter, Count:=-1
TextToTranslate$ = Selection.Text



Don't let WF change double spaces to single spaces, or it will reopen the segment.
Collapse


 
Evelien Snel
Evelien Snel  Identity Verified
Netherlands
Local time: 02:31
English to Dutch
+ ...
TOPIC STARTER
So I could use a timer? Dec 8, 2011

John Fossey wrote:

I'm not sure if you can. I tried it and in the end sent the output to an external program for displaying in a separate window. It's a question of timing - maybe you can build in a small delay so that your macro overwrites WF and not the other way around?


Interesting suggestion John, thanks!

Until now I thought everything in WF was happening strictly sequentially. Maybe I was wrong in that assumption.

So the macro that is called by WF directly could set a timer event to call MY macro when WF has finished work on the current segment. This sounds feasible...



[Edited at 2011-12-08 10:56 GMT]


 
Evelien Snel
Evelien Snel  Identity Verified
Netherlands
Local time: 02:31
English to Dutch
+ ...
TOPIC STARTER
Wow, this is very useful information Dec 8, 2011

Daniel Grau wrote:
1) Run WF's Next Segment
...
2) Decide based on the match percentage
...
3) Identify zero matches
...
4)Select the source text


What an elaborate reply, thank you very much!

It is amazing how much you know about the internals of WF. With this knowledge I am sure I will be able to make a lot of progress. Is there any source where I can learn things like this, or is it all gained by experience and reverse engineering?

I will dive into this and experiment with it, I feel very inspired now!


[Edited at 2011-12-08 11:03 GMT]


 
Daniel Grau
Daniel Grau  Identity Verified
Argentina
Member (2008)
English to Spanish
Just experience Dec 8, 2011

I just looked at how WF works. For instance, by looking at the bookmarks as WF is running and looking at the names of the macros in the WF template.

You can't reverse-engineer software without complex tools and WF's code is not accessible.

Should you want to go the "delay" way, take a look at "Application.OnTime" command, which triggers the execution of a macro at a certain time. For instance, to launch it 1 minute from "now" (or ASAP after that):

Applicati
... See more
I just looked at how WF works. For instance, by looking at the bookmarks as WF is running and looking at the names of the macros in the WF template.

You can't reverse-engineer software without complex tools and WF's code is not accessible.

Should you want to go the "delay" way, take a look at "Application.OnTime" command, which triggers the execution of a macro at a certain time. For instance, to launch it 1 minute from "now" (or ASAP after that):

Application.OnTime When:=Now + TimeValue("00:01:00"), Name:="YOUR_MACRO_HERE"

Only one macro can be pending execution, though.
Collapse


 
Evelien Snel
Evelien Snel  Identity Verified
Netherlands
Local time: 02:31
English to Dutch
+ ...
TOPIC STARTER
I tried, but... Dec 8, 2011

Daniel Grau wrote:

...
Application.OnTime When:=Now + TimeValue("00:01:00"), Name:="YOUR_MACRO_HERE"
...


Thanks Daniel!

I immediately tried that this morning.... And it failed!
SO.... It looks like WF is using Application.OnTime itself.
This proves NOT everything is happening sequentially.

After that I have started to experiment with the WfNextSegment macro you pointed me to. This seems to work a lot better. I can wrap a call to WfNextSegment plus a call to my own macro together in a macro called MyNextSegment.

So I am now not really wrapping my own macro into WF, it is the other way around!

So I thought I did not need to fill in a macro name in the MT tab any more...
But when I unticked that option, the unwanted copy source went away!
And I DO want it to provide my macro with input text...

My conclusion for now is I do need a small macro to be called there.
It can set a global variable "UseMyMT". (It is only called if there is no TM match.)
After return from WfNextSegment, my wrapper macro can check the variable UseMyMT and only call my TranslateSegment macro if the variabel has been set. (No need to find and check the PercentMatch field.)

Investigation is still in progress....


 
Daniel Grau
Daniel Grau  Identity Verified
Argentina
Member (2008)
English to Spanish
Some comments Dec 9, 2011

It seems WF uses Application.OnTime associated to: a "WfLauncher" macro (whatever it launches), and "{Escape}" sequence (possibly MT), and AutoCorrect (the AC tab) with delays from 0 to 2 seconds.

I use none of those features, so WF's calls to Application.OnTime don't interfere with another Application.OnTime macro that I have constantly running in the background, once per minute.

It is not clear to me why WF would copy the source text when there is no match. The only t
... See more
It seems WF uses Application.OnTime associated to: a "WfLauncher" macro (whatever it launches), and "{Escape}" sequence (possibly MT), and AutoCorrect (the AC tab) with delays from 0 to 2 seconds.

I use none of those features, so WF's calls to Application.OnTime don't interfere with another Application.OnTime macro that I have constantly running in the background, once per minute.

It is not clear to me why WF would copy the source text when there is no match. The only trigger I know for that is PB's CopySourceWhenNoMatch, but you said you've disabled PB. Perhaps if WF is not getting a result from whatever MT it is supposed to be using, it decides to copy the source.

Do a step-by-step execution to debug, but add an execution break right after calling WfNextSegment, i.e., in the text statement fter it. For some reason, when WF macros are called, they do not return control to the calling Sub. Instead, execution proceeds all the way to the end of the calling Sub.

To cheer you up, I did manage (in old WF 5.17z, now I'm using a newer WF 5.92m) to have WF call an MT routine. I just added a new toolbar and a menu item called CAT associated to the CAT macro. No deletion of extraneous material was required, so do find out where that extra text is coming from.

Or perhaps I'm not following what you are trying to do?
Collapse


 
Evelien Snel
Evelien Snel  Identity Verified
Netherlands
Local time: 02:31
English to Dutch
+ ...
TOPIC STARTER
Wordfast working with macro based MT fine now Dec 15, 2011

Well, I have figured it out by now. The solution I found works in two stages: I have wrapped the Wordfast macro that opens the next segment in a macro of my own and I use the macro call that is done by Wordfast just to set a flag to indicate to my wrapper macro it should do a translation on this segment.

The macro code I used for this
... See more
Well, I have figured it out by now. The solution I found works in two stages: I have wrapped the Wordfast macro that opens the next segment in a macro of my own and I use the macro call that is done by Wordfast just to set a flag to indicate to my wrapper macro it should do a translation on this segment.

The macro code I used for this can be found in a posting on my blog:
Machine translation from Wordfast

I would like to thank you all for thinking along with me and providing me with useful tips to find the solution.
Collapse


 
Alex Lago
Alex Lago  Identity Verified
Spain
Local time: 02:31
English to Spanish
+ ...
Macro MT? Dec 17, 2011

You mention you use your own macro-based MT, could you elaborate on that and offer some insight as to what exactly it is these macros do?

 
Evelien Snel
Evelien Snel  Identity Verified
Netherlands
Local time: 02:31
English to Dutch
+ ...
TOPIC STARTER
This question was to be expected :) Dec 17, 2011

Alex Lago wrote:

You mention you use your own macro-based MT, could you elaborate on that and offer some insight as to what exactly it is these macros do?


Good question Alex.

The details of THAT macro are left as an exercise to the user in my blog posting for a very good reason: It is the result of years of research and trial-and-error and it is part of my competitive edge over other translators.

It started as a macro I recorded to do a series of search-and-replace commands over the more boring sections of my translations: Parts lists. So that was a pure word-for-word translation; useful for parts lists, not for normal texts.
Over the years I have kept improving upon this, step by step. And by now it has grown into a grammatical analysis of the source text and generation of the target text. Of course it does not always work, it is still growing...


 
Alex Lago
Alex Lago  Identity Verified
Spain
Local time: 02:31
English to Spanish
+ ...
Broad information as opposed to specific details Dec 17, 2011

Evelien Snel wrote:
... and it is part of my competitive edge over other translators.


I expected this answer which is why I mentioned "insight" as opposed to "details".

If I understand you correctly, you basically started out with a kind of "terminology" software which looked for and replaced terms, but over time you now actually analyze the grammar of the source text, so you are using a "different" approach to mainstream MT which uses a "statistical" approach, probably more similar to the old approach MT used.

I thought you might use some kind of grammar analysis as I very much doubted you had the amount of quality source/translation texts to build a useful "statistical" system, and that is what interested me, what kind of approach you take to analyze the text.

I don't want to detract from your "competitive edge" but any information you could give on the approach you have adopted would be appreciated.


 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Disable copy source to use a macro







Protemos translation business management system
Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!

The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.

More info »
CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

Buy now! »