Search in sources :

Example 1 with TermEntry

use of gen.core.tbx.TermEntry in project omegat by omegat-org.

the class GlossaryReaderTBX method readMartif.

public static List<GlossaryEntry> readMartif(final Martif tbx, boolean priorityGlossary, String origin) throws Exception {
    if (tbx.getText() == null) {
        return Collections.emptyList();
    }
    String sLang = Core.getProject().getProjectProperties().getSourceLanguage().getLanguageCode();
    String tLang = Core.getProject().getProjectProperties().getTargetLanguage().getLanguageCode();
    StringBuilder note = new StringBuilder();
    StringBuilder descTerm = new StringBuilder();
    StringBuilder descTig = new StringBuilder();
    List<GlossaryEntry> result = new ArrayList<GlossaryEntry>();
    List<String> sTerms = new ArrayList<String>();
    List<String> tTerms = new ArrayList<String>();
    for (TermEntry te : tbx.getText().getBody().getTermEntry()) {
        note.setLength(0);
        descTerm.setLength(0);
        descTig.setLength(0);
        appendDescOrNote(te.getDescripOrDescripGrpOrAdmin(), descTerm);
        for (LangSet ls : te.getLangSet()) {
            Language termLanguage = new Language(ls.getLang());
            // We use only the language code
            String lang = termLanguage.getLanguageCode();
            appendDescOrNote(ls.getDescripOrDescripGrpOrAdmin(), descTig);
            for (Object o : ls.getTigOrNtig()) {
                if (o instanceof Tig) {
                    Tig t = (Tig) o;
                    if (sLang.equalsIgnoreCase(lang)) {
                        sTerms.add(readContent(t.getTerm().getContent()));
                    } else if (tLang.equalsIgnoreCase(lang)) {
                        tTerms.add(readContent(t.getTerm().getContent()));
                        appendDescOrNote(t.getTermNote(), note);
                    }
                    appendDescOrNote(t.getDescripOrDescripGrpOrAdmin(), descTig);
                } else if (o instanceof Ntig) {
                    Ntig n = (Ntig) o;
                    if (sLang.equalsIgnoreCase(lang)) {
                        sTerms.add(readContent(n.getTermGrp().getTerm().getContent()));
                    } else if (tLang.equalsIgnoreCase(lang)) {
                        tTerms.add(readContent(n.getTermGrp().getTerm().getContent()));
                        appendDescOrNote(n.getTermGrp().getTermNoteOrTermNoteGrp(), note);
                    }
                    appendDescOrNote(n.getDescripOrDescripGrpOrAdmin(), descTig);
                }
            }
        }
        StringBuilder comment = new StringBuilder();
        appendLine(comment, descTerm.toString());
        appendLine(comment, descTig.toString());
        appendLine(comment, note.toString());
        for (String s : sTerms) {
            boolean addedForLang = false;
            for (String t : tTerms) {
                result.add(new GlossaryEntry(s, t, comment.toString(), priorityGlossary, origin));
                addedForLang = true;
            }
            if (!addedForLang) {
                // An entry is created just to get the definition
                result.add(new GlossaryEntry(s, "", comment.toString(), priorityGlossary, origin));
            }
        }
        sTerms.clear();
        tTerms.clear();
    }
    return result;
}
Also used : Ntig(gen.core.tbx.Ntig) ArrayList(java.util.ArrayList) LangSet(gen.core.tbx.LangSet) Tig(gen.core.tbx.Tig) Language(org.omegat.util.Language) TermEntry(gen.core.tbx.TermEntry)

Aggregations

LangSet (gen.core.tbx.LangSet)1 Ntig (gen.core.tbx.Ntig)1 TermEntry (gen.core.tbx.TermEntry)1 Tig (gen.core.tbx.Tig)1 ArrayList (java.util.ArrayList)1 Language (org.omegat.util.Language)1