Does anyone know where in the matrix code there is a function for sorting and formatting the choices file? The website does this whenever the user views the choices file and I’ll like to do this when writing inferred choices files in AGGREGATION, but I having trouble finding what part of the code base does this work.
Could you clarify a bit on what you mean by sorting and formatting in this case?
Right now the aggregation code prints the choices in any order (it groups those that are sorted in the same object, eg all of the choices for a lexical item will be together), but eg. the word order choices are dispersed through the file. When you load it into the questionnaire and then download the choices file they are sorted and grouped into sections, like below.
Interestingly, it only does this if there aren’t validation errors.
It might be in gmcs/deffile.py, see e.g. the function save_choices() in MatrixDefFile class?
Thanks Olga! This is the relevant function and I was able to use it.
It took a little work to remove the web-specific functionality and the function relies on some other files in the matrix (matrixdef and matrix_utils.py). For future reference, a working example can be found in the aggregation repo (https://git.ling.washington.edu/agg/aggregation at revision 52cc6e6b). Look in src/main.py for the lines where MatrixDefFile is initialized and save_choices is called.