From 658c504cbbd02e8d1ef8b730e93239810312cf20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Sat, 24 Apr 2010 17:41:31 +0000
Subject: [PATCH] - Fixed javadoc errors - Implemented transformations

---
 examples/omwg/total.xml                       | 41 +++++++++++-
 .../exmo/align/parser/AlignmentParser.java    |  7 +-
 .../exmo/align/parser/RDFParser.java          | 64 ++++++++++++++-----
 .../exmo/align/parser/SyntaxElement.java      |  7 +-
 .../align/parser/TypeCheckingVisitor.java     |  5 +-
 .../exmo/align/parser/XMLParser.java          | 27 ++++----
 6 files changed, 114 insertions(+), 37 deletions(-)

diff --git a/examples/omwg/total.xml b/examples/omwg/total.xml
index c54e37cb..8ed92b34 100644
--- a/examples/omwg/total.xml
+++ b/examples/omwg/total.xml
@@ -599,7 +599,7 @@
 	    <edoal:and rdf:parseType="Collection">
 	      <edoal:Class rdf:about="&wine;Bordeaux17"/>
 	      <edoal:Class>
-		<edoal:or parseType="Collection">
+		<edoal:or rdf:parseType="Collection">
 		  <edoal:Class rdf:about="&wine;Bordeaux18"/>
 		  <edoal:Class rdf:about="&wine;Bordeaux18"/>
 		</edoal:or>
@@ -651,6 +651,41 @@
         <measure rdf:datatype='&xsd;float'>1.</measure>
         <relation>SubsumedBy</relation>
       </Cell>
-   </map>
+    </map>
+    <map>
+      <Cell rdf:about="TransformationTest">
+	<entity1>
+	  <edoal:Property rdf:about="foaf:name"/>
+	</entity1>
+	<entity2>
+	  <edoal:Relation rdf:about="vcard:name"/>
+	</entity2>
+        <measure rdf:datatype='&xsd;float'>1.</measure>
+        <relation>SubsumedBy</relation>
+	<edoal:transformation>
+	  <edoal:Transformation edoal:type="o-">
+	    <edoal:entity1>
+	      <!--edoal:Property rdf:about="foaf:name"/-->
+	      <!-- BELOW DOES NOT WORK -->
+	      <edoal:Property><edoal:compose rdf:parseType="Collection"/></edoal:Property>
+	      <!--edoal:Property><edoal:self/></edoal:Property-->
+	    </edoal:entity1>
+	    <edoal:entity2>
+	      <!-- APPLY DOES NOT WORK -->
+	      <edoal:Apply edoal:operator="concat">
+		<edoal:arguments rdf:parseType="Collection">
+		  <edoal:Property rdf:about="vcard:firstname"/>
+		  <edoal:Literal edoal:string=" "/>
+		  <!-- or even compute middle initial from middlename -->
+		  <edoal:Property rdf:about="vcard:middleinitial"/>
+		  <edoal:Literal edoal:string=". "/>
+		  <edoal:Property rdf:about="vcard:lastname"/>
+		</edoal:arguments>
+	      </edoal:Apply>
+	    </edoal:entity2>
+	  </edoal:Transformation>
+	</edoal:transformation>
+      </Cell>
+    </map>
   </Alignment>
