diff --git a/lib/procalign.jar b/lib/procalign.jar index 14c03f07cc3d981fa5f157d2b647195e5e1eb977..4592a6f29e3c6e8d2695b5839cdfc8c91cb5ba06 100644 Binary files a/lib/procalign.jar and b/lib/procalign.jar differ diff --git a/src/fr/inrialpes/exmo/align/impl/BasicParameters.java b/src/fr/inrialpes/exmo/align/impl/BasicParameters.java index 2cd41c23240b47f34beb827f9f0bb3f8ebf83b37..54f180fc0371bf91a8c5bdf89109ace2f0689008 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicParameters.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicParameters.java @@ -1,7 +1,8 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2004 + * Copyright (C) INRIA Rhône-Alpes, 2004-2005 + * Copyright (C) University of Montréal, 2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -24,6 +25,19 @@ package fr.inrialpes.exmo.align.impl; // import java classes import java.util.Hashtable; import java.util.Enumeration; +import java.io.PrintStream; +import java.io.File; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Element; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.DocumentBuilder; + +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; import org.semanticweb.owl.align.Parameters; @@ -68,11 +82,49 @@ public class BasicParameters implements Parameters { System.out.println("</Parameters>"); } + /** + * displays the current parameters (debugging) + */ + public void displayParameters( PrintStream stream ){ + stream.println("Parameters:"); + for (Enumeration e = parameters.keys(); e.hasMoreElements();) { + String k = (String)e.nextElement(); + stream.println(" "+k+" = "+parameters.get(k)); + } + } + public static Parameters read(){ Parameters p = new BasicParameters(); - // open the stream - // parse it - // fill the structure + String filename = "params.xml"; + + try { + // open the stream + DocumentBuilderFactory docBuilderFactory = + DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + Document doc = docBuilder.parse(new File(filename)); + + // normalize text representation + doc.getDocumentElement().normalize(); + + // Get the params + NodeList paramList = doc.getElementsByTagName("param"); + int totalParams = paramList.getLength(); + for (int s = 0; s < totalParams; s++) { + Element paramElement = (Element)paramList.item(s); + String paramName = paramElement.getAttribute("name"); + NodeList paramContent = paramElement.getChildNodes(); + String paramValue =((Node)paramContent.item(0)).getNodeValue().trim(); + p.setParameter(paramName, paramValue); + } + } catch (SAXParseException err) { + System.err.println("** Parsing error: ["+ err.getLineNumber()+"]: "+err.getSystemId()); + System.err.println(" " + err.getMessage()); + } catch (SAXException e) { + Exception x = e.getException(); + ((x == null) ? e : x).printStackTrace(); + } catch (Throwable t) { t.printStackTrace(); } + return p; } } diff --git a/src/fr/inrialpes/exmo/align/util/Procalign.java b/src/fr/inrialpes/exmo/align/util/Procalign.java index 47ce7aaf242b3b91072356142a2dcb3a7103fd77..7d24ad1694b6265e78b33c61aed85fe3b4fdd57b 100644 --- a/src/fr/inrialpes/exmo/align/util/Procalign.java +++ b/src/fr/inrialpes/exmo/align/util/Procalign.java @@ -84,6 +84,7 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser; where the options are: <pre> --alignment=filename -a filename Start from an XML alignment file + --params=filename -p filename Read the parameters in file --debug[=n] -d [n] Report debug info at level n, --output=filename -o filename Output the alignment in filename --impl=className -i classname Use the given alignment implementation. @@ -123,6 +124,7 @@ public class Procalign { Alignment init = null; String alignmentClassName = "fr.inrialpes.exmo.align.impl.method.ClassNameEqAlignment"; String filename = null; + String paramfile = null; String rendererClass = "fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor"; //PrintStream writer = null; PrintWriter writer = null; @@ -131,7 +133,7 @@ public class Procalign { double threshold = 0; Parameters params = new BasicParameters(); - LongOpt[] longopts = new LongOpt[9]; + LongOpt[] longopts = new LongOpt[10]; longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'); longopts[1] = new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o'); @@ -141,10 +143,11 @@ public class Procalign { longopts[5] = new LongOpt("impl", LongOpt.REQUIRED_ARGUMENT, null, 'i'); longopts[6] = new LongOpt("threshold", LongOpt.REQUIRED_ARGUMENT, null, 't'); longopts[7] = new LongOpt("cutmethod", LongOpt.REQUIRED_ARGUMENT, null, 'T'); + longopts[8] = new LongOpt("params", LongOpt.REQUIRED_ARGUMENT, null, 'p'); // Is there a way for that in LongOpt ??? - longopts[8] = new LongOpt("D", LongOpt.REQUIRED_ARGUMENT, null, 'D'); + longopts[9] = new LongOpt("D", LongOpt.REQUIRED_ARGUMENT, null, 'D'); - Getopt g = new Getopt("", args, "ho:a:d::r:t:T:i:D::", longopts); + Getopt g = new Getopt("", args, "ho:a:p:d::r:t:T:i:D::", longopts); int c; String arg; @@ -154,9 +157,13 @@ public class Procalign { usage(); return null; case 'o' : - /* Write warnings to stdout rather than stderr */ + /* Use filename instead of stdout */ filename = g.getOptarg(); break; + case 'p' : + /* Read parameters from filename */ + paramfile = g.getOptarg(); + break; case 'r' : /* Use the given class for rendering */ rendererClass = g.getOptarg(); @@ -202,6 +209,10 @@ public class Procalign { int i = g.getOptind(); + // Read the param file here + // This should include redirecting input + this should be before + if ( paramfile != null ) params = (Parameters)BasicParameters.read(); + loadedOntologies = new Hashtable(); if (debug > 0) params.setParameter("debug", new Integer(debug)); // debug = ((Integer)params.getParameter("debug")).intValue(); @@ -233,7 +244,7 @@ public class Procalign { throw new SAXException(message.toString()); } public void warning(String message) throws SAXException { - System.out.println("WARNING: " + message); + System.err.println("WARNING: " + message); } }; @@ -322,16 +333,17 @@ public class Procalign { } public static void usage() { - System.out.println("usage: Procalign [options] URI1 URI2"); - System.out.println("options are:"); - System.out.println("\t--impl=className -i classname\t\tUse the given alignment implementation."); - System.out.println("\t--renderer=className -r className\tSpecifies the alignment renderer"); - System.out.println("\t--output=filename -o filename\tOutput the alignment in filename"); - System.out.println("\t--alignment=filename -a filename Start from an XML alignment file"); - System.out.println("\t--threshold=double -t double\tFilters the similarities under threshold"); - System.out.println("\t--cutmethod=hard|perc|prop|best|span -T hard|perc|prop|best|span\tmethod for computing the threshold"); - System.out.println("\t--debug[=n] -d [n]\t\tReport debug info at level n"); - System.out.println("\t-Dparam=value\t\t\tSet parameter"); - System.out.println("\t--help -h\t\t\tPrint this message"); + System.err.println("usage: Procalign [options] URI1 URI2"); + System.err.println("options are:"); + System.err.println("\t--impl=className -i classname\t\tUse the given alignment implementation."); + System.err.println("\t--renderer=className -r className\tSpecifies the alignment renderer"); + System.err.println("\t--output=filename -o filename\tOutput the alignment in filename"); + System.err.println("\t--params=filename -p filename\tReads parameters from filename"); + System.err.println("\t--alignment=filename -a filename Start from an XML alignment file"); + System.err.println("\t--threshold=double -t double\tFilters the similarities under threshold"); + System.err.println("\t--cutmethod=hard|perc|prop|best|span -T hard|perc|prop|best|span\tmethod for computing the threshold"); + System.err.println("\t--debug[=n] -d [n]\t\tReport debug info at level n"); + System.err.println("\t-Dparam=value\t\t\tSet parameter"); + System.err.println("\t--help -h\t\t\tPrint this message"); } }