From 14e67b079105fc26744491ce461955d448ab5207 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Thu, 18 Mar 2010 12:38:34 +0000
Subject: [PATCH] - re-installed parsing from String, InputStream, Reader

---
 examples/omwg/wine.xml                        |   2 +-
 .../exmo/align/parser/AlignmentParser.java    |  66 ++++++--
 .../exmo/align/parser/RDFParser.java          | 158 +++++++++---------
 .../exmo/align/parser/XMLParser.java          |  70 +++++---
 test/src/EDOALTest.java                       |   8 +-
 5 files changed, 178 insertions(+), 126 deletions(-)

diff --git a/examples/omwg/wine.xml b/examples/omwg/wine.xml
index 26d2bd7e..e66370d2 100644
--- a/examples/omwg/wine.xml
+++ b/examples/omwg/wine.xml
@@ -86,7 +86,7 @@
 		      <edoal:Relation rdf:about="&proton;locatedIn"/>
 		    </edoal:compose>
 		  </edoal:Relation>
-		</edoal:onProperty>
+		</edoal:onAttribute>
 		<edoal:comparator rdf:resource="&xsd;equals"/>
   		<!--edoal:value>loc:Aquitaine</edoal:value-->
   		<edoal:value><edoal:Instance rdf:about="&vin;Aquitaine"/></edoal:value>
diff --git a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java
index 43517ba1..55ccb3dc 100644
--- a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java
+++ b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java
@@ -23,6 +23,7 @@ package fr.inrialpes.exmo.align.parser;
 //Imported JAVA classes
 import java.io.IOException;
 import java.io.StringReader;
+import java.io.Reader;
 import java.io.InputStream;
 import java.io.File;
 import java.net.URI;
@@ -34,14 +35,12 @@ import java.util.Hashtable;
 import org.semanticweb.owl.align.Alignment;
 import org.semanticweb.owl.align.Cell;
 import org.semanticweb.owl.align.AlignmentException;
-import org.semanticweb.owl.align.Parameters;
 
 import fr.inrialpes.exmo.ontowrap.Ontology;
 import fr.inrialpes.exmo.ontowrap.LoadedOntology;
 import fr.inrialpes.exmo.ontowrap.BasicOntology;
 
 import fr.inrialpes.exmo.align.impl.URIAlignment;
-import fr.inrialpes.exmo.align.impl.BasicParameters;
 import fr.inrialpes.exmo.align.impl.Annotations;
 
 /**
@@ -126,48 +125,83 @@ public class AlignmentParser {
      * parsed.
      * @param uri URI of the document to parse
      */
