1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.okapi.connectors.google.v3;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import net.sf.okapi.common.query.MatchType;
25 import net.sf.okapi.common.query.QueryResult;
26 import net.sf.okapi.common.resource.TextFragment;
27
28
29
30
31 public class TextQueryResultBuilder implements QueryResultBuilder<String> {
32
33 private final String origin;
34 private final int weight;
35
36 public TextQueryResultBuilder(String origin, int weight) {
37 this.origin = origin;
38 this.weight = weight;
39 }
40
41 @Override
42 public List<QueryResult> convertResponses(List<TranslationResponse> responses,
43 String originalSource) {
44 List<QueryResult> results = new ArrayList<>();
45
46 for (TranslationResponse response : responses) {
47 QueryResult qr = new QueryResult();
48
49 qr.source = new TextFragment(originalSource);
50 qr.target = new TextFragment(response.getTranslatedText());
51 qr.setFuzzyScore(100);
52 qr.setCombinedScore(100);
53 qr.matchType = MatchType.MT;
54 qr.origin = origin;
55 qr.weight = weight;
56 qr.setQuality(QueryResult.QUALITY_UNDEFINED);
57
58 results.add(qr);
59 }
60
61 return results;
62 }
63
64 @Override
65 public QueryResult createDummyResponse(String originalSource) {
66 QueryResult qr = new QueryResult();
67
68 qr.source = new TextFragment(originalSource);
69 qr.target = new TextFragment(originalSource);
70 qr.setFuzzyScore(0);
71 qr.setCombinedScore(0);
72 qr.matchType = MatchType.MT;
73 qr.origin = origin;
74 qr.weight = weight;
75 qr.setQuality(QueryResult.QUALITY_UNDEFINED);
76
77 return qr;
78 }
79 }