In order to avoid loading spacy models a whole bunch of times, we'll save references to them,
    keyed by the options we used to create the spacy model, so any particular configuration only
    gets loaded once.
549805
def get_spacy_model(spacy_model_name: str, pos_tags: bool, parse: bool, ner: bool) -> SpacyModelType:
    

    options = (spacy_model_name, pos_tags, parse, ner)
    if options not in LOADED_SPACY_MODELS:
        disable = ['vectors', 'textcat']
        if not pos_tags:
            disable.append('tagger')
        if not parse:
            disable.append('parser')
        if not ner:
            disable.append('ner')
        try:
            spacy_model = spacy.load(spacy_model_name, disable=disable)
        except OSError:
            logger.warning(f"Spacy models '{spacy_model_name}' not found.  Downloading and installing.")
            spacy_download(spacy_model_name)
            # NOTE(mattg): The following four lines are a workaround suggested by Ines for spacy
            # 2.1.0, which removed the linking that was done in spacy 2.0.  importlib doesn't find
            # packages that were installed in the same python session, so the way `spacy_download`
            # works in 2.1.0 is broken for this use case.  These four lines can probably be removed
            # at some point in the future, once spacy has figured out a better way to handle this.
            # See https://github.com/explosion/spaCy/issues/3435.
            from spacy.cli import link
            from spacy.util import get_package_path
            package_path = get_package_path(spacy_model_name)
            link(spacy_model_name, spacy_model_name, model_path=package_path)
            spacy_model = spacy.load(spacy_model_name, disable=disable)

        LOADED_SPACY_MODELS[options] = spacy_model
    return LOADED_SPACY_MODELS[options]
1271277
def save(self):
        

        kf = self._kf

        # force all attributes to be computed. this is only necessary
        # if the class uses properties that compute data only when
        # accessed
        for prop in self.properties:
            self._DL[prop[0]].append(getattr(kf, prop[0]))

        v = copy.deepcopy(kf.__dict__)

        if self._skip_private:
            for key in list(v.keys()):
                if key.startswith('_'):
                    print('deleting', key)
                    del v[key]

        if self._skip_callable:
            for key in list(v.keys()):
                if callable(v[key]):
                    del v[key]

        for ig in self._ignore:
            if ig in v:
                del v[ig]

        for key in list(v.keys()):
            self._DL[key].append(v[key])

        self.__dict__.update(self._DL)
        self._len += 1
23310
private void cascadeMarkedForInsert()
    {
        // This list was used to avoid endless recursion on circular references
        List alreadyPrepared = new ArrayList();
        for(int i = 0; i < markedForInsertList.size(); i++)
        {
            ObjectEnvelope mod = (ObjectEnvelope) markedForInsertList.get(i);
            // only if a new object was found we cascade to register the dependent objects
            if(mod.needsInsert())
            {
                cascadeInsertFor(mod, alreadyPrepared);
                alreadyPrepared.clear();
            }
        }
        markedForInsertList.clear();
    }
1164240
public void cleanUpNullReferences() {
        synchronized (map) {
            final Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {
                final Map.Entry<K, V> entry = iterator.next();
                final Object value = entry.getValue();

                if (!(value instanceof SoftReference)) continue;
                if (((SoftReference) value).get() == null) iterator.remove();
            }
        }
    }
1122438
def store_model(constrs, vars)
      # Store all constraints
      constrs.each do |constr|
        store_constraint constr
        @constraints << constr
      end

      # We store variables now since they didn't exist earlier
      vars.each_with_index do |var, i|
        var.index = i
        var.model = self
        store_variable var
      end
    end