- </rdf:RDF>
+</rdf:RDF>
diff --git a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java
index af8ef02a..53bdb777 100644
--- a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java
+++ b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java
@@ -121,10 +121,11 @@ public class AlignmentParser {
     }
 
     /** 
-     * Parses the document corresponding to the URI given in parameter
+     * Parses the document given in parameter
      * If the current process has links (import or include) to others documents then they are 
      * parsed.
-     * @param uri URI of the document to parse
+     * @param o
+     *     A URI, InputStream, String or Reader
      */
     private Alignment callParser( Object o ) throws AlignmentException {
 	try { 
@@ -176,7 +177,7 @@ public class AlignmentParser {
      * @param s String the string to parse
      */
     public Alignment parseString( String s ) throws AlignmentException {
-	// JE: The problem here is that InputStream are consumed by parsers
+	// The problem here is that InputStream are consumed by parsers
 	// So they must be opened again! Like Readers...
 	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 f43e1f4c..5cc40886 100644
--- a/src/fr/inrialpes/exmo/align/parser/RDFParser.java
+++ b/src/fr/inrialpes/exmo/align/parser/RDFParser.java
@@ -61,7 +61,7 @@ import fr.inrialpes.exmo.align.impl.edoal.RelationCoDomainRestriction;
 import fr.inrialpes.exmo.align.impl.edoal.InstanceExpression;
 import fr.inrialpes.exmo.align.impl.edoal.InstanceId;
 
-import fr.inrialpes.exmo.align.impl.edoal.TransfService;
+import fr.inrialpes.exmo.align.impl.edoal.Transformation;
 import fr.inrialpes.exmo.align.impl.edoal.ValueExpression;
 import fr.inrialpes.exmo.align.impl.edoal.Value;
 import fr.inrialpes.exmo.align.impl.edoal.Apply;
@@ -113,7 +113,6 @@ import com.hp.hpl.jena.vocabulary.RDF;
  * 
  * @author Richard Pöttler
  * @version $Revision: 1.7 $
- * @date $Date: 2010-03-07 20:41:03 +0100 (Sun, 07 Mar 2010) $
  */
 public class RDFParser {
 
@@ -166,7 +165,7 @@ public class RDFParser {
 
     /**
      * Parse the input model. The model shall include one statement that include (?,RDF.type,Alignment)
-     * @param align
+     * @param rdfmodel the rdfmodel containing the RDF representation of the parsed alignment
      * @return the result EDOALAlignment
      * @throws AlignmentException if there is any exception, throw AlignmentException that include describe infomation
      * and a caused exception.
@@ -365,17 +364,13 @@ public class RDFParser {
 		throw new IllegalArgumentException("Couln't parse the string \"" + relation
 						   +"\" to a valid rule type");
 	    }
-	    
 	    // parse the measure, the node shall be Literal and it's a number
 	    final float m = node.getProperty((Property)SyntaxElement.MEASURE.resource).getFloat();
-	    
 	    // get the id
 	    final String id = node.getURI();
-	    
 	    //parsing the entity1 and entity2 
 	    Resource entity1 = node.getProperty((Property)SyntaxElement.ENTITY1.resource).getResource();
 	    Resource entity2 = node.getProperty((Property)SyntaxElement.ENTITY2.resource).getResource();
-
 	    // JE2010:
 	    // Here it would be better to check if the entity has a type.
 	    // If both have none, then we get a old-style correspondence for free
@@ -389,13 +384,47 @@ public class RDFParser {
 		System.err.println(" t : "+t);
 	    }
 
-	    return new EDOALCell( id, s, t, type, m );
+	    EDOALCell cell = new EDOALCell( id, s, t, type, m );
+	    // Parse the possible transformations
+	    StmtIterator stmtIt = node.listProperties((Property)SyntaxElement.TRANSFORMATION.resource );
+	    while ( stmtIt.hasNext() ) {
+		Statement stmt = stmtIt.nextStatement();
+		try { cell.addTransformation( parseTransformation( stmt.getResource() ) ); }
+		catch ( AlignmentException ae ) {
+		    System.err.println( "Error "+ae );
+		    ae.printStackTrace();
+		}
+	    }
+	    return cell;
 	} 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);
 	}
     }
 
+    protected Transformation parseTransformation( final Resource node ) throws AlignmentException {
+	if (node == null) throw new NullPointerException("The node must not be null");
+	try {
+	    // parsing type
+	    Statement stmt = node.getProperty( (Property)SyntaxElement.TRDIR.resource );
+	    if ( stmt == null ) throw new AlignmentException( "Required edoal:type property in Transformation" );
+	    String type = stmt.getLiteral().toString();
+	    // parsing entity1 and entity2 
+	    Resource entity1 = node.getProperty((Property)SyntaxElement.TRENT1.resource).getResource();
+	    Resource entity2 = node.getProperty((Property)SyntaxElement.TRENT2.resource).getResource();
+	    ValueExpression s = parseValue( entity1 );
+	    ValueExpression t = parseValue( entity2 );
+	    if ( debug > 0 ) {
+		System.err.println(" (Transf)s : "+s);	    
+		System.err.println(" (Transf)t : "+t);
+	    }
+	    return new Transformation( type, s, t );
+	} 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 transformation " + node, e);
+	}
+    }
+
     // Here given the type of expression, this can be grand dispatch
     protected Expression parseExpression( final Resource node ) throws AlignmentException {
 	Expression result;
@@ -465,6 +494,8 @@ public class RDFParser {
 		    }
 		}
 		Resource coll = stmt.getResource(); // MUSTCHECK
+		// JE: I guess that this may be NULL and thus be kept OK
+		// for <and />, <or /> and <compose />
 		if ( op == SyntaxElement.NOT.getOperator() ) {
 		    clexpr.add( parseClass( coll ) );
 		} else { // Jena encode these collections as first/rest statements
@@ -584,6 +615,8 @@ public class RDFParser {
 		    }
 		}
 		Resource coll = stmt.getResource(); // MUSTCHECK
+		// JE: I guess that this may be NULL and thus be kept OK
+		// for <and />, <or /> and <compose />
 		if ( op == SyntaxElement.NOT.getOperator() ) {
 		    clexpr.add( parseProperty( coll ) );
 		} else if ( op == SyntaxElement.COMPOSE.getOperator() ) {
@@ -684,6 +717,8 @@ public class RDFParser {
 		    }
 		}
 		Resource coll = stmt.getResource(); // MUSTCHECK
+		// JE: I guess that this may be NULL and thus be kept OK
+		// for <and />, <or /> and <compose />
 		if ( op == SyntaxElement.NOT.getOperator() ||
 		     op == SyntaxElement.INVERSE.getOperator() || 
 		     op == SyntaxElement.REFLEXIVE.getOperator() || 
@@ -803,17 +838,14 @@ public class RDFParser {
     /**
      * Parses a given annotaion in the the given node.
      * 
-     * @param node
-     *            which is the parent of the annotation node
-     * @param e
-     *            the tag which contains the annotation.
-     * @return the parsed annotation, with the id set to the element and the
-     *         value set to the text of the parsed node, or null, if nothing
-     *         could be found
+     * @param stmt
+     *            the annotation statement
+     * @param al
+     *            the alignment in which the annotation is
      * @throws NullPointerException
      *             if the node or the element is null
      */
-    protected 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/SyntaxElement.java b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java
index 2b7a230c..f0ebf940 100644
--- a/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java
+++ b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java
@@ -41,7 +41,6 @@ import org.semanticweb.owl.align.AlignmentException;
  * 
  * @author richi
  * @version $Revision: 1.6 $
- * @date $Date: 2010-03-07 20:40:40 +0100 (Sun, 07 Mar 2010) $
  */
 
 public enum SyntaxElement {
@@ -120,7 +119,11 @@ public enum SyntaxElement {
 	STRING(          Namespace.EDOAL, "string"),
 	SYMMETRIC(      Namespace.EDOAL, "symmetric", Constructor.SYMMETRIC),
 	TOCLASS(        Namespace.EDOAL, "class"),
-	TRANSF(         Namespace.EDOAL, "transf"),
+	TRENT1(         Namespace.EDOAL, "entity1"),
+	TRENT2(         Namespace.EDOAL, "entity2"),
+	TRANSF(         Namespace.EDOAL, "Transformation", true),
+	TRDIR(          Namespace.EDOAL, "type"),
+	TRANSFORMATION( Namespace.EDOAL, "transformation"),
 	TRANSITIVE(     Namespace.EDOAL, "transitive", Constructor.TRANSITIVE),
 	TYPE_COND(Namespace.EDOAL, "AttributeTypeRestriction", true), // undocumented
 	VALUE(          Namespace.EDOAL, "value"),
diff --git a/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java
index 4eab3a81..895843fe 100644
--- a/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java
+++ b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java
@@ -71,7 +71,7 @@ import fr.inrialpes.exmo.align.impl.edoal.RelationCoDomainRestriction;
 import fr.inrialpes.exmo.align.impl.edoal.InstanceExpression;
 import fr.inrialpes.exmo.align.impl.edoal.InstanceId;
 
-import fr.inrialpes.exmo.align.impl.edoal.TransfService;
+import fr.inrialpes.exmo.align.impl.edoal.Transformation;
 import fr.inrialpes.exmo.align.impl.edoal.Value;
 import fr.inrialpes.exmo.align.impl.edoal.ValueExpression;
 import fr.inrialpes.exmo.align.impl.edoal.Apply;
@@ -138,6 +138,9 @@ public class TypeCheckingVisitor {
     public void visit( EDOALRelation rel ) {
     };
 
+    public void visit( final Transformation trsf ) throws AlignmentException {
+    }
+
     public void visit( final PathExpression p ) throws AlignmentException {
 	if ( p instanceof RelationExpression ) visit( (RelationExpression)p );
 	else if ( p instanceof PropertyExpression ) visit( (PropertyExpression)p );
diff --git a/src/fr/inrialpes/exmo/align/parser/XMLParser.java b/src/fr/inrialpes/exmo/align/parser/XMLParser.java
index d56ae28a..d3a4ae7d 100644
--- a/src/fr/inrialpes/exmo/align/parser/XMLParser.java
+++ b/src/fr/inrialpes/exmo/align/parser/XMLParser.java
@@ -215,7 +215,7 @@ public class XMLParser extends DefaultHandler {
 
     /** 
      * Parses a reader, used for reading from a string
-     * @param s String the string to parse
+     * @param r the reader from which to parse
      */
     public Alignment parse( Reader r ) throws AlignmentException {
 	try {
@@ -311,11 +311,10 @@ public class XMLParser extends DefaultHandler {
 		    throw new SAXException("Catched alignment exception", e );
 		}
 	    } else if (pName.equals( SyntaxElement.FORMALISM.name )) {
-		// JE: Check that this is OK with EDOAL
 		if ( atts.getValue( SyntaxElement.URI.name ) != null )
 		    try {
 			curronto.setFormURI( new URI(atts.getValue("uri")) );
-		    } catch (Exception e) {
+		    } catch ( URISyntaxException e ) {
 			throw new SAXException("Malformed URI"+atts.getValue("uri"), e );
 		    };
 		if ( atts.getValue("name") != null )
@@ -325,13 +324,13 @@ public class XMLParser extends DefaultHandler {
 	    } else if (pName.equals( SyntaxElement.ONTOLOGY.name )) {
 		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( about ) );
-			} catch (URISyntaxException e) {
-			    throw new SAXException("onto2: malformed URI");
-			}
+		    try {
+			// JE: Onto
+			//curronto.setOntology( new URI( atts.getValue("rdf:about") ) );
+			curronto.setURI( new URI( about ) );
+		    } catch (URISyntaxException e) {
+			throw new SAXException("onto2: malformed URI");
+		    }
 		}
 	    } else if (pName.equals( SyntaxElement.MAPPING_TARGET.name )) {
 		curronto = onto2;
@@ -355,13 +354,15 @@ public class XMLParser extends DefaultHandler {
 	    } else {
 		if ( debugMode > 0 ) System.err.println("[XMLParser] Unknown element name : "+pName);
 	    };
-	} else if( namespaceURI.equals( Namespace.SOAP_ENV.prefix )) { //"http://schemas.xmlsoap.org/soap/envelope/"))  {
+	} else if ( namespaceURI.equals( Namespace.SOAP_ENV.prefix )) { //"http://schemas.xmlsoap.org/soap/envelope/"))  {
 	    // Ignore SOAP namespace
 	    if ( !pName.equals("Envelope") && !pName.equals("Body") ) {
 		throw new SAXException("[XMLParser] unknown element name: "+pName); };
-	} else if(namespaceURI.equals( Namespace.RDF.prefix )) { //"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+	} else if (namespaceURI.equals( Namespace.RDF.prefix )) { //"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 	    if ( !pName.equals("RDF") ) {
 		throw new SAXException("[XMLParser] unknown element name: "+pName); };
+	} else if (namespaceURI.equals( Namespace.EDOAL.prefix )) { 
+	    throw new SAXException("[XMLParser] EDOAL alignment must have type EDOAL: "+pName);
 	} else {
 	    if ( alignLevel != -1 && parseLevel != 3 && parseLevel != 5 && !embedded ) throw new SAXException("[XMLParser("+parseLevel+")] Unknown namespace : "+namespaceURI);
 	}
@@ -519,6 +520,8 @@ public class XMLParser extends DefaultHandler {
 	} else if(namespaceURI.equals( Namespace.RDF.prefix ) ) {//"http://www.w3.org/1999/02/22-rdf-syntax-ns#"))  {
 	    if ( !pName.equals("RDF") ) {
 		throw new SAXException("[XMLParser] unknown element name: "+pName); };
+	} else if (namespaceURI.equals( Namespace.EDOAL.prefix )) { 
+	    throw new SAXException("[XMLParser] EDOAL alignment must have type EDOAL: "+pName);
 	} else {
 	    if ( parseLevel == 3 && alignLevel != -1 ){
 		alignment.setExtension( namespaceURI, pName, content );
-- 
GitLab