Search in sources :

Example 1 with ColumnModel

use of com.google.refine.model.ColumnModel in project polymap4-core by Polymap4.

the class ImportCSVTest method testSSV.

@Test
public void testSSV() throws Exception {
    // ; separated file
    File wohngebiete = new File(this.getClass().getResource("/data/wohngebiete_sachsen.csv").getFile());
    File tmp = File.createTempFile("foo", ".csv");
    com.google.common.io.Files.copy(wohngebiete, tmp);
    ImportResponse<CSVFormatAndOptions> response = service.importFile(tmp, CSVFormatAndOptions.createDefault(), null);
    assertEquals(";", response.options().separator());
    // get the loaded models
    ColumnModel columns = response.job().project.columnModel;
    assertEquals(12, columns.columns.size());
    List<Row> rows = response.job().project.rows;
    assertEquals("Baugenehmigungen: Neue Wohn-u.Nichtwohngeb. einschl. Wohnh.,", rows.get(0).cells.get(0).value);
    assertEquals(471, rows.size());
    assertEquals("neue Wohngeb. mit 1 od.2 Wohnungen, Räume u.Fläche d.Wohn.,", rows.get(1).cells.get(0).value);
    CSVFormatAndOptions options = response.options();
    options.setSeparator("\\t");
    service.updateOptions(response.job(), options, null);
    columns = response.job().project.columnModel;
    assertEquals(1, columns.columns.size());
    rows = response.job().project.rows;
    assertEquals("Baugenehmigungen: Neue Wohn-u.Nichtwohngeb. einschl. Wohnh.,;;;;;;;;;;;", rows.get(0).cells.get(0).value);
    assertEquals(471, rows.size());
    Project project = service.createProject(response.job(), options, null);
    rows = project.rows;
    assertEquals("Baugenehmigungen: Neue Wohn-u.Nichtwohngeb. einschl. Wohnh.,;;;;;;;;;;;", rows.get(0).cells.get(0).value);
    assertEquals(471, rows.size());
}
Also used : Project(com.google.refine.model.Project) ColumnModel(com.google.refine.model.ColumnModel) Row(com.google.refine.model.Row) File(java.io.File) CSVFormatAndOptions(org.polymap.core.data.refine.impl.CSVFormatAndOptions) Test(org.junit.Test)

Example 2 with ColumnModel

use of com.google.refine.model.ColumnModel in project polymap4-core by Polymap4.

the class ImportCSVTest method testEncodingTSV.

@Test
public void testEncodingTSV() throws Exception {
    // ; separated file
    File wohngebiete = new File(this.getClass().getResource("/data/example-utf8.tsv").getFile());
    ImportResponse<CSVFormatAndOptions> response = service.importFile(wohngebiete, CSVFormatAndOptions.createDefault(), null);
    assertEquals("\\t", response.options().separator());
    assertEquals("UTF-8", response.options().encoding());
    // get the loaded models
    ColumnModel columns = response.job().project.columnModel;
    assertEquals(12, columns.columns.size());
    List<Row> rows = response.job().project.rows;
    assertEquals(2, rows.size());
    // assertEquals( "Jay Roach", rows.get( 1 ).cells.get( 4 ).value );
    Serializable valueBefore = rows.get(1).cells.get(3).value;
    response.options().setEncoding("ISO-8859-1");
    // Map<String,String> params = Maps.newHashMap();
    // params.put( "importingJobID", "" + response.job().id );
    // params.put( "start", "0" );
    // params.put( "limit", "5" );
    // rowsResponse = service.post( GetRowsCommand.class, params );
    // JSONObject rowsResponseBefore = new JSONObject( rowsResponse.toString() );
    service.updateOptions(response.job(), response.options(), null);
    rows = response.job().project.rows;
    assertEquals(2, rows.size());
    Serializable valueAfter = rows.get(1).cells.get(3).value;
    assertEquals(valueBefore, valueAfter);
// // Serializable valueBefore = rows.get( 1 ).cells.get( 4 ).value;
// 
// rowsResponse = service.post( GetRowsCommand.class, params );
// JSONObject rowsResponseAfter = new JSONObject( rowsResponse.toString() );
}
Also used : Serializable(java.io.Serializable) ColumnModel(com.google.refine.model.ColumnModel) Row(com.google.refine.model.Row) File(java.io.File) CSVFormatAndOptions(org.polymap.core.data.refine.impl.CSVFormatAndOptions) Test(org.junit.Test)