461579
def _create_reference_value_options(self, keys, finished_keys):
        """"""
        # a set of known reference_value_from_links
        set_of_reference_value_option_names = set()
        for key in keys:
            if key in finished_keys:
                continue
            an_option = self.option_definitions[key]
            if an_option.reference_value_from:

                fully_qualified_reference_name = '.'.join((
                    an_option.reference_value_from,
                    an_option.name
                ))
                if fully_qualified_reference_name in keys:
                    continue  # this referenced value has already been defined
                              # no need to repeat it - skip on to the next key
                reference_option = an_option.copy()
                reference_option.reference_value_from = None
                reference_option.name = fully_qualified_reference_name
                # wait, aren't we setting a fully qualified dotted name into
                # the name field?  Yes, 'add_option' below sees that
                # full pathname and does the right thing with it to ensure
                # that the reference_option is created within the
                # correct namespace
                set_of_reference_value_option_names.add(
                    fully_qualified_reference_name
                )
                self.option_definitions.add_option(reference_option)

        for a_reference_value_option_name in set_of_reference_value_option_names:
            for x in range(a_reference_value_option_name.count('.')):
                namespace_path = \
                    a_reference_value_option_name.rsplit('.', x + 1)[0]
                self.option_definitions[namespace_path].ref_value_namespace()

        return set_of_reference_value_option_names
1144422
def init(self, key_value_pairs):
        
        for k, v in key_value_pairs.items():
            if k not in DatastoreLegacy.store[self.domain]:
                DatastoreLegacy.store[self.domain][k] = v
607522
public boolean putReference(K key, ServiceReference<V> reference) {
        if (key == null || reference == null)
            return false;

        ConcurrentServiceReferenceSet<V> csrs = elementMap.get(key);
        if (csrs == null) {
            // No set for this key: allocate a new set that shares a context reference.
            ConcurrentServiceReferenceSet<V> newSet = new ConcurrentServiceReferenceSet<V>(referenceName, contextRef);

            // Try to add the set to the map: the value returned will be non-null if something else beat us there.
            ConcurrentServiceReferenceSet<V> currentSet = elementMap.putIfAbsent(key, newSet);
            csrs = (currentSet == null) ? newSet : currentSet;
        }

        return csrs.addReference(reference);
    }
736407
def save(self):
        
        if self.path.is_collection:
            self.session.post_json(self.href,
                                   {self.type: dict(self.data)},
                                   cls=ResourceEncoder)
        else:
            self.session.put_json(self.href,
                                  {self.type: dict(self.data)},
                                  cls=ResourceEncoder)
        return self.fetch(exclude_children=True, exclude_back_refs=True)
891643
public void save(String storageName) {
        //store the objects on storage
        storageEngine.saveObject("modelParameters", modelParameters);
        storageEngine.saveObject("trainingParameters", trainingParameters);

        //rename the storage
        storageEngine.rename(storageName);

        //reload the model parameters, necessary for the maps to point to the new location
        modelParameters = (MP) storageEngine.loadObject("modelParameters", ModelParameters.class);
    }
1008560
def save
      # Don't save default values
      save_config = Rails.application.config.theme.reject { |k, _| @defaults.keys.include?(k) }
      full_config[Rails.env].merge!(save_config)
      File.open(config_pathname, 'w') { |f| f << full_config.to_yaml }
    end
1256111
function (model, options, callback) {
                var schema = model.schema,
                    subModels = [],
                    type,
                    subCollection,
                    subModel,
                    addSubModel = function (model) {
                        subModels.push(model);
                    };

                for (var reference in schema) {
                    if (schema.hasOwnProperty(reference)) {
                        type = schema[reference];
                        if (type.classof) {
                            // TODO: remove $nestedModels and use options to specify, which subModels should also be saved
                            // This depends on the changes of the model.
                            // If the submodels haven't changed, than there is no need to save sub models/collections.
                            if (type.classof(Model)) {
                                subModel = model.$[reference];
                                if (subModel && _.include(model.$nestedModels, reference)) {
                                    subModels.push(subModel);
                                }
                            } else if (type.classof(Collection)) {
                                subCollection = model.$[reference];
                                if (subCollection) {
                                    subCollection.each(addSubModel);
                                }
                            }
                        }

                    }
                }

                flow()
                    .parEach(subModels, function (model, cb) {
                        model.save(options, cb);
                    })
                    .exec(callback);
            }
1236302
def save(self, *args, **kwargs):
        
        self.__class__.objects.exclude(id=self.id).delete()
        super(SingletonModel, self).save(*args, **kwargs)