-    public Alignment parse( String uri ) throws AlignmentException {
-	this.uri = uri;
+    private Alignment callParser( Object o ) throws AlignmentException {
 	try { 
 	    XMLParser parser = new XMLParser( debugMode );
 	    if ( embedded ) parser.setEmbedded( embedded );
-	    alignment = parser.parse( uri );
+	    //alignment = parser.parse( o );
+	    alignment = callParser( parser, o );
 	} catch ( Exception e ) {
 	    if ( debugMode > 0 ) {
-		System.err.println(" TEST TRAPPED FOR ALIGNMENT ");
+		System.err.println("XMLParser failed to parse alignment (INFO)");
 		e.printStackTrace();
 	    }
 	    try {
 		if ( !embedded ) {
-		    alignment = new RDFParser().parse( new File( uri ) );
+		    RDFParser rparser = new RDFParser( debugMode );
+		    alignment = callParser( rparser, o );
 		} else {
-		    throw new AlignmentException( "Cannot parse "+uri, e );
+		    throw new AlignmentException( "Cannot parse "+o, e );
 		}
 	    } catch ( Exception ex ) {
 		// JE: should contain both ex and e
-		throw new AlignmentException( "Cannot parse "+uri, ex );
+		throw new AlignmentException( "Cannot parse "+o, ex );
 	    }
 	}
 	return alignment;
     }
 
+    /**
+     * This dispatch is ridiculous, but that's life
+     */
+    private Alignment callParser( XMLParser p, Object o ) throws AlignmentException {
+	if ( o instanceof String ) return p.parse((String)o);
+	if ( o instanceof Reader ) return p.parse((Reader)o);
+	if ( o instanceof InputStream ) return p.parse((InputStream)o);
+	throw new AlignmentException( "AlignmentParser: cannot parse :"+o );
+    }
+
+    private Alignment callParser( RDFParser p, Object o ) throws AlignmentException {
+	if ( o instanceof String ) return p.parse((String)o);
+	if ( o instanceof Reader ) return p.parse((Reader)o);
+	if ( o instanceof InputStream ) return p.parse((InputStream)o);
+	throw new AlignmentException( "AlignmentParser: cannot parse :"+o );
+    }
+
     /** 
-     * Parses a string instead of a URI
+     * Parses the content of a string
      * @param s String the string to parse
      */
-    //JE2009: this must change: parse( StringReader ) should be OK
-    // But I have no parser anyway...
     public Alignment parseString( String s ) throws AlignmentException {
-	//parser.parse( new InputSource( new StringReader( s ) ), this );
+	parse( new StringReader( s ) );
 	return alignment;
     }
 
     /** 
-     * Parses a string instead of a URI
-     * @param s String the string to parse
+     * Parses a the content of a reader
+     * @param r the reader to parse
+     */
+    public Alignment parse( Reader r ) throws AlignmentException {
+	callParser( r );
+	return alignment;
+    }
+
+    /** 
+     * Parses a URI expressed as a String
+     * @param uri the URI
+     */
+    public Alignment parse( String uri ) throws AlignmentException {
+	this.uri = uri; // should be obsoloted
+	callParser( uri );
+	return alignment;
+    }
+
+    /** 
+     * Parses an inputStream
+     * @param s the Stream to parse
      */
     public Alignment parse( InputStream s ) throws AlignmentException {
-	//parser.parse( s, this );
+	callParser( s );
 	return alignment;
     }
 
diff --git a/src/fr/inrialpes/exmo/align/parser/RDFParser.java b/src/fr/inrialpes/exmo/align/parser/RDFParser.java
index 6901efc5..aaa0cd85 100644
--- a/src/fr/inrialpes/exmo/align/parser/RDFParser.java
+++ b/src/fr/inrialpes/exmo/align/parser/RDFParser.java
@@ -118,11 +118,28 @@ import com.hp.hpl.jena.vocabulary.RDF;
  */
 public class RDFParser {
 
-    static Logger logger = Logger.getLogger(RDFParser.class.toString());
+    private static Logger logger = Logger.getLogger(RDFParser.class.toString());
 
-    static Model rDFModel;
+    private static Model rDFModel;
 
-    static private boolean debug = false;
+    private int debug = 0;
+
+    private boolean isPattern = false; //2010: why is parseAlignment static????
+
+    /** 
+     * Creates an RDF Parser.
+     */
+    public RDFParser() {
+	this(0);
+    }
+
+    /** 
+     * Creates an RDF Parser.
+     * @param debugMode The value of the debug mode
+     */
+    public RDFParser( int debugMode ) {
+	debug = debugMode;
+    }
 
     /**
      * Initialisation of the structures
@@ -153,83 +170,55 @@ public class RDFParser {
      * @throws AlignmentException if there is any exception, throw AlignmentException that include describe infomation
      * and a caused exception.
      */
-    public static EDOALAlignment parse( final Model align ) throws AlignmentException {
+    public EDOALAlignment parse( final Model align ) throws AlignmentException {
 	// Initialize the syntax description
 	initSyntax();
-	// Shut up logging handling (should put a 
+	// Shut up logging handling
 	com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler.silent = true;
-	//get the statement including alignment resource as rdf:type
+	// Get the statement including alignment resource as rdf:type
 	StmtIterator stmtIt = align.listStatements(null, RDF.type,(Resource)SyntaxElement.getResource("Alignment"));
-	// take the first one if it exists
-	Statement alignDoc;
-	if (stmtIt.hasNext()) {
-	    alignDoc = stmtIt.nextStatement();
-	} else {
-	    throw new AlignmentException("There is no alignment in the RDF docuemnt");
-	}
-
+	// Take the first one if it exists
+	if ( !stmtIt.hasNext() ) throw new AlignmentException("There is no alignment in the RDF docuemnt");
+	Statement alignDoc = stmtIt.nextStatement();
 	// Step from this statement
 	final EDOALAlignment doc = parseAlignment( alignDoc.getSubject() );
-	// JE 2010: Clean up the RDF stuff
+	// Clean up memory
+	align.close(); // JE: I am not sure that I will not have trouble with initSyntax
 	return doc;
-//
-//		 getting and adding the xml namespaces
-//		 final NamedNodeMap attrs = root.getAttributes();
-//		 for (int iCounter = 0; iCounter < attrs.getLength(); iCounter++) {
-//		 final Node tempNode = attrs.item(iCounter);
-//		 if (tempNode.getNodeName().equals("xmlns")) {
-//		 doc.addNamespace(new Namespace(Namespace.DEFAULT_NS_PREFIX,
-//		 new URI(tempNode.getNodeValue())));
-//		 } else if (tempNode.getNodeName().startsWith("xmlns")) {
-//		 doc.addNamespace(new Namespace(tempNode.getNodeName()
-//		 .substring(6), new URI(tempNode.getNodeValue())));
-//		 }
-//		 }
     }
 
     // Below is the plumbing:
     // Load the RDF under an RDFModel
     // Call the above parse: RDFModel -> EDOALAlignment
 
-    public static EDOALAlignment parse( final File file )
-			throws AlignmentException {
-	Model align = ModelFactory.createDefaultModel();
+    public EDOALAlignment parse( final File file ) throws AlignmentException {
 	try {
-	    align.read(new FileInputStream(file), null);
+	    return parse( new FileInputStream( file ) );
 	} catch ( FileNotFoundException fnfe ) {
-	    throw new AlignmentException("RDFParser: There isn't such file: "
-					 + file.getName(), fnfe);
+	    throw new AlignmentException("RDFParser: There isn't such file: "+ file.getName(), fnfe);
 	}
-	return parse(align);
     }
 
-    public static EDOALAlignment parse(final Reader is)
-	throws AlignmentException {
-	if (is == null) {
-	    throw new AlignmentException("The inputstream must not be null");
-	}
+    public EDOALAlignment parse( final Reader is ) throws AlignmentException {
+	if (is == null) throw new AlignmentException("The reader must not be null");
 	Model align = ModelFactory.createDefaultModel();
-	align.read(is, null);
+	align.read( is, null );
 	// debug align.write(System.out);
-	return parse(align);
+	return parse( align );
     }
     
-    public static EDOALAlignment parse(final InputStream is)
-	throws AlignmentException {
-	if (is == null) {
-	    throw new AlignmentException("The inputstream must not be null");
-	}
+    public EDOALAlignment parse( final InputStream is ) throws AlignmentException {
+	if (is == null) throw new AlignmentException("The inputstream must not be null");
 	Model align = ModelFactory.createDefaultModel();
-	align.read(is, null);
+	align.read( is, null );
 	//debug	align.write(System.out);
-	return parse(align);
+	return parse( align );
     }
 
-    public static EDOALAlignment parse(final String file)
-	throws AlignmentException {
+    public EDOALAlignment parse( final String uri ) throws AlignmentException {
 	Model align = ModelFactory.createDefaultModel();
-	align.read(file);
-	return parse(align);
+	align.read( uri );
+	return parse( align );
     }
 
     // Below is the real work
@@ -241,11 +230,8 @@ public class RDFParser {
      * @return the parsed mapping document
      * @throws AlignmentException
      */
-    static EDOALAlignment parseAlignment( final Resource node ) throws AlignmentException {
-	if (node == null) {
-	    throw new NullPointerException("Alignment must not be null");
-	}
-
+    public EDOALAlignment parseAlignment( final Resource node ) throws AlignmentException {
+	if (node == null) throw new NullPointerException("Alignment must not be null");
 	try {
 	    Ontology source = null;
 	    Ontology target = null;
@@ -273,7 +259,12 @@ public class RDFParser {
 	    if ( stmtIt.hasNext() ) {
 		final String level = stmtIt.nextStatement().getString();
 		if ((level != null) && (!level.equals(""))) {
-		    doc.setLevel( level );
+		    if ( level.startsWith("2EDOAL") ) {
+			doc.setLevel( level );
+			if ( level.equals("2EDOALPattern") ) isPattern = true;
+		    } else {
+			throw new AlignmentException( "Cannot parse alignment of level "+level );
+		    }
 		}			    
 	    } else {
 		throw new AlignmentException( "Missing level " );
@@ -292,7 +283,7 @@ public class RDFParser {
 	    stmtIt = node.listProperties((Property)SyntaxElement.MAP.resource );
 	    while (stmtIt.hasNext()) {
 		Statement stmt = stmtIt.nextStatement();
-		if ( debug ) System.err.println( "  ---------------> "+stmt );
+		if ( debug > 0 ) System.err.println( "  ---------------> "+stmt );
 		//doc.addRule(parseCell(stmt.getResource()));
 		try { doc.addAlignCell( parseCell( stmt.getResource() ) ); }
 		catch ( AlignmentException ae ) {
@@ -332,7 +323,7 @@ public class RDFParser {
      * @throws NullPointerException
      *             if the node is null
      */
-    static Ontology parseOntology(final Resource node) throws AlignmentException {
+    protected Ontology parseOntology(final Resource node) throws AlignmentException {
 	if (node == null) {
 	    throw new AlignmentException("The ontology node must not be null");
 	}
@@ -363,7 +354,7 @@ public class RDFParser {
      * @return the parsed rule
      * @exception AlignmentException
      */
-    public static EDOALCell parseCell( final Resource node ) throws AlignmentException {
+    protected EDOALCell parseCell( final Resource node ) throws AlignmentException {
 	if (node == null) {
 	    throw new NullPointerException("The node must not be null");
 	}
@@ -382,7 +373,7 @@ public class RDFParser {
 	    final float m = node.getProperty((Property)SyntaxElement.MEASURE.resource).getFloat();
 	    
 	    // get the id
-	    final URI id = getNodeId( node );
+	    final String id = node.getURI();
 	    
 	    //parsing the entity1 and entity2 
 	    Resource entity1 = node.getProperty((Property)SyntaxElement.ENTITY1.resource).getResource();
@@ -396,12 +387,12 @@ public class RDFParser {
 	    
 	    Expression s = parseExpression( entity1 );
 	    Expression t = parseExpression( entity2 );
-	    if ( debug ) {
+	    if ( debug > 0 ) {
 		System.err.println(" s : "+s);	    
 		System.err.println(" t : "+t);
 	    }
 
-	    return new EDOALCell( id.toString(), s, t, type, m );
+	    return new EDOALCell( id, s, t, type, m );
 	} catch (Exception e) {  //wrap other type exception
 	    logger.log(java.util.logging.Level.SEVERE, "The cell isn't correct:" + node.getLocalName() + " "+e.getMessage());
 	    throw new AlignmentException("Cannot parse correspondence " + node.getLocalName(), e);
@@ -409,31 +400,36 @@ public class RDFParser {
     }
 
     // Here given the type of expression, this can be grand dispatch
-    public static Expression parseExpression( final Resource node ) throws AlignmentException {
+    protected Expression parseExpression( final Resource node ) throws AlignmentException {
+	Expression result;
 	Resource rdfType = node.getProperty( RDF.type ).getResource();
 	if ( rdfType.equals( SyntaxElement.CLASS_EXPR.resource ) ||
 	     rdfType.equals( SyntaxElement.PROPERTY_OCCURENCE_COND.resource ) ||
 	     rdfType.equals( SyntaxElement.PROPERTY_TYPE_COND.resource ) ||
 	     rdfType.equals( SyntaxElement.PROPERTY_VALUE_COND.resource ) ) {
-	    return parseClass( node );
+	    result = parseClass( node );
 	} else if ( rdfType.equals( SyntaxElement.PROPERTY_EXPR.resource ) ||
 		    rdfType.equals( SyntaxElement.DOMAIN_RESTRICTION.resource ) ||
 		    rdfType.equals( SyntaxElement.TYPE_COND.resource ) ||
 		    rdfType.equals( SyntaxElement.VALUE_COND.resource ) ) {
-	    return parseProperty( node );
+	    result = parseProperty( node );
 	} else if ( rdfType.equals( SyntaxElement.RELATION_EXPR.resource ) ||
 		    rdfType.equals( SyntaxElement.DOMAIN_RESTRICTION.resource ) || // JE 2010: no chance
 		    rdfType.equals( SyntaxElement.CODOMAIN_RESTRICTION.resource ) ) {
-	    return parseRelation( node );
+	    result = parseRelation( node );
 	} else if ( rdfType.equals( SyntaxElement.INSTANCE_EXPR.resource ) ) {
-	    return parseInstance( node );
+	    result = parseInstance( node );
 	} else {
 	    throw new AlignmentException("There is no parser for entity "+rdfType.getLocalName());
 	}
+	//2010 test for variable? if yes store it!
+	if ( isPattern ) {
+	}
+	return result;
     }
     
-    public static ClassExpression parseClass( final Resource node ) throws AlignmentException {
-	if ( debug ) {
+    protected ClassExpression parseClass( final Resource node ) throws AlignmentException {
+	if ( debug > 1 ) {
 	    StmtIterator it = node.listProperties();
 	    while ( it.hasNext() ) System.err.println( "   > "+it.next() );
 	}
@@ -488,6 +484,8 @@ public class RDFParser {
 	    //JE2010MUSTCHECK
 	    pe = parsePathExpression( stmt.getResource() );
 	    if ( rdfType.equals( SyntaxElement.PROPERTY_TYPE_COND.resource ) ) {
+		// JEZ010: check that pe is a Property / Relation
+		// ==> different treatment
 		// Datatype could also be defined as objets...? (like rdf:resource="")
 		// Or classes? OF COURSE????
 		stmt = node.getProperty( (Property)SyntaxElement.DATATYPE.resource );
@@ -532,8 +530,10 @@ public class RDFParser {
 			// get the type
 			Resource nnType = ((Resource)nn).getProperty(RDF.type).getResource();
 			if ( nnType.equals( SyntaxElement.INSTANCE_EXPR.resource ) ) {
+			    // JE2010: Check that pe is a Relation
 			    return new ClassValueRestriction( pe, comp, parseInstance( (Resource)nn ) );
 			} else {
+			    // JE2010: Check that pe is a Property
 			    return new ClassValueRestriction( pe, comp, parsePathExpression( (Resource)nn ) );
 			} // This one will raise the error
 		    } else {
@@ -546,7 +546,7 @@ public class RDFParser {
     }
 
     // JE2010: Here is the problem again with DOMAIN (for instance)
-    static PathExpression parsePathExpression( final Resource node ) throws AlignmentException {
+    protected PathExpression parsePathExpression( final Resource node ) throws AlignmentException {
 	Resource rdfType = node.getProperty(RDF.type).getResource();
 	if ( rdfType.equals( SyntaxElement.PROPERTY_EXPR.resource ) ||
 	     rdfType.equals( SyntaxElement.DOMAIN_RESTRICTION.resource ) ||
@@ -563,7 +563,7 @@ public class RDFParser {
 
     // rdf:parseType="Collection" is supposed to preserve the order ()
     // Jena indeed always preserves the order so this can be used
-    static PropertyExpression parseProperty( final Resource node ) throws AlignmentException {
+    protected PropertyExpression parseProperty( final Resource node ) throws AlignmentException {
 	Resource rdfType = node.getProperty(RDF.type).getResource();
 	Statement stmt = null;
 	if ( rdfType.equals( SyntaxElement.PROPERTY_EXPR.resource ) ) {
@@ -671,7 +671,7 @@ public class RDFParser {
 	}
     }
 
-    static RelationExpression parseRelation( final Resource node ) throws AlignmentException {
+    protected RelationExpression parseRelation( final Resource node ) throws AlignmentException {
 	Resource rdfType = node.getProperty(RDF.type).getResource();
 	Statement stmt = null;
 	if ( rdfType.equals( SyntaxElement.RELATION_EXPR.resource ) ) {
@@ -749,7 +749,7 @@ public class RDFParser {
 	}
     }
 
-    static InstanceExpression parseInstance( final Resource node ) throws AlignmentException {
+    protected InstanceExpression parseInstance( final Resource node ) throws AlignmentException {
 	Resource rdfType = node.getProperty(RDF.type).getResource();
 	if ( rdfType.equals( SyntaxElement.INSTANCE_EXPR.resource ) ) {
 	    URI id = getNodeId( node );
@@ -760,11 +760,11 @@ public class RDFParser {
 	}
     }
 
-    static Value parseValue( final Resource node ) throws AlignmentException {
+    protected Value parseValue( final Resource node ) throws AlignmentException {
 	return null;
     }
 
-    static URI getNodeId( final Resource node ) throws AlignmentException {
+    protected URI getNodeId( final Resource node ) throws AlignmentException {
 	final String idS = node.getURI();
 	if ((idS != null) && (idS.length() > 0)) {
 	    try {
@@ -790,7 +790,7 @@ public class RDFParser {
      * @throws NullPointerException
      *             if the node or the element is null
      */
-    static void parseAnnotation(final Statement stmt, EDOALAlignment al ) throws AlignmentException {
+    protected void parseAnnotation(final Statement stmt, EDOALAlignment al ) throws AlignmentException {
 	try {
 	    final String anno = stmt.getString();
 	    if ((anno != null) && (anno.length() > 0)) {
diff --git a/src/fr/inrialpes/exmo/align/parser/XMLParser.java b/src/fr/inrialpes/exmo/align/parser/XMLParser.java
index 564aa367..d56ae28a 100644
--- a/src/fr/inrialpes/exmo/align/parser/XMLParser.java
+++ b/src/fr/inrialpes/exmo/align/parser/XMLParser.java
@@ -34,6 +34,7 @@ import javax.xml.parsers.ParserConfigurationException;
 //Imported JAVA classes
 import java.io.IOException;
 import java.io.StringReader;
+import java.io.Reader;
 import java.io.InputStream;
 import java.io.File;
 import java.net.URI;
@@ -45,7 +46,6 @@ import java.util.Hashtable;
 import org.semanticweb.owl.align.Alignment;
 import org.semanticweb.owl.align.Cell;
 import org.semanticweb.owl.align.AlignmentException;
-import org.semanticweb.owl.align.Parameters;
 
 import fr.inrialpes.exmo.ontowrap.Ontology;
 import fr.inrialpes.exmo.ontowrap.LoadedOntology;
@@ -53,7 +53,6 @@ import fr.inrialpes.exmo.ontowrap.BasicOntology;
 
 import fr.inrialpes.exmo.align.impl.URIAlignment;
 import fr.inrialpes.exmo.align.impl.BasicCell;
-import fr.inrialpes.exmo.align.impl.BasicParameters;
 import fr.inrialpes.exmo.align.impl.Annotations;
 import fr.inrialpes.exmo.align.impl.Namespace;
 import fr.inrialpes.exmo.align.impl.Extensions;
@@ -172,7 +171,6 @@ public class XMLParser extends DefaultHandler {
 
     /** 
      * Creates an XML Parser.
-     * @param debugMode The value of the debug mode
      */
     public XMLParser() throws ParserConfigurationException, SAXException {
 	this(0);
@@ -204,26 +202,44 @@ public class XMLParser extends DefaultHandler {
      * parsed.
      * @param uri URI of the document to parse
      */
-    public Alignment parse( String uri ) throws SAXException, IOException {
-	parser.parse( uri, this );
+    public Alignment parse( String uri ) throws AlignmentException {
+	try {
+	    parser.parse( uri, this );
+	} catch ( SAXException sex ) {
+	    throw new AlignmentException( "Parsing error", sex );
+	} catch ( IOException ioex ) {
+	    throw new AlignmentException( "I/O error", ioex );
+	}
 	return alignment;
     }
 
     /** 
-     * Parses a string instead of a URI
+     * Parses a reader, used for reading from a string
      * @param s String the string to parse
      */
-    /*    public Alignment parseString( String s ) throws SAXException, IOException {
-	parser.parse( new InputSource( new StringReader( s ) ), this );
+    public Alignment parse( Reader r ) throws AlignmentException {
+	try {
+	    parser.parse( new InputSource( r ), this );
+	} catch ( SAXException sex ) {
+	    throw new AlignmentException( "Parsing error", sex );
+	} catch ( IOException ioex ) {
+	    throw new AlignmentException( "I/O error", ioex );
+	}
 	return alignment;
     }
-*/
+
     /** 
      * Parses a string instead of a URI
      * @param s String the string to parse
      */
-    public Alignment parse( InputStream s ) throws SAXException, IOException {
-	parser.parse( s, this );
+    public Alignment parse( InputStream s ) throws AlignmentException {
+	try {
+	    parser.parse( s, this );
+	} catch ( SAXException sex ) {
+	    throw new AlignmentException( "Parsing error", sex );
+	} catch ( IOException ioex ) {
+	    throw new AlignmentException( "I/O error", ioex );
+	}
 	return alignment;
     }
 
@@ -259,27 +275,27 @@ public class XMLParser extends DefaultHandler {
 	    } else if (pName.equals( SyntaxElement.MEASURE.name )) {
 	    } else if (pName.equals( SyntaxElement.ENTITY2.name )) {
 		if(debugMode > 2) 
-		    System.err.println(" resource = " + atts.getValue("rdf:resource"));
+		    System.err.println(" resource = " + atts.getValue(SyntaxElement.RDF_RESOURCE.print()));
 		try {
-		    cl2 = new URI( atts.getValue("rdf:resource") );
+		    cl2 = new URI( atts.getValue(SyntaxElement.RDF_RESOURCE.print()) );
 		} catch (URISyntaxException e) {
-		    throw new SAXException("Malformed URI: "+atts.getValue("rdf:resource"));
+		    throw new SAXException("Malformed URI: "+atts.getValue(SyntaxElement.RDF_RESOURCE.print()));
 		}
 	    } else if (pName.equals( SyntaxElement.ENTITY1.name )) {
 		if(debugMode > 2) 
-		    System.err.println(" resource = " + atts.getValue("rdf:resource"));
+		    System.err.println(" resource = " + atts.getValue(SyntaxElement.RDF_RESOURCE.print()));
 		try {
-		    cl1 = new URI( atts.getValue("rdf:resource") );
+		    cl1 = new URI( atts.getValue( SyntaxElement.RDF_RESOURCE.print() ) );
 		} catch (URISyntaxException e) {
-		    throw new SAXException("Malformed URI: "+atts.getValue("rdf:resource"));
+		    throw new SAXException("Malformed URI: "+atts.getValue(SyntaxElement.RDF_RESOURCE.print()));
 		}
 	    } else if (pName.equals( SyntaxElement.CELL.name )) {
 		if ( alignment == null )
 		    { throw new SAXException("No alignment provided"); };
-		if ( atts.getValue("rdf:ID") != null ){
-		    id = atts.getValue("rdf:ID");
-		} else if ( atts.getValue("rdf:about") != null ){
-		    id = atts.getValue("rdf:about");
+		if ( atts.getValue( SyntaxElement.RDF_ID.print() ) != null ){
+		    id = atts.getValue( SyntaxElement.RDF_ID.print() );
+		} else if ( atts.getValue( SyntaxElement.RDF_ABOUT.print() ) != null ){
+		    id = atts.getValue( SyntaxElement.RDF_ABOUT.print() );
 		}
 		sem = null;
 		measure = null;
@@ -307,11 +323,12 @@ public class XMLParser extends DefaultHandler {
 	    } else if (pName.equals( SyntaxElement.FORMATT.name )) {
 	    } else if (pName.equals( SyntaxElement.LOCATION.name )) {
 	    } else if (pName.equals( SyntaxElement.ONTOLOGY.name )) {
-		if ( atts.getValue("rdf:about") != null && !atts.getValue("rdf:about").equals("") ) {
+		String about = atts.getValue( SyntaxElement.RDF_ABOUT.print() );
+		if ( about != null && !about.equals("") ) {
 			try {
 			    // JE: Onto
 			    //curronto.setOntology( new URI( atts.getValue("rdf:about") ) );
-			    curronto.setURI( new URI( atts.getValue("rdf:about") ) );
+			    curronto.setURI( new URI( about ) );
 			} catch (URISyntaxException e) {
 			    throw new SAXException("onto2: malformed URI");
 			}
@@ -331,8 +348,9 @@ public class XMLParser extends DefaultHandler {
 		if ( alignment == null ) alignment = new URIAlignment();
 		onto1 = ((URIAlignment)alignment).getOntologyObject1();
 		onto2 = ((URIAlignment)alignment).getOntologyObject2();
-		if ( atts.getValue("rdf:about") != null && !atts.getValue("rdf:about").equals("") ) {
-		    alignment.setExtension( Namespace.ALIGNMENT.uri, Annotations.ID, atts.getValue("rdf:about") );
+		String about = atts.getValue( SyntaxElement.RDF_ABOUT.print() );
+		if ( about != null && !about.equals("") ) {
+		    alignment.setExtension( Namespace.ALIGNMENT.uri, Annotations.ID, about );
 		};
 	    } else {
 		if ( debugMode > 0 ) System.err.println("[XMLParser] Unknown element name : "+pName);
@@ -473,7 +491,7 @@ public class XMLParser extends DefaultHandler {
 		} else if (pName.equals( SyntaxElement.TYPE.name )) {
 		    alignment.setType( content );
 		} else if (pName.equals( SyntaxElement.LEVEL.name )) {
-		    if ( content.startsWith("2") ) { // instead of equals("2OMWG")
+		    if ( content.startsWith("2") ) { // Maybe !startsWith("0") would be better
 			throw new SAXException("Cannot parse Level 2 alignments (so far)");
 		    } else {
 			alignment.setLevel( content );
diff --git a/test/src/EDOALTest.java b/test/src/EDOALTest.java
index edbb9595..e9f8d718 100644
--- a/test/src/EDOALTest.java
+++ b/test/src/EDOALTest.java
@@ -68,7 +68,7 @@ java -cp ../../lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter wine
 	*/
 	aparser1 = new AlignmentParser( 0 );
 	assertNotNull( aparser1 );
-	alignment = aparser1.parse( "examples/omwg/wine.xml" );
+	alignment = aparser1.parse( "file:examples/omwg/wine.xml" );
 	assertNotNull( alignment );
 	//assertTrue( alignment instanceof EDOALAlignment );
 	FileOutputStream stream = new FileOutputStream("test/output/wine2.xml");
@@ -87,7 +87,7 @@ java -cp ../../lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter wine
 java -cp ../../lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter wine2.xml > wine3.xml
 	*/
 	aparser1.initAlignment( null );
-	alignment = aparser1.parse( "test/output/wine2.xml" );
+	alignment = aparser1.parse( "file:test/output/wine2.xml" );
 	assertNotNull( alignment );
 	FileOutputStream stream = new FileOutputStream("test/output/wine3.xml");
 	PrintWriter writer = new PrintWriter (
@@ -105,9 +105,9 @@ java -cp ../../lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter wine
 diff wine2.xml wine3.xml
 	*/
 	aparser1.initAlignment( null );
-	Alignment oldal = aparser1.parse( "test/output/wine2.xml" );
+	Alignment oldal = aparser1.parse( "file:test/output/wine2.xml" );
 	aparser1.initAlignment( null );
-	alignment = aparser1.parse( "test/output/wine3.xml" );
+	alignment = aparser1.parse( "file:test/output/wine3.xml" );
 	assertNotNull( alignment );
 	ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
 	PrintWriter writer = new PrintWriter (
-- 
GitLab