<commit_before>###*
 * Backbone JJRelational
 * v0.2.9
 *
 * A relational plugin for Backbone JS that provides one-to-one, one-to-many and many-to-many relations between Backbone models.
 *
 * Tested with Backbone v1.0.0 and Underscore v.1.5.0
 * 
###

do () ->
	"use strict"

	# CommonJS shim

	if typeof window is 'undefined'
		_ = require 'underscore'
		Backbone = require 'backbone' 
		exports = Backbone
		typeof module is 'undefined' || (module.exports = exports)
	else
		_ = window._
		Backbone = window.Backbone
		exports = window

	that = @

	# !-
	# ! Backbone.JJStore
	# !-
	###*
	 * 
	 * The Store - well, stores all models in it.
	 * On creation, a model registers itself in the store by its `storeIdentifier`-attribute.
	 * Backbone JJStore provides some methods to get models by id/cid, for example, etc.
	 * 
	###

	# Basic setup
	
	Backbone.JJStore = {}
	Backbone.JJStore.Models = {}
	Backbone.JJStore.Events = _.extend {}, Backbone.Events

	###*
	 * Adds a store for the given `storeIdentifier` if one doesn't exist yet.
	 * @param  {String} storeIdentifier
	 * @return {Backbone.Collection}                 The matching store array
	###
	Backbone.JJStore.__registerModelType = (storeIdentifier) ->
		@.Models[storeIdentifier] = new Backbone.Collection() unless @.Models[storeIdentifier]
		@.Models[storeIdentifier]

	###*
	 * Adds a model to its store if it's not present yet.
	 * @param  {Backbone.JJRelationalModel} model    The model to register
	 * @return {Boolean} true
	###
	Backbone.JJStore.__registerModelInStore = (model) ->
		store = @.__registerModelType model.storeIdentifier
		if not store.get(model)
			store.add model, { silent: true }
			Backbone.JJStore.Events.trigger('added:' + model.storeIdentifier, model)
		true

	###*
	 * Removes a model from its store if present.
	 * @param  {Backbone.JJRelationalModel} model    The model to remove
	 * @return {Boolean} true
	###
	Backbone.JJStore.__removeModelFromStore = (model) ->
		@.Models[model.storeIdentifier].remove model
		true

	## Convenience functions

	Backbone.JJStore._byId = (store, id) ->
		if _.isString store then store = @.Models[store]
		if store
			return store.get id
		null


	# !-
	# ! Backbone JJRelationalModel
	# !-
	###*
	 *
	 * The main part
	 * 
	###

	# ! Basic setup

	Backbone.JJRelational = {}

	Backbone.JJRelational.VERSION = '0.2.9'

	Backbone.JJRelational.Config = {
		url_id_appendix : '?ids='
		# if this is true and you create a new model with an id that already exists in the store,
		# the existing model will be updated and returned instead of a new one
		work_with_store	: true
	}

	Backbone.JJRelational.CollectionTypes = {}
 
	# ! General functions


	###*
	 * Find a type on the global object by name. Splits name on dots.
	 * (i.e. 'Store.Models.MyModel' will return exports['Store']['Models']['MyModel'])
	 * @param  {String} name                           Name to look for
	 * @return {mixed}                                 Global var
	###
	Backbone.JJRelational.__getObjectByName = (name) ->
		type = _.reduce name.split('.'), (memo, val) ->
			memo[val]
		, exports

		if type isnt exports then return type else return null

	###*
	 * Registers one or many collection-types, in order to build a correct collection instance for many-relations.
	 * @param  {Object} collTypes                      key => value pairs, where `key` is the name under which to store the collection type (`value`)
	 * @return {Boolean}           					   Success or not.
	###
	Backbone.JJRelational.registerCollectionTypes = (collTypes) ->
		if not _.isObject(collTypes) then return false

		for name, collection of collTypes
			Backbone.JJRelational.CollectionTypes[name] = collection
		true

	###*
	 * Returns a collection type by the registered name.
	 * If none is found, Backbone.Collection will be returned.
	 * @param  {String} name                           Name under which the collection type is stored
	 * @return {Backbone.Collection}                   Found collection type or Backbone.Collection
	###	
	Backbone.JJRelational.__getCollectionType = (name) ->
		for n, coll of Backbone.JJRelational.CollectionTypes
			if n is name then return coll
<commit_msg>Migrated functionality from Backbone Relational so that it is possible to add and deal with Models that are created on a custom namespace rather than on the global object<commit_after>###*
 * Backbone JJRelational
 * v0.2.9
 *
 * A relational plugin for Backbone JS that provides one-to-one, one-to-many and many-to-many relations between Backbone models.
 *
 * Tested with Backbone v1.0.0 and Underscore v.1.5.0
 * 
###

