One more
[apertium.git] / crossdics / src / ProcessDics.java
blob2f768d525a5d5cf9105cbf1bbdf62e0c869ac8a0
1 /*
2 * Copyright (C) 2007 Universitat d'Alacant / Universidad de Alicante
3 * Author: Enrique Benimeli Bofarull
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 * 02111-1307, USA.
21 import misc.DicFormatE1Line;
22 import misc.GetTranslation;
23 import dics.elements.utils.Msg;
24 import dictools.DicConsistent;
25 import dictools.DicCross;
26 import dictools.DicFindEquivPar;
27 import dictools.DicFormat;
28 import dictools.DicGather;
29 import dictools.DicMerge;
30 import dictools.DicReader;
31 import dictools.DicReverse;
32 import dictools.DicSort;
34 /**
36 * @author Enrique Benimeli Bofarull
39 public class ProcessDics {
41 /**
44 private String action;
46 /**
49 private String[] arguments;
51 /**
54 private Msg msg;
56 /**
57 * Método principal.
59 * @param args
61 public static void main(final String[] args) {
62 final ProcessDics ps = new ProcessDics(args);
63 ps.go();
66 /**
68 * @param args
70 public ProcessDics(final String[] args) {
71 msg = new Msg();
72 setArguments(args);
75 /**
79 public final void go() {
80 checkAction();
83 /**
87 public final void checkAction() {
88 if (getArguments().length == 0) {
89 msg.err("Usage: java ProcessDics <action> [options]");
90 System.exit(-1);
93 setAction(getArguments()[0]);
95 if (getAction().equals("consistent")) {
96 if (getArguments().length < 8) {
97 msg
98 .err("Usage: java ProcessDics consistent -bilAB [-r] <bilAB> -bilBC [-r] <bilBC> -monA <mon-A> -monC <monC>");
99 System.exit(-1);
100 } else {
101 DicConsistent dicConsistent = new DicConsistent();
102 dicConsistent.setArguments(getArguments());
103 dicConsistent.doConsistent();
107 if (getAction().equals("merge")) {
108 if (getArguments().length < 8) {
110 .err("Usage: java ProcessDics merge -bilAB [-r] <bilAB> -bilAB2 [-r] <bilAB2> -monA <mon-A> - monA2 <monA2> -monB <monB> -monB2 <monB2>");
111 System.exit(-1);
112 } else {
113 DicMerge dicMerge = new DicMerge();
114 dicMerge.setArguments(getArguments());
115 dicMerge.doMerge();
119 if (getAction().equals("merge-morph")) {
120 if (getArguments().length < 6) {
122 .err("Usage: java ProcessDics merge-morph -monA1 monA1.dix -monA2 monA2.dix -out merged.dix");
123 System.exit(-1);
124 } else {
125 DicMerge dicMerge = new DicMerge();
126 dicMerge.setArguments(getArguments());
127 dicMerge.doMergeMorph();
131 if (getAction().equals("merge-bil")) {
132 if (getArguments().length < 6) {
134 .err("Usage: java ProcessDics merge-bil -bilAB1 bilAb1.dix -bilAB2 bilAB2.dix -out merged.dix");
135 System.exit(-1);
136 } else {
137 DicMerge dicMerge = new DicMerge();
138 dicMerge.setArguments(getArguments());
139 dicMerge.doMergeBil();
143 if (getAction().equals("cross")) {
144 if (getArguments().length < 8) {
146 .err("Usage: java ProcessDics cross -bilAB [-r] <bilAB> -bilBC [-r] <bilBC> -monA <mon-A> -monC <monC>");
147 System.exit(-1);
148 } else {
149 DicCross dicCross = new DicCross();
150 dicCross.setArguments(getArguments());
151 dicCross.doCross();
155 if (getAction().equals("reverse")) {
156 if ((getArguments().length > 3) || (getArguments().length < 2)) {
157 msg.err("Usage: java ProcessDics reverse <bil> <bil-reversed>");
158 System.exit(-1);
159 } else {
160 DicReverse dicReverse = new DicReverse();
161 dicReverse.setArguments(arguments);
162 dicReverse.doReverse();
166 if (getAction().equals("format")) {
167 if (getArguments().length != 4) {
169 .err("Usage: java ProcessDics format <-mon|-bil> <dic> <dic-formatted>");
170 System.exit(-1);
171 } else {
172 final DicFormat dicFormat = new DicFormat();
173 dicFormat.setArguments(arguments);
174 dicFormat.doFormat();
178 if (getAction().equals("sort")) {
179 if (getArguments().length != 5) {
181 .err("Usage: java ProcessDics sort <-mon|-bil> <-xinclude|-same-file> <dic> <dic-sorted>");
182 System.exit(-1);
183 } else {
184 DicSort dicSort = new DicSort();
185 dicSort.setArguments(arguments);
186 dicSort.doSort();
190 if (getAction().equals("gather")) {
191 if (getArguments().length != 3) {
192 msg.err("Usage: java ProcessDics gather <dic> <dic-sorted>");
193 System.exit(-1);
194 } else {
195 DicGather dicGather = new DicGather(arguments[1], arguments[2]);
196 // dicGather.setArguments(arguments);
197 dicGather.doGather();
201 if (getAction().equals("get-bil-omegawiki")) {
202 if (getArguments().length != 4) {
204 .err("Usage: java ProcessDics get-bil-omegawiki <source-lang> <target-lang> <dic-out>");
205 System.exit(-1);
206 } else {
207 GetTranslation gt = new GetTranslation(arguments[1],
208 arguments[2]);
209 gt.setOutFileName(arguments[3]);
210 gt.printDictionary();
214 if (getAction().equals("format-1line")) {
215 if (getArguments().length != 3) {
216 msg.err("Usage: java ProcessDics format-1line <dic> <dic-out>");
217 System.exit(-1);
218 } else {
219 DicFormatE1Line dicFormat = new DicFormatE1Line(arguments[1]);
220 dicFormat.printXML(arguments[2]);
224 if (getAction().equals("dic-reader")) {
225 if (getArguments().length < 3) {
226 msg.err("Usage: java ProcessDics dic-reader <action> [-url] <dic>");
227 System.exit(-1);
228 } else {
229 DicReader dicReader = new DicReader();
230 dicReader.setAction(arguments[1]);
231 if (arguments[2].equals("-url")) {
232 dicReader.setUrlDic(true);
233 dicReader.setUrl(arguments[3]);
234 System.out.println("URL: " + arguments[3]);
235 } else {
236 dicReader.setDic(arguments[2]);
238 dicReader.doit();
242 if (getAction().equals("equiv-paradigms")) {
243 if (getArguments().length != 3) {
244 msg.err("Usage: java ProcessDics equiv-paradigms <dic> <dic-out>");
245 System.exit(-1);
246 } else {
247 DicFindEquivPar finder = new DicFindEquivPar(arguments[1]);
248 finder.setOutFileName(arguments[2]);
249 finder.findEquivalents();
256 * @return the action
258 private final String getAction() {
259 return action;
263 * @param action
264 * the action to set
266 private final void setAction(final String action) {
267 this.action = action;
271 * @return the arguments
273 private final String[] getArguments() {
274 return arguments;
278 * @param arguments
279 * the arguments to set
281 private final void setArguments(final String[] arguments) {
282 this.arguments = arguments;