<commit_before>###########################################################################
#          (C) Vrije Universiteit, Amsterdam (the Netherlands)            #
#                                                                         #
# This file is part of AmCAT - The Amsterdam Content Analysis Toolkit     #
#                                                                         #
# AmCAT is free software: you can redistribute it and/or modify it under  #
# the terms of the GNU Affero General Public License as published by the  #
# Free Software Foundation, either version 3 of the License, or (at your  #
# option) any later version.                                              #
#                                                                         #
# AmCAT is distributed in the hope that it will be useful, but WITHOUT    #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public     #
# License for more details.                                               #
#                                                                         #
# You should have received a copy of the GNU Affero General Public        #
# License along with AmCAT.  If not, see <http://www.gnu.org/licenses/>.  #
###########################################################################


from webscript import WebScript
from django import forms
from amcat.scripts.processors.save_set import SaveAsSetScript, SaveAsSetForm
from amcat.tools import keywordsearch

import logging
import json

log = logging.getLogger(__name__)

class SaveAsSetWebScriptForm(SaveAsSetForm):
    output = forms.CharField(widget=forms.HiddenInput(), initial='json-html')
    length = forms.IntegerField(widget=forms.HiddenInput(), max_value=99999999, initial=99999999)
    start = forms.IntegerField(widget=forms.HiddenInput(), initial=0)

    
class SaveAsSet(WebScript):
    name = "Save as Set"
    form_template = None#"api/webscripts/save_set_form.html"
    form = SaveAsSetWebScriptForm
    displayLocation = ('ShowSummary', 'ShowArticleList')
    output_template = "api/webscripts/save_set.html" 
    
    
    def run(self):
        article_ids = list(keywordsearch.get_ids(self.data))
        result = SaveAsSetScript(self.data).run(article_ids)
        result.provenance = json.dumps(dict(self.data))
        result.save()

        return self.outputResponse(result, object)
        <commit_msg>SaveAsSet now uses SelectionForm to validate/clean data.<commit_after>###########################################################################
#          (C) Vrije Universiteit, Amsterdam (the Netherlands)            #
#                                                                         #
# This file is part of AmCAT - The Amsterdam Content Analysis Toolkit     #
#                                                                         #
# AmCAT is free software: you can redistribute it and/or modify it under  #
# the terms of the GNU Affero General Public License as published by the  #
# Free Software Foundation, either version 3 of the License, or (at your  #
# option) any later version.                                              #
#                                                                         #
# AmCAT is distributed in the hope that it will be useful, but WITHOUT    #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public     #
# License for more details.                                               #
#                                                                         #
# You should have received a copy of the GNU Affero General Public        #
# License along with AmCAT.  If not, see <http://www.gnu.org/licenses/>.  #
###########################################################################
from amcat.scripts.forms import SelectionForm

from webscript import WebScript
from django import forms
from amcat.scripts.processors.save_set import SaveAsSetScript, SaveAsSetForm
from amcat.tools import keywordsearch

import logging
import json

log = logging.getLogger(__name__)

class SaveAsSetWebScriptForm(SaveAsSetForm):
    output = forms.CharField(widget=forms.HiddenInput(), initial='json-html')
    length = forms.IntegerField(widget=forms.HiddenInput(), max_value=99999999, initial=99999999)
    start = forms.IntegerField(widget=forms.HiddenInput(), initial=0)

    
class SaveAsSet(WebScript):
    name = "Save as Set"
    form_template = None#"api/webscripts/save_set_form.html"
    form = SaveAsSetWebScriptForm
    displayLocation = ('ShowSummary', 'ShowArticleList')
    output_template = "api/webscripts/save_set.html" 
    
    
    def run(self):
        sf = SelectionForm(self.project, self.data)
        sf.full_clean()

        article_ids = list(keywordsearch.get_ids(sf.cleaned_data))
        result = SaveAsSetScript(self.data).run(article_ids)
        result.provenance = json.dumps(dict(self.data))
        result.save()

        return self.outputResponse(result, object)
        
{'fraction_non_alphanumeric': 0.12775502243027112, 'fraction_numerical': 0.007021650087770626, 'mean_word_length': 2.144083384426732, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6480461', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1154, 'n_words': 372}