2 * Copyright (C) 2007 Universitat d'Alacant / Universidad de Alicante
3 * Author: Enrique Benimeli Bofarull
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
23 import dics
.elements
.dtd
.DictionaryElement
;
24 import dics
.elements
.dtd
.EElement
;
25 import dics
.elements
.dtd
.SectionElement
;
26 import dics
.elements
.utils
.EElementList
;
27 import dics
.elements
.utils
.EHashMap
;
28 import dics
.elements
.utils
.Msg
;
32 * @author Enrique Benimeli Bofarull
35 public class DicFormat
{
40 private DictionaryElement dicFormatted
;
45 private String
[] arguments
;
50 public static final int BIL
= 0;
55 public static final int MON
= 1;
84 public DicFormat(final DictionaryElement dic
) {
93 public final DictionaryElement
format() {
94 final EHashMap eMap
= new EHashMap();
95 for (SectionElement section
: dicFormatted
.getSections()) {
97 final EElementList elements
= section
.getEElements();
98 for (final EElement e
: elements
) {
99 final String e1Key
= e
.toString();
100 if (!eMap
.containsKey(e1Key
)) {
103 // EElement other = (EElement)eMap.get(e1Key);
104 String left
= e
.getValue("L");
105 String right
= e
.getValue("R");
106 msg
.err("Duplicated: " + left
+ "/" + right
);
110 String errorMsg
= duplicated
+ " duplicated entries in section '"
111 + section
.getID() + "'";
116 DicSort dicSort
= new DicSort(dicFormatted
);
118 * dicSort.setDicType(getDicType()); dicSort.setOut(this.getOut());
119 * DictionaryElement formatted = dicSort.sort();
120 * formatted.printXML(getOut()); return formatted;
129 public final void doFormat() {
138 private void processArguments() {
139 if (arguments
[1].equals("-mon")) {
140 dicType
= DicSort
.MON
;
142 dicType
= DicSort
.BIL
;
144 DictionaryReader dicReader
= new DictionaryReader(arguments
[2]);
145 DictionaryElement dic
= dicReader
.readDic();
147 setDicFormatted(dic
);
149 if (getArguments().length
== 4) {
150 if (getArguments()[3].equals("out.dix")) {
151 out
= DicTools
.removeExtension(getArguments()[3]);
152 out
= out
+ "-formatted.dix";
154 setOut(getArguments()[3]);
163 private final void actionFormat() {
164 final DictionaryElement dicFormatted
= format();
165 dicFormatted
.printXML(getOut());
169 * @param dicFormatted
170 * the dicFormatted to set
172 private final void setDicFormatted(DictionaryElement dicFormatted
) {
173 this.dicFormatted
= dicFormatted
;
177 * @return the arguments
179 public final String
[] getArguments() {
185 * the arguments to set
187 public final void setArguments(String
[] arguments
) {
188 this.arguments
= arguments
;
192 * @return the dicType
194 public final int getDicType() {
202 public final void setDicType(int dicType
) {
203 this.dicType
= dicType
;
209 public final String
getOut() {
217 public final void setOut(String out
) {