Commit 6c1f3154 by Robbie Hott

Fixed Eclipse formatting errors

parent 8f62992f
...@@ -35,12 +35,12 @@ import javax.swing.filechooser.FileNameExtensionFilter; ...@@ -35,12 +35,12 @@ import javax.swing.filechooser.FileNameExtensionFilter;
* *
*/ */
public class CBWReconcileUI extends javax.swing.JFrame { public class CBWReconcileUI extends javax.swing.JFrame {
/** /**
* Serial ID * Serial ID
*/ */
private static final long serialVersionUID = -8115653654144568030L; private static final long serialVersionUID = -8115653654144568030L;
/** /**
* GUI Variables * GUI Variables
*/ */
...@@ -61,20 +61,20 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -61,20 +61,20 @@ public class CBWReconcileUI extends javax.swing.JFrame {
private JLabel toCSVFileLabel; private JLabel toCSVFileLabel;
private JLabel toCSVFileLocationLabel; private JLabel toCSVFileLocationLabel;
private JButton toCSVFileButton; private JButton toCSVFileButton;
/** /**
* Reconciliation File Variables * Reconciliation File Variables
*/ */
private String fromCSVFile; private String fromCSVFile;
private String toCSVFile; private String toCSVFile;
{ {
//Set Look & Feel //Set Look & Feel
try { try {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) { } catch(Exception e) {
//e.printStackTrace(); // Silently ignoring errors
} }
} }
...@@ -89,7 +89,7 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -89,7 +89,7 @@ public class CBWReconcileUI extends javax.swing.JFrame {
//Mac Niceness //Mac Niceness
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "CBW-SNAC Reconciler"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "CBW-SNAC Reconciler");
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
CBWReconcileUI inst = new CBWReconcileUI(); CBWReconcileUI inst = new CBWReconcileUI();
...@@ -98,7 +98,7 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -98,7 +98,7 @@ public class CBWReconcileUI extends javax.swing.JFrame {
} }
}); });
} }
/** /**
* Constructor * Constructor
* *
...@@ -108,7 +108,7 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -108,7 +108,7 @@ public class CBWReconcileUI extends javax.swing.JFrame {
super(); super();
initGUI(); initGUI();
} }
/** /**
* Initialize GUI * Initialize GUI
* *
...@@ -116,7 +116,7 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -116,7 +116,7 @@ public class CBWReconcileUI extends javax.swing.JFrame {
*/ */
private void initGUI() { private void initGUI() {
try { try {
BorderLayout thisLayout = new BorderLayout(); BorderLayout thisLayout = new BorderLayout();
getContentPane().setLayout(thisLayout); getContentPane().setLayout(thisLayout);
{ {
...@@ -139,7 +139,7 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -139,7 +139,7 @@ public class CBWReconcileUI extends javax.swing.JFrame {
bodyPanel.add(reconcilePanel); bodyPanel.add(reconcilePanel);
reconcilePanel.setSize(700, 200); reconcilePanel.setSize(700, 200);
reconcilePanel.setPreferredSize(new java.awt.Dimension(700, 200)); reconcilePanel.setPreferredSize(new java.awt.Dimension(700, 200));
// lookup buttons // lookup buttons
{ {
fromCSVFileLabel = new JLabel(); fromCSVFileLabel = new JLabel();
...@@ -159,13 +159,13 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -159,13 +159,13 @@ public class CBWReconcileUI extends javax.swing.JFrame {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
// Pop up a file chooser for the user to pick a CSV file // Pop up a file chooser for the user to pick a CSV file
JFileChooser chooser2 = new JFileChooser(); JFileChooser chooser2 = new JFileChooser();
chooser2.setDialogTitle("Choose a CSV File."); chooser2.setDialogTitle("Choose a CSV File.");
chooser2.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); chooser2.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv"));
int returnVal = chooser2.showOpenDialog(null); int returnVal = chooser2.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) { if(returnVal == JFileChooser.APPROVE_OPTION) {
fromCSVFile = chooser2.getSelectedFile().getAbsolutePath(); fromCSVFile = chooser2.getSelectedFile().getAbsolutePath();
fromCSVFileLocationLabel.setText(fromCSVFile); fromCSVFileLocationLabel.setText(fromCSVFile);
} }
} }
}); });
...@@ -194,18 +194,18 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -194,18 +194,18 @@ public class CBWReconcileUI extends javax.swing.JFrame {
// Pop up a file chooser for the user to find a directory and // Pop up a file chooser for the user to find a directory and
// enter a filename for the destination CSV. // enter a filename for the destination CSV.
JFileChooser chooser2 = new JFileChooser(); JFileChooser chooser2 = new JFileChooser();
chooser2.setDialogTitle("Choose a Destination CSV File."); chooser2.setDialogTitle("Choose a Destination CSV File.");
chooser2.setFileFilter(new FileNameExtensionFilter("CSV Files","csv")); chooser2.setFileFilter(new FileNameExtensionFilter("CSV Files","csv"));
int returnVal = chooser2.showOpenDialog(null); int returnVal = chooser2.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) { if(returnVal == JFileChooser.APPROVE_OPTION) {
toCSVFile = chooser2.getSelectedFile().getAbsolutePath(); toCSVFile = chooser2.getSelectedFile().getAbsolutePath();
toCSVFileLocationLabel.setText(toCSVFile); toCSVFileLocationLabel.setText(toCSVFile);
} }
} }
}); });
} }
{ {
jSeparator2 = new JSeparator(); jSeparator2 = new JSeparator();
reconcilePanel.add(jSeparator2); reconcilePanel.add(jSeparator2);
...@@ -230,14 +230,14 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -230,14 +230,14 @@ public class CBWReconcileUI extends javax.swing.JFrame {
@Override @Override
public void propertyChange( public void propertyChange(
PropertyChangeEvent evt) { PropertyChangeEvent evt) {
if ("progress" == evt.getPropertyName()) { if ("progress" == evt.getPropertyName()) {
int progress = (Integer) evt.getNewValue(); int progress = (Integer) evt.getNewValue();
reconcileProgressBar.setValue(progress); reconcileProgressBar.setValue(progress);
reconcileProgressLabel.setText(rw.getProgressText()); reconcileProgressLabel.setText(rw.getProgressText());
} }
} }
}); });
rw.execute(); rw.execute();
} catch (Exception e) { } catch (Exception e) {
// Silently ignoring errors // Silently ignoring errors
} }
...@@ -267,7 +267,7 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -267,7 +267,7 @@ public class CBWReconcileUI extends javax.swing.JFrame {
reconcilePanel.add(reconcileProgressLabel); reconcilePanel.add(reconcileProgressLabel);
} }
} }
this.setSize(700, 400); this.setSize(700, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
...@@ -275,8 +275,8 @@ public class CBWReconcileUI extends javax.swing.JFrame { ...@@ -275,8 +275,8 @@ public class CBWReconcileUI extends javax.swing.JFrame {
// Silently ignoring errors // Silently ignoring errors
} }
} }
} }
...@@ -37,18 +37,18 @@ import com.opencsv.CSVWriter; ...@@ -37,18 +37,18 @@ import com.opencsv.CSVWriter;
* *
*/ */
public class CBWReconcileWorker extends SwingWorker<Void, Void> { public class CBWReconcileWorker extends SwingWorker<Void, Void> {
/** /**
* Filenames to use * Filenames to use
*/ */
private String fromFile; private String fromFile;
private String toFile; private String toFile;
/** /**
* Progress of the reconciliation * Progress of the reconciliation
*/ */
double progress; double progress;
/** /**
* Where the application is currently looking * Where the application is currently looking
*/ */
...@@ -68,7 +68,7 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> { ...@@ -68,7 +68,7 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> {
progress = 0.0; progress = 0.0;
progressText = ""; progressText = "";
} }
/** /**
* Background worker * Background worker
* *
...@@ -76,16 +76,16 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> { ...@@ -76,16 +76,16 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> {
* then calls the actual reconcile method to perform the reconcilation. * then calls the actual reconcile method to perform the reconcilation.
*/ */
public Void doInBackground() { public Void doInBackground() {
try { try {
reconcile(); reconcile();
} catch (Exception e) { } catch (Exception e) {
// Silently ignoring errors // Silently ignoring errors
} }
return null; return null;
} }
/** /**
* Set the progress text * Set the progress text
* *
...@@ -94,7 +94,7 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> { ...@@ -94,7 +94,7 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> {
private void setProgressText(String text) { private void setProgressText(String text) {
progressText = text; progressText = text;
} }
/** /**
* Get progress text * Get progress text
* *
...@@ -102,101 +102,101 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> { ...@@ -102,101 +102,101 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> {
* *
* @return The progress text * @return The progress text
*/ */
public String getProgressText() { public String getProgressText() {
return progressText; return progressText;
} }
/** /**
* Main Reconcile Method * Main Reconcile Method
* *
* This method performs the heart of the client-side reconciliation process. * This method performs the heart of the client-side reconciliation process.
* *
* @throws Exception * @throws Exception
*/ */
private void reconcile() throws Exception { private void reconcile() throws Exception {
// Use a pre-packaged reader to read the given CSV file // Use a pre-packaged reader to read the given CSV file
CSVReader reader = new CSVReader(new FileReader(fromFile)); CSVReader reader = new CSVReader(new FileReader(fromFile));
List<String[]> toReconcile = reader.readAll(); List<String[]> toReconcile = reader.readAll();
// Number of lines in the CSV file (minus the header) // Number of lines in the CSV file (minus the header)
int reconcileCount = toReconcile.size() - 1; int reconcileCount = toReconcile.size() - 1;
// Use a pre-packaged writer to write out the CSV file // Use a pre-packaged writer to write out the CSV file
CSVWriter writer = new CSVWriter(new FileWriter(toFile)); CSVWriter writer = new CSVWriter(new FileWriter(toFile));
// Write out header of the CSV // Write out header of the CSV
String[] headers = { String[] headers = {
"CBW Name", "CBW Name",
"CBW ID", "CBW ID",
"Snac Name", "Snac Name",
"Snac ARK", "Snac ARK",
"Overall Reconciliation Score", "Overall Reconciliation Score",
"Elastic Full Name Score", "Elastic Full Name Score",
"Elastic Name-Only Score", "Elastic Name-Only Score",
"Elastic75 Score", "Elastic75 Score",
"Original Length Score", "Original Length Score",
"Original Length Difference Score", "Original Length Difference Score",
"Entity Type Filter Score", "Entity Type Filter Score",
"SNAC Degree Score" "SNAC Degree Score"
}; };
writer.writeNext(headers); writer.writeNext(headers);
// Step through the input data lines // Step through the input data lines
for (int i = 1; i < toReconcile.size(); i++) { for (int i = 1; i < toReconcile.size(); i++) {
// Calculate a "percent done" maxing out at 95% // Calculate a "percent done" maxing out at 95%
int percentage = (i * 95) / reconcileCount; int percentage = (i * 95) / reconcileCount;
// Pull the current line of the CSV as array // Pull the current line of the CSV as array
String[] data = toReconcile.get(i); String[] data = toReconcile.get(i);
// grab the name components from the CSV file and create a snac-like name heading // grab the name components from the CSV file and create a snac-like name heading
String nameOnly = data[4].trim() + ", " + data[2].trim() + " " + data[3].trim(); String nameOnly = data[4].trim() + ", " + data[2].trim() + " " + data[3].trim();
nameOnly = nameOnly.trim(); nameOnly = nameOnly.trim();
if (nameOnly.endsWith(",")) { if (nameOnly.endsWith(",")) {
nameOnly = nameOnly.substring(0, nameOnly.length()-1); nameOnly = nameOnly.substring(0, nameOnly.length()-1);
} }
// Create the given name // Create the given name
String name = nameOnly; String name = nameOnly;
// If the input line has a 12th column (dates), then use a regex to grab 4-digit years // If the input line has a 12th column (dates), then use a regex to grab 4-digit years
// and add them to the name // and add them to the name
if (data.length >= 13) { if (data.length >= 13) {
String pattern = "[0-9][0-9][0-9][0-9]"; String pattern = "[0-9][0-9][0-9][0-9]";
Pattern r = Pattern.compile(pattern); Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(data[12]); Matcher m = r.matcher(data[12]);
String date = ""; String date = "";
while (m.find()) { while (m.find()) {
date += data[12].substring(m.start(), m.end()) + "-"; date += data[12].substring(m.start(), m.end()) + "-";
} }
if (date.length() > 0) { if (date.length() > 0) {
date = date.substring(0, date.length()-1); date = date.substring(0, date.length()-1);
name = nameOnly + ", " + date; name = nameOnly + ", " + date;
} }
} }
// Update the progress for this run of the reconciliation // Update the progress for this run of the reconciliation
setProgress(percentage); setProgress(percentage);
setProgressText(name); setProgressText(name);
// Create the JSON query string for the SNAC RestAPI // Create the JSON query string for the SNAC RestAPI
String query = "{"+ String query = "{"+
"\"command\" : \"reconcile\"," + "\"command\" : \"reconcile\"," +
"\"constellation\" : { " + "\"constellation\" : { " +
"\"dataType\" : \"Constellation\"," + "\"dataType\" : \"Constellation\"," +
"\"entityType\" : {" + "\"entityType\" : {" +
"\"term\" : \"person\"" + "\"term\" : \"person\"" +
"}," + "}," +
"\"nameEntries\" : [" + "\"nameEntries\" : [" +
"{" + "{" +
"\"dataType\" : \"NameEntry\"," + "\"dataType\" : \"NameEntry\"," +
"\"original\" : \""+ name +"\"," + "\"original\" : \""+ name +"\"," +
"\"preferenceScore\" : 1" + "\"preferenceScore\" : 1" +
"}" + "}" +
"]" + "]" +
"}" + "}" +
"}"; "}";
// Perform connection to SNAC // Perform connection to SNAC
HttpURLConnection httpcon = (HttpURLConnection) ((new URL("http://snac-web.iath.virginia.edu:81/").openConnection())); HttpURLConnection httpcon = (HttpURLConnection) ((new URL("http://snac-web.iath.virginia.edu:81/").openConnection()));
...@@ -219,47 +219,47 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> { ...@@ -219,47 +219,47 @@ public class CBWReconcileWorker extends SwingWorker<Void, Void> {
// Close the connection // Close the connection
httpcon.disconnect(); httpcon.disconnect();
// If reconciliation succeeded, then process the results // If reconciliation succeeded, then process the results
if (resultObj.has("reconciliation")) { if (resultObj.has("reconciliation")) {
for (int j = 0; j < resultObj.getJSONArray("reconciliation").length(); j++) { for (int j = 0; j < resultObj.getJSONArray("reconciliation").length(); j++) {
JSONObject result = (JSONObject) resultObj.getJSONArray("reconciliation").get(j); JSONObject result = (JSONObject) resultObj.getJSONArray("reconciliation").get(j);
// only grab the first 6 results // only grab the first 6 results
if (j > 5) break; if (j > 5) break;
if (!result.has("vector")) if (!result.has("vector"))
continue; continue;
JSONObject vector = result.getJSONObject("vector"); JSONObject vector = result.getJSONObject("vector");
// Create the result data to add to the CSV output file // Create the result data to add to the CSV output file
String[] output = { String[] output = {
name, name,
toReconcile.get(i)[0], toReconcile.get(i)[0],
((JSONObject) result.getJSONObject("identity").getJSONArray("nameEntries").get(0)).getString("original"), ((JSONObject) result.getJSONObject("identity").getJSONArray("nameEntries").get(0)).getString("original"),
result.getJSONObject("identity").getString("ark"), result.getJSONObject("identity").getString("ark"),
String.format("%.2f", result.getDouble("strength")), String.format("%.2f", result.getDouble("strength")),
vector.has("ElasticOriginalNameEntry") ? JSONObject.doubleToString(vector.getDouble("ElasticOriginalNameEntry")) : "0", vector.has("ElasticOriginalNameEntry") ? JSONObject.doubleToString(vector.getDouble("ElasticOriginalNameEntry")) : "0",
vector.has("ElasticNameOnly") ? JSONObject.doubleToString(vector.getDouble("ElasticNameOnly")) : "0", vector.has("ElasticNameOnly") ? JSONObject.doubleToString(vector.getDouble("ElasticNameOnly")) : "0",
vector.has("ElasticSeventyFive") ? JSONObject.doubleToString(vector.getDouble("ElasticSeventyFive")) : "0", vector.has("ElasticSeventyFive") ? JSONObject.doubleToString(vector.getDouble("ElasticSeventyFive")) : "0",
vector.has("OriginalLength") ? JSONObject.doubleToString(vector.getDouble("OriginalLength")) : "0", vector.has("OriginalLength") ? JSONObject.doubleToString(vector.getDouble("OriginalLength")) : "0",
vector.has("MultiStage:ElasticNameOnly:OriginalLengthDifference") ? JSONObject.doubleToString(vector.getDouble("MultiStage:ElasticNameOnly:OriginalLengthDifference")) : "0", vector.has("MultiStage:ElasticNameOnly:OriginalLengthDifference") ? JSONObject.doubleToString(vector.getDouble("MultiStage:ElasticNameOnly:OriginalLengthDifference")) : "0",
vector.has("MultiStage:ElasticNameOnly:EntityTypeFilter") ? JSONObject.doubleToString(vector.getDouble("MultiStage:ElasticNameOnly:EntityTypeFilter")) : "0", vector.has("MultiStage:ElasticNameOnly:EntityTypeFilter") ? JSONObject.doubleToString(vector.getDouble("MultiStage:ElasticNameOnly:EntityTypeFilter")) : "0",
vector.has("MultiStage:ElasticNameOnly:SNACDegree") ? JSONObject.doubleToString(vector.getDouble("MultiStage:ElasticNameOnly:SNACDegree")) : "0" vector.has("MultiStage:ElasticNameOnly:SNACDegree") ? JSONObject.doubleToString(vector.getDouble("MultiStage:ElasticNameOnly:SNACDegree")) : "0"
}; };
// Write the line to the CSV file // Write the line to the CSV file
writer.writeNext(output); writer.writeNext(output);
} }
} }
} }
// Close the CSV Writer // Close the CSV Writer
writer.close(); writer.close();
// Close the CSV Reader // Close the CSV Reader
reader.close(); reader.close();
// Update the progress to 100% // Update the progress to 100%
progressText = "DONE!"; progressText = "DONE!";
setProgress(100); setProgress(100);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment