Retrieve actual tags(ph, bpt, ept) information from the placeholders using API.

Hi Everyone,

I would like to retrieve actual tags(ph, bpt, ept) from the placeholders.
The only information I have is WScontext object. I got to the point where I could retrieve AssetManager information using WScontext object.

Iterator textSegmentsIterator = context.getAssetManager().getAsset("AIS path").textSegmentIterator();
However, I don't know how to get the AIS path.

Is there any API to get actual tags from the placeholders using WScontext object?

 

Thanks in advance.
Sonal

Parents
  • Hi Sonal,

    Please try this code to acquire actual contents of the placeholders.

    WSAssetTask task = (WSAssetTask) context.getWorkflowManager().getTask(TASK_ID);
    System.out.println(task.getSourceAisNode().getName());

    Iterator<WSSegmentTranslation> iterator = task.getAssetTranslation().segmentIterator();
    while(iterator.hasNext()) {
    WSSegmentTranslation translation = iterator.next();

    if(translation instanceof WSMarkupSegmentTranslation) {
    //System.out.println("Markup: " + translation.getSource());
    } else if(translation instanceof WSTextSegmentTranslation) {
    WSTextSegmentPlaceholder[] placeholders = ((WSTextSegmentTranslation) translation).getSourcePlaceholders();
    if(placeholders.length > 0){
    System.out.println("PH1 = " + placeholders[0].getText());
    }
    System.out.printf("Text (%d): %s%n", ((WSTextSegmentTranslation) translation).getSourceWordCount(), translation.getSource());
    } else {
    //System.out.println("Misc.: " + translation.getSource());
    }
    }

    You can get the actual tags by calling getSourcePlaceholders() or getTargetPlaceholders() methods with WSTextSegmentTranslation object.

    The above sample is for a specific task in a project specified by its ID. If you want to get by specifying an AIS path, please try the below:

    WSAssetManager     manager  = context.getAssetManager();
    WSAssetTranslation assetTrx = manager.getAssetTranslation(sourceAisPath, targetAisPath);
    Iterator<WSSegmentTranslation> iterator = assetTrx.segmentIterator();

    Best,

    Taiki

     

  • Thank You Taiki for your response.

    Unfortunately we do not have Project or Task information with us. We have access to following
    WorldServer Translate interface

    public void translate(final WSContext context, final WSMTRequest parentMtRequests[],
    final WSLanguage sourceLanguage, final WSLanguage targetLanguage) {}

    Can we include some other package to get TASK_ID of the current task being worked upon?
  • A-ha, I guess you are developing an MT adapter.

    However and unfortunately, if you are working inside that tranlsate() method of the WSMTAdapter class, I think there is no way to get the contents of the placeholders.

    But one of the ideas is to wrap the WSMTService class.

    This class comes with the following method.

    public void translate(WSAssetTranslation wsAssetTranslation, double v)

    You might need to implement all of the methods provided by the WSMTService class, but by overriding the above method, you can get the WSAssetTranslation instead of just a simple string.

    Once you can get the WSAssetTranslation object, you can get the placeholder contents as shown in my last reply.

    Sorry, it is totally figuring out inside my head without any actual testing. This is little annoying of implementation, but I think feasible.

    If I can find availability myself, I will try this. Otherwise, testing by yourself might be faster:)

    A few notices.

    This way of MT implementation requires users of your MT adapter class to use your wrapper class of the WSMTService instead of calling the WSMTAdapter directly.

    Please do a good enough testing since you will implement all of the methods in the WSMTService by yourself, to make sure there is no side effect.

    Best,

    Taiki

  • Hi Taiki,

    Thank you for the response. You are right, we have an existing MT adapter.

    Option #1
    You mentioned about WSMTService class.
    If we write a class that extends WSMTService class, how does it get invoked. Do we need to upload the jar as Machine Translation Adapter itself?


    Option #2
    Inside our MT jar we have MT Adaptor code and Automatic Action code.
    Normally, we upload the jar under custom component - Machine Translation Adaptor. Currently, Automatic Action code has not been invoked.
    One of things I tried is to upload the jar to custom component - Automatic Actions as well. However, the Automatic Action code wasn't invoked.

    Is there anyway to invoke Automatic Action code from MT adaptor? or
    Does it require customized workflow to invoke it?
  • 4150.TestMTAdapter.zip

    I did a test and have created some code samples as above. I think this can be your answer.

    This sample contains sample Java code files for two components (with one desc.xml):

    • My Test MT: An dummy MT component, which is just to catch the target text with specific suffix and prefix. 
    • My Test AA: An automatic action to apply that My Test MT. Along with that process, it adds a comment to a segment if any italic tag is in the tags. 

    So if you build it and create a ZIP file to install, the sample can show:

    • Adding both an automatic action and an MT component by uploading a single installer ZIP into WorldServer.
    • The automatic action which applies this "My Test MT"MT automatically. 
      • And since it adds a comment if a tag is for italic, this means you can get the actual tag information along with the actual MT process.
    • Since a class implementing the WSMTService class has been used in the AA, that might be a good sample of how to use such a class.

    This is a sample workflow I used for this test.

    Workflow diagram in Trados Studio showing a process with steps including Start, Clear Segment, Segment Auto, My Test AA, Auto Error, and Finish.

    And the results on BWB.

    Trados Studio interface displaying segment comments indicating the presence of an italic tag in the translation segments.

    Please feel free to reply for any further question if any.

    Best,

    Taiki



    Generated Image Alt-Text
    [edited by: Trados AI at 10:37 AM (GMT 0) on 4 Mar 2024]
  • Thanks Taiki. We have to make changes to the workflow to invoke Automatic Action. Will keep you posted.
  • Hi Taiki,

    I created custom workflow to include Automatic Action.
    1. I upload the .jar in Management/Customization - Machine Translation Adapters.
    It gets updated in Automatic Actions as well.
    2. Created custom workflow to invoke our Automatic Action.
    3. Selected custom workflow under Business Rule Linkage

    When I create a project for translation it still invokes MT Adapter code before automatic action code.
    Is MT Adapter always invoked before Automatic Action?
  • I think that was done by the Segment Assets AA. Please try to turn off the Leverage Assigne MT parameter.
Reply Children
No Data