1247943
private void storeOriginal(Pair<String, Object> keyValue) {
		String key = SharedPreferenceUtils.keyTestMode + keyValue.first;

		if (!preferenceUtils.isValueExistForKey(key)) {
			preferenceUtils.put(key, keyValue.second);

		}
	}
188807
@Override
	public void clearCache(CPSpecificationOption cpSpecificationOption) {
		entityCache.removeResult(CPSpecificationOptionModelImpl.ENTITY_CACHE_ENABLED,
			CPSpecificationOptionImpl.class,
			cpSpecificationOption.getPrimaryKey());

		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache((CPSpecificationOptionModelImpl)cpSpecificationOption,
			true);
	}
1241824
def set_references(self, references):
        
        descriptor = Descriptor(None, "counters", None, None, None)
        counters = references.get_optional(descriptor)
        for counter in counters:
            if isinstance(counter, ICounters):
                self._counters.append(counter)
1330857
@SuppressWarnings("checkstyle:cyclomaticcomplexity")
	private static String initializePersistedSREs() {
		//		// FOR DEBUG
		//		try {
		//			clearSREConfiguration();
		//		} catch (CoreException e1) {
		//			e1.printStackTrace();
		//		}
		final String rawXml = SARLEclipsePlugin.getDefault().getPreferences().get(
				getCurrentPreferenceKey(), ""); //$NON-NLS-1$

		try {
			Element config = null;
			// If the preference was found, load SREs from it into memory
			if (!Strings.isNullOrEmpty(rawXml)) {
				config = parseXML(rawXml, true);
			} else {
				// Otherwise, look for the old file that previously held the SRE definitions
				final SARLEclipsePlugin plugin = SARLEclipsePlugin.getDefault();
				if (plugin.getBundle() != null) {
					final IPath stateLocation = plugin.getStateLocation();
					final IPath stateFile = stateLocation.append("sreConfiguration.xml"); //$NON-NLS-1$
					final File file = stateFile.toFile();
					if (file.exists()) {
						// If file exists, load SRE definitions from it into memory and
						// write the definitions to the preference store WITHOUT triggering
						// any processing of the new value
						try (InputStream fileInputStream = new BufferedInputStream(new FileInputStream(file))) {
							config = parseXML(fileInputStream, true);
						} catch (IOException e) {
							SARLEclipsePlugin.getDefault().log(e);
						}
					}
				}
			}
			if (config != null) {
				final String defaultId = config.getAttribute("defaultSRE"); //$NON-NLS-1$
				final NodeList children = config.getChildNodes();
				for (int i = 0; i < children.getLength(); ++i) {
					try {
						final Node child = children.item(i);
						if ("SRE".equalsIgnoreCase(child.getNodeName()) //$NON-NLS-1$
								&& child instanceof Element) {
							final Element element = (Element) child;
							final boolean isPlatform = Boolean.parseBoolean(element.getAttribute("platform")); //$NON-NLS-1$
							final String id = element.getAttribute("id"); //$NON-NLS-1$
							if (!isPlatform || !(ALL_SRE_INSTALLS.containsKey(id))) {
								final ISREInstall sre = createSRE(
										element.getAttribute("class"), //$NON-NLS-1$
										id);
								if (sre == null) {
									throw new IOException("Invalid XML format of the SRE preferences of " + id); //$NON-NLS-1$
								}
								try {
									sre.setFromXML(element);
								} catch (IOException e) {
									SARLEclipsePlugin.getDefault().log(e);
								}
								ALL_SRE_INSTALLS.put(id, sre);
								if (isPlatform) {
									platformSREInstalls.add(id);
								}
							} else {
								final ISREInstall sre = ALL_SRE_INSTALLS.get(id);
								if (sre != null) {
									try {
										sre.setFromXML(element);
									} catch (IOException e) {
										SARLEclipsePlugin.getDefault().log(e);
									}
								}
							}
						}
					} catch (IOException e) {
						SARLEclipsePlugin.getDefault().log(e);
					}
				}
				return defaultId;
			}
		} catch (IOException e) {
			SARLEclipsePlugin.getDefault().log(e);
		}
		return null;
	}