Merging and Splitting Segments in #OmegaT without editing segmentation rules.

One of the complains OmegaT gets is impossibility to split and merge segments without editing projects’ or global segmentation rules.  There were a few attempts to address the issue, but they required a third-party utility that would edit segmentation.conf. One of the most recent attempt was Dimitry Prihodko’s Merge utility. If I understood it right, Dimitry asked Yu Tang to rework his thingy, and Yu Tang came up with a Groovy script that did all the merging using only OmegaT internals. It wasn’t limited to any OS or dependent on other tools (so much for hard Pascal coding, Dimitry). There was only a minor issue that the script couldn’t be used to split segments. And that’s what I’ve added and what I’m sharing here.

The script and its .properties (only English and Russian so far) can be downloaded from SF.net.

The script works only with the project specific segmentation. When the script is invoked, it will try to split the current segment or merge it with the next. It will try to split the segment when there’s a selection in the current source that goes from the split point up to the end of the segment (right before the segment marker). If anything else is selected, even in the current source, it will be ignored and the merge with the next segment will be attempted.

So, in order to merge just run the script, and it will try to put the current and the next segments together. If a segment needs to be split, activate it, select the part that needs to become the next segment (till the very end), and run the script.

The script will show a confirm message with the perspective merge/split result, so it could be canceled. It will also prompt to reload the project, and that prompt was added because there might be a situation when several rules need to be added, and reloading after each of them would be a waste of time.

Of course, the script isn’t too universal, and if one joined two segments together and later wanted to split them, the chances are it won’t work as the added rules will clash. Or there might be a rule somewhere that is simply wider than the one just added, so the desired split or merge wouldn’t actually occur. And therefore from time to time one might need to call up Project properties and get their hands dirty with the rules.

All the credits go to Yu Tang for cool Groovy coding and Dimitry Prihodko for the idea and hard pushing. Any further help and/or comments are very welcome. If any of native English speakers wanted to edit the .properties (somewhat hastily put together, sorry), that would be really awesome.


But as of now,
Good luck

Advertisements

10 thoughts on “Merging and Splitting Segments in #OmegaT without editing segmentation rules.

  1. Very good job Kos, Dimitry and Yu Tang!

    I tried the script on a test project and it works correctly. I will use for real projects and see how it works.

    As for the properties file, I noticed an error in the English version:

    wrongSelected=Selection in not at the end of the segment, trying to merge…
    must be
    wrongSelected=Selection is not at the end of the segment, trying to merge…

    Now OmegaT is a complete CAT!

      • The script no longer works with the version 4.0.1:
        The script “C:\Program Files (x86)\OmegaT\scripts\merge_split.groovy” is running…
        An error occurred
        javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.escapeNonRegex() is applicable for argument types: (java.lang.String) values:

  2. hello,
    I have tried the newest version 0.4.11 in my Omegat 3.6.0_3 in Linux. I think it used to work for me. Now when I run the script it tells me “Nothing to merge! Terminating now!”. Please help.
    thank you

  3. Hello Kos, first of all, thanks so much for the script. I installed a couple of days ago and it worked flawlessly on the first document I tried but today, as I had to use it on a different document, even though the confirmation dialogue appears and shows the correct merging segments and I confirm that I want to reopen/refresh the file, the segments do not get merged! In other words, nothing happens! Very weird! Do you have any idea of what might be happening and how to “fix it”? The segmentation settings are set to “project specific”. Thanks so much!

    • Hi Marco,
      If there’s a hard break or a tab between the text presented in OmegaT as two segments, there’s nothing you can do with or without this script to merge them into one, except editing the source file. If it’s a line break, and the source file is .docx, there’s a file filter option to segment on line breaks or present them as tags, but you need to be careful with this option, as it applies either globally or to the whole project, not to the current segment or current file.

      If it’s not the things described above, I’ll need to see what you’re trying to merge, and, possibly, your segmentation.conf

      • Thank you so much for your quick and helpful response. I had three instances where I wanted to merge the segments within the same document and the plugin worked in one of them but not the other two so it probably has to do with the possible issues you mentioned. I will check the source file and report back. Thank you so much! Best regards!

      • AWESOME!!! It was exactly as you described. The segments that were not being merged had line breaks in them! (duh! 🙂 ) I did fix the source file, clicked on “Reload” and then “re-copied” the source files. It worked perfectly! Thanks again! Awesome plug in and support!!!! Best regards!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s