Example 3 with ColumnModel

use of com.google.refine.model.ColumnModel in project polymap4-core by Polymap4.

the class OperationsTest method testSSV.

@Test
public void testSSV() throws Exception {
    // ; separated file
    File wohngebiete = new File(this.getClass().getResource("/data/wohngebiete_sachsen.csv").getFile());
    File tmp = File.createTempFile("foo", ".csv");
    Files.copy(wohngebiete, tmp);
    ImportResponse<CSVFormatAndOptions> response = service.importFile(tmp, CSVFormatAndOptions.createDefault(), null);
    assertEquals(";", response.options().separator());
    assertEquals("ISO-8859-1", response.options().encoding());
    // get the loaded models
    ColumnModel columns = response.job().project.columnModel;
    assertEquals(12, columns.columns.size());
    List<Row> rows = response.job().project.rows;
    assertEquals("Baugenehmigungen: Neue Wohn-u.Nichtwohngeb. einschl. Wohnh.,", rows.get(0).cells.get(0).value);
    assertEquals(471, rows.size());
    assertEquals("neue Wohngeb. mit 1 od.2 Wohnungen, Räume u.Fläche d.Wohn.,", rows.get(1).cells.get(0).value);
    CSVFormatAndOptions options = response.options();
    options.setSeparator("\\t");
    service.updateOptions(response.job(), options, null);
// Map<String, String> params = Maps.newHashMap();
// String columnToRemove = columns.columns.get( 2 ).getName();
// params.put( "columnName", columnToRemove );
// params.put( "project", "" + response.job().project.id );
// service.post( ReorderRowsCommand.class, params );
// 
// columns = response.job().project.columnModel;
// assertEquals( 11, columns.columns.size() );
}
Also used : ColumnModel(com.google.refine.model.ColumnModel) Row(com.google.refine.model.Row) File(java.io.File) CSVFormatAndOptions(org.polymap.core.data.refine.impl.CSVFormatAndOptions) Test(org.junit.Test)

Example 4 with ColumnModel

use of com.google.refine.model.ColumnModel in project polymap4-core by Polymap4.

the class ImportCSVTest method testMoviesTSV.

@Test
public void testMoviesTSV() throws Exception {
    // ; separated file
    File wohngebiete = new File(this.getClass().getResource("/data/movies-condensed.tsv").getFile());
    ImportResponse<CSVFormatAndOptions> response = service.importStream(new FileInputStream(wohngebiete), "wohngebiete_sachsen.csv", "text/csv", CSVFormatAndOptions.createDefault(), null);
    assertEquals("\\t", response.options().separator());
    // get the loaded models
    ColumnModel columns = response.job().project.columnModel;
    assertEquals(8, columns.columns.size());
    List<Row> rows = response.job().project.rows;
    assertEquals(20, rows.size());
    assertEquals("Jay Roach", rows.get(3).cells.get(1).value);
}
Also used : ColumnModel(com.google.refine.model.ColumnModel) Row(com.google.refine.model.Row) File(java.io.File) CSVFormatAndOptions(org.polymap.core.data.refine.impl.CSVFormatAndOptions) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

ColumnModel (com.google.refine.model.ColumnModel)4 Row (com.google.refine.model.Row)4 File (java.io.File)4 Test (org.junit.Test)4 CSVFormatAndOptions (org.polymap.core.data.refine.impl.CSVFormatAndOptions)4 Project (com.google.refine.model.Project)1 FileInputStream (java.io.FileInputStream)1 Serializable (java.io.Serializable)1