do () ->
	"use strict"

	# CommonJS shim

	if typeof window is 'undefined'
		_ = require 'underscore'
		Backbone = require 'backbone' 
		exports = Backbone
		typeof module is 'undefined' || (module.exports = exports)
	else
		_ = window._
		Backbone = window.Backbone
		exports = window

	that = @

	# !-
	# ! Backbone.JJStore
	# !-
	###*
	 * 
	 * The Store - well, stores all models in it.
	 * On creation, a model registers itself in the store by its `storeIdentifier`-attribute.
	 * Backbone JJStore provides some methods to get models by id/cid, for example, etc.
	 * 
	###

	# Basic setup
	
	Backbone.JJStore = {}
	Backbone.JJStore._modelScopes = [exports];
	Backbone.JJStore.Models = {}
	Backbone.JJStore.Events = _.extend {}, Backbone.Events

	###*
	 * Adds a store for the given `storeIdentifier` if one doesn't exist yet.
	 * @param  {String} storeIdentifier
	 * @return {Backbone.Collection}                 The matching store array
	###
	Backbone.JJStore.__registerModelType = (storeIdentifier) ->
		@.Models[storeIdentifier] = new Backbone.Collection() unless @.Models[storeIdentifier]
		@.Models[storeIdentifier]

	###*
	 * Adds a model to its store if it's not present yet.
	 * @param  {Backbone.JJRelationalModel} model    The model to register
	 * @return {Boolean} true
	###
	Backbone.JJStore.__registerModelInStore = (model) ->
		store = @.__registerModelType model.storeIdentifier
		if not store.get(model)
			store.add model, { silent: true }
			Backbone.JJStore.Events.trigger('added:' + model.storeIdentifier, model)
		true

	###*
	 * Removes a model from its store if present.
	 * @param  {Backbone.JJRelationalModel} model    The model to remove
	 * @return {Boolean} true
	###
	Backbone.JJStore.__removeModelFromStore = (model) ->
		@.Models[model.storeIdentifier].remove model
		true

	## Convenience functions

	Backbone.JJStore._byId = (store, id) ->
		if _.isString store then store = @.Models[store]
		if store
			return store.get id
		null

	###*
	 * Adds a scope for `getObjectByName` to look for model types by name.
	 * @param {Object} scope
	###
	Backbone.JJStore.addModelScope = (scope) ->
		@._modelScopes.push scope
  
	###*
	 * Removes a model scope
	 * @param {Object} scope
	###
	Backbone.JJStore.removeModelScope = (scope) ->
		@._modelScopes = _.without @._modelScopes, scope
  

	# !-
	# ! Backbone JJRelationalModel
	# !-
	###*
	 *
	 * The main part
	 * 
	###

	# ! Basic setup

	Backbone.JJRelational = {}

	Backbone.JJRelational.VERSION = '0.2.9'

	Backbone.JJRelational.Config = {
		url_id_appendix : '?ids='
		# if this is true and you create a new model with an id that already exists in the store,
		# the existing model will be updated and returned instead of a new one
		work_with_store	: true
	}

	Backbone.JJRelational.CollectionTypes = {}
 
	# ! General functions


	###*
	 * Find a model type on one of the modelScopes by name. Names are split on dots.
	 * @param  {String} name                           
	 * @return {mixed}                                 
	###
	Backbone.JJRelational.__getObjectByName = (name) ->
	  parts = name.split('.')
	  type = null
	  _.find Backbone.JJStore._modelScopes, ((scope) ->
	    type = _.reduce(parts or [], (memo, val) ->
	      (if memo then memo[val] else `undefined`)
	    , scope)
	    true  if type and type isnt scope
	  ), this
	  type

	###*
	 * Registers one or many collection-types, in order to build a correct collection instance for many-relations.
	 * @param  {Object} collTypes                      key => value pairs, where `key` is the name under which to store the collection type (`value`)
	 * @return {Boolean}           					   Success or not.
	###
	Backbone.JJRelational.registerCollectionTypes = (collTypes) ->
		if not _.isObject(collTypes) then return false

		for name, collection of collTypes
			Backbone.JJRelational.CollectionTypes[name] = collection
		true

	###*
	 * Returns a collection type by the registered name.
	 * If none is found, Backbone.Collection will be returned.
	 * @param  {String} name                           Name under which the collection type is stored
	 * @return {Backbone.Collection}                   Found collection type or Backbone.Collection
	###	
	Backbone.JJRelational.__getCollectionType = (name) ->
		for n, coll of Backbone.JJRelational.CollectionTypes
			if n is name then return coll

{'fraction_non_alphanumeric': 0.10668007149240394, 'fraction_numerical': 0.002680965147453083, 'mean_word_length': 3.034700315457413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1180144', 'n_tokens_mistral': 2942, 'n_tokens_neox': 2658, 'n_words': 875}