Search in sources :

Example 1 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class ExecuteGoogleTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    // check the google translation state: check the key availability
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.getState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteGoogleTransHandler.msgTitle"), Messages.getString("handler.ExecuteGoogleTransHandler.msg"));
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    //		int currentRowIndex = selectedRowIndexs[0];
    //		TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(currentRowIndex);
    //		if (transUnitBean == null) {
    //			return null;
    //		}
    //		String srcPureText = transUnitBean.getSrcText();
    //		String tgtLanguage = xliffEditor.getTgtColumnName();
    //		String srcLanguage = xliffEditor.getSrcColumnName();
    //		TransUnitInfo2TranslationBean tuInfo2Trans = new TransUnitInfo2TranslationBean();
    //		tuInfo2Trans.setSrcPureText(srcPureText);
    //		tuInfo2Trans.setSrcLanguage(srcLanguage);
    //		tuInfo2Trans.setTgtLangugage(tgtLanguage);
    String tshelp = System.getProperties().getProperty("TSHelp");
    String tsstate = System.getProperties().getProperty("TSState");
    if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
        LoggerFactory.getLogger(ExecuteGoogleTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
        System.exit(0);
    }
    ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
    //		String tgtText = matcher.executeMatch(tuInfo2Trans);
    //		if (tgtText.equals("")) {
    //			return null;
    //		}
    //		AltTransBean bean = new AltTransBean(srcPureText, tgtText, srcLanguage, tgtLanguage,
    //				matcher.getMathcerOrigin(), matcher.getMathcerToolId());
    //		bean.getMatchProps().put("match-quality", "100");
    //		bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
    //		bean.setSrcContent(srcPureText);
    //		bean.setTgtContent(tgtText);
    //		List<AltTransBean> newAltTrans = new ArrayList<AltTransBean>();
    //		newAltTrans.add(bean);
    // check if need save the AltTrans to file
    //		if (CommonFunction.checkEdition("U") && matcher.isSuportPreTrans()) {
    //			List<String> oldToolIds = new ArrayList<String>();
    //			oldToolIds.add(matcher.getMathcerToolId());
    //			xliffEditor.getXLFHandler().updateAltTrans(xliffEditor.getXLFHandler().getRowId(currentRowIndex), newAltTrans, oldToolIds);
    //		}
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(matcher);
    //matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
    //			matchView.replaceMatchs(newAltTrans);
    //			matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
    //			newAltTrans.clear();
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.googletrans.bean.PrefrenceParameters) SimpleMatcherGoogleImpl(net.heartsome.cat.ts.googletrans.SimpleMatcherGoogleImpl) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 2 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class ExecuteBingTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    // check the google translation state: check the key availability
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.getState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
        return null;
    }
    String tshelp = System.getProperties().getProperty("TSHelp");
    String tsstate = System.getProperties().getProperty("TSState");
    if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
        LoggerFactory.getLogger(ExecuteBingTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
        System.exit(0);
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    //		int currentRowIndex = selectedRowIndexs[0];
    //		TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(currentRowIndex);
    //		if (transUnitBean == null) {
    //			return null;
    //		}
    //		String srcPureText = transUnitBean.getSrcText();
    //		String tgtLanguage = xliffEditor.getTgtColumnName();
    //		String srcLanguage = xliffEditor.getSrcColumnName();
    //		TransUnitInfo2TranslationBean tuInfo2Trans = new TransUnitInfo2TranslationBean();
    //		tuInfo2Trans.setSrcPureText(srcPureText);
    //		tuInfo2Trans.setSrcLanguage(srcLanguage);
    //		tuInfo2Trans.setTgtLangugage(tgtLanguage);
    ISimpleMatcher matcher = new SimpleMatcherBingImpl();
    //		String tgtText = matcher.executeMatch(tuInfo2Trans);
    //		if (tgtText.equals("")) {
    //			return null;
    //		}
    //		AltTransBean bean = new AltTransBean(srcPureText, tgtText, srcLanguage, tgtLanguage,
    //				matcher.getMathcerOrigin(), matcher.getMathcerToolId());
    //		bean.getMatchProps().put("match-quality", "100");
    //		bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
    //		bean.setSrcContent(srcPureText);
    //		bean.setTgtContent(tgtText);
    //		List<AltTransBean> newAltTrans = new ArrayList<AltTransBean>();
    //		newAltTrans.add(bean);
    // check if need save the AltTrans to file
    //		if (CommonFunction.checkEdition("U") && matcher.isSuportPreTrans()) {
    //			List<String> oldToolIds = new ArrayList<String>();
    //			oldToolIds.add(matcher.getMathcerToolId());
    //			xliffEditor.getXLFHandler().updateAltTrans(xliffEditor.getXLFHandler().getRowId(currentRowIndex), newAltTrans, oldToolIds);
    //		}
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        //matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
        //			matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
        //			matchView.replaceMatchs(newAltTrans);
        //			newAltTrans.clear();
        matchView.manualExecSimpleTranslation(matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SimpleMatcherBingImpl(net.heartsome.cat.ts.bingtrans.SimpleMatcherBingImpl) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.bingtrans.bean.PrefrenceParameters) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 3 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class ExecuteBingTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    // check the google translation state: check the key availability
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.isBingState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    ISimpleMatcher matcher = new SimpleMatcherBingImpl();
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SimpleMatcherBingImpl(net.heartsome.cat.ts.machinetranslation.SimpleMatcherBingImpl) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 4 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class ExecuteGoogleTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.isGoogleState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteGoogleTransHandler.msgTitle"), Messages.getString("handler.ExecuteGoogleTransHandler.msg"));
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters) SimpleMatcherGoogleImpl(net.heartsome.cat.ts.machinetranslation.SimpleMatcherGoogleImpl) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 5 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class PreTranslation method executeSimpleMatch.

