File: AmbiguityResolver.java

package info (click to toggle)
natbraille 2.0rc3-14
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,080 kB
  • sloc: java: 31,266; xml: 7,747; sh: 165; haskell: 50; makefile: 32
file content (95 lines) | stat: -rw-r--r-- 2,805 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Nat Braille
 * Copyright (C) 2008 Bruno Mascret
 * Contact: bmascret@free.fr
 * http://natbraille.free.fr
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package nat.transcodeur;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import nat.ConfigNat;
import nat.Nat;
import gestionnaires.GestionnaireErreur;

/**
 * Résoud les ambiguïtés détectée lors de la transcription
 * @author bruno
 *
 */
public class AmbiguityResolver
{
	/** Nom du fichier transcrit contenant des ambiguïtés */
	private String fTransAmb ="";
	/** Instance du gestionnaire d'erreurs */
	private GestionnaireErreur gest = null;
	/** liste des ambiguités */
	private ArrayList<Ambiguity> ambiguities = new ArrayList<Ambiguity>();
	
	/**
	 * Crée une instance de AmbiguityResolver
	 * @param fTrAmb adresse du fichier à analyser
	 * @param g instance du gestionnaire d'erreur
	 */
	public AmbiguityResolver(String fTrAmb, GestionnaireErreur g)
	{
		fTransAmb = fTrAmb;
		gest = g;
		resolveAmbiguity();
	}
	
	/**
	 * Charge les ambiguités
	 * @return true si analyse terminée correctement
	 */
	private boolean resolveAmbiguity()
	{
		boolean retour = true;
		
		gest.afficheMessage("Chargement du fichier transcrit pour analyse", Nat.LOG_VERBEUX);
		Document doc;
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(ConfigNat.getCurrentConfig().getNiveauLog()==Nat.LOG_DEBUG);
    
        DocumentBuilder db;
		try
		{
			db = dbf.newDocumentBuilder();
			doc = db.parse(new File(fTransAmb));
			
			NodeList ambs = doc.getElementsByTagName("ambiguity");
			for(int i=0;i<ambs.getLength();i++)
			{	
				ambiguities.add(new Ambiguity(ambs.item(i)));
			}
		}
		catch (ParserConfigurationException e) {e.printStackTrace();}//TODO
		catch (SAXException e) {e.printStackTrace();}//TODO
		catch (IOException e) {e.printStackTrace();}//TODO
		return retour;		
	}
}