From 8a0231b75588aa89f4a2bf9d131ff0f6b277e942 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Thu, 25 Mar 2010 14:18:52 +0000
Subject: [PATCH] - implemented parsing/storing/rendering of nameless entities
 (for patterns)

---
 .../exmo/align/impl/edoal/ClassId.java        |  7 +++++-
 .../exmo/align/impl/edoal/InstanceId.java     |  7 +++++-
 .../exmo/align/impl/edoal/PropertyId.java     |  7 +++++-
 .../exmo/align/impl/edoal/RelationId.java     |  7 +++++-
 .../impl/renderer/RDFRendererVisitor.java     | 24 ++++++++++++-------
 .../exmo/align/parser/RDFParser.java          | 23 ++++++++++++++----
 6 files changed, 58 insertions(+), 17 deletions(-)

diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/ClassId.java b/src/fr/inrialpes/exmo/align/impl/edoal/ClassId.java
index 60426584..d6b48a9c 100644
--- a/src/fr/inrialpes/exmo/align/impl/edoal/ClassId.java
+++ b/src/fr/inrialpes/exmo/align/impl/edoal/ClassId.java
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006 Digital Enterprise Research Insitute (DERI) Innsbruck
  * Sourceforge version 1.5 - 2006
- * Copyright (C) INRIA, 2009
+ * Copyright (C) INRIA, 2009-2010
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -44,6 +44,11 @@ public class ClassId extends ClassExpression implements Id {
     
     URI uri;
 
+    /**
+     * Creates an anonymous class pattern
+     */
+    public ClassId() {}
+
     public ClassId(final String id) throws AlignmentException {
 	if (id == null) {
 	    throw new NullPointerException("The id must not be null");
diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/InstanceId.java b/src/fr/inrialpes/exmo/align/impl/edoal/InstanceId.java
index fc945cff..df8d9073 100644
--- a/src/fr/inrialpes/exmo/align/impl/edoal/InstanceId.java
+++ b/src/fr/inrialpes/exmo/align/impl/edoal/InstanceId.java
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006 Digital Enterprise Research Insitute (DERI) Innsbruck
  * Sourceforge version 1.4 - 2006 -- then InstanceExpr
- * Copyright (C) INRIA, 2009
+ * Copyright (C) INRIA, 2009-2010
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -44,6 +44,11 @@ public class InstanceId extends InstanceExpression implements Id {
 	uri = u;
     }
 
+    /**
+     * Creates an anonymous instance pattern
+     */
+    public InstanceId() {}
+
     /**
      * Constructs a InstanceId.
      * 
diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/PropertyId.java b/src/fr/inrialpes/exmo/align/impl/edoal/PropertyId.java
index e6012fc3..67ad461f 100644
--- a/src/fr/inrialpes/exmo/align/impl/edoal/PropertyId.java
+++ b/src/fr/inrialpes/exmo/align/impl/edoal/PropertyId.java
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006 Digital Enterprise Research Insitute (DERI) Innsbruck
  * Sourceforge version 1.7 - 2006 -- then AttributeExpr.java
- * Copyright (C) INRIA, 2009
+ * Copyright (C) INRIA, 2009-2010
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -43,6 +43,11 @@ public class PropertyId extends PropertyExpression implements Id {
 	
     URI uri;
 
+    /**
+     * Creates an anonymous property pattern
+     */
+    public PropertyId() {}
+
     public PropertyId( final URI u ) {
 	if ( u == null ) {
 	    throw new NullPointerException("The URI must not be null");
diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/RelationId.java b/src/fr/inrialpes/exmo/align/impl/edoal/RelationId.java
index 3255100f..33a989e7 100644
--- a/src/fr/inrialpes/exmo/align/impl/edoal/RelationId.java
+++ b/src/fr/inrialpes/exmo/align/impl/edoal/RelationId.java
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006 Digital Enterprise Research Insitute (DERI) Innsbruck
  * Sourceforge version 1.5 - 2006 -- then RelationExpr
- * Copyright (C) INRIA, 2009
+ * Copyright (C) INRIA, 2009-2010
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -39,6 +39,11 @@ public class RelationId extends RelationExpression implements Id {
     
     URI uri;
 
+    /**
+     * Creates an anonymous relation pattern
+     */
+    public RelationId() {}
+
     public RelationId(final String id) throws AlignmentException {
 	if (id == null) {
 	    throw new NullPointerException("The id must not be null");
diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java
index 0892954a..c2db45db 100644
--- a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java
+++ b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java
@@ -361,8 +361,10 @@ public class RDFRendererVisitor implements AlignmentVisitor {
     // DONE+TESTED
     public void visit( final ClassId e ) throws AlignmentException {
 	indentedOutput("<"+SyntaxElement.CLASS_EXPR.print(DEF));
-	writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
-	writer.print("=\""+e.getURI()+"\"");
+	if ( e.getURI() != null ) {
+	    writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
+	    writer.print("=\""+e.getURI()+"\"");
+	}
 	if ( isPattern ) renderVariables( e );
 	writer.print("/>");
     }
@@ -512,8 +514,10 @@ public class RDFRendererVisitor implements AlignmentVisitor {
     // DONE
     public void visit(final PropertyId e) throws AlignmentException {
 	indentedOutput("<"+SyntaxElement.PROPERTY_EXPR.print(DEF));
-	writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
-	writer.print("=\""+e.getURI()+"\"");
+	if ( e.getURI() != null ){
+	    writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
+	    writer.print("=\""+e.getURI()+"\"");
+	}
 	if ( isPattern ) renderVariables( e );
 	writer.print("/>");
     }
@@ -621,8 +625,10 @@ public class RDFRendererVisitor implements AlignmentVisitor {
     // DONE
     public void visit( final RelationId e ) throws AlignmentException {
 	indentedOutput("<"+SyntaxElement.RELATION_EXPR.print(DEF));
-	writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
-	writer.print("=\""+e.getURI()+"\"");
+	if ( e.getURI() != null ) {
+	    writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
+	    writer.print("=\""+e.getURI()+"\"");
+	}
 	if ( isPattern ) renderVariables( e );
 	writer.print("/>");
     }
@@ -704,8 +710,10 @@ public class RDFRendererVisitor implements AlignmentVisitor {
     // DONE+TESTED
     public void visit( final InstanceId e ) throws AlignmentException {
 	indentedOutput("<"+SyntaxElement.INSTANCE_EXPR.print(DEF));
-	writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
-	writer.print("=\""+e.getURI()+"\"");
+	if ( e.getURI() != null ) {
+	    writer.print(" "+SyntaxElement.RDF_ABOUT.print(DEF));
+	    writer.print("=\""+e.getURI()+"\"");
+	}
 	if ( isPattern ) renderVariables( e );
 	writer.print("/>");
     }
diff --git a/src/fr/inrialpes/exmo/align/parser/RDFParser.java b/src/fr/inrialpes/exmo/align/parser/RDFParser.java
index cf634ba3..5a946617 100644
--- a/src/fr/inrialpes/exmo/align/parser/RDFParser.java
+++ b/src/fr/inrialpes/exmo/align/parser/RDFParser.java
@@ -420,9 +420,8 @@ public class RDFParser {
 	} else {
 	    throw new AlignmentException("There is no parser for entity "+rdfType.getLocalName());
 	}
-	//2010 test for variable? if yes store it!
 	if ( isPattern ) {
-	    StmtIterator stmtIt = node.listProperties((Property)SyntaxElement.VAR.resource );
+	    StmtIterator stmtIt = node.listProperties( (Property)SyntaxElement.VAR.resource );
 	    if ( stmtIt.hasNext() ) {
 		final String varname = stmtIt.nextStatement().getString();
 		final Variable var = alignment.recordVariable( varname, result );
@@ -459,7 +458,11 @@ public class RDFParser {
 		    op = SyntaxElement.NOT.getOperator();
 		    stmt = node.getProperty( (Property)SyntaxElement.NOT.resource );
 		} else {
-		    throw new AlignmentException( "Class statement must containt one constructor or Id : "+node );
+		    if ( isPattern ) { // not necessarily with a variable (real patterns)
+			return new ClassId();
+		    } else {
+			throw new AlignmentException( "Class statement must containt one constructor or Id : "+node );
+		    }
 		}
 		//JE2010MUSTCHECK
 		Resource coll = stmt.getResource(); //JE2010MUSTCHECK
@@ -599,7 +602,11 @@ public class RDFParser {
 		    op = SyntaxElement.NOT.getOperator();
 		    stmt = node.getProperty( (Property)SyntaxElement.NOT.resource );
 		} else {
-		    throw new AlignmentException( "Property statement must containt one constructor or Id : "+node );
+		    if ( isPattern ) { // not necessarily with a variable (real patterns)
+			return new PropertyId();
+		    } else {
+			throw new AlignmentException( "Property statement must containt one constructor or Id : "+node );
+		    }
 		}
 		Resource coll = stmt.getResource(); //JE2010MUSTCHECK
 		if ( op == SyntaxElement.NOT.getOperator() ) {
@@ -720,7 +727,11 @@ public class RDFParser {
 		    op = SyntaxElement.TRANSITIVE.getOperator();
 		    stmt = node.getProperty( (Property)SyntaxElement.TRANSITIVE.resource );
 		} else {
-		    throw new AlignmentException( "Relation statement must containt one constructor or Id : "+node );
+		    if ( isPattern ) { // not necessarily with a variable (real patterns)
+			return new RelationId();
+		    } else {
+			throw new AlignmentException( "Relation statement must containt one constructor or Id : "+node );
+		    }
 		}
 		Resource coll = stmt.getResource(); //JE2010MUSTCHECK
 		if ( op == SyntaxElement.NOT.getOperator() ||
@@ -768,6 +779,8 @@ public class RDFParser {
 	    URI id = getNodeId( node );
 	    if ( id != null ) return new InstanceId( id );
 	    else throw new AlignmentException("Cannot parse anonymous individual");
+	} else if ( isPattern ) { // not necessarily with a variable (real patterns)
+	    return new InstanceId();
 	} else {
 	    throw new AlignmentException("There is no pasrser for entity "+rdfType.getLocalName());
 	}
-- 
GitLab