1 package com.acumenvelocity.ath.common;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import com.acumenvelocity.ath.model.x.LayeredTextX;
9
10 import net.sf.okapi.common.LocaleId;
11 import net.sf.okapi.common.annotation.IAnnotation;
12 import net.sf.okapi.common.resource.ISegments;
13 import net.sf.okapi.common.resource.ITextUnit;
14 import net.sf.okapi.common.resource.Segment;
15 import net.sf.okapi.common.resource.TextContainer;
16 import net.sf.okapi.common.resource.TextFragment;
17
18 public class OriginalTuAnnotation implements IAnnotation {
19
20 private ITextUnit tu;
21 private final List<LayeredTextX> sourceSegments;
22 private final Map<LocaleId, List<LayeredTextX>> targetSegments;
23
24 public OriginalTuAnnotation(ITextUnit tu, LocaleId srcLoc) {
25 super();
26
27 this.tu = tu;
28 sourceSegments = new ArrayList<>();
29 targetSegments = new HashMap<>();
30
31 TextContainer src = tu.getSource();
32 ISegments ssegs = src.getSegments();
33
34 for (Segment sseg : ssegs) {
35 TextFragment tf = sseg.text;
36 LayeredTextX lt = ConversionUtil.toLayeredText(tf, srcLoc);
37 sourceSegments.add(lt);
38 }
39
40 for (LocaleId trgLoc : tu.getTargetLocales()) {
41 TextContainer trg = tu.getTarget(trgLoc);
42 ISegments tsegs = trg.getSegments();
43
44 List<LayeredTextX> lts = new ArrayList<>();
45
46 for (Segment tseg : tsegs) {
47 TextFragment tf = tseg.text;
48 LayeredTextX lt = ConversionUtil.toLayeredText(tf, trgLoc);
49 lts.add(lt);
50 }
51
52 targetSegments.put(trgLoc, lts);
53 }
54 }
55
56 public ITextUnit getTu() {
57 return tu;
58 }
59
60 public List<LayeredTextX> getSourceSegments() {
61 return sourceSegments;
62 }
63
64 public List<LayeredTextX> getTargetSegments(LocaleId locId) {
65 return targetSegments.get(locId);
66 }
67
68 }