if "collationUCAData" in self.filters_json_data:
self.coll_han_type = self.filters_json_data["collationUCAData"]
+ # Either "additive" or "subtractive"
+ self.strategy = "subtractive"
+ if "strategy" in self.filters_json_data:
+ self.strategy = self.filters_json_data["strategy"]
+
def _parse_filter_file(self, f):
# Use the Hjson parser if it is available; otherwise, use vanilla JSON.
try:
all_categories = list(sorted(all_categories))
json_data = config.filters_json_data
filters = {}
+ default_filter_json = "exclude" if config.strategy == "additive" else "include"
for category in all_categories:
+ filter_json = default_filter_json
+ # Figure out the correct filter to create
if "featureFilters" in json_data and category in json_data["featureFilters"]:
- filters[category] = Filter.create_from_json(
- json_data["featureFilters"][category]
- )
- elif "localeFilter" in json_data and category[-5:] == "_tree":
- filters[category] = Filter.create_from_json(
- json_data["localeFilter"]
- )
+ filter_json = json_data["featureFilters"][category]
+ if filter_json == "include" and "localeFilter" in json_data and category.endswith("_tree"):
+ filter_json = json_data["localeFilter"]
+ # Resolve the filter JSON into a filter object
+ if filter_json == "exclude":
+ filters[category] = ExclusionFilter()
+ elif filter_json == "include":
+ pass # no-op
+ else:
+ filters[category] = Filter.create_from_json(filter_json)
if "featureFilters" in json_data:
for category in json_data["featureFilters"]:
if category not in all_categories:
class ResourceFilterInfo(object):
- def __init__(self, category):
+ def __init__(self, category, strategy):
self.category = category
+ self.strategy = strategy
self.filter_tmp_dir = "filters/%s" % category
self.input_files = None
self.filter_files = None
for file in files
)
]
- self.rules_by_file = [[] for _ in range(len(files))]
+ if self.strategy == "additive":
+ self.rules_by_file = [["-/*"] for _ in range(len(files))]
+ else:
+ self.rules_by_file = [["+/*"] for _ in range(len(files))]
def add_rules(self, file_filter, rules):
for file, rule_list in zip(self.input_files, self.rules_by_file):
for category in entry["categories"]:
# not defaultdict because we need to pass arguments to the constructor
if category not in collected:
- filter_info = ResourceFilterInfo(category)
+ filter_info = ResourceFilterInfo(category, config.strategy)
filter_info.apply_to_requests(all_requests)
collected[category] = filter_info
else:
"description": "JSON Schema for an ICU data filter file",
"type": "object",
"properties": {
+ "strategy": {
+ "type": "string",
+ "enum": ["additive", "subtractive"]
+ },
"localeFilter": { "$ref": "#/definitions/filter" },
"featureFilters": {
"type": "object",
- "additionalProperties": { "$ref": "#/definitions/filter" }
+ "additionalProperties": {
+ "oneOf": [
+ { "$ref": "#/definitions/filter" },
+ {
+ "type": "string",
+ "enum": ["include", "exclude"]
+ }
+ ]
+ }
},
"resourceFilters": {
"type": "array",