diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java index 6058fca30abb0c49aec2b3c32688bfab113ccbb7..697b1a2af5c44273601724f79dc81d6e2c8bb422 100755 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java @@ -32,6 +32,9 @@ import java.util.Enumeration; import org.semanticweb.kaon2.api.formatting.OntologyFileFormat; import org.semanticweb.owl.align.Alignment; import fr.inrialpes.exmo.align.impl.BasicAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.impl.URIAlignment; + import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Parameters; @@ -100,7 +103,7 @@ public class OfflineAlign { SWTInterface.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + name.toString(), (Alignment)A1 ); - // for saving locally + //for saving locally FileWriter rdfF = new FileWriter(new File( alignFolder.getAbsolutePath() + File.separator + name.toString()+ ".rdf" )); AlignmentVisitor rdfV = new RDFRendererVisitor( new PrintWriter ( rdfF ) ); A1.render(rdfV); @@ -112,8 +115,9 @@ public class OfflineAlign { AlignmentVisitor V = new OWLAxiomsRendererVisitor( new PrintWriter ( owlF ) ); - - A1.render(V); + ObjectAlignment al = ObjectAlignment.toObjectAlignment( (URIAlignment)A1 ); + al.render( V ); + //A1.render(V); owlF.flush(); owlF.close(); @@ -159,8 +163,9 @@ public class OfflineAlign { FileWriter owlF = new FileWriter( owlFile ); AlignmentVisitor owlV = new OWLAxiomsRendererVisitor( new PrintWriter ( owlF ) ); - - clonedA1.render(owlV); + ObjectAlignment al = ObjectAlignment.toObjectAlignment( (URIAlignment)clonedA1 ); + al.render( owlV ); + //clonedA1.render(owlV); owlF.flush(); owlF.close(); } diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java index cdc9f39a52e1aa5609b51349a6f260c88ec05e7a..ea177fd62910ed1256fd098337814faafdb32d16 100755 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java @@ -21,14 +21,27 @@ package fr.inrialpes.exmo.align.plugin.neontk; import java.io.BufferedReader; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.ByteArrayInputStream; + +//mport javax.swing.JOptionPane; +import javax.swing.ProgressMonitorInputStream; +//import javax.swing.JComponent; +//import javax.swing.JDialog; +import javax.swing.ProgressMonitor; +import javax.swing.JButton; +//import java.awt.FlowLayout; +//import java.awt.EventQueue; import java.io.OutputStream; +//import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.net.HttpURLConnection; @@ -66,10 +79,22 @@ public class OnlineAlign { URL SOAPUrl = null; String SOAPAction = null; String uploadFile = null; + + HttpURLConnection globalConn = null; + + String globalAnswer = null; + + //InputStream globalInput = null; + JButton export = null; + JButton store = null; + JButton trim = null; + //Parameters globalParam = null; + //String rdfString = null; + private static DocumentBuilder BUILDER = null; final DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); - public OnlineAlign( String htmlPort, String host ) { + public OnlineAlign( String htmlPort, String host ) { try { HOST = host; PORT = htmlPort; @@ -173,9 +198,7 @@ public class OnlineAlign { //System.out.println("Trim Align="+ result[0]); return result[0]; - - - + } public String[] getMethods() { @@ -376,6 +399,7 @@ public class OnlineAlign { Parameters params = new BasicParameters(); + params.setParameter( "host", HOST ); //params.setParameter( "http", PORT ); //params.setParameter( "wsdl", WSDL ); @@ -423,20 +447,47 @@ public class OnlineAlign { return result[0]; } - public String getRDFAlignment(String alignId) { - - //retrieve alignment for storing in OWL file + public String getRDFAlignmentParsed() { + + Document domMessage = null; + try { + domMessage = BUILDER.parse( new ByteArrayInputStream( globalAnswer.getBytes()) ); + + } catch ( IOException ioex ) { + ioex.printStackTrace(); + } catch ( SAXException saxex ) { + saxex.printStackTrace(); + } - Parameters params = new BasicParameters(); - params.setParameter( "host", HOST ); + String result[] = getTagFromSOAP( domMessage, "retrieveResponse/result/RDF" ); + + + //System.out.println("RDFAlign="+ result[0]); + + //InputStream fromServer = new BufferedInputStream( + // new ProgressMonitorInputStream(component, "Reading ... " , new ByteArrayInputStream( result[0].getBytes()) )); + //new FileInputStream(fileName ) )); + + return result[0]; + } + + public void getRDFAlignment(String alignId, JButton exp, JButton st, JButton tr) { + + //retrieve alignment for storing in OWL file + export = exp; + store = st; + trim = tr; + Parameters params = new BasicParameters(); + params = new BasicParameters(); + params.setParameter( "host", HOST ); //params.setParameter( "http", PORT ); //params.setParameter( "wsdl", WSDL ); - params.setParameter( "command","retrieve"); - params.setParameter( "arg1", alignId); - params.setParameter( "arg2", "fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor"); + params.setParameter( "command","retrieve"); + params.setParameter( "arg1", alignId); + params.setParameter( "arg2", "fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor"); - String answer=null; + //String answer = null; try { // Read parameters @@ -444,43 +495,20 @@ public class OnlineAlign { // Create the SOAP message String message = createMessage( params ); - + //globalMess = createMessage( globalParam ); //System.out.println("URL SOAP :"+ SOAPUrl + ", Action:"+ SOAPAction); //System.out.println("Message :" + message); // Send message - answer = sendMessage( message, params ); - if(! connected ) return null; - + //answer = sendMessage( message, params ); + //the result is put in "globalAnswer" + sendMessage( message, params ); + + //if(! connected ) return null; } catch ( Exception ex ) { ex.printStackTrace(); }; - - - // Cut SOAP header - - //answer = "<?xml version='1.0' encoding='utf-8' standalone='no'?>" + answer ; - //answer = answer.replace("<?xml version='1.0' encoding='utf-8' standalone='no'?>", ""); - - - Document domMessage = null; - try { - domMessage = BUILDER.parse( new ByteArrayInputStream( answer.getBytes()) ); - - } catch ( IOException ioex ) { - ioex.printStackTrace(); - } catch ( SAXException saxex ) { - saxex.printStackTrace(); - } - - - String result[] = getTagFromSOAP( domMessage, "retrieveResponse/result/RDF" ); - - - //System.out.println("RDFAlign="+ result[0]); - - return result[0]; - } + } @@ -511,11 +539,8 @@ public class OnlineAlign { // Send message answer = sendMessage( message, params ); - - - //corrList = getCorresFromAnswer( answer, "tr", "#" ); - - } + + } catch ( Exception ex ) { ex.printStackTrace() ;}; if(! connected ) return null; @@ -753,18 +778,18 @@ public class OnlineAlign { byte[] b = message.getBytes(); String answer = ""; + // Create HTTP Request try { URLConnection connection = SOAPUrl.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) connection; + globalConn = httpConn; httpConn.setRequestProperty( "Content-Length", String.valueOf( b.length ) ); httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8"); - - - httpConn.setRequestProperty("SOAPAction",SOAPAction); + httpConn.setRequestProperty("SOAPAction",SOAPAction); httpConn.setRequestMethod( "POST" ); httpConn.setDoOutput(true); httpConn.setDoInput(true); @@ -772,23 +797,74 @@ public class OnlineAlign { // Send the request through the connection OutputStream out = httpConn.getOutputStream(); - //System.out.println("ResponseMessage= "+httpConn.getResponseMessage()); - out.write( b ); out.close(); - - //System.out.println("Message Length= "+String.valueOf( b.length )); - - // Read the response and write it to standard output - InputStreamReader isr = new InputStreamReader(httpConn.getInputStream()); - BufferedReader in = new BufferedReader(isr); - String line; - while ((line = in.readLine()) != null) { - answer += line + "\n"; - } - if (in != null) in.close(); + if( param.getParameter("command").equals("retrieve") ) { + + globalAnswer = ""; + Thread th = new Thread() { + + public void run() { + + try { + + String mess = "Fetching alignment from server,"; + int maxSize = 5000000; // size in byte + + ProgressMonitorInputStream pin = new ProgressMonitorInputStream( null, mess, globalConn.getInputStream() ); + + ProgressMonitor pm = pin.getProgressMonitor(); + pm.setMaximum( maxSize ); + pm.setMillisToPopup( 1 ); + pm.setMillisToDecideToPopup( 2 ); + + InputStreamReader isr = new InputStreamReader(pin); + BufferedReader in = new BufferedReader(isr); + + String line; + int co = 0; + //int coL = 0; + while ((line = in.readLine()) != null) { + globalAnswer += line + "\n"; + co += line.length(); + pm.setNote(co + " bytes read."); + if( co >= maxSize -10000 ) { + maxSize = co + line.length() + maxSize; + pm.setMaximum( maxSize ); + pm.setProgress( co ); + } + } + + if( ! pm.isCanceled() ) { + export.setEnabled(true); + store.setEnabled(true); + trim.setEnabled(true); + } + + pm.setProgress( maxSize - 1 ); + pin.close(); + } catch (Exception e) {e.printStackTrace();} + } + + }; + + th.start(); + + } else { + + InputStreamReader isr = new InputStreamReader( httpConn.getInputStream() ); + BufferedReader in = new BufferedReader( isr ); + String line; + while ((line = in.readLine()) != null) { + answer += line + "\n"; + } + + in.close(); + } + //System.out.println("answer= " + answer); + if(httpConn.HTTP_REQ_TOO_LONG == httpConn.getResponseCode()) System.err.println("Request too long"); //if(httpConn.HTTP_OK == httpConn.getResponseCode()) System.out.println("Request OK"); @@ -798,6 +874,7 @@ public class OnlineAlign { } connected = true; + return answer; } @@ -879,4 +956,5 @@ public class OnlineAlign { connected = true; return answer; } + } diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/SWTInterface.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/SWTInterface.java index 25362c64a135f7f2d48bbe52d45cb4d8b2a10ff8..dce84b0600e9fe25202a20a3fd1180e998ed9148 100644 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/SWTInterface.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/SWTInterface.java @@ -20,10 +20,14 @@ package fr.inrialpes.exmo.align.plugin.neontk; +import java.io.BufferedReader; import java.io.File; import java.io.FileWriter; +import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringWriter; +import java.io.InputStream; +import java.io.FileInputStream; import java.net.MalformedURLException; import java.net.URI; import java.awt.Component; @@ -37,6 +41,8 @@ import java.awt.event.ItemEvent; import java.awt.event.ActionEvent; import java.awt.Container; import java.awt.Dimension; +import java.awt.Insets; +import java.awt.Toolkit; import java.util.Properties; import java.util.Set; import java.util.Vector; @@ -47,9 +53,12 @@ import java.util.HashMap; import javax.swing.JLabel; import javax.swing.JComboBox; import javax.swing.JPanel; +import javax.swing.JFrame; import javax.swing.JSplitPane; import javax.swing.JComponent; import javax.swing.JTextField; +import javax.swing.ProgressMonitor; +import javax.swing.ProgressMonitorInputStream; //import javax.swing.JFileChooser; import javax.swing.JTextArea; import javax.swing.JButton; @@ -59,11 +68,30 @@ import javax.swing.JScrollPane; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JEditorPane; +import javax.swing.Timer; +import javax.swing.SwingUtilities; + + + + +import java.net.HttpURLConnection; + +//import java.net.URL; +import java.net.URLConnection; + +//import javax.swing.JFrame; +//import javax.swing.ProgressMonitor; +//import javax.swing.SwingUtilities; +//import javax.swing.Timer; +//import javax.swing.UIManager; + //import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.Parameters; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -73,6 +101,7 @@ import org.w3c.dom.NodeList; //import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.IPath; +import org.eclipse.swt.widgets.Composite; //import org.eclipse.core.resources.IProject; //import org.semanticweb.kaon2.api.Ontology; @@ -92,6 +121,7 @@ import com.ontoprise.ontostudio.datamodel.exception.ControlException; //import org.semanticweb.kaon2.api.formatting.OntologyFileFormat; //import org.eclipse.core.runtime.IProgressMonitor; //import com.ontoprise.ontostudio.owl.datamodel.*; +import fr.inrialpes.exmo.align.onto.OntologyCache; import fr.inrialpes.exmo.align.parser.AlignmentParser; import org.semanticweb.owl.align.Cell; @@ -100,18 +130,20 @@ import fr.inrialpes.exmo.align.impl.BasicCell; //import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.BasicAlignment; +import fr.inrialpes.exmo.align.impl.BasicParameters; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; import fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor; +import fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor; public class SWTInterface extends JPanel { private static final long serialVersionUID = 330; private static JSplitPane _mainSplitter = new JSplitPane (JSplitPane.VERTICAL_SPLIT); - - //private URL SOAPUrl = null; - //private String SOAPAction = null; - + + JLabel hostName, portName;//, thresLabel;//, alignProjLabel; //JComboBox hostList, portList; @@ -128,26 +160,24 @@ public class SWTInterface extends JPanel { public static Hashtable<String,Alignment> alignmentTable = new Hashtable<String,Alignment>(); static String [] forUniqueness = new String[0]; static int alignId = 0; - //public static Vector<String> alignProjects = new Vector<String>(); - //Procalign procalign = null; - //Parameters p = new BasicParameters(); - + JComponent phrases;// Res=null; + JTextField fileName1, fileName2, hostField, portField; SWTInterface frame; JEditorPane htmlView; JButton cancelButton, mapButton, resButton, ontoRefresh, allAlignButton, - alignImportButton, localAlignImportButton, alignUploadButton, + alignImportButton, localAlignImportButton, alignUploadButton, localAlignTrimButton, serverAlignTrimButton, alignFindButton, alignStoreButton, connButton, offlineButton, onlineButton;// disconnButton ; JDialog dialog; //JPanel pane2; - Component result=null; + Component result = null; JComboBox strategy, renderer, alignBox, localAlignBox, ontoBox1, ontoBox2; JLabel strat, render, ontoLabel1, ontoLabel2, alignLabel, localAlignLabel; - + //lists obtained from from server public String [] methodList = new String[0]; @@ -182,6 +212,7 @@ public class SWTInterface extends JPanel { public File ontoFolder = null; public File alignFolder = null; public static File basicFolder = null; + public void offlineInit(boolean init){ online = false; @@ -208,6 +239,7 @@ public class SWTInterface extends JPanel { alignFindButton.setEnabled(false); alignImportButton.setEnabled(false); + //fetchButton.setEnabled(false); alignUploadButton.setEnabled(false); alignBox.setEnabled(false); @@ -392,7 +424,8 @@ public class SWTInterface extends JPanel { selectedHost = hostField.getText(); selectedPort = portField.getText(); - onAlign = new OnlineAlign(selectedPort, selectedHost); + //parentComponent = getParent(); + onAlign = new OnlineAlign(selectedPort, selectedHost ); String list[] = onAlign.getMethods(); if(list == null || list.length ==0) { @@ -418,22 +451,23 @@ public class SWTInterface extends JPanel { alignBox.setEnabled(true); localAlignBox.setEnabled(true); - alignImportButton.setEnabled(true); + + alignImportButton.setEnabled(false); + alignStoreButton.setEnabled(false); + serverAlignTrimButton.setEnabled(false); + //fetchButton.setEnabled(true); + localAlignImportButton.setEnabled(true); alignUploadButton.setEnabled(true); alignFindButton.setEnabled(true); allAlignButton.setEnabled(true); - alignStoreButton.setEnabled(true); - offlineButton.setEnabled(true); onlineButton.setEnabled(false); - serverAlignTrimButton.setEnabled(true); - localAlignTrimButton.setEnabled(true); - - alignStoreButton.setEnabled(true); + localAlignTrimButton.setEnabled(true); + ontoRefresh.setEnabled(true); mapButton.setEnabled(true); @@ -607,18 +641,22 @@ public class SWTInterface extends JPanel { //the name originated from the server is a URL so slashes are used //String [] sali = selectedAlign.split("/"); //String uniqueId = sali[sali.length-2].concat(sali[sali.length-1]); - + + String inputName = null; + FileWriter out = null; - String inputName = null; - - //export to local List - String rdfalignStr = onAlign.getRDFAlignment( selectedAlign ); + + String rdfalignStr = onAlign.getRDFAlignmentParsed( ); + String alignKey = alignFolder.getAbsolutePath() + File.separator + getNewAlignId(); String rdfPath = alignKey + ".rdf"; + URIAlignment align = null; + String owlalignStr = null; + try { File rdfFile = new File( rdfPath ); @@ -633,7 +671,7 @@ public class SWTInterface extends JPanel { AlignmentParser ap = new AlignmentParser(0); ap.setEmbedded(true); - Alignment align = ap.parse(file.toURI().toString()); + align = (URIAlignment)ap.parse(file.toURI().toString()); SWTInterface.alignmentTable.put( alignKey , (Alignment)align ); @@ -666,20 +704,26 @@ public class SWTInterface extends JPanel { htmlView.setVisible(true); + //get align from server, then export it as owl onto + + //String owlalignStr = onAlign.getOWLAlignment( selectedAlign ); + + StringWriter owlMessage = new StringWriter(); + AlignmentVisitor owlV = new OWLAxiomsRendererVisitor( new PrintWriter ( owlMessage ) ); + //align.init( ); + ObjectAlignment al = ObjectAlignment.toObjectAlignment( (URIAlignment)align ); + al.render( owlV ); + + owlalignStr = owlMessage.toString(); } catch ( Exception ex ) { ex.printStackTrace();}; - - //get align from server, then export it as owl onto - String owlalignStr = onAlign.getOWLAlignment( selectedAlign ); - if(owlalignStr==null) { - JOptionPane.showMessageDialog(null, "Alignment cannot be exported.","Warning",2); + JOptionPane.showMessageDialog(null, "OWL alignment cannot be exported.","Warning",2); return; } - try { inputName = JOptionPane.showInputDialog(null, "Enter a project name", "AlignmentProject"); @@ -972,20 +1016,28 @@ public class SWTInterface extends JPanel { return; } + alignImportButton.setEnabled(false); + alignStoreButton.setEnabled(false); + serverAlignTrimButton.setEnabled(false); + //if (matchMethod.equals("es.upm.fi.dia.ontology.semanticmapper.pronto.ODEAlignment")) { + // JOptionPane.showMessageDialog(null, "This method may take some minutes.\n Please click OK and wait.","Warning",2); + + //} + String answer = onAlign.getAlignId( matchMethod, selectedOnto1, selectedOnto2 ); if(answer==null || answer.equals("")) { JOptionPane.showMessageDialog(null, "Alignment is not produced.","Warning",2); return; } - alignIdList = new String[1]; alignIdList[0] = answer; alignBox.removeAllItems(); alignBox.addItem(alignIdList[0]); selectedAlign = alignIdList[0]; - - + + onAlign.getRDFAlignment( selectedAlign , alignImportButton, alignStoreButton, serverAlignTrimButton); + } else { //offline @@ -1133,6 +1185,7 @@ private JPanel createPhraseList () { fourLabel.add(alignLabel); fourLabel.add(alignBox); + //fourLabel.add(fetchButton); fourLabel.add(alignImportButton); fourLabel.add(serverAlignTrimButton); fourLabel.add(alignStoreButton); @@ -1329,9 +1382,6 @@ private HashMap<String,String> refreshOntoList() { } - - - public static Vector<String[]> getCorresFromAnswer( String answer, String type ,String separator) { Document doc=null; Vector<String[]> names = new Vector<String[]>(); @@ -1429,9 +1479,6 @@ private HashMap<String,String> refreshOntoList() { return doc; } - } - -