Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #10

Merged
merged 3 commits into from
Feb 14, 2022
Merged

Dev #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Arguments-enhanced IR
![version](https://img.shields.io/badge/version-0.8.0-blue)
![last-update](https://img.shields.io/badge/last_update-2/10/2022-orange)
![version](https://img.shields.io/badge/version-0.8.5-blue)
![last-update](https://img.shields.io/badge/last_update-2/14/2022-orange)
![license](https://img.shields.io/badge/license-Apache_2.0-brightgreen)

Argument-enhanced information retrieval project repository. A case study in the <a href="https://decide.madrid.es" target="_blank">Decide Madrid</a> database.
Expand Down
3 changes: 3 additions & 0 deletions code/ArgumentIR/Resources/views/validate-argument.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div style="width: 110px; font-size: 90%; border: 1px solid #BCBCBC; background-color: #F0F0F0; padding: 5px; text-align: center; display:inline-block;" >
<a href="$ARG_ID$/RELEVANT">Relevant</a> | <a href="$ARG_ID$/VALID">Valid</a> | <a href="$ARG_ID$/NOT_VALID">Not valid</a>
</div>
87 changes: 81 additions & 6 deletions code/ArgumentIR/src/es/uam/irg/io/IOManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
package es.uam.irg.io;

import es.uam.irg.utils.FunctionUtils;
import es.uam.irg.utils.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -38,18 +41,57 @@
*/
public class IOManager {

/**
*
* @param filepath
* @return
*/
public static Map<String, String> readDictFromCsvFile(String filepath) {
Map<String, String> csvData = new HashMap<>();

try {
File csvFile = new File(filepath);

if (csvFile.exists() && csvFile.isFile()) {
try ( BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
String row;
String id;
String label;
String timestamp;
String value;

reader.readLine();
while ((row = reader.readLine()) != null) {
String[] data = row.split(",");

if (data.length == 3) {
id = data[0];
label = data[1];
timestamp = data[2];
value = label + "," + timestamp;
csvData.put(id, value);
}
}
}
}

} catch (IOException ex) {
Logger.getLogger(IOManager.class.getName()).log(Level.SEVERE, null, ex);
}

return csvData;
}

/**
*
* @param folderPath
* @return
*/
public static Map<String, String> readHtmlReports(String folderPath) {
Map<String, String> reports = null;

if (!StringUtils.isEmpty(folderPath)) {
reports = new HashMap<>();
File folder = new File(folderPath);
Map<String, String> reports = new HashMap<>();
File folder = new File(folderPath);

if (folder.exists() && folder.isDirectory()) {
for (File fileEntry : folder.listFiles()) {
if (fileEntry.isFile()) {
Path filepath = Paths.get(fileEntry.getPath());
Expand Down Expand Up @@ -89,6 +131,39 @@ public static Map<String, Object> readYamlFile(String filepath) {
return data;
}

/**
*
* @param filepath
* @param header
* @param csvData
* @return
*/
public static boolean saveDictToCsvFile(String filepath, String header, Map<String, String> csvData) {
boolean result = false;

if (csvData.size() > 0) {

// Add data
StringBuilder sb = new StringBuilder(header);

csvData.entrySet().forEach(entry -> {
String file = entry.getKey() + "," + entry.getValue() + "\n";
sb.append(file);
});

// Save data
try ( PrintWriter out = new PrintWriter(filepath)) {
out.println(sb.toString());
result = true;

} catch (FileNotFoundException ex) {
Logger.getLogger(IOManager.class.getName()).log(Level.SEVERE, null, ex);
}
}

return result;
}

/**
*
* @param filename
Expand Down
21 changes: 18 additions & 3 deletions code/ArgumentIR/src/es/uam/irg/ir/gui/ArgumentIRForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="menuLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Label"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="mItemSaveLabels">
<Properties>
<Property name="text" type="java.lang.String" value="Save Labels"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mItemSaveLabelsActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
</SubComponents>
</Menu>
</NonVisualComponents>
Expand All @@ -51,15 +66,15 @@
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[800, 400]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[1200, 600]"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="menuBar" type="java.lang.String" value="menuBar"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="true"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
Expand Down
84 changes: 75 additions & 9 deletions code/ArgumentIR/src/es/uam/irg/ir/gui/ArgumentIRForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import es.uam.irg.utils.FunctionUtils;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.BadLocationException;

Expand All @@ -34,7 +37,7 @@ public class ArgumentIRForm extends javax.swing.JFrame {

public static final String HTML_CONTENT_TYPE = "text/html";
public static final String DECIMAL_FORMAT = "0.000";
public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

private final ArgumentIRModel model;

Expand All @@ -43,11 +46,25 @@ public class ArgumentIRForm extends javax.swing.JFrame {
*/
public ArgumentIRForm() {
initComponents();
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.txtResult.setContentType(HTML_CONTENT_TYPE);
this.txtResult.setEditable(false);
this.model = new ArgumentIRModel(DECIMAL_FORMAT, DATE_FORMAT);
}

/**
*
*/
private void closeForm() {
if (model.isDirty()) {
if (JOptionPane.showConfirmDialog(this, "Arguments have been annotated. Do you want to save the new labels?", "Confirm Dialog", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
model.saveLabelsToFile();
}
}
this.setVisible(false);
this.dispose();
}

/**
*
* @param type
Expand Down Expand Up @@ -102,13 +119,19 @@ private void initComponents() {
mItemExportText = new javax.swing.JMenuItem();
menuSeparator = new javax.swing.JPopupMenu.Separator();
mItemClose = new javax.swing.JMenuItem();
menuLabel = new javax.swing.JMenu();
mItemSaveLabels = new javax.swing.JMenuItem();

fileChooser.setDialogTitle("Export report");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Argument-enhanced Information Retrieval");
setMinimumSize(new java.awt.Dimension(800, 400));
setPreferredSize(new java.awt.Dimension(1200, 600));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});

lblQuery.setText("Query:");

Expand Down Expand Up @@ -166,6 +189,18 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

menuBar.add(menuFile);

menuLabel.setText("Label");

mItemSaveLabels.setText("Save Labels");
mItemSaveLabels.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mItemSaveLabelsActionPerformed(evt);
}
});
menuLabel.add(mItemSaveLabels);

menuBar.add(menuLabel);

setJMenuBar(menuBar);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
Expand Down Expand Up @@ -246,8 +281,7 @@ private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
*/
private void mItemCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mItemCloseActionPerformed
// TODO add your handling code here:
this.setVisible(false);
this.dispose();
closeForm();
}//GEN-LAST:event_mItemCloseActionPerformed

/**
Expand Down Expand Up @@ -289,16 +323,46 @@ private void mItemExportTextActionPerformed(java.awt.event.ActionEvent evt) {//G
private void txtResultHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_txtResultHyperlinkUpdate
// TODO add your handling code here:
if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(evt.getURL().toURI());
} catch (URISyntaxException | IOException ex) {
Logger.getLogger(ArgumentIRForm.class.getName()).log(Level.SEVERE, null, ex);
try {
String evtValue = evt.getURL().toURI().toString();

if (evtValue.startsWith(ReportFormatter.APP_URL)) {
String[] tokens = evtValue.replace(ReportFormatter.APP_URL, "").split("/");
String argumentId = tokens[0];
String action = tokens[1];
model.updateModelLabel(argumentId, action);

} else {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(new URI(evtValue));
}
}

} catch (URISyntaxException | IOException ex) {
Logger.getLogger(ArgumentIRForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_txtResultHyperlinkUpdate

/**
* Event: save labels to file.
*
* @param evt
*/
private void mItemSaveLabelsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mItemSaveLabelsActionPerformed
// TODO add your handling code here:
model.saveLabelsToFile();
}//GEN-LAST:event_mItemSaveLabelsActionPerformed

/**
*
* @param evt
*/
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
closeForm();
}//GEN-LAST:event_formWindowClosing

/**
*
* @return
Expand All @@ -324,8 +388,10 @@ private String selectExportFile(String ext) {
private javax.swing.JMenuItem mItemClose;
private javax.swing.JMenuItem mItemExportHtml;
private javax.swing.JMenuItem mItemExportText;
private javax.swing.JMenuItem mItemSaveLabels;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenu menuFile;
private javax.swing.JMenu menuLabel;
private javax.swing.JPopupMenu.Separator menuSeparator;
private javax.swing.JScrollPane scrollPane;
private javax.swing.JTextField txtQuery;
Expand Down
Loading