Search in sources :

Example 6 with LEGATO

use of legato.LEGATO in project legato by DOREMUS-ANR.

the class GUI method initialize.

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    try {
        frame = new JFrame();
        frame.setTitle("LEGATO");
        frame.setSize(890, 900);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
        frame.getContentPane().setLayout(null);
        /**
         ***************************
         * Description panel
         ****************************
         */
        JPanel panel_1 = new JPanel();
        panel_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
        panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Results", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
        panel_1.setBounds(25, 677, 828, 151);
        panel_1.setLayout(null);
        resultsArea = new JTextArea();
        JScrollPane scrollPane = new JScrollPane(resultsArea);
        scrollPane.setBounds(15, 39, 798, 96);
        panel_1.add(scrollPane);
        frame.getContentPane().add(panel_1);
        JPanel panel_2 = new JPanel();
        panel_2.setFont(new Font("Tahoma", Font.PLAIN, 11));
        panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Properties", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
        panel_2.setBounds(15, 298, 838, 384);
        panel_2.setLayout(null);
        inputProp = new JTextArea();
        inputProp.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                int line;
                try {
                    line = inputProp.getLineOfOffset(inputProp.getCaretPosition());
                    int start = inputProp.getLineStartOffset(line);
                    int end = inputProp.getLineEndOffset(line);
                    DefaultHighlighter highlighter = (DefaultHighlighter) inputProp.getHighlighter();
                    DefaultHighlighter.DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.lightGray);
                    // this is the key line
                    highlighter.setDrawsLayeredHighlights(false);
                    highlighter.addHighlight(start, end, painter);
                    selectedProp = inputProp.getDocument().getText(start, end - start);
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            }
        });
        JScrollPane scrollPane2 = new JScrollPane(inputProp);
        scrollPane2.setBounds(15, 36, 342, 330);
        panel_2.add(scrollPane2);
        frame.getContentPane().add(panel_2);
        JScrollPane scrollPane_1 = new JScrollPane((Component) null);
        scrollPane_1.setBounds(500, 36, 323, 330);
        panel_2.add(scrollPane_1);
        JTextArea outputProp = new JTextArea();
        scrollPane_1.setViewportView(outputProp);
        outputProp.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                int line;
                try {
                    line = outputProp.getLineOfOffset(outputProp.getCaretPosition());
                    int start = outputProp.getLineStartOffset(line);
                    int end = outputProp.getLineEndOffset(line);
                    DefaultHighlighter highlighter = (DefaultHighlighter) outputProp.getHighlighter();
                    DefaultHighlighter.DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.lightGray);
                    // this is the key line
                    highlighter.setDrawsLayeredHighlights(false);
                    highlighter.addHighlight(start, end, painter);
                    propForDelete = outputProp.getDocument().getText(start, end - start);
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            }
        });
        JPanel panel = new JPanel();
        panel.setFont(new Font("Tahoma", Font.BOLD, 12));
        panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Input Files", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
        panel.setBounds(14, 12, 839, 132);
        frame.getContentPane().add(panel);
        panel.setLayout(null);
        JLabel lblSourceDataset = new JLabel("Source Dataset :");
        lblSourceDataset.setBounds(15, 29, 125, 20);
        panel.add(lblSourceDataset);
        JLabel lblTargetDataset = new JLabel("Target Dataset :");
        lblTargetDataset.setBounds(15, 63, 125, 20);
        panel.add(lblTargetDataset);
        JLabel lblAlignmentFile = new JLabel("Alignment File :");
        lblAlignmentFile.setBounds(15, 99, 125, 20);
        panel.add(lblAlignmentFile);
        sourceField = new JTextField();
        sourceField.setBounds(138, 26, 603, 26);
        panel.add(sourceField);
        sourceField.setColumns(10);
        targetField = new JTextField();
        targetField.setColumns(10);
        targetField.setBounds(138, 60, 603, 26);
        panel.add(targetField);
        alignmentField = new JTextField();
        alignmentField.setColumns(10);
        alignmentField.setBounds(138, 96, 603, 26);
        panel.add(alignmentField);
        JPanel panel_3 = new JPanel();
        panel_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Classes", TitledBorder.LEADING, TitledBorder.TOP, null, Color.BLUE));
        panel_3.setToolTipText("");
        panel_3.setBounds(15, 172, 838, 123);
        frame.getContentPane().add(panel_3);
        panel_3.setLayout(null);
        JScrollPane scrollPane_2 = new JScrollPane((Component) null);
        scrollPane_2.setBounds(15, 26, 342, 81);
        panel_3.add(scrollPane_2);
        JTextArea inputClasses = new JTextArea();
        scrollPane_2.setViewportView(inputClasses);
        inputClasses.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                int line;
                try {
                    line = inputClasses.getLineOfOffset(inputClasses.getCaretPosition());
                    int start = inputClasses.getLineStartOffset(line);
                    int end = inputClasses.getLineEndOffset(line);
                    DefaultHighlighter highlighter = (DefaultHighlighter) inputClasses.getHighlighter();
                    DefaultHighlighter.DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.lightGray);
                    // this is the key line
                    highlighter.setDrawsLayeredHighlights(false);
                    highlighter.addHighlight(start, end, painter);
                    selectedClass = inputClasses.getDocument().getText(start, end - start);
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            }
        });
        JScrollPane scrollPane_3 = new JScrollPane((Component) null);
        scrollPane_3.setBounds(496, 26, 327, 81);
        panel_3.add(scrollPane_3);
        JTextArea outputClasses = new JTextArea();
        outputClasses.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                int line;
                try {
                    line = outputClasses.getLineOfOffset(outputClasses.getCaretPosition());
                    int start = outputClasses.getLineStartOffset(line);
                    int end = outputClasses.getLineEndOffset(line);
                    DefaultHighlighter highlighter = (DefaultHighlighter) outputClasses.getHighlighter();
                    DefaultHighlighter.DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.lightGray);
                    // this is the key line
                    highlighter.setDrawsLayeredHighlights(false);
                    highlighter.addHighlight(start, end, painter);
                    classForDelete = outputClasses.getDocument().getText(start, end - start);
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            }
        });
        scrollPane_3.setViewportView(outputClasses);
        /**
         ************************
         * Buttons
         *************************
         */
        JButton propAdd = new JButton("Add");
        propAdd.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (!selectedProp.equals(null)) {
                    if (!outputProp.getText().contains(selectedProp)) {
                        outputProp.setText((outputProp.getText() + "\n" + selectedProp).trim());
                        selectedProp = null;
                    }
                }
            }
        });
        propAdd.setBounds(372, 142, 115, 29);
        panel_2.add(propAdd);
        JButton propDelete = new JButton("Delete");
        propDelete.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (!propForDelete.equals(null)) {
                    if (outputProp.getText().contains(propForDelete)) {
                        outputProp.setText((outputProp.getText().replaceAll(propForDelete, "")).trim());
                    }
                }
            }
        });
        propDelete.setBounds(372, 199, 115, 29);
        panel_2.add(propDelete);
        JButton btnRun = new JButton("Run");
        btnRun.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                long beginTime = System.currentTimeMillis() / 1000;
                LEGATO legato = LEGATO.getInstance();
                legato.setBeginTime(beginTime);
                legato.addClasses(outputClasses.getText().trim());
                if (!alignmentField.getText().isEmpty())
                    legato.setRefAlign(new File(alignmentField.getText()));
                if (rdbtnAutomatic.isSelected()) {
                    matching = "automatic";
                    PropList propList = new PropList();
                    legato.setPropList(propList);
                    try {
                        PropertyHandler.clean(sourceField.getText(), targetField.getText());
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                } else if (rdbtnManuel.isSelected()) {
                    matching = "manual";
                    legato.addProperties(outputProp.getText().trim());
                    Model srcModel = ModelManager.loadModel(sourceField.getText());
                    Model tgtModel = ModelManager.loadModel(targetField.getText());
                    try {
                        legato.setSource(FileManager.getCreatedRDFile("source", srcModel));
                        legato.setTarget(FileManager.getCreatedRDFile("target", tgtModel));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
                try {
                    legato.buildDocuments();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });
        btnRun.setBounds(372, 339, 115, 29);
        panel_2.add(btnRun);
        JButton sourceAdd = new JButton("Add");
        sourceAdd.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                DatasetFileChooser dfc = new DatasetFileChooser(sourceField);
            }
        });
        sourceAdd.setBounds(756, 29, 68, 24);
        panel.add(sourceAdd);
        JButton targetAdd = new JButton("Add");
        targetAdd.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                DatasetFileChooser dfc = new DatasetFileChooser(targetField);
            }
        });
        targetAdd.setBounds(756, 64, 68, 24);
        panel.add(targetAdd);
        JButton alignmentAdd = new JButton("Add");
        alignmentAdd.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                DatasetFileChooser dfc = new DatasetFileChooser(alignmentField);
            }
        });
        alignmentAdd.setBounds(756, 100, 68, 24);
        panel.add(alignmentAdd);
        JButton classAdd = new JButton("Add");
        classAdd.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (!selectedClass.equals(null)) {
                    if (!outputClasses.getText().contains(selectedClass)) {
                        outputClasses.setText((outputClasses.getText() + "\n" + selectedClass).trim());
                    }
                }
            }
        });
        classAdd.setBounds(372, 26, 115, 29);
        panel_3.add(classAdd);
        JButton classDelete = new JButton("Delete");
        classDelete.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (!classForDelete.equals(null)) {
                    if (outputClasses.getText().contains(classForDelete)) {
                        outputClasses.setText((outputClasses.getText().replaceAll(classForDelete, "")).trim());
                    }
                }
            }
        });
        classDelete.setBounds(372, 71, 115, 29);
        panel_3.add(classDelete);
        rdbtnManuel = new JRadioButton("Manual");
        rdbtnManuel.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                rdbtnAutomatic.setSelected(false);
                Model srcModel = ModelManager.loadModel(sourceField.getText());
                Model tgtModel = ModelManager.loadModel(targetField.getText());
                List<Resource> classList = new ArrayList<Resource>();
                classList = ModelManager.getAllClassesFromModels(srcModel, tgtModel);
                inputClasses.setText(classList.toString().replaceAll(", ", "\n"));
                List<Property> propList = new ArrayList<Property>();
                propList = ModelManager.getAllPropFromModels(srcModel, tgtModel);
                inputProp.setText(propList.toString().replaceAll(", ", "\n"));
            }
        });
        rdbtnManuel.setBounds(465, 147, 155, 29);
        frame.getContentPane().add(rdbtnManuel);
        rdbtnAutomatic = new JRadioButton("Automatic");
        rdbtnAutomatic.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                rdbtnManuel.setSelected(false);
                inputProp.setText("");
                outputProp.setText("");
                Model srcModel = ModelManager.loadModel(sourceField.getText());
                Model tgtModel = ModelManager.loadModel(targetField.getText());
                List<Resource> classList = new ArrayList<Resource>();
                classList = ModelManager.getAllClassesFromModels(srcModel, tgtModel);
                inputClasses.setText(classList.toString().replaceAll(", ", "\n"));
            }
        });
        rdbtnAutomatic.setBounds(323, 147, 155, 29);
        frame.getContentPane().add(rdbtnAutomatic);
    } catch (Exception e) {
        e.printStackTrace();
    }
