<commit_before>// BusinessProcess data forms (step 1 of Part A) resolution

'use strict';

var memoize                     = require('memoizee/plain')
  , definePropertyGroupsProcess = require('../lib/property-groups-process')
  , defineInitial               = require('./base')
  , defineFormSectionBase       = require('../form-section-base');

module.exports = memoize(function (db/* options */) {
	var BusinessProcess       = defineInitial(db, arguments[1])
	  , PropertyGroupsProcess = definePropertyGroupsProcess(db)
	  , FormSectionBase       = defineFormSectionBase(db);

	BusinessProcess.prototype.defineProperties({
		dataForms: { type: PropertyGroupsProcess, nested: true }
	});

	BusinessProcess.prototype.dataForms.defineProperties({
		// Applicable form sections across all derivedProcesses
		processChainApplicable: {
			type: FormSectionBase,
			multiple: true,
			value: function (_observe) {
				var sections = [], sectionNames = {}, derivatives = [], sectionFilter;

				sectionFilter = function (section, sectionName) {
					if (!sectionNames[sectionName] && _observe(section._status) > 0) {
						sectionNames[sectionName] = true;
						sections.push(section);
					}
				};

				// we want to avoid potential race condition, hence no toArray
				if (this.master.derivedBusinessProcesses) {
					_observe(this.master.derivedBusinessProcesses).forEach(function (derived) {
						derivatives.push(derived);
					});
					derivatives.reverse().forEach(function (derived) {
						if (derived.dataForms) {
							derived.dataForms.applicable.forEach(sectionFilter);
						}
					});
				}
				if (this.applicable) {
					this.applicable.forEach(sectionFilter);
				}

				return sections;
			}
		}
	});

	return BusinessProcess;
}, { normalizer: require('memoizee/normalizers/get-1')() });<commit_msg>#681 refacotred alogrithm, to be like the one for documents<commit_after>// BusinessProcess data forms (step 1 of Part A) resolution

'use strict';

var memoize                     = require('memoizee/plain')
  , definePropertyGroupsProcess = require('../lib/property-groups-process')
  , defineInitial               = require('./base')
  , defineFormSectionBase       = require('../form-section-base');

module.exports = memoize(function (db/* options */) {
	var BusinessProcess       = defineInitial(db, arguments[1])
	  , PropertyGroupsProcess = definePropertyGroupsProcess(db)
	  , FormSectionBase       = defineFormSectionBase(db);

	BusinessProcess.prototype.defineProperties({
		dataForms: { type: PropertyGroupsProcess, nested: true }
	});

	BusinessProcess.prototype.dataForms.defineProperties({
		// Applicable form sections across all derivedProcesses
		processChainApplicable: {
			type: FormSectionBase,
			multiple: true,
			value: function (_observe) {
                var processes = [this.master], sections = [], taken = Object.create(null);

                // Gather all business processes in chain
                _observe(this.master.derivedBusinessProcesses).forEach(function (process) {
                    processes.push(process);
                });
                // Iterate processes in reverse order (latest one should be considered first);
                processes.reverse().forEach(function (process) {
                    _observe(process.dataForms.applicable).forEach(function (section, name) {
                        if (_observe(section._status) === 0) return;
                        if (taken[name]) return;
                        taken[name] = true;
                        sections.push(section);
                    });
                });

				return sections;
			}
		}
	});

	return BusinessProcess;
}, { normalizer: require('memoizee/normalizers/get-1')() });
{'fraction_non_alphanumeric': 0.1168726491133799, 'fraction_numerical': 0.002955400322407308, 'mean_word_length': 2.830246913580247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2259400', 'n_tokens_mistral': 1137, 'n_tokens_neox': 957, 'n_words': 209}