<commit_before>
from rest_framework.viewsets import ReadOnlyModelViewSet
from amcat.models import RuleSet, Rule
from api.rest.viewset import AmCATViewSetMixin
from api.rest.serializer import AmCATModelSerializer

from api.rest.viewsets.articleset import ArticleSetViewSetMixin
from api.rest.viewsets.article import ArticleViewSetMixin
from api.rest.viewsets.project import ProjectViewSetMixin
from api.rest.mixins import DatatablesMixin
from amcat.tools.amcatxtas import ANALYSES, get_result

class RulesetViewSetMixin(AmCATViewSetMixin):
    model_key = "ruleset"
    model = RuleSet

class RulesetViewSet(RulesetViewSetMixin, ReadOnlyModelViewSet):
    model_serializer_class =  AmCATModelSerializer
    model = RuleSet

    def filter_queryset(self, queryset):
        return queryset

class RuleViewSetMixin(AmCATViewSetMixin):
    model_key = "rule"
    model = Rule

class RuleViewSet(RulesetViewSetMixin, RuleViewSetMixin, ReadOnlyModelViewSet):
    model_serializer_class =  AmCATModelSerializer
    model = Rule

    def filter_queryset(self, queryset):
        return queryset.filter(ruleset_id=self.kwargs['ruleset'])


from rest_framework.serializers import Serializer
from api.rest.serializer import AmCATModelSerializer
from syntaxrules import SyntaxTree

class RulesetSerializer(AmCATModelSerializer):

    def to_native(self, ruleset):
        if self.many is False: # explicit compare because we don't want None
            # Get parse
            module = ruleset.preprocessing
            saf = get_result(self.context['article'], module)
            t = SyntaxTree(saf)

            if self.context['preprocess']:
                r = RuleSet.objects.get(pk=int(self.context['preprocess']))
                t.apply_ruleset(r.get_ruleset())<commit_msg>lazy import<commit_after>
from rest_framework.viewsets import ReadOnlyModelViewSet
from amcat.models import RuleSet, Rule
from api.rest.viewset import AmCATViewSetMixin
from api.rest.serializer import AmCATModelSerializer

from api.rest.viewsets.articleset import ArticleSetViewSetMixin
from api.rest.viewsets.article import ArticleViewSetMixin
from api.rest.viewsets.project import ProjectViewSetMixin
from api.rest.mixins import DatatablesMixin
from amcat.tools.amcatxtas import ANALYSES, get_result

class RulesetViewSetMixin(AmCATViewSetMixin):
    model_key = "ruleset"
    model = RuleSet

class RulesetViewSet(RulesetViewSetMixin, ReadOnlyModelViewSet):
    model_serializer_class =  AmCATModelSerializer
    model = RuleSet

    def filter_queryset(self, queryset):
        return queryset

class RuleViewSetMixin(AmCATViewSetMixin):
    model_key = "rule"
    model = Rule

class RuleViewSet(RulesetViewSetMixin, RuleViewSetMixin, ReadOnlyModelViewSet):
    model_serializer_class =  AmCATModelSerializer
    model = Rule

    def filter_queryset(self, queryset):
        return queryset.filter(ruleset_id=self.kwargs['ruleset'])


from rest_framework.serializers import Serializer
from api.rest.serializer import AmCATModelSerializer

class RulesetSerializer(AmCATModelSerializer):

    def to_native(self, ruleset):
        from syntaxrules import SyntaxTree
        if self.many is False: # explicit compare because we don't want None
            # Get parse
            module = ruleset.preprocessing
            saf = get_result(self.context['article'], module)
            t = SyntaxTree(saf)

            if self.context['preprocess']:
                r = RuleSet.objects.get(pk=int(self.context['preprocess']))
                t.apply_ruleset(r.get_ruleset())
{'fraction_non_alphanumeric': 0.06880992667794698, 'fraction_numerical': 0.0, 'mean_word_length': 4.170553935860059, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7288860', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1027, 'n_words': 236}