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

Reply
  • 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

Children