use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class RowTests method SetUp.
@BeforeMethod
public void SetUp() {
writer = new StringWriter();
project = new Project();
options = mock(Properties.class);
}
use of com.google.refine.model.Project 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());
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class Cross method call.
@Override
public Object call(Properties bindings, Object[] args) {
if (1 <= args.length && args.length <= 3) {
// 1st argument can take either value or cell(for backward compatibility)
Object v = args[0];
// if 2nd argument is omitted or set to "", use the current project name
Object targetProjectName = "";
boolean isCurrentProject = false;
if (args.length < 2 || args[1].equals("")) {
isCurrentProject = true;
} else {
targetProjectName = args[1];
}
// if 3rd argument is omitted or set to "", use the index column
Object targetColumnName = args.length < 3 || args[2].equals("") ? INDEX_COLUMN_NAME : args[2];
long targetProjectID;
ProjectLookup lookup;
if (v != null && targetProjectName instanceof String && targetColumnName instanceof String) {
try {
targetProjectID = isCurrentProject ? ((Project) bindings.get("project")).id : ProjectManager.singleton.getProjectID((String) targetProjectName);
} catch (GetProjectIDException e) {
return new EvalError(e.getMessage());
}
try {
lookup = ProjectManager.singleton.getLookupCacheManager().getLookup(targetProjectID, (String) targetColumnName);
} catch (LookupException e) {
return new EvalError(e.getMessage());
}
if (v instanceof WrappedCell) {
return lookup.getRows(((WrappedCell) v).cell.value);
} else {
return lookup.getRows(v);
}
}
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a cell or value, a project name to look up (optional), and a column name in that project (optional)");
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class Reinterpret method call.
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length == 2 || args.length == 3) {
Object o1 = args[0];
Object o2 = args[1];
if (o1 != null && o2 != null && o2 instanceof String) {
String str = (o1 instanceof String) ? (String) o1 : o1.toString();
String decoder;
String encoder;
encoder = (String) o2;
if (args.length == 2) {
Project project = (Project) bindings.get("project");
ProjectMetadata metadata = ProjectManager.singleton.getProjectMetadata(project.id);
// can return "" for broken projects
decoder = metadata.getEncoding();
} else {
decoder = (String) args[2];
}
return reinterpret(str, decoder, encoder);
}
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects String to reinterpret with a given target encoding and optional source encoding");
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class FacetCount method call.
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length == 3 && args[1] instanceof String && args[2] instanceof String) {
// choice value to look up
Object choiceValue = args[0];
String facetExpression = (String) args[1];
String columnName = (String) args[2];
Project project = (Project) bindings.get("project");
Column column = project.columnModel.getColumnByName(columnName);
if (column == null) {
return new EvalError("No such column named " + columnName);
}
String key = "nominal-bin:" + facetExpression;
ExpressionNominalValueGrouper grouper = (ExpressionNominalValueGrouper) column.getPrecompute(key);
if (grouper == null) {
try {
Evaluable eval = MetaParser.parse(facetExpression);
Engine engine = new Engine(project);
grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex());
engine.getAllRows().accept(project, grouper);
column.setPrecompute(key, grouper);
} catch (ParsingException e) {
return new EvalError("Error parsing facet expression " + facetExpression);
}
}
return grouper.getChoiceValueCountMultiple(choiceValue);
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a choice value, an expression as a string, and a column name");
}
Aggregations