private static Map<String, Map<String, DocumentScript>>  createScriptsMap(DocumentTypeManager documentTypes,
                                                                              IlscriptsConfig config,
                                                                              Linguistics linguistics,
                                                                              Map<String, Chunker> chunkers,
                                                                              Map<String, Embedder> embedders,
                                                                              Map<String, FieldGenerator> generators) {
        Map<String, Map<String, DocumentScript>> documentFieldScripts = new HashMap<>(config.ilscript().size());
        ScriptParserContext parserContext = new ScriptParserContext(linguistics, chunkers, embedders, generators);
        parserContext.getAnnotatorConfig().setMaxTermOccurrences(config.maxtermoccurrences());
        parserContext.getAnnotatorConfig().setMaxTokenizeLength(config.fieldmatchmaxlength());

        for (IlscriptsConfig.Ilscript ilscript : config.ilscript()) {
            DocumentType documentType = documentTypes.getDocumentType(ilscript.doctype());
            InputExpression.FieldPathOptimizer fieldPathOptimizer = new InputExpression.FieldPathOptimizer(documentType);
            List<StatementExpression> allStatements = new ArrayList<>(ilscript.content().size());
            Map<String, DocumentScript> fieldScripts = new HashMap<>(ilscript.content().size());
            for (String content : ilscript.content()) {
                StatementExpression statement = parse(documentType, parserContext, content);
                allStatements.add(statement);
                List<String> allInputFieldNames = InputExpression.InputFieldNameExtractor.runOn(statement);
                Set<String> requiredInputFields = InputExpression.RequiredInputFieldsExtractor.runOn(statement);
                OutputExpression.OutputFieldNameExtractor outputFieldNameExtractor = new OutputExpression.OutputFieldNameExtractor();
                statement.select(outputFieldNameExtractor, outputFieldNameExtractor);
                statement.select(fieldPathOptimizer, fieldPathOptimizer);
                if ( ! outputFieldNameExtractor.getOutputFieldNames().isEmpty()) {
                    String outputFieldName = outputFieldNameExtractor.getOutputFieldNames().get(0);
                    statement.setStatementOutput(documentType, documentType.getField(outputFieldName));
                }
                if (allInputFieldNames.size() == 1 || requiredInputFields.size() == 1) {
                    String fieldName = (allInputFieldNames.size() == 1)
                            ? allInputFieldNames.iterator().next()
                            : requiredInputFields.iterator().next();
                    ScriptExpression fieldScript;
                    if (fieldScripts.containsKey(fieldName)) {
                        DocumentScript existing = fieldScripts.get(fieldName);
                        List<StatementExpression> appendedList = new ArrayList<>(existing.getExpression().asList());
                        appendedList.add(statement);
                        fieldScript = new ScriptExpression(appendedList);
                    } else {
                        fieldScript = new ScriptExpression(statement);
                    }
                    fieldScripts.put(fieldName, new DocumentScript(documentType, List.of(fieldName), fieldScript));
                }
            }

            var script = new ScriptExpression(allStatements);
            script.select(fieldPathOptimizer, fieldPathOptimizer);
            fieldScripts.put(FULL, new DocumentScript(documentType, ilscript.docfield(), script));
            documentFieldScripts.put(ilscript.doctype(), Collections.unmodifiableMap(fieldScripts));
        }
        return Collections.unmodifiableMap(documentFieldScripts);
    }
Returns an unmodifiable map from document type name to a map of the subset of indexing statements
to run for each input field which *only* depend on that field.
docprocs/src/main/java/com/yahoo/docprocs/indexing/ScriptManager.java