View Javadoc
1   package com.acumenvelocity.ath.solr.tm;
2   
3   import java.util.UUID;
4   
5   import com.acumenvelocity.ath.common.Const;
6   
7   import net.sf.okapi.common.ParametersDescription;
8   import net.sf.okapi.common.StringParameters;
9   import net.sf.okapi.common.uidescription.EditorDescription;
10  import net.sf.okapi.common.uidescription.IEditorDescriptionProvider;
11  
12  public class Parameters extends StringParameters implements IEditorDescriptionProvider {
13    static final String TM_ID = "tmId";
14  
15    static final String SOLR_CORE_NAME = "solrCoreName";
16    static final String SEARCH_IN_SOURCE = "searchInSource";
17  
18    static final String PENALIZE_SOURCE_TAGS_DIFFERENCE = "penalizeSourceTagsDifference";
19    static final String PENALIZE_TARGET_TAGS_DIFFERENCE = "penalizeTargetTagsDifference";
20  
21    public Parameters() {
22      super();
23    }
24  
25    public Parameters(String initialData) {
26      super(initialData);
27    }
28  
29    public String getTmId() {
30      return getString(TM_ID);
31    }
32  
33    public void setTmId(String tmId) {
34      setString(TM_ID, tmId);
35    }
36  
37    public String getSolrCoreName() {
38      return getString(SOLR_CORE_NAME);
39    }
40  
41    public void setSolrCoreName(String solrCoreName) {
42      setString(SOLR_CORE_NAME, solrCoreName);
43    }
44  
45    public boolean getSearchInSource() {
46      return getBoolean(SEARCH_IN_SOURCE);
47    }
48  
49    public void setSearchInSource(boolean searchInSource) {
50      setBoolean(SEARCH_IN_SOURCE, searchInSource);
51    }
52  
53    public boolean getPenalizeSourceTagsDifference() {
54      return getBoolean(PENALIZE_SOURCE_TAGS_DIFFERENCE);
55    }
56  
57    public void setPenalizeSourceTagsDifference(boolean penalizeSourceTagsDifference) {
58      setBoolean(PENALIZE_SOURCE_TAGS_DIFFERENCE, penalizeSourceTagsDifference);
59    }
60  
61    public boolean getPenalizeTargetTagsDifference() {
62      return getBoolean(PENALIZE_TARGET_TAGS_DIFFERENCE);
63    }
64  
65    public void setPenalizeTargetTagsDifference(boolean penalizeTargetTagsDifference) {
66      setBoolean(PENALIZE_TARGET_TAGS_DIFFERENCE, penalizeTargetTagsDifference);
67    }
68  
69    @Override
70    public void reset() {
71      super.reset();
72  
73      setTmId(UUID.randomUUID().toString());
74  
75      setSolrCoreName(Const.SOLR_CORE_ATH_TM_SEGMENTS);
76      setSearchInSource(true);
77  
78      setPenalizeSourceTagsDifference(true);
79      setPenalizeTargetTagsDifference(true);
80    }
81  
82    @Override
83    public ParametersDescription getParametersDescription() {
84      ParametersDescription desc = new ParametersDescription(this);
85  
86      desc.add(TM_ID,
87          "TM ID", null);
88  
89      desc.add(SOLR_CORE_NAME,
90          "Solr core name", null);
91  
92      desc.add(SEARCH_IN_SOURCE,
93          "Search in the source parts of TM segments", null);
94  
95      desc.add(PENALIZE_SOURCE_TAGS_DIFFERENCE,
96          "Penalize TM matches when the source has different codes than the query", null);
97  
98      desc.add(PENALIZE_TARGET_TAGS_DIFFERENCE,
99          "Penalize TM matches when the target has different codes than the query", null);
100 
101     return desc;
102   }
103 
104   @Override
105   public EditorDescription createEditorDescription(ParametersDescription paramsDesc) {
106     EditorDescription desc = new EditorDescription("Solr TM Connector Settings", true, false);
107 
108     desc.addTextInputPart(paramsDesc.get(Parameters.TM_ID));
109 
110     desc.addTextInputPart(paramsDesc.get(Parameters.SOLR_CORE_NAME));
111     desc.addCheckboxPart(paramsDesc.get(Parameters.SEARCH_IN_SOURCE));
112 
113     desc.addCheckboxPart(paramsDesc.get(Parameters.PENALIZE_SOURCE_TAGS_DIFFERENCE));
114     desc.addCheckboxPart(paramsDesc.get(Parameters.PENALIZE_TARGET_TAGS_DIFFERENCE));
115 
116     return desc;
117   }
118 }