Search in sources :

Example 1 with Facet

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();
}
Also used : Facet(com.google.refine.browsing.facets.Facet) ScatterplotFacet(com.google.refine.browsing.facets.ScatterplotFacet) ListFacet(com.google.refine.browsing.facets.ListFacet) TimeRangeFacet(com.google.refine.browsing.facets.TimeRangeFacet) TextSearchFacet(com.google.refine.browsing.facets.TextSearchFacet) RangeFacet(com.google.refine.browsing.facets.RangeFacet)

Example 2 with Facet

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;
    }
}
Also used : ScatterplotFacet(com.google.refine.browsing.facets.ScatterplotFacet) TimeRangeFacet(com.google.refine.browsing.facets.TimeRangeFacet) RangeFacet(com.google.refine.browsing.facets.RangeFacet) JSONObject(org.json.JSONObject) TextSearchFacet(com.google.refine.browsing.facets.TextSearchFacet) JSONArray(org.json.JSONArray) ListFacet(com.google.refine.browsing.facets.ListFacet) TimeRangeFacet(com.google.refine.browsing.facets.TimeRangeFacet) Facet(com.google.refine.browsing.facets.Facet) ScatterplotFacet(com.google.refine.browsing.facets.ScatterplotFacet) ListFacet(com.google.refine.browsing.facets.ListFacet) TimeRangeFacet(com.google.refine.browsing.facets.TimeRangeFacet) TextSearchFacet(com.google.refine.browsing.facets.TextSearchFacet) RangeFacet(com.google.refine.browsing.facets.RangeFacet)

Example 3 with Facet

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.");
    }
}
Also used : ConjunctiveFilteredRecords(com.google.refine.browsing.util.ConjunctiveFilteredRecords) ConjunctiveFilteredRows(com.google.refine.browsing.util.ConjunctiveFilteredRows) FilteredRecordsAsFilteredRows(com.google.refine.browsing.util.FilteredRecordsAsFilteredRows) Facet(com.google.refine.browsing.facets.Facet)

Example 4 with Facet

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);
}
Also used : Project(com.google.refine.model.Project) ListFacetConfig(com.google.refine.browsing.facets.ListFacet.ListFacetConfig) Facet(com.google.refine.browsing.facets.Facet) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test)

Example 5 with Facet

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);
}
Also used : Project(com.google.refine.model.Project) ListFacetConfig(com.google.refine.browsing.facets.ListFacet.ListFacetConfig) Engine(com.google.refine.browsing.Engine) Facet(com.google.refine.browsing.facets.Facet) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test)

Aggregations

Facet (com.google.refine.browsing.facets.Facet)6 RefineTest (com.google.refine.RefineTest)3 ListFacetConfig (com.google.refine.browsing.facets.ListFacet.ListFacetConfig)3 Project (com.google.refine.model.Project)3 Test (org.testng.annotations.Test)3 Engine (com.google.refine.browsing.Engine)2 ListFacet (com.google.refine.browsing.facets.ListFacet)2 RangeFacet (com.google.refine.browsing.facets.RangeFacet)2 ScatterplotFacet (com.google.refine.browsing.facets.ScatterplotFacet)2 TextSearchFacet (com.google.refine.browsing.facets.TextSearchFacet)2 TimeRangeFacet (com.google.refine.browsing.facets.TimeRangeFacet)2 ConjunctiveFilteredRecords (com.google.refine.browsing.util.ConjunctiveFilteredRecords)1 ConjunctiveFilteredRows (com.google.refine.browsing.util.ConjunctiveFilteredRows)1 FilteredRecordsAsFilteredRows (com.google.refine.browsing.util.FilteredRecordsAsFilteredRows)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1