/*	JButton btnMatch = new JButton("Run");
		btnMatch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				long beginTime = System.currentTimeMillis()/1000;
				LEGATO legato = LEGATO.getInstance();
				legato.setBeginTime(beginTime);
				PropList propList = new PropList();
				legato.setPropList(propList);
				if (!alignmentField.getText().isEmpty()) legato.setRefAlign(new File(alignmentField.getText()));
					try {
					//	ConceptFinder.loadVocabularies();
						PropertyHandler.clean(sourceField.getText(), targetField.getText());
						legato.buildDocuments();
					} catch (Exception e1) {
						e1.printStackTrace();
					}
			}
		});
		btnMatch.setBounds(306, 129, 68, 24);
		panel.add(btnMatch);*/
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) DefaultHighlighter(javax.swing.text.DefaultHighlighter) JButton(javax.swing.JButton) TitledBorder(javax.swing.border.TitledBorder) JTextField(javax.swing.JTextField) Font(java.awt.Font) LEGATO(legato.LEGATO) JFrame(javax.swing.JFrame) ArrayList(java.util.ArrayList) PropList(legato.rdf.PropList) List(java.util.List) PropList(legato.rdf.PropList) Property(org.apache.jena.rdf.model.Property) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) Resource(org.apache.jena.rdf.model.Resource) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) IOException(java.io.IOException) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException) ActionListener(java.awt.event.ActionListener) Model(org.apache.jena.rdf.model.Model) File(java.io.File) BadLocationException(javax.swing.text.BadLocationException)

