• Not Answered

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

6 Replies Latest Replies: 31 Jan 2019 5:11 AM by Taiki Takada < 1   2  >

6 Replies

  • 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

     

  • In reply to Taiki Takada:

    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?
  • In reply to Sonal Rana:

    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

  • In reply to Taiki Takada:

    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?
  • In reply to Sonal Rana:

    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.

    And the results on BWB.

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

    Best,

    Taiki

< 1   2  >
Related