RdfTripleImporter correctly adds empty cells to existing rows when a column is added.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@815 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
311cc14dcd
commit
043f46c562
@ -66,7 +66,6 @@ public class RdfTripleImporter implements Importer{
|
||||
|
||||
ClosableIterable<Triple> triples = graph.find(ANY_SUBJECT_NODE, ANY_PREDICATE_NODE, ANY_OBJECT_NODE);
|
||||
try {
|
||||
int numberOfColumns = 1;
|
||||
for (Triple triple : triples) {
|
||||
|
||||
//System.out.println("Triple : " + triple);
|
||||
@ -81,11 +80,7 @@ public class RdfTripleImporter implements Importer{
|
||||
|
||||
//creates new column for every predicate
|
||||
if(project.columnModel.getColumnByName(predicate) == null){
|
||||
//System.out.println("adding new column");
|
||||
project.columnModel.columns.add(numberOfColumns, new Column(numberOfColumns, predicate));
|
||||
project.columnModel.update();
|
||||
numberOfColumns++;
|
||||
//System.out.println("New total number of columns : " + numberOfColumns);
|
||||
AddNewColumn(project, predicate);
|
||||
}
|
||||
|
||||
//FIXME - this is sparse (one row per triple), need to reconcile on subjects.
|
||||
@ -96,6 +91,21 @@ public class RdfTripleImporter implements Importer{
|
||||
triples.iterator().close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void AddNewColumn(Project project, String predicate){
|
||||
//System.out.println("adding new column");
|
||||
int numberOfColumns = project.columnModel.columns.size();
|
||||
|
||||
project.columnModel.columns.add(numberOfColumns, new Column(numberOfColumns, predicate));
|
||||
project.columnModel.update();
|
||||
//update existing rows with new column
|
||||
for(Row r : project.rows){
|
||||
r.cells.add(numberOfColumns, null);
|
||||
}
|
||||
//numberOfColumns = project.columnModel.columns.size();
|
||||
//System.out.println("New total number of columns : " + numberOfColumns);
|
||||
|
||||
}
|
||||
|
||||
protected void AddNewRow(Project project, String subject, String predicate, String object){
|
||||
int numberOfColumns = project.columnModel.columns.size();
|
||||
|
@ -92,10 +92,10 @@ public class RdfTripleImporterTests {
|
||||
Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/music.artist.album");
|
||||
Assert.assertEquals(project.columnModel.columns.get(2).getName(), "http://rdf.freebase.com/ns/music.artist.genre");
|
||||
Assert.assertEquals(project.rows.size(), 3);
|
||||
Assert.assertEquals(project.rows.get(0).cells.size(), 2);//FIXME should the number of cells == 3? should be updated if a column is added after the row is created
|
||||
Assert.assertEquals(project.rows.get(0).cells.size(), 3);
|
||||
Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan");
|
||||
Assert.assertEquals(project.rows.get(0).cells.get(1).value, "http://rdf.freebase.com/ns/en.blood_on_the_tracks");
|
||||
Assert.assertEquals(project.rows.get(1).cells.size(), 2);//FIXME should the number of cells == 3? should be updated if a column is added after the row is created
|
||||
Assert.assertEquals(project.rows.get(1).cells.size(), 3);
|
||||
Assert.assertEquals(project.rows.get(1).cells.get(1).value, "http://rdf.freebase.com/ns/en.bringing_it_all_back_home"); //NB triples aren't created in order they were input
|
||||
Assert.assertEquals(project.rows.get(2).cells.size(), 3);
|
||||
Assert.assertEquals(project.rows.get(2).cells.get(2).value, "http://rdf.freebase.com/ns/en.folk_rock"); //NB triples aren't created in order they were input
|
||||
|
Loading…
Reference in New Issue
Block a user