Revision: 17632
          http://sourceforge.net/p/gate/code/17632
Author:   markagreenwood
Date:     2014-03-11 16:18:28 +0000 (Tue, 11 Mar 2014)
Log Message:
-----------
an option to set the encoding used to read the csv file

Modified Paths:
--------------
    gate/trunk/plugins/Format_CSV/src/gate/corpora/CSVImporter.java

Modified: gate/trunk/plugins/Format_CSV/src/gate/corpora/CSVImporter.java
===================================================================
--- gate/trunk/plugins/Format_CSV/src/gate/corpora/CSVImporter.java     
2014-03-11 16:03:33 UTC (rev 17631)
+++ gate/trunk/plugins/Format_CSV/src/gate/corpora/CSVImporter.java     
2014-03-11 16:18:28 UTC (rev 17632)
@@ -77,6 +77,8 @@
   private static JTextField txtSeparator = new JTextField(",", 3);
 
   private static JTextField txtQuoteChar = new JTextField("\"", 3);
+  
+  private static JTextField txtEncoding = new JTextField("UTF-8");
 
   private static FileFilter CSV_FILE_FILTER = new ExtensionFileFilter(
       "CSV Files (*.csv)", "csv");
@@ -115,9 +117,25 @@
     constraints = new GridBagConstraints();
     constraints.gridx = GridBagConstraints.RELATIVE;
     constraints.gridy = 1;
-    constraints.gridwidth = 2;
+    constraints.gridwidth = 1;
     constraints.fill = GridBagConstraints.HORIZONTAL;
     constraints.insets = new Insets(0, 0, 15, 5);
+    dialog.add(new JLabel("Encoding:"), constraints);
+    
+    constraints = new GridBagConstraints();
+    constraints.gridx = GridBagConstraints.RELATIVE;
+    constraints.gridy = 1;
+    constraints.gridwidth = 1;
+    constraints.fill = GridBagConstraints.HORIZONTAL;
+    constraints.insets = new Insets(0, 15, 15, 10);
+    dialog.add(txtEncoding, constraints);
+    
+    constraints = new GridBagConstraints();
+    constraints.gridx = GridBagConstraints.RELATIVE;
+    constraints.gridy = 1;
+    constraints.gridwidth = 1;
+    constraints.fill = GridBagConstraints.HORIZONTAL;
+    constraints.insets = new Insets(0, 0, 15, 5);
     dialog.add(new JLabel("Column Separator:"), constraints);
 
     constraints = new GridBagConstraints();
@@ -260,7 +278,7 @@
                         // file
                         // then call the populate method passing through all 
the
                         // options from the GUI
-                        populate((Corpus)handle.getTarget(), f.toURI().toURL(),
+                        populate((Corpus)handle.getTarget(), 
f.toURI().toURL(), txtEncoding.getText(),
                             (Integer)textColModel.getValue(),
                             cboFeatures.isSelected(), separator, quote);
                       } else {
@@ -270,7 +288,7 @@
                         // the
                         // options from the GUI
                         createDoc((Corpus)handle.getTarget(),
-                            f.toURI().toURL(),
+                            f.toURI().toURL(), txtEncoding.getText(),
                             (Integer)textColModel.getValue(),
                             cboFeatures.isSelected(), separator, quote);
                       }
@@ -283,7 +301,7 @@
                       // then call the populate method passing through all the
                       // options from the GUI
                       populate((Corpus)handle.getTarget(),
-                          new URL(txtURL.getText()),
+                          new URL(txtURL.getText()), txtEncoding.getText(),
                           (Integer)textColModel.getValue(),
                           cboFeatures.isSelected(), separator, quote);
                     } else {
@@ -291,7 +309,7 @@
                       // then call the createDoc method passing through all the
                       // options from the GUI
                       createDoc((Corpus)handle.getTarget(),
-                          new URL(txtURL.getText()),
+                          new URL(txtURL.getText()), txtEncoding.getText(),
                           (Integer)textColModel.getValue(),
                           cboFeatures.isSelected(), separator, quote);
                     }
@@ -315,9 +333,9 @@
     return actions;
   }
 
-  public static void populate(Corpus corpus, URL csv, int column,
+  public static void populate(Corpus corpus, URL csv, String encoding, int 
column,
       boolean colLabels) {
-    populate(corpus, csv, column, colLabels, ',', '"');
+    populate(corpus, csv, encoding, column, colLabels, ',', '"');
   }
 
   /**
@@ -337,13 +355,13 @@
    *          the character used to quote data that includes the column
    *          separator (usually ")
    */
-  public static void populate(Corpus corpus, URL csv, int column,
+  public static void populate(Corpus corpus, URL csv, String encoding, int 
column,
       boolean colLabels, char separator, char quote) {
     CSVReader reader = null;
     try {
       // open a CSVReader over the URL
       reader =
-          new CSVReader(new InputStreamReader(csv.openStream()), separator,
+          new CSVReader(new InputStreamReader(csv.openStream(),encoding), 
separator,
               quote);
 
       // if we are adding features read the first line
@@ -406,9 +424,9 @@
     }
   }
 
-  public static void createDoc(Corpus corpus, URL csv, int column,
+  public static void createDoc(Corpus corpus, URL csv, String encoding, int 
column,
       boolean colLabels) {
-    createDoc(corpus, csv, column, colLabels, ',', '"');
+    createDoc(corpus, csv, encoding, column, colLabels, ',', '"');
   }
 
   /**
@@ -428,14 +446,14 @@
    *          the character used to quote data that includes the column
    *          separator (usually ")
    */
-  public static void createDoc(Corpus corpus, URL csv, int column,
+  public static void createDoc(Corpus corpus, URL csv, String encoding, int 
column,
       boolean colLabels, char separator, char quote) {
     CSVReader reader = null;
     Document doc = null;
     try {
       // open a CSVReader over the URL
       reader =
-          new CSVReader(new InputStreamReader(csv.openStream()), separator,
+          new CSVReader(new InputStreamReader(csv.openStream(),encoding), 
separator,
               quote);
 
       // if we are adding features read the first line

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to