<commit_before><commit_msg>[input] GeoJSON line/FeatureCollection parsing<commit_after>import ujson as json


class GeoJSONParser(object):
    def __init__(self, filename):
        self.i = 0
        self.data = json.load(open(filename))
        self.features = self.data.get('features', [])
        self.num_features = len(self.features)

    def __iter__(self):
        self.i = 0
        return self

    def next_feature(self):
        if self.i < self.num_features:
            feature = self.data['features'][self.i]
            self.i += 1
            return feature
        else:
            raise StopIteration

    def next(self):
        return self.next_feature()


class GeoJSONLineParser(GeoJSONParser):
    def __init__(self, filename):
        self.f = open(filename)

    def next_feature(self):
        return json.loads(self.f.next().rstrip())
{'fraction_non_alphanumeric': 0.11136890951276102, 'fraction_numerical': 0.0034802784222737818, 'mean_word_length': 2.3976377952755907, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4579705', 'n_tokens_mistral': 263, 'n_tokens_neox': 250, 'n_words': 55}