diff --git a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java index 8460a28cc174a03c79bd85412f062b9bb1819c97..31979f255a1f6052d7bd8ebfc1f74dfda8281a05 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2003-2011 + * Copyright (C) INRIA, 2003-2011, 2013 * Copyright (C) CNR Pisa, 2005 * * This program is free software; you can redistribute it and/or modify @@ -229,7 +229,7 @@ public class BasicAlignment implements Alignment { }; public String getXNamespace( String label ) { - return (String)namespaces.getProperty( label ); + return namespaces.getProperty( label ); }; public Enumeration<Cell> getElements() { diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java index 24820d7def2559124fc0acf352ad643d1eedec12..9bdbe41807740de7244bc657978949c968ee745e 100644 --- a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java @@ -81,8 +81,7 @@ public class ObjectAlignment extends BasicAlignment { public void loadInit( Alignment al ) throws AlignmentException { if ( al instanceof URIAlignment ) { - try { init = toObjectAlignment( (URIAlignment)al ); } - catch (SAXException e) { e.printStackTrace(); } + init = toObjectAlignment( (URIAlignment)al ); } else if ( al instanceof ObjectAlignment ) { init = (ObjectAlignment)al; } @@ -134,7 +133,7 @@ public class ObjectAlignment extends BasicAlignment { return align; } - public static ObjectAlignment toObjectAlignment( URIAlignment al ) throws AlignmentException, SAXException { + public static ObjectAlignment toObjectAlignment( URIAlignment al ) throws AlignmentException { ObjectAlignment alignment = new ObjectAlignment(); try { alignment.init( al.getFile1(), al.getFile2() ); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java index cfe2acb3c9d81682388ff9688d23b8e8733434e3..6fea16c4bbe76174ff4109a6009380c987030971 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2012 + * Copyright (C) INRIA, 2012-2013 * * 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 @@ -41,44 +41,43 @@ import java.util.Set; public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor implements AlignmentVisitor{ - Alignment alignment = null; Cell cell = null; Hashtable<String,String> nslist = null; boolean embedded = false; boolean split = false; String splitdir = ""; - private String content_Corese = ""; + private String content_Corese = ""; private String GP1; private String GP2; private List<String> listGP1 = new ArrayList<String>(); private List<String> listGP2 = new ArrayList<String>(); - public SPARQLConstructRendererVisitor(PrintWriter writer) { - super(writer); - } - - public void init(Properties p) { - if ( p.getProperty( "embedded" ) != null - && !p.getProperty( "embedded" ).equals("") ) embedded = true; - if ( p.getProperty( "blanks" ) != null && !p.getProperty( "blanks" ).equals("") ) - blanks = true; - if ( p.getProperty( "weakens" ) != null && !p.getProperty( "weakens" ).equals("") ) - weakens = true; - if ( p.getProperty( "ignoreerrors" ) != null && !p.getProperty( "ignoreerrors" ).equals("") ) - ignoreerrors = true; - if ( p.getProperty( "corese" ) != null && !p.getProperty( "corese" ).equals("") ) - corese = true; - split = ( p.getProperty( "split" ) != null && !p.getProperty( "split" ).equals("") ); - if ( p.getProperty( "dir" ) != null && !p.getProperty( "dir" ).equals("") ) - splitdir = p.getProperty( "dir" )+"/"; - if ( p.getProperty( "indent" ) != null ) - INDENT = p.getProperty( "indent" ); - if ( p.getProperty( "newline" ) != null ) - NL = p.getProperty( "newline" ); - } - - public void visit(Alignment align) throws AlignmentException { + public SPARQLConstructRendererVisitor(PrintWriter writer) { + super(writer); + } + + public void init(Properties p) { + if ( p.getProperty( "embedded" ) != null + && !p.getProperty( "embedded" ).equals("") ) embedded = true; + if ( p.getProperty( "blanks" ) != null && !p.getProperty( "blanks" ).equals("") ) + blanks = true; + if ( p.getProperty( "weakens" ) != null && !p.getProperty( "weakens" ).equals("") ) + weakens = true; + if ( p.getProperty( "ignoreerrors" ) != null && !p.getProperty( "ignoreerrors" ).equals("") ) + ignoreerrors = true; + if ( p.getProperty( "corese" ) != null && !p.getProperty( "corese" ).equals("") ) + corese = true; + split = ( p.getProperty( "split" ) != null && !p.getProperty( "split" ).equals("") ); + if ( p.getProperty( "dir" ) != null && !p.getProperty( "dir" ).equals("") ) + splitdir = p.getProperty( "dir" )+"/"; + if ( p.getProperty( "indent" ) != null ) + INDENT = p.getProperty( "indent" ); + if ( p.getProperty( "newline" ) != null ) + NL = p.getProperty( "newline" ); + } + + public void visit(Alignment align) throws AlignmentException { if ( subsumedInvocableMethod( this, align, Alignment.class ) ) return; alignment = align; content_Corese = ""; @@ -92,17 +91,15 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor for( Cell c : align ){ c.accept( this ); }; content_Corese += "</rdf:RDF>" + NL; if ( corese ) { - if( split ) { - createQueryFile( splitdir, content_Corese ); - } - else { - writer.println( content_Corese ); - } + if( split ) { + createQueryFile( splitdir, content_Corese ); + } else { + writer.println( content_Corese ); + } } - } - - public void visit(Cell cell) throws AlignmentException { - + } + + public void visit(Cell cell) throws AlignmentException { if ( subsumedInvocableMethod( this, cell, Cell.class ) ) return; // default behaviour this.cell = cell; @@ -114,173 +111,156 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor URI u2 = cell.getObject2AsURI(alignment); if ( ( u1 != null && u2 != null) || alignment.getLevel().startsWith("2EDOAL") ){ //expensive test - - resetVariables("s", "o"); - ((Expression)(cell.getObject1())).accept( this ); - GP1 = getGP(); - listGP1 = new ArrayList<String>(getBGP()); - resetVariables("s", "o"); - ((Expression)(cell.getObject2())).accept( this ); - GP2 = getGP(); - listGP2 = new ArrayList<String>(getBGP()); - - if( !GP1.contains("UNION") && !GP1.contains("FILTER") ){ - for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query += "CONSTRUCT {"+NL; - query += GP1; - query += "}"+NL; - query += "WHERE {"+NL; - query += GP2; - query += "}"+NL; - query_weaken = query; - content_Corese += "<rule>" + NL; - content_Corese += "<body>" + NL; - content_Corese += "<![CDATA[" + NL; - content_Corese += query; - content_Corese += "]]>" + NL; - content_Corese += "</body>" + NL; - content_Corese += "</rule>" + NL + NL; - } else { - Iterator<String> list = listGP1.iterator(); - while ( list.hasNext() ) { - String str = list.next(); - if ( !str.contains("UNION") && !str.contains("FILTER") ) { - tmp += str; - } - } - if ( !tmp.equals("") ) { - for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query_weaken += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query_weaken += "CONSTRUCT {"+NL; - query_weaken += tmp; - query_weaken += "}"+NL; - query_weaken += "WHERE {"+NL; - query_weaken += GP2; - query_weaken += "}"+NL; - } - } - for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query_IgnoreErrors += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query_IgnoreErrors += "CONSTRUCT {"+NL; - query_IgnoreErrors += GP1; - query_IgnoreErrors += "}"+NL; - query_IgnoreErrors += "WHERE {"+NL; - query_IgnoreErrors += GP2; - query_IgnoreErrors += "}"+NL; - if ( corese ) return; - if( split ) { - if ( ignoreerrors ) { - createQueryFile( splitdir, query_IgnoreErrors ); - } - else if ( weakens ) { - createQueryFile( splitdir, query_weaken ); - } - else { - createQueryFile( splitdir, query ); - } - } else { - if ( ignoreerrors ) { - writer.println( query_IgnoreErrors ); - } - else if ( weakens ) { - writer.println( query_weaken ); - } - else { - writer.println( query ); - } - } - query=""; - query_weaken = ""; - query_IgnoreErrors = ""; - tmp = ""; - - if( !GP2.contains("UNION") && !GP2.contains("FILTER") ){ - for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query += "CONSTRUCT {"+NL; - query += GP2; - query += "}"+NL; - query += "WHERE {"+NL; - query += GP1; - query += "}"+NL; - query_weaken = query; - content_Corese += "<rule>" + NL; - content_Corese += "<body>" + NL; - content_Corese += "<![CDATA[" + NL; - content_Corese += query; - content_Corese += "]]>" + NL; - content_Corese += "</body>" + NL; - content_Corese += "</rule>" + NL + NL; - } else { - Iterator<String> list = listGP2.iterator(); - while ( list.hasNext() ) { - String str = list.next(); - if ( !str.contains("UNION") && !str.contains("FILTER") ) { - tmp += str; - } - } - if ( !tmp.equals("") ) { - for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query_weaken += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query_weaken += "CONSTRUCT {"+NL; - query_weaken += tmp; - query_weaken += "}"+NL; - query_weaken += "WHERE {"+NL; - query_weaken += GP1; - query_weaken += "}"+NL; - } - } - for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query_IgnoreErrors += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query_IgnoreErrors += "CONSTRUCT {"+NL; - query_IgnoreErrors += GP2; - query_IgnoreErrors += "}"+NL; - query_IgnoreErrors += "WHERE {"+NL; - query_IgnoreErrors += GP1; - query_IgnoreErrors += "}"+NL; - if ( corese ) return; - if( split ) { - if ( ignoreerrors ) { - createQueryFile( splitdir, query_IgnoreErrors ); - } - else if ( weakens ) { - createQueryFile( splitdir, query_weaken ); - } - else { - createQueryFile( splitdir, query ); - } - } else { - if ( ignoreerrors ) { - writer.println( query_IgnoreErrors ); - } - else if ( weakens ) { - writer.println( query_weaken ); - } - else { - writer.println( query ); - } - } - + resetVariables("s", "o"); + ((Expression)(cell.getObject1())).accept( this ); + GP1 = getGP(); + listGP1 = new ArrayList<String>(getBGP()); + resetVariables("s", "o"); + ((Expression)(cell.getObject2())).accept( this ); + GP2 = getGP(); + listGP2 = new ArrayList<String>(getBGP()); + + if( !GP1.contains("UNION") && !GP1.contains("FILTER") ){ + for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = e.nextElement(); + query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query += "CONSTRUCT {"+NL; + query += GP1; + query += "}"+NL; + query += "WHERE {"+NL; + query += GP2; + query += "}"+NL; + query_weaken = query; + content_Corese += "<rule>" + NL; + content_Corese += "<body>" + NL; + content_Corese += "<![CDATA[" + NL; + content_Corese += query; + content_Corese += "]]>" + NL; + content_Corese += "</body>" + NL; + content_Corese += "</rule>" + NL + NL; + } else { + Iterator<String> list = listGP1.iterator(); + while ( list.hasNext() ) { + String str = list.next(); + if ( !str.contains("UNION") && !str.contains("FILTER") ) { + tmp += str; + } + } + if ( !tmp.equals("") ) { + for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = e.nextElement(); + query_weaken += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query_weaken += "CONSTRUCT {"+NL; + query_weaken += tmp; + query_weaken += "}"+NL; + query_weaken += "WHERE {"+NL; + query_weaken += GP2; + query_weaken += "}"+NL; + } + } + for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = e.nextElement(); + query_IgnoreErrors += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query_IgnoreErrors += "CONSTRUCT {"+NL; + query_IgnoreErrors += GP1; + query_IgnoreErrors += "}"+NL; + query_IgnoreErrors += "WHERE {"+NL; + query_IgnoreErrors += GP2; + query_IgnoreErrors += "}"+NL; + if ( corese ) return; + if( split ) { + if ( ignoreerrors ) { + createQueryFile( splitdir, query_IgnoreErrors ); + } else if ( weakens ) { + createQueryFile( splitdir, query_weaken ); + } else { + createQueryFile( splitdir, query ); + } + } else if ( ignoreerrors ) { + writer.println( query_IgnoreErrors ); + } else if ( weakens ) { + writer.println( query_weaken ); + } else { + writer.println( query ); + } + query=""; + query_weaken = ""; + query_IgnoreErrors = ""; + tmp = ""; + + if( !GP2.contains("UNION") && !GP2.contains("FILTER") ){ + for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = e.nextElement(); + query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query += "CONSTRUCT {"+NL; + query += GP2; + query += "}"+NL; + query += "WHERE {"+NL; + query += GP1; + query += "}"+NL; + query_weaken = query; + content_Corese += "<rule>" + NL; + content_Corese += "<body>" + NL; + content_Corese += "<![CDATA[" + NL; + content_Corese += query; + content_Corese += "]]>" + NL; + content_Corese += "</body>" + NL; + content_Corese += "</rule>" + NL + NL; + } else { + Iterator<String> list = listGP2.iterator(); + while ( list.hasNext() ) { + String str = list.next(); + if ( !str.contains("UNION") && !str.contains("FILTER") ) { + tmp += str; + } + } + if ( !tmp.equals("") ) { + for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = e.nextElement(); + query_weaken += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query_weaken += "CONSTRUCT {"+NL; + query_weaken += tmp; + query_weaken += "}"+NL; + query_weaken += "WHERE {"+NL; + query_weaken += GP1; + query_weaken += "}"+NL; + } + } + for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = e.nextElement(); + query_IgnoreErrors += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query_IgnoreErrors += "CONSTRUCT {"+NL; + query_IgnoreErrors += GP2; + query_IgnoreErrors += "}"+NL; + query_IgnoreErrors += "WHERE {"+NL; + query_IgnoreErrors += GP1; + query_IgnoreErrors += "}"+NL; + if ( corese ) return; + if( split ) { + if ( ignoreerrors ) { + createQueryFile( splitdir, query_IgnoreErrors ); + } else if ( weakens ) { + createQueryFile( splitdir, query_weaken ); + } else { + createQueryFile( splitdir, query ); + } + } else if ( ignoreerrors ) { + writer.println( query_IgnoreErrors ); + } else if ( weakens ) { + writer.println( query_weaken ); + } else { writer.println( query ); } } - } - - public void visit( Relation rel ) throws AlignmentException { - if ( subsumedInvocableMethod( this, rel, Relation.class ) ) return; - // default behaviour - // rel.write( writer ); - } - + } + + public void visit( Relation rel ) throws AlignmentException { + if ( subsumedInvocableMethod( this, rel, Relation.class ) ) return; + // default behaviour + // rel.write( writer ); + } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java index 899d91fe244315e06061a01f810faefec6aa1c74..957da61d2cb49f5bfaeb8af5dba9d6d67c8e92ab 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2012 + * Copyright (C) INRIA, 2012-2013 * * 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 @@ -34,7 +34,6 @@ import java.util.Properties; public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor implements AlignmentVisitor{ - Alignment alignment = null; Cell cell = null; Hashtable<String,String> nslist = null; @@ -44,37 +43,36 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp private String GP1; private String GP2; - public SPARQLSelectRendererVisitor(PrintWriter writer) { - super(writer); - } + public SPARQLSelectRendererVisitor(PrintWriter writer) { + super(writer); + } - public void init(Properties p) { - if ( p.getProperty( "embedded" ) != null && !p.getProperty( "embedded" ).equals("") ) - embedded = true; - if ( p.getProperty( "blanks" ) != null && !p.getProperty( "blanks" ).equals("") ) - blanks = true; - if ( p.getProperty( "weakens" ) != null && !p.getProperty( "weakens" ).equals("") ) - weakens = true; - if ( p.getProperty( "ignoreerrors" ) != null && !p.getProperty( "ignoreerrors" ).equals("") ) - ignoreerrors = true; - split = ( p.getProperty( "split" ) != null && !p.getProperty( "split" ).equals("") ); - if ( p.getProperty( "dir" ) != null && !p.getProperty( "dir" ).equals("") ) - splitdir = p.getProperty( "dir" )+"/"; - if ( p.getProperty( "indent" ) != null ) - INDENT = p.getProperty( "indent" ); - if ( p.getProperty( "newline" ) != null ) - NL = p.getProperty( "newline" ); - } + public void init(Properties p) { + if ( p.getProperty( "embedded" ) != null && !p.getProperty( "embedded" ).equals("") ) + embedded = true; + if ( p.getProperty( "blanks" ) != null && !p.getProperty( "blanks" ).equals("") ) + blanks = true; + if ( p.getProperty( "weakens" ) != null && !p.getProperty( "weakens" ).equals("") ) + weakens = true; + if ( p.getProperty( "ignoreerrors" ) != null && !p.getProperty( "ignoreerrors" ).equals("") ) + ignoreerrors = true; + split = ( p.getProperty( "split" ) != null && !p.getProperty( "split" ).equals("") ); + if ( p.getProperty( "dir" ) != null && !p.getProperty( "dir" ).equals("") ) + splitdir = p.getProperty( "dir" )+"/"; + if ( p.getProperty( "indent" ) != null ) + INDENT = p.getProperty( "indent" ); + if ( p.getProperty( "newline" ) != null ) + NL = p.getProperty( "newline" ); + } - public void visit(Alignment align) throws AlignmentException { - if ( subsumedInvocableMethod( this, align, Alignment.class ) ) return; - alignment = align; - for( Cell c : align ){ c.accept( this ); }; - } + public void visit(Alignment align) throws AlignmentException { + if ( subsumedInvocableMethod( this, align, Alignment.class ) ) return; + alignment = align; + for( Cell c : align ){ c.accept( this ); }; + } - public void visit(Cell cell) throws AlignmentException { - - if ( subsumedInvocableMethod( this, cell, Cell.class ) ) return; + public void visit(Cell cell) throws AlignmentException { + if ( subsumedInvocableMethod( this, cell, Cell.class ) ) return; String query = ""; this.cell = cell; @@ -82,44 +80,43 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp URI u2 = cell.getObject2AsURI(alignment); if ( ( u1 != null && u2 != null) || alignment.getLevel().startsWith("2EDOAL") ){ - resetVariables("s", "o"); - ((Expression)(cell.getObject1())).accept( this ); - GP1 = getGP(); - resetVariables("s", "o"); - ((Expression)(cell.getObject2())).accept( this ); - GP2 = getGP(); - for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query += "SELECT ?s WHERE {"+NL; - query += GP1; - query += "}"+NL; - if ( split ) { - createQueryFile( splitdir, query ); - } else { - writer.println(query); - } + resetVariables("s", "o"); + ((Expression)(cell.getObject1())).accept( this ); + GP1 = getGP(); + resetVariables("s", "o"); + ((Expression)(cell.getObject2())).accept( this ); + GP2 = getGP(); + for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = e.nextElement(); + query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query += "SELECT ?s WHERE {"+NL; + query += GP1; + query += "}"+NL; + if ( split ) { + createQueryFile( splitdir, query ); + } else { + writer.println(query); + } query=""; for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + String k = e.nextElement(); + query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; } query += "SELECT ?s WHERE {"+NL; query += GP2; query += "}"+NL; if ( split ) { - createQueryFile( splitdir, query ); + createQueryFile( splitdir, query ); } else { writer.println(query); - } + } } - } - - public void visit( Relation rel ) throws AlignmentException { - if ( subsumedInvocableMethod( this, rel, Relation.class ) ) return; - // default behaviour - // rel.write( writer ); } - + + public void visit( Relation rel ) throws AlignmentException { + if ( subsumedInvocableMethod( this, rel, Relation.class ) ) return; + // default behaviour + // rel.write( writer ); + } }