diff --git a/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java b/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java index cea055fed684b8e064c693b2be31e6b55c2869c1..169cde710eb78f11294fddb8e1ccd067f4ed46d9 100644 --- a/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java +++ b/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java @@ -26,14 +26,7 @@ package fr.inrialpes.exmo.align.cli; import java.lang.Integer; import java.lang.Double; import java.util.Hashtable; - -import org.semanticweb.owl.align.Alignment; -import org.semanticweb.owl.align.AlignmentVisitor; -import org.semanticweb.owl.align.AlignmentException; - -import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; -import fr.inrialpes.exmo.align.impl.ObjectAlignment; -import fr.inrialpes.exmo.align.impl.URIAlignment; +import java.util.Properties; import java.io.File; import java.io.OutputStream; @@ -47,6 +40,13 @@ import org.xml.sax.SAXException; import gnu.getopt.LongOpt; import gnu.getopt.Getopt; +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.AlignmentException; + +import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.parser.AlignmentParser; /** A really simple utility that loads and alignment and prints it. @@ -77,7 +77,6 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser; $Id$ </pre> -@author J�r�me Euzenat */ public class ParserPrinter { @@ -94,7 +93,7 @@ public class ParserPrinter { String dirName = null; PrintWriter writer = null; AlignmentVisitor renderer = null; - LongOpt[] longopts = new LongOpt[10]; + LongOpt[] longopts = new LongOpt[11]; int debug = 0; String rendererClass = null; String parserClass = null; @@ -102,6 +101,7 @@ public class ParserPrinter { boolean embedded = false; double threshold = 0; String cutMethod = "hard"; + Properties params = new Properties(); longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'); longopts[1] = new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o'); @@ -113,8 +113,10 @@ public class ParserPrinter { longopts[7] = new LongOpt("cutmethod", LongOpt.REQUIRED_ARGUMENT, null, 'T'); longopts[8] = new LongOpt("embedded", LongOpt.NO_ARGUMENT, null, 'e'); longopts[9] = new LongOpt("dirName", LongOpt.REQUIRED_ARGUMENT, null, 'c'); + // Is there a way for that in LongOpt ??? + longopts[10] = new LongOpt("D", LongOpt.REQUIRED_ARGUMENT, null, 'D'); - Getopt g = new Getopt("", args, "ehio:t:T:d::r:p:c:", longopts); + Getopt g = new Getopt("", args, "ehio:t:T:d::r:p:c:D:", longopts); int c; String arg; @@ -134,8 +136,8 @@ public class ParserPrinter { filename = g.getOptarg(); break; case 'c': - dirName = g.getOptarg(); - break; + dirName = g.getOptarg(); + break; case 'r': /* Use the given class for rendernig */ rendererClass = g.getOptarg(); @@ -158,6 +160,19 @@ public class ParserPrinter { if ( arg != null ) debug = Integer.parseInt(arg.trim()); else debug = 4; break; + case 'D' : + /* Parameter definition */ + arg = g.getOptarg(); + int index = arg.indexOf('='); + if ( index != -1 ) { + params.setProperty( arg.substring( 0, index), + arg.substring(index+1)); + } else { + System.err.println("Bad parameter syntax: "+g); + usage(); + System.exit(0); + } + break; } } @@ -182,8 +197,7 @@ public class ParserPrinter { Object[] mparams = { (Object)debug }; java.lang.reflect.Constructor[] parserConstructors = Class.forName(parserClass).getConstructors(); - aparser = - (AlignmentParser) parserConstructors[0].newInstance(mparams); + aparser = (AlignmentParser) parserConstructors[0].newInstance(mparams); } catch (Exception ex) { System.err.println("Cannot create parser " + parserClass + "\n" + ex.getMessage() ); @@ -205,11 +219,11 @@ public class ParserPrinter { //writer = new PrintStream(new FileOutputStream(filename)); stream = new FileOutputStream(filename); } - if (dirName != null) { + if ( dirName != null ) { File f = new File(dirName); - f.mkdir(); - System.setProperty("user.dir", dirName); - System.setProperty("Split", "true"); + f.mkdir(); + params.setProperty( "dir", dirName ); + params.setProperty( "split", "true" ); } writer = new PrintWriter ( new BufferedWriter( @@ -236,6 +250,9 @@ public class ParserPrinter { return; } } + + renderer.init( params ); + // Render the alignment try { result.render( renderer ); @@ -271,6 +288,7 @@ public class ParserPrinter { System.out.println("\t--output=filename -o filename\tOutput the alignment in filename"); System.out.println("\t--outputDir=dirName -c dirName\tSplit the output in a directory (SPARQL)"); System.out.println("\t--help -h\t\t\tPrint this message"); + System.err.println("\t-Dparam=value\t\t\tSet parameter"); System.err.print("\n"+ParserPrinter.class.getPackage().getImplementationTitle()+" "+ParserPrinter.class.getPackage().getImplementationVersion()); System.err.println(" ($Id$)\n"); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java index 68229043705269b2578a5af5e80857e1f8f85dbc..68b36572d0bcf6e4a06af1bbb6cc62241165b7ad 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java @@ -1,5 +1,7 @@ /* - * Copyright (C) INRIA, 2003-2010, 2012 + * $Id$ + * + * Copyright (C) INRIA, 2012 * * 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 @@ -77,6 +79,8 @@ import fr.inrialpes.exmo.align.parser.SyntaxElement.Constructor; * @version */ +// JE: create a string... problem with increment. + public abstract class GraphPatternRendererVisitor extends IndentedRendererVisitor implements EDOALVisitor { Alignment alignment = null; @@ -177,19 +181,18 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito return "ns" + numberNs++; } - public void createQueryFiles(String query) { + public void createQueryFile( String dir, String query ) { BufferedWriter out = null; try { - FileWriter writer1 = new FileWriter(new File("").getAbsolutePath()+"/query"+ number +".rq"); - out = new BufferedWriter(writer1); - number++; - out.write(query); - - if (out != null) // there was at least one file - out.close(); - } catch(IOException ioe) { - System.err.println(ioe); - } + FileWriter writer = new FileWriter( dir+"query"+number +".rq" ); + out = new BufferedWriter( writer ); + number++; + out.write(query); + if ( out != null ) // there was at least one file + out.close(); + } catch(IOException ioe) { + System.err.println(ioe); + } } public void visit( Expression o ) throws AlignmentException { diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java index 9705f6c4f4c5a0d3a547db7c8c68ccfc931300b0..a48a30ad55bfef9bc509f1fb257b8f56acd98e24 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java @@ -41,11 +41,13 @@ import java.util.Random; public class SILKRendererVisitor extends GraphPatternRendererVisitor implements AlignmentVisitor{ - Alignment alignment = null; Cell cell = null; Hashtable<String,String> nslist = null; - boolean embedded = false; + private boolean embedded = false; + private boolean ignoreerrors = false; + private boolean blanks = false; + private boolean weakens = false; private static Namespace DEF = Namespace.ALIGNMENT; @@ -63,9 +65,15 @@ public class SILKRendererVisitor extends GraphPatternRendererVisitor implements super(writer); } - public void init(Properties p) { - if ( p.getProperty( "embedded" ) != null - && !p.getProperty( "embedded" ).equals("") ) embedded = true; + 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( "indent" ) != null ) INDENT = p.getProperty( "indent" ); if ( p.getProperty( "newline" ) != null ) diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java index c317a08eeb74584f8ded96246a3be53829db4da1..97da25e892843a0f22a549d742bf68dd866e3476 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2012 + * + * 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 + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + package fr.inrialpes.exmo.align.impl.renderer; import fr.inrialpes.exmo.align.impl.edoal.Expression; @@ -20,10 +40,12 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor Alignment alignment = null; Cell cell = null; Hashtable<String,String> nslist = null; - boolean embedded = false; + boolean embedded = false; + boolean split = false; + String splitdir = ""; - private List<String> listBGP1; - private List<String> listBGP2; + private List<String> listBGP1; + private List<String> listBGP2; private List<String> listCond1; private List<String> listCond2; @@ -38,12 +60,15 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor } public void init(Properties p) { - if ( p.getProperty( "embedded" ) != null - && !p.getProperty( "embedded" ).equals("") ) embedded = true; - if ( p.getProperty( "indent" ) != null ) - INDENT = p.getProperty( "indent" ); - if ( p.getProperty( "newline" ) != null ) - NL = p.getProperty( "newline" ); + if ( p.getProperty( "embedded" ) != null + && !p.getProperty( "embedded" ).equals("") ) embedded = 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 { @@ -77,54 +102,56 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor listBGP2 = new ArrayList<String>(getBGP()); listCond2 = new ArrayList<String>(getCondition()); - if(!listBGP1.get(listBGP1.size()-1).contains("UNION") && - !listBGP1.get(listBGP1.size()-1).contains("FILTER") && - !listBGP1.get(listBGP1.size()-1).contains("MINUS")){ - for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query += "CONSTRUCT {"+NL; - query += listBGP1.get(listBGP1.size()-1)+NL; - - query += "}"+NL; - query += "WHERE {"+NL; - query += listBGP2.get(listBGP2.size()-1)+NL; - query += "}"+NL; - if(System.getProperty("Split")=="true") - createQueryFiles(query); - else - indentedOutputln(query); - } - query=""; + if(!listBGP1.get(listBGP1.size()-1).contains("UNION") && + !listBGP1.get(listBGP1.size()-1).contains("FILTER") && + !listBGP1.get(listBGP1.size()-1).contains("MINUS")){ + for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = (String)e.nextElement(); + query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query += "CONSTRUCT {"+NL; + query += listBGP1.get(listBGP1.size()-1)+NL; + + query += "}"+NL; + query += "WHERE {"+NL; + query += listBGP2.get(listBGP2.size()-1)+NL; + query += "}"+NL; + if( split ) { + createQueryFile( splitdir, query ); + } else { + indentedOutputln(query); + } + } + query=""; + /* if(!listBGP2.get(listBGP2.size()-1).contains("UNION") && - !listBGP2.get(listBGP2.size()-1).contains("FILTER") && - !listBGP2.get(listBGP2.size()-1).contains("MINUS")){ - for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) { - String k = (String)e.nextElement(); - query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; - } - query += "CONSTRUCT {"+NL; - query += listBGP2.get(listBGP2.size()-1)+NL; - - query += "}"+NL; - query += "WHERE {"+NL; - query += listBGP1.get(listBGP1.size()-1)+NL; - query += "}"+NL; - if(System.getProperty("Split")=="true") - createQueryFiles(query); - else - indentedOutputln(query); - } + !listBGP2.get(listBGP2.size()-1).contains("FILTER") && + !listBGP2.get(listBGP2.size()-1).contains("MINUS")){ + for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) { + String k = (String)e.nextElement(); + query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL; + } + query += "CONSTRUCT {"+NL; + query += listBGP2.get(listBGP2.size()-1)+NL; + + query += "}"+NL; + query += "WHERE {"+NL; + query += listBGP1.get(listBGP1.size()-1)+NL; + query += "}"+NL; + if(System.getProperty("Split")=="true") + createQueryFile(query); + else + indentedOutputln(query); + } + */ } - } 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 25dfb83a6db9292523fe8fbe84fd3a313a0caeac..61cd1c5bd188e163aea7c5d3c9c99bf4abf8de89 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2012 + * + * 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 + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + package fr.inrialpes.exmo.align.impl.renderer; import fr.inrialpes.exmo.align.impl.edoal.Expression; @@ -20,10 +40,12 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp Alignment alignment = null; Cell cell = null; Hashtable<String,String> nslist = null; - boolean embedded = false; + boolean embedded = false; + boolean split = false; + String splitdir = ""; - private List<String> listBGP1; - private List<String> listBGP2; + private List<String> listBGP1; + private List<String> listBGP2; private List<String> listCond1; private List<String> listCond2; @@ -33,8 +55,11 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp } public void init(Properties p) { - if ( p.getProperty( "embedded" ) != null - && !p.getProperty( "embedded" ).equals("") ) embedded = true; + if ( p.getProperty( "embedded" ) != null && !p.getProperty( "embedded" ).equals("") ) + embedded = 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 ) @@ -58,12 +83,12 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp if ( ( u1 != null && u2 != null) || alignment.getLevel().startsWith("2EDOAL") ){ resetVariables("s", "o"); - ((Expression)(cell.getObject1())).accept( this ); + ((Expression)(cell.getObject1())).accept( this ); - listBGP1 = new ArrayList<String>(getBGP()); - listCond1 = new ArrayList<String>(getCondition()); + listBGP1 = new ArrayList<String>(getBGP()); + listCond1 = new ArrayList<String>(getCondition()); - resetVariables("s", "o"); + resetVariables("s", "o"); ((Expression)(cell.getObject2())).accept( this ); listBGP2 = new ArrayList<String>(getBGP()); listCond2 = new ArrayList<String>(getCondition()); @@ -75,11 +100,11 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp query += "SELECT ?s WHERE {"+NL; query += listBGP1.get(listBGP1.size()-1)+NL; query += "}"+NL; - if(System.getProperty("Split")=="true") - createQueryFiles(query); - else - indentedOutputln(query); - + if ( split ) { + createQueryFile( splitdir, query ); + } else { + indentedOutputln(query); + } query=""; for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) { String k = (String)e.nextElement(); @@ -88,10 +113,11 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp query += "SELECT ?s WHERE {"+NL; query += listBGP2.get(listBGP2.size()-1)+NL; query += "}"+NL; - if(System.getProperty("Split")=="true") - createQueryFiles(query); - else + if ( split ) { + createQueryFile( splitdir, query ); + } else { indentedOutputln(query); + } } }