Search in sources :

Example 1 with TaasExtractionResult

use of gen.taas.TaasExtractionResult in project omegat by omegat-org.

the class TaaSClient method termExtraction.

/**
 * Term Extraction method. Domain can be null for request all domains.
 */
TaasExtractionResult termExtraction(Language sourceLang, Language targetLang, String text, String domain) throws IOException, Unauthorized, FormatError {
    StringBuilder r = new StringBuilder();
    r.append(WS_URL).append("/extraction/");
    r.append("?sourceLang=").append(sourceLang.getLanguageCode().toLowerCase(Locale.ENGLISH));
    r.append("&targetLang=").append(targetLang.getLanguageCode().toLowerCase(Locale.ENGLISH));
    r.append("&method=").append(EXTRACTION_METHOD);
    if (!StringUtil.isEmpty(domain)) {
        r.append("&domain=").append(URLEncoder.encode(domain, "UTF-8"));
    }
    HttpURLConnection conn = requestPost(r.toString(), text);
    checkXMLUTF8ContentType(conn);
    String data = readUTF8(conn);
    TaasExtractionResult result;
    try {
        result = (TaasExtractionResult) context.createUnmarshaller().unmarshal(new StringReader(data));
    } catch (Exception ex) {
        throw new FormatError("Wrong content: " + ex.getMessage());
    }
    Log.logDebug(LOGGER, "termExtraction returns data");
    return result;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StringReader(java.io.StringReader) TaasExtractionResult(gen.taas.TaasExtractionResult) IOException(java.io.IOException)

Example 2 with TaasExtractionResult

use of gen.taas.TaasExtractionResult in project omegat by omegat-org.

the class TaaSGlossary method search.

@Override
public List<GlossaryEntry> search(Language sLang, Language tLang, String srcText) throws Exception {
    if (!Preferences.isPreferenceDefault(Preferences.TAAS_LOOKUP, false) || !TaaSPlugin.getClient().isAllowed()) {
        return Collections.emptyList();
    }
    TaasExtractionResult res = TaaSPlugin.getClient().termExtraction(sLang, tLang, srcText, Preferences.getPreference(Preferences.TAAS_DOMAIN));
    String data = TaaSPlugin.filterTaasResult(res.getTerms());
    List<GlossaryEntry> entries = GlossaryReaderTBX.read(data, false, OStrings.getString("TAAS_GLOSSARY_NAME"));
    Log.logDebug(LOGGER, "TaaS returns {0} glossary entries", entries.size());
    return entries;
}
Also used : GlossaryEntry(org.omegat.gui.glossary.GlossaryEntry) TaasExtractionResult(gen.taas.TaasExtractionResult)

Aggregations

TaasExtractionResult (gen.taas.TaasExtractionResult)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HttpURLConnection (java.net.HttpURLConnection)1 GlossaryEntry (org.omegat.gui.glossary.GlossaryEntry)1