use of com.google.refine.browsing.facets.Facet in project OpenRefine by OpenRefine.
the class Engine method write.
@Override
public void write(JSONWriter writer, Properties options) throws JSONException {
writer.object();
writer.key("facets");
writer.array();
for (Facet facet : _facets) {
facet.write(writer, options);
}
writer.endArray();
writer.key(MODE);
writer.value(_mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED);
writer.endObject();
}
use of com.google.refine.browsing.facets.Facet in project OpenRefine by OpenRefine.
the class Engine method initializeFromJSON.
public void initializeFromJSON(JSONObject o) throws JSONException {
if (o == null) {
return;
}
if (o.has("facets") && !o.isNull("facets")) {
JSONArray a = o.getJSONArray("facets");
int length = a.length();
for (int i = 0; i < length; i++) {
JSONObject fo = a.getJSONObject(i);
String type = fo.has("type") ? fo.getString("type") : "list";
Facet facet = null;
if ("list".equals(type)) {
facet = new ListFacet();
} else if ("range".equals(type)) {
facet = new RangeFacet();
} else if ("timerange".equals(type)) {
facet = new TimeRangeFacet();
} else if ("scatterplot".equals(type)) {
facet = new ScatterplotFacet();
} else if ("text".equals(type)) {
facet = new TextSearchFacet();
}
if (facet != null) {
facet.initializeFromJSON(_project, fo);
_facets.add(facet);
}
}
}
// for backward compatibility
if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) {
_mode = o.getBoolean(INCLUDE_DEPENDENT) ? Mode.RecordBased : Mode.RowBased;
}
if (o.has(MODE) && !o.isNull(MODE)) {
_mode = MODE_ROW_BASED.equals(o.getString(MODE)) ? Mode.RowBased : Mode.RecordBased;
}
}
use of com.google.refine.browsing.facets.Facet in project OpenRefine by OpenRefine.
the class Engine method computeFacets.
public void computeFacets() {
if (_config.getMode().equals(Mode.RowBased)) {
for (Facet facet : _facets) {
FilteredRows filteredRows = getFilteredRows(facet);
facet.computeChoices(_project, filteredRows);
}
} else if (_config.getMode().equals(Mode.RecordBased)) {
for (Facet facet : _facets) {
FilteredRecords filteredRecords = getFilteredRecords(facet);
facet.computeChoices(_project, filteredRecords);
}
} else {
throw new InternalError("Unknown mode.");
}
}
use of com.google.refine.browsing.facets.Facet in project OpenRefine by OpenRefine.
the class ListFacetTests method serializeListFacetWithError.
@Test
public void serializeListFacetWithError() throws JsonParseException, JsonMappingException, IOException {
Project project = createCSVProject("other column\n" + "foo\n" + "bar\n");
ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class);
Facet facet = facetConfig.apply(project);
TestUtils.isSerializedTo(facet, jsonFacetError);
}
use of com.google.refine.browsing.facets.Facet in project OpenRefine by OpenRefine.
the class ListFacetTests method serializeListFacet.
@Test
public void serializeListFacet() throws JsonParseException, JsonMappingException, IOException {
Project project = createCSVProject("Column A\n" + "foo\n" + "bar\n");
Engine engine = new Engine(project);
ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class);
Facet facet = facetConfig.apply(project);
facet.computeChoices(project, engine.getAllFilteredRows());
TestUtils.isSerializedTo(facet, jsonFacet);
}
Aggregations