// private String defaultSimplematcher;
private String executeSimpleMatch(VTDUtils vu, TransUnitInfo2TranslationBean tuInfo, XMLModifier xm) throws /*
																										 * , boolean
																										 * updateTarget
																										 */
XPathParseException, XPathEvalException, NavException {
    List<ISimpleMatcher> simpleMatchers = SimpleMatcherFactory.getInstance().getCuurentMatcher();
    StringBuffer bf = new StringBuffer();
    for (ISimpleMatcher matcher : simpleMatchers) {
        if (!matcher.isSuportPreTrans()) {
            continue;
        }
        String toolId = matcher.getMathcerToolId();
        boolean isOverwrite = matcher.isOverwriteMatch();
        boolean needClear = false;
        vu.getVTDNav().push();
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath("./alt-trans[@tool-id='" + toolId + "']");
        if (ap.evalXPath() != -1) {
            if (!isOverwrite) {
                vu.getVTDNav().pop();
                continue;
            } else {
                needClear = true;
            }
        }
        vu.getVTDNav().pop();
        if (needClear) {
            vu.delete(new AutoPilot(vu.getVTDNav()), xm, "./alt-trans[@tool-id='" + toolId + "']", VTDUtils.PILOT_TO_END);
        }
        String tgtText = matcher.executeMatch(tuInfo);
        if (tgtText.equals("")) {
            continue;
        }
        /*
			 * if (updateTarget && defaultSimplematcher.equals(toolId)) { vu.delete(new AutoPilot(vu.getVTDNav()), xm,
			 * "./target", VTDUtils.PILOT_TO_END); bf.append("<target xml:lang=\"" + tuInfo.getTgtLangugage() +
			 * "\" state=\"new\"  hs:matchType=\"" + matcher.getMatcherType() + "\" hs:quality=\"100\">");
			 * bf.append(tgtText); bf.append("</target>");
			 * 
			 * currentCounter.countTransTu(); }
			 */
        AltTransBean bean = new AltTransBean(tuInfo.getSrcPureText(), tgtText, tuInfo.getSrcLanguage(), tuInfo.getTgtLangugage(), matcher.getMathcerOrigin(), matcher.getMathcerToolId());
        bean.getMatchProps().put("match-quality", "100");
        bean.setSrcContent(tuInfo.getSrcPureText());
        bean.setTgtContent(tgtText);
        bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
        bf.append(bean.toXMLString());
    }
    return bf.toString();
}
Also used : AltTransBean(net.heartsome.cat.ts.core.bean.AltTransBean) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) AutoPilot(com.ximpleware.AutoPilot)

Aggregations

ISimpleMatcher (net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher)8 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)4 MatchViewPart (net.heartsome.cat.ts.ui.translation.view.MatchViewPart)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IViewPart (org.eclipse.ui.IViewPart)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 AutoPilot (com.ximpleware.AutoPilot)2 AltTransBean (net.heartsome.cat.ts.core.bean.AltTransBean)2 PrefrenceParameters (net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters)2 ArrayList (java.util.ArrayList)1 SimpleMatcherBingImpl (net.heartsome.cat.ts.bingtrans.SimpleMatcherBingImpl)1 PrefrenceParameters (net.heartsome.cat.ts.bingtrans.bean.PrefrenceParameters)1 SimpleMatcherGoogleImpl (net.heartsome.cat.ts.googletrans.SimpleMatcherGoogleImpl)1 PrefrenceParameters (net.heartsome.cat.ts.googletrans.bean.PrefrenceParameters)1 SimpleMatcherBingImpl (net.heartsome.cat.ts.machinetranslation.SimpleMatcherBingImpl)1 SimpleMatcherGoogleImpl (net.heartsome.cat.ts.machinetranslation.SimpleMatcherGoogleImpl)1 IComplexMatch (net.heartsome.cat.ts.tm.complexMatch.IComplexMatch)1