Example 7 with LEGATO

use of legato.LEGATO in project legato by DOREMUS-ANR.

the class CBDBuilder method getAllCBDs.

/**
 *******************************************
 * Get the CBD of all resources from an RDF model
 ********************************************
 */
public static Model getAllCBDs(Model model) {
    LEGATO legato = LEGATO.getInstance();
    List<Resource> resources = new ArrayList<Resource>();
    resources = getResources(model, legato.getClassResources());
    Model allCBDs = ModelFactory.createDefaultModel();
    Iterator iter = resources.iterator();
    while (iter.hasNext()) {
        Resource resource = (Resource) iter.next();
        String sparqlQueryString = "DESCRIBE <" + resource + ">";
        QueryFactory.create(sparqlQueryString);
        QueryExecution qexec = QueryExecutionFactory.create(sparqlQueryString, model);
        Model cbd = qexec.execDescribe();
        allCBDs.add(cbd);
        qexec.close();
    }
    return allCBDs;
}
Also used : LEGATO(legato.LEGATO) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) Model(org.apache.jena.rdf.model.Model) Iterator(java.util.Iterator) QueryExecution(org.apache.jena.query.QueryExecution)

Example 8 with LEGATO

use of legato.LEGATO in project legato by DOREMUS-ANR.

the class FileManager method getCreatedRDFile.

public static File getCreatedRDFile(String fileName, Model model) throws IOException {
    LEGATO legato = LEGATO.getInstance();
    FileWriter out = new FileWriter(legato.getPath() + File.separator + fileName + ".rdf");
    model.write(out, "RDF/XML");
    File file = new File(legato.getPath() + File.separator + fileName + ".rdf");
    out.close();
    return file;
}
Also used : LEGATO(legato.LEGATO) FileWriter(java.io.FileWriter) File(java.io.File)

Example 9 with LEGATO

use of legato.LEGATO in project legato by DOREMUS-ANR.

the class Align method evaluateMappings.

public static void evaluateMappings() throws AlignmentException {
    LEGATO legato = LEGATO.getInstance();
    if (legato.getRefAlign() == null)
        GUI.resultsArea.append("\nNo reference alignment file found !");
    else {
        AlignmentParser parser = new AlignmentParser(0);
        Alignment refAlign = parser.parse((legato.refAlign).toURI());
        Alignment mapFile = parser.parse(new File(legato.getPath() + File.separator + "results.rdf").toURI());
        Properties p = new Properties();
        Evaluator evaluator = new PRecEvaluator(refAlign, mapFile);
        evaluator.eval(p);
        GUI.resultsArea.append("\nEvaluation results:");
        GUI.resultsArea.append("\nF-Measure = " + Math.floor(((PRecEvaluator) evaluator).getFmeasure() * 100) / 100);
        GUI.resultsArea.append("\nPrecision = " + Math.floor(((PRecEvaluator) evaluator).getPrecision() * 100) / 100);
        GUI.resultsArea.append("\nRecall = " + Math.floor(((PRecEvaluator) evaluator).getRecall() * 100) / 100);
    }
}
Also used : Alignment(org.semanticweb.owl.align.Alignment) PRecEvaluator(fr.inrialpes.exmo.align.impl.eval.PRecEvaluator) LEGATO(legato.LEGATO) Properties(java.util.Properties) PRecEvaluator(fr.inrialpes.exmo.align.impl.eval.PRecEvaluator) Evaluator(org.semanticweb.owl.align.Evaluator) File(java.io.File) AlignmentParser(fr.inrialpes.exmo.align.parser.AlignmentParser)

Example 10 with LEGATO

use of legato.LEGATO in project legato by DOREMUS-ANR.

the class Align method saveMappings.

/**
 *******
 ** Create and save the alignment file
 ********
 */
public static void saveMappings(MapList mapList) throws Exception {
    LEGATO legato = LEGATO.getInstance();
    FileWriter alignFile = new FileWriter(legato.getPath() + File.separator + "results.rdf");
    BufferedWriter bw = new BufferedWriter(alignFile);
    PrintWriter pw = new PrintWriter(bw);
    pw.println("<?xml version='1.0' encoding='utf-8'?>");
    pw.println("<rdf:RDF xmlns='http://knowledgeweb.semanticweb.org/heterogeneity/alignment'");
    pw.println("xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'");
    pw.println("xmlns:xsd='http://www.w3.org/2001/XMLSchema#'>");
    pw.println("<Alignment>");
    pw.println("<xml>yes</xml>");
    pw.println("<level>0</level>");
    pw.println("<type>??</type>");
    pw.println(mapList.getAlignments());
    pw.println("</Alignment>");
    pw.println("</rdf:RDF>");
    pw.close();
    GUI.resultsArea.append("\nRunning time = " + (System.currentTimeMillis() / 1000 - legato.getBeginTime()) + " seconds");
    evaluateMappings();
}
Also used : LEGATO(legato.LEGATO) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter) PrintWriter(java.io.PrintWriter)

Aggregations

LEGATO (legato.LEGATO)14 File (java.io.File)7 Resource (org.apache.jena.rdf.model.Resource)7 Model (org.apache.jena.rdf.model.Model)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 QueryExecution (org.apache.jena.query.QueryExecution)4 FileWriter (java.io.FileWriter)3 Iterator (java.util.Iterator)3 Query (org.apache.jena.query.Query)3 QuerySolution (org.apache.jena.query.QuerySolution)3 ResultSet (org.apache.jena.query.ResultSet)3 Property (org.apache.jena.rdf.model.Property)3 DoubleArray (ca.pfv.spmf.patterns.cluster.DoubleArray)2 AlignmentParser (fr.inrialpes.exmo.align.parser.AlignmentParser)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 TreeMap (java.util.TreeMap)2 Key (legato.keys.def.Key)2