use of com.google.refine.browsing.DecoratedValue in project OpenRefine by OpenRefine.
the class ListFacet method initializeFromJSON.
@Override
public void initializeFromJSON(Project project, JSONObject o) throws JSONException {
_name = o.getString("name");
_expression = o.getString("expression");
_columnName = o.getString("columnName");
_invert = o.has("invert") && o.getBoolean("invert");
if (_columnName.length() > 0) {
Column column = project.columnModel.getColumnByName(_columnName);
if (column != null) {
_cellIndex = column.getCellIndex();
} else {
_errorMessage = "No column named " + _columnName;
}
} else {
_cellIndex = -1;
}
try {
_eval = MetaParser.parse(_expression);
} catch (ParsingException e) {
_errorMessage = e.getMessage();
}
_selection.clear();
JSONArray a = o.getJSONArray("selection");
int length = a.length();
for (int i = 0; i < length; i++) {
JSONObject oc = a.getJSONObject(i);
JSONObject ocv = oc.getJSONObject("v");
DecoratedValue decoratedValue = new DecoratedValue(ocv.get("v"), ocv.getString("l"));
NominalFacetChoice nominalFacetChoice = new NominalFacetChoice(decoratedValue);
nominalFacetChoice.selected = true;
_selection.add(nominalFacetChoice);
}
_omitBlank = JSONUtilities.getBoolean(o, "omitBlank", false);
_omitError = JSONUtilities.getBoolean(o, "omitError", false);
_selectBlank = JSONUtilities.getBoolean(o, "selectBlank", false);
_selectError = JSONUtilities.getBoolean(o, "selectError", false);
}
use of com.google.refine.browsing.DecoratedValue in project OpenRefine by OpenRefine.
the class ListFacet method postProcessGrouper.
protected void postProcessGrouper(ExpressionNominalValueGrouper grouper) {
_choices.clear();
_choices.addAll(grouper.choices.values());
for (DecoratedValue decoratedValue : _config.selection) {
String valueString = decoratedValue.value.toString();
if (grouper.choices.containsKey(valueString)) {
grouper.choices.get(valueString).selected = true;
} else {
/*
* A selected choice can have zero count if it is selected together
* with other choices, and some other facets' constraints eliminate
* all rows projected to this choice altogether. For example, if you
* select both "car" and "bicycle" in the "type of vehicle" facet, and
* then constrain the "wheels" facet to more than 2, then the "bicycle"
* choice now has zero count even if it's still selected. The grouper
* won't be able to detect the "bicycle" choice, so we need to inject
* that choice into the choice list ourselves.
*/
NominalFacetChoice choice = new NominalFacetChoice(decoratedValue);
choice.count = 0;
choice.selected = true;
_choices.add(choice);
}
}
_blankCount = grouper.blankCount;
_errorCount = grouper.errorCount;
}
use of com.google.refine.browsing.DecoratedValue in project OpenRefine by OpenRefine.
the class DecoratedValueTests method serializeDecoratedValue.
@Test
public void serializeDecoratedValue() {
OffsetDateTime date = OffsetDateTime.parse("2017-03-04T12:56:32Z");
DecoratedValue dv = new DecoratedValue(date, "[date 2017-03-04T12:56:32Z]");
TestUtils.isSerializedTo(dv, "{\"v\":\"2017-03-04T12:56:32Z\",\"l\":\"[date 2017-03-04T12:56:32Z]\"}");
}
use of com.google.refine.browsing.DecoratedValue in project OpenRefine by OpenRefine.
the class NominalFacetChoiceTests method serializeNominalFacetChoice.
@Test
public void serializeNominalFacetChoice() {
DecoratedValue value = new DecoratedValue("some string", "some string");
NominalFacetChoice choice = new NominalFacetChoice(value);
choice.count = 3;
choice.selected = true;
TestUtils.isSerializedTo(choice, "{" + "\"v\":" + " {\"v\":\"some string\"," + " \"l\":\"some string\"}," + "\"c\":3," + "\"s\":true}");
}
Aggregations