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 c1f26ea68ad48a3cf89a087d9a9379f67ce3ad69..e918fbd6e4dee2776dd035c7345d0b157dfe344a 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 @@ -78,10 +78,7 @@ public class OfflineAlign { System.out.println("Filename 1="+ selectedNeOnOnto1); System.out.println("Filename 2="+ selectedNeOnOnto2); - - - Parameters p = new BasicParameters(); AlignmentProcess A1 = null; //String htmlString = null; @@ -125,42 +122,6 @@ public class OfflineAlign { owlF.flush(); owlF.close(); - String str1 = fileToString(new File(ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl") ); - - //Add URI to OWL file : rethink !!! - File f0 = new File( ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl" ); - String s1 = str1.substring(0, str1.indexOf('>') + 1 ); - String s2 = str1.substring(str1.indexOf('>') + 2, str1.length()); - - String[] ss2 = s1.split("xmlns"); - String s3 = "<?xml version=\"1.0\"?>\n" + ss2[0] + " "; - - s3 = s3 + "xmlns=\"" + "file:" + f0.getAbsolutePath() + "#\"\n "; - s3 = s3 + "xml:base=\"" + "file:" + f0.getAbsolutePath() + "\"\n "; - s3 = s3 + "xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n " + "xmlns"; - - for(int i=2; i<ss2.length;i++) { - s3 = s3 + ss2[i]; - if(i != ss2.length-1 ) s3 = s3 + "xmlns"; - } - - - File owlFile = new File( ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl" ); - FileWriter out = new FileWriter( owlFile ); - out.write( s3 + s2 ); - out.flush(); - out.close(); - - //for displaying - /* - FileWriter htmlF = new FileWriter( alignFolder.getAbsolutePath() + File.separator + name.toString() + ".html" ); - AlignmentVisitor V1 = new HTMLRendererVisitor( - new PrintWriter ( htmlF ) ); - - A1.render(V1); - htmlF.flush(); - htmlF.close(); - */ } catch ( Exception ex ) { ex.printStackTrace(); }; @@ -175,23 +136,30 @@ public class OfflineAlign { Integer name = new Integer(SWTInterface.getNewAlignId()); Alignment A1 = SWTInterface.alignmentTable.get( id ); - Alignment clonedA1 = (BasicAlignment)((BasicAlignment)A1).clone(); + //BasicAlignment clonedA1 = (BasicAlignment)((BasicAlignment)A1).clone(); + BasicAlignment clonedA1 = null; try { - - clonedA1.cut(thres); - SWTInterface.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + name.toString(), clonedA1 ); - + + File exFile = new File(id + ".rdf"); + + AlignmentParser ap = new AlignmentParser(1); + clonedA1 = (BasicAlignment) ap.parse(exFile.toURI().toString()); + File fnRdf = new File( alignFolder.getAbsolutePath() + File.separator + name.toString()+ ".rdf" ); if (fnRdf.exists()) fnRdf.delete(); - FileWriter rdfF = new FileWriter(fnRdf); + FileWriter rdfF = new FileWriter( fnRdf ); AlignmentVisitor rdfV = new RDFRendererVisitor( new PrintWriter ( rdfF ) ); clonedA1.render(rdfV); rdfF.flush(); rdfF.close(); + clonedA1.cut(thres); + SWTInterface.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + name.toString(), clonedA1 ); + + File owlFile = new File( ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl"); if (owlFile.exists()) owlFile.delete(); @@ -204,49 +172,7 @@ public class OfflineAlign { clonedA1.render(owlV); owlF.flush(); owlF.close(); - - - String str1 = fileToString(new File( ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl") ); - - - //Add URI to OWL file : rethink !!! - File f0 = new File( ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl" ); - String s1 = str1.substring(0, str1.indexOf('>') + 1 ); - String s2 = str1.substring(str1.indexOf('>') + 2, str1.length()); - - String[] ss2 = s1.split("xmlns"); - String s3 = "<?xml version=\"1.0\"?>\n" + ss2[0] + " "; - - s3 = s3 + "xmlns=\"" + "file:" + f0.getAbsolutePath() + "#\"\n "; - s3 = s3 + "xml:base=\"" + "file:" + f0.getAbsolutePath() + "\"\n "; - s3 = s3 + "xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n " + "xmlns"; - - for(int i=2; i<ss2.length;i++) { - s3 = s3 + ss2[i]; - if(i != ss2.length-1 ) s3 = s3 + "xmlns"; - } - - - File owlFile2 = new File( ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl" ); - if (owlFile2.exists()) owlFile2.delete(); - FileWriter out = new FileWriter( owlFile2 ); - out.write( s3 + s2 ); - out.flush(); - out.close(); - - //for displaying - /* - File htmlFile = new File( ontoFolder.getAbsolutePath()+ File.separator + name.toString()+ ".html" ); - if (htmlFile.exists()) htmlFile.delete(); - FileWriter htmlF = new FileWriter( htmlFile ); - - AlignmentVisitor V1 = new HTMLRendererVisitor( - new PrintWriter ( htmlF ) ); - - clonedA1.render(V1); - htmlF.flush(); - htmlF.close(); - */ + } catch ( Exception ex ) { ex.printStackTrace();}; 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 afe284fc4db088c646d1792ee194984cfcdab370..99fb4d12452cdb88936173ebc0a1c94418fe0bb4 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 @@ -29,8 +29,10 @@ import java.io.FileInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.ByteArrayInputStream; import java.io.OutputStream; +import java.io.ByteArrayOutputStream; import java.net.HttpURLConnection; import java.net.URL; @@ -41,6 +43,23 @@ import java.util.zip.ZipInputStream; import javax.swing.JOptionPane; import org.semanticweb.owl.align.Parameters; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import fr.inrialpes.exmo.align.impl.BasicParameters; @@ -54,7 +73,8 @@ public class OnlineAlign { URL SOAPUrl = null; String SOAPAction = null; String uploadFile = null; - + private static DocumentBuilder BUILDER = null; + final DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); public OnlineAlign( String htmlPort, String host) { try { @@ -65,6 +85,10 @@ public class OnlineAlign { } catch ( Exception ex ) { ex.printStackTrace(); }; + fac.setValidating(false); + fac.setNamespaceAware(false); + try { BUILDER = fac.newDocumentBuilder(); } + catch (ParserConfigurationException e) { }; } public String uploadAlign(String alignId) { @@ -85,17 +109,32 @@ public class OnlineAlign { String message = createMessage( params ); System.out.println("HOST= "+ HOST + ", PORT= " + PORT + ", Action = "+ SOAPAction); - System.out.println("Message :"+ message); + System.out.println("Message for load file :"+ message); // Send message //answer = sendMessage( message, params ); answer = sendFile( message, params ); - - System.out.println("Loaded Align="+ answer); + System.out.println("SOAP loaded align=" + answer ); } catch ( Exception ex ) { ex.printStackTrace(); }; - if(! connected ) return null; - return answer; + if(! connected ) return null; + + 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, "loadResponse" ); + System.out.println("Loaded Align="+ result[0]); + + return result[0]; + } public String trimAlign(String alignId, String thres) { @@ -121,15 +160,32 @@ public class OnlineAlign { // Send message answer = sendMessage( message, params ); - System.out.println("Trim Align="+ answer); + } catch ( Exception ex ) { ex.printStackTrace(); }; if(! connected ) return null; - return answer; + + 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, "cutResponse" ); + + System.out.println("Trim Align="+ result[0]); + + return result[0]; + + } - public String getMethods() { + public String[] getMethods() { String answer = null; @@ -154,13 +210,25 @@ public class OnlineAlign { } catch ( Exception ex ) { ex.printStackTrace(); }; if(! connected ) return null; - return answer; - - + 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, "listmethodsResponse/classList/method" ) ; + for(int i=0; i< result.length;i++) System.out.println("methods=" + result[i]); + return result; + } - public String findAlignForOntos(String onto1, String onto2) { + public String[] findAlignForOntos(String onto1, String onto2) { String answer = null; @@ -185,11 +253,25 @@ public class OnlineAlign { catch ( Exception ex ) { ex.printStackTrace(); }; if(! connected ) return null; - return answer; + 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, "findResponse/alignmentList/alid" ); + + for(int i=0; i< result.length;i++) System.out.println("aligns for ontos=" + result[i]); + + return result; } - public String getAllAlign() { + public String[] getAllAlign() { String answer = null; @@ -215,8 +297,24 @@ public class OnlineAlign { catch ( Exception ex ) { ex.printStackTrace(); }; if(! connected ) return null; - - return answer; + + // Cut SOAP header + //answer = "<?xml version='1.0' encoding='utf-8' standalone='no'?>" + answer ; + 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, "listalignmentsResponse/alignmentList/alid" ); + for(int i=0; i< result.length;i++) System.out.println("aligns=" + result[i]); + + return result; @@ -250,12 +348,31 @@ public class OnlineAlign { // Send message answer = sendMessage( message, params ); - // Displays it - System.out.println("alignId="+ answer); + System.out.println("SOAP Match align=" + answer ); + } + catch ( Exception ex ) { ex.printStackTrace(); }; if(! connected ) return null; - return answer; + + // Cut SOAP header + //answer = "<?xml version='1.0' encoding='utf-8' standalone='no'?>" + answer ; + 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, "matchResponse" ); + + System.out.println("Match align Id=" + result[0]); + + return result[0]; } @@ -289,52 +406,34 @@ public class OnlineAlign { answer = sendMessage( message, params ); if(! connected ) return null; - System.out.println("OwlAlign="+ answer); + } catch ( Exception ex ) { ex.printStackTrace(); }; - // Cut SOAP header - String [] cutResult = answer.split("result"); + // 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'?>", ""); + - if(cutResult==null) return null; - - String str = ""; - - for(int i= 0; i< cutResult.length; i++){ - - if(i >= 1 && i <= cutResult.length -2) - str = str + cutResult[i]; + Document domMessage = null; + try { + domMessage = BUILDER.parse( new ByteArrayInputStream( answer.getBytes()) ); + + } catch ( IOException ioex ) { + ioex.printStackTrace(); + } catch ( SAXException saxex ) { + saxex.printStackTrace(); } - - //System.out.println("OwlAlign STR ="+ str); - if(str.equals("")) return null; - String str1 = str.substring(1, str.length() - 3); - - //extract id from "alid" - //String [] sali = alignId.split("/"); - //String uniqueId = sali[sali.length-2].concat(sali[sali.length-1]); - - - //Add URI to OWL file : rethink !!! - String s1 = str1.substring(0, str1.indexOf('>') + 1 ); - String s2 = str1.substring(str1.indexOf('>') + 2, str1.length()); - - String[] ss2 = s1.split("xmlns"); - String s3 = "<?xml version=\"1.0\"?>\n" + ss2[0] + " "; - - s3 = s3 + "xmlns=\"" + alignId + "#\"\n "; - s3 = s3 + "xml:base=\"" + alignId + "\"\n "; - s3 = s3 + "xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n " + "xmlns"; - - for(int i=2; i<ss2.length;i++) { - s3 = s3 + ss2[i]; - if(i != ss2.length-1 ) s3 = s3 + "xmlns"; - } - - return s3 + s2; + + String result[] = getTagFromSOAP( domMessage, "retrieveResponse/result/RDF" ); + + + + System.out.println("OWLAlign="+ result[0]); + return result[0]; } public String getRDFAlignment(String alignId) { @@ -366,77 +465,37 @@ public class OnlineAlign { answer = sendMessage( message, params ); if(! connected ) return null; - System.out.println("RDFAlign="+ answer); + } catch ( Exception ex ) { ex.printStackTrace(); }; // Cut SOAP header - String [] cutResult = answer.split("result"); - if(cutResult==null) return null; - - String str = ""; + //answer = "<?xml version='1.0' encoding='utf-8' standalone='no'?>" + answer ; + answer = answer.replace("<?xml version='1.0' encoding='utf-8' standalone='no'?>", ""); + - for(int i= 0; i< cutResult.length; i++){ - - if(i >= 1 && i <= cutResult.length -2) - str = str + cutResult[i]; + Document domMessage = null; + try { + domMessage = BUILDER.parse( new ByteArrayInputStream( answer.getBytes()) ); + + } catch ( IOException ioex ) { + ioex.printStackTrace(); + } catch ( SAXException saxex ) { + saxex.printStackTrace(); } - - //System.out.println("OwlAlign STR ="+ str); - - if(str.equals("")) return null; - String str1 = str.substring(1, str.length() - 3); - - //Add URI to RDF file : rethink !!! - String s1 = str1.substring(0, str1.indexOf('>') + 1 ); - String s2 = str1.substring(str1.indexOf('>') + 2, str1.length()); - + String result[] = getTagFromSOAP( domMessage, "retrieveResponse/result/RDF" ); + + + System.out.println("RDFAlign="+ result[0]); - return s2; + return result[0]; } - public String getHTMLAlignment(String alignId) { - - //retrieve alignment for displaying - - Parameters 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.HTMLRendererVisitor"); - - Vector corrList = new Vector(); - - String answer = null; - - try { - // Read parameters - - //Parameters params = ws.readParameters( aservArgRetrieve ); - - // Create the SOAP message - String message = createMessage( params ); - - System.out.println("URL SOAP :"+ SOAPUrl+ ", Action:"+ SOAPAction); - System.out.println("Message :"+ message); - - // Send message - answer = sendMessage( message, params ); - - //corrList = getCorresFromAnswer( answer, "tr", "#" ); - - } - catch ( Exception ex ) { ex.printStackTrace(); }; - if(! connected ) return null; - return answer; - - } + public String storeAlign(String alignId) { @@ -466,7 +525,7 @@ public class OnlineAlign { // Send message answer = sendMessage( message, params ); - System.out.println("Stored Align="+ answer); + //corrList = getCorresFromAnswer( answer, "tr", "#" ); } @@ -474,9 +533,86 @@ public class OnlineAlign { if(! connected ) return null; - return answer; + 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, "storeResponse" ); + + + System.out.println("Stored Align="+ result[0]); + + return result[0]; - } + } + + public String[] getTagFromSOAP( Document dom, String tag ){ + XPath XPATH = XPathFactory.newInstance().newXPath(); + String[] result = null; + Node n = null; + NodeList nl = null; + try { + // The two first elements are prefixed by: "SOAP-ENV:" + if(tag.equals("listmethodsResponse/classList/method") || tag.equals("listalignmentsResponse/alignmentList/alid") + || tag.equals("findResponse/alignmentList/alid") ) { + nl = (NodeList)(XPATH.evaluate("/Envelope/Body/" + tag, dom, XPathConstants.NODESET)); + result = new String[nl.getLength()]; + + for (int i=0; i< nl.getLength(); i++) { + Node method = (Node) nl.item(i); + + Node firstnode = method.getFirstChild(); + String nm = firstnode.getNodeValue(); + + if(nm!=null) result[i] = nm; + + } + } else if (tag.equals("retrieveResponse/result/RDF") ) { + n = (Node)(XPATH.evaluate("/Envelope/Body/" + tag, dom, XPathConstants.NODE)); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try { + Transformer tf = TransformerFactory.newInstance().newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING,"utf-8"); + tf.setOutputProperty(OutputKeys.INDENT,"yes"); + + tf.transform(new DOMSource(n),new StreamResult(stream)); + } + catch (Exception e){} + //Node firstnode = n.getFirstChild(); + + String nm = stream.toString(); + result = new String[1]; + result[0] = nm; + //System.out.println("result retrieve="+result[0]); + //System.out.println("no first="+ n.getNodeValue()); + } else { + Node nn = (Node)(XPATH.evaluate("/Envelope/Body/" + tag, dom, XPathConstants.NODE)); + result = new String[1]; + + NodeList ns = nn.getChildNodes(); + + //tag "alid" is third + Node n3 = (Node) ns.item(2); + Node nx = n3.getFirstChild(); + String nm = nx.getNodeValue(); + + result[0] = nm; + } + + } catch (XPathExpressionException e) { + } catch (NullPointerException e) { + } + + return result; + } + public String createMessage( Parameters params ) throws Exception { String messageBegin = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\'http://schemas.xmlsoap.org/soap/envelope/\' " + @@ -736,6 +872,7 @@ public class OnlineAlign { fi.close(); System.out.println("Upload Read done."); + // Read the response InputStreamReader isr = new InputStreamReader(httpConn.getInputStream()); BufferedReader in = new BufferedReader(isr); 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 606cc7ab1f0ba55df79f7329fab7dedac37a5147..bc7b8d37a35c8aec0d30d1845c09104cedd3800d 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 @@ -99,6 +99,8 @@ import com.ontoprise.ontostudio.datamodel.exception.ControlException; import fr.inrialpes.exmo.align.parser.AlignmentParser; import org.semanticweb.owl.align.Cell; +import fr.inrialpes.exmo.align.impl.Ontology; +import fr.inrialpes.exmo.align.impl.BasicCell; //import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.BasicAlignment; @@ -397,13 +399,13 @@ public class SWTInterface extends JPanel { selectedPort = portField.getText(); onAlign = new OnlineAlign(selectedPort, selectedHost); - String mt = onAlign.getMethods(); - if(mt == null) { + String list[] = onAlign.getMethods(); + if(list == null || list.length ==0) { JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); return; } - String[] list = getResultsFromAnswer( mt, "method", null ); //"." + //String[] list = getResultsFromAnswer( mt, "method", null ); //"." methodList = new String[list.length]; strategy.removeAllItems(); @@ -517,7 +519,7 @@ public class SWTInterface extends JPanel { } File fn = new File(selectedLocalAlign + ".owl"); - + //if (fn.exists()) fn.delete(); //System.out.println("Filename off to export :"+ fn.getAbsolutePath()); corrList = getCorresFromAnswer( SWTInterface.alignmentTable.get(selectedLocalAlign) ); @@ -569,7 +571,6 @@ public class SWTInterface extends JPanel { proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString()); new CreateProject( inputName, DatamodelTypes.RAM, proper ).run(); - // ProjectControl.getDefault().createNewOntologyProject(inputName, new String[0]); } ImportExportControl ieControl = new ImportExportControl(); @@ -599,12 +600,14 @@ public class SWTInterface extends JPanel { //System.out.println("file name off to export :"+ fn.getName()); try { - onAlign.uploadAlign(selectedLocalAlign + ".rdf"); + String uploaded = onAlign.uploadAlign(selectedLocalAlign + ".rdf"); localAlignIdList = new String[1]; localAlignIdList[0] = selectedLocalAlign; localAlignBox.removeAllItems(); localAlignBox.addItem(selectedLocalAlign); + + JOptionPane.showMessageDialog(null, "Uploaded alignment : "+ uploaded,"Warning",2); } catch ( Exception ex ) { ex.printStackTrace();} } @@ -640,11 +643,15 @@ public class SWTInterface extends JPanel { try { File rdfFile = new File( rdfPath ); + //if (rdfFile.exists()) rdfFile.delete(); + out = new FileWriter( rdfFile ); out.write( rdfalignStr ); - //out.write( answer ); + out.flush(); out.close(); + File file = new File(rdfPath); + AlignmentParser ap = new AlignmentParser(1); Alignment align = ap.parse(file.toURI().toString()); @@ -699,8 +706,6 @@ public class SWTInterface extends JPanel { catch ( Exception ex ) { ex.printStackTrace();}; //get align from server, then export it as owl onto - String owlPath = ontoFolder.getAbsolutePath() + File.separator + getNewAlignId() + ".owl"; - String owlalignStr = onAlign.getOWLAlignment( selectedAlign ); @@ -736,17 +741,21 @@ public class SWTInterface extends JPanel { new CreateProject( inputName, DatamodelTypes.RAM, proper ).run(); } } - + + String owlPath = ontoFolder.getAbsolutePath() + File.separator + getNewAlignId() + ".owl"; File owlFile = new File( owlPath ); + if (owlFile.exists()) owlFile.delete(); + out = new FileWriter( owlFile ); out.write( owlalignStr ); - //out.write( answer ); + out.flush(); out.close(); + try { ImportExportControl ieControl = new ImportExportControl(); String[] importedModules = ieControl.importFileSystem(inputName, "file:" + owlPath, null); - //ieControl.addOntologies2Project(importedModules, inputName); + //ieControl.addOntologies2Project(importedModules, inputName); } catch ( ControlException ex ) { } } @@ -764,14 +773,15 @@ public class SWTInterface extends JPanel { // for connecting to server //onAlign = new OnlineAlign(selectedPort, selectedHost); + String[] list = null; if(online) { - String aa = onAlign.getAllAlign(); - if(aa == null) { + list = onAlign.getAllAlign(); + if(list == null || list.length==0) { JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); return; } - String[] list = getResultsFromAnswer( aa , "alid", null ); + //String[] list = getResultsFromAnswer( aa , "alid", null ); alignIdList = new String[list.length]; alignBox.removeAllItems(); @@ -804,7 +814,7 @@ public class SWTInterface extends JPanel { } else { //offline - String[] list = offAlign.getAllAlign( ); + list = offAlign.getAllAlign( ); if(list!=null) { localAlignIdList = new String[list.length]; localAlignBox.removeAllItems(); @@ -835,11 +845,11 @@ public class SWTInterface extends JPanel { JOptionPane.showMessageDialog(null, "Choose two ontologies from lists!","Warning",2); else { - String ao = onAlign.findAlignForOntos(selectedOnto1, selectedOnto2); - if(ao == null) + String[] list = onAlign.findAlignForOntos(selectedOnto1, selectedOnto2); + if(list == null || list.length==0) JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); else { - String[] list = getResultsFromAnswer(ao, "alid", null ); + //String[] list = getResultsFromAnswer(ao, "alid", null ); alignIdList = new String[list.length]; alignBox.removeAllItems(); @@ -879,22 +889,21 @@ public class SWTInterface extends JPanel { String at = onAlign.trimAlign(selectedAlign, thres); - if(at == null) + if(at == null || at.equals("")) JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); else { - String[] list = getResultsFromAnswer( at, "alid", null ); + //String[] list = getResultsFromAnswer( at, "alid", null ); - alignIdList = new String[list.length]; + //alignIdList = new String[list.length]; + alignIdList = new String[1]; alignBox.removeAllItems(); - for(int i=0; i< list.length; i++){ - alignIdList[i]= list[i]; - alignBox.addItem(list[i]); - } + alignIdList[0]= at; + alignBox.addItem(at); + + selectedAlign = alignIdList[0]; - if(alignIdList.length > 0) { - selectedAlign = alignIdList[0]; - } + } } @@ -947,9 +956,21 @@ public class SWTInterface extends JPanel { else { String sto = onAlign.storeAlign(selectedAlign); - if(sto == null) + + if(sto == null || sto.equals("") ) JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); - + else { + alignIdList = new String[1]; + alignBox.removeAllItems(); + + alignIdList[0]= sto; + alignBox.addItem(sto); + + selectedAlign = alignIdList[0]; + JOptionPane.showMessageDialog(null, "Stored alignment : "+ sto ,"Warning",2); + } + + } } @@ -987,30 +1008,19 @@ public class SWTInterface extends JPanel { } String answer = onAlign.getAlignId( matchMethod, selectedOnto1, selectedOnto2 ); - if(answer==null) { + if(answer==null || answer.equals("")) { JOptionPane.showMessageDialog(null, "Alignment is not produced.","Warning",2); return; } - - alignIdList = getResultsFromAnswer( answer, "alid", null ); - if(alignIdList==null || alignIdList[0].equals("null")) JOptionPane.showMessageDialog(null, "Alignment is not produced.","Warning",2); - else { - - alignBox.removeAllItems(); + + alignIdList = new String[1]; + alignIdList[0] = answer; + alignBox.removeAllItems(); + alignBox.addItem(alignIdList[0]); + selectedAlign = alignIdList[0]; - for(int i=0; i< alignIdList.length; i++){ - - alignBox.addItem(alignIdList[i]); - } - - if(alignIdList.length > 0) { - selectedAlign = alignIdList[0]; - } - } - - - + } else { //offline @@ -1349,18 +1359,18 @@ private HashMap<String,String> refreshOntoList() { for(int i=0; i<cells.size(); i++) { try { - corr = new String[4]; + corr = new String[4]; - corr[0] = cells.get(i).getObject1AsURI().toString(); + corr[0] = ((BasicCell)cells.get(i)).getObject1().toString(); //by default : equivalence //corr[1] = cells.get(i).getRelation().toString(); corr[1] = "="; corr[2] = (new Double(cells.get(i).getStrength())).toString(); - corr[3] = cells.get(i).getObject2AsURI().toString(); + corr[3] = ((BasicCell)cells.get(i)).getObject2().toString(); names.add(corr); - }catch (Exception e) {} + }catch (Exception ex) { ex.printStackTrace(); } } return names;