Validate if classification is not already associated with the entities

@param guid            unique entity id
@param classifications list of classifications to be associated
498089
private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
        List<String> entityClassifications = getClassificationNames(guid);

        for (AtlasClassification classification : classifications) {
            String newClassification = classification.getTypeName();

            if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) {
                throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid +
                        ", already associated with classification: " + newClassification);
            }
        }
    }
1218835
public static boolean shouldIgnoreType(EClassifier classifier) {
		EAnnotation annotation = classifier.getEAnnotation("JsonType");

		return annotation != null && "false".equalsIgnoreCase(annotation.getDetails().get("include"));
	}
685354
public void setDomainValidationRecords(java.util.Collection<LoadBalancerTlsCertificateDomainValidationRecord> domainValidationRecords) {
        if (domainValidationRecords == null) {
            this.domainValidationRecords = null;
            return;
        }

        this.domainValidationRecords = new java.util.ArrayList<LoadBalancerTlsCertificateDomainValidationRecord>(domainValidationRecords);
    }
914729
protected void addClassifiedByType(final Classification _classification)
    {
        this.checked4classifiedBy = true;
        this.classifiedByTypes.add(_classification.getId());
        setDirty();
    }
197471
@POST
    @Path("/bulk/classification")
    @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
    @Produces(Servlets.JSON_MEDIA_TYPE)
    public void addClassification(ClassificationAssociateRequest request) throws AtlasBaseException {
        AtlasPerfTracer perf = null;

        try {
            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addClassification(" + request  + ")");
            }

            AtlasClassification classification = request == null ? null : request.getClassification();
            List<String>        entityGuids    = request == null ? null : request.getEntityGuids();

            if (classification == null || StringUtils.isEmpty(classification.getTypeName())) {
                throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
            }

            if (CollectionUtils.isEmpty(entityGuids)) {
                throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "empty guid list");
            }

            entitiesStore.addClassification(entityGuids, classification);
        } finally {
            AtlasPerfTracer.log(perf);
        }
    }
142461
def validate_categories_equal_entities(categories, entities, message=None,
                                       exception=MatrixError):
    """"""
    nb_categories = len(categories)
    nb_entities = len(entities)
    if message is None:
        message = 'Number of categories: %s != number of entities: %s' % (
            nb_categories, nb_entities)
    if categories and nb_categories != nb_entities:
        raise exception(message)
758867
@Override
	public C classify(T classifiable) {

		if (classifiable == null) {
			return this.defaultValue;
		}

		@SuppressWarnings("unchecked")
		Class<? extends T> exceptionClass = (Class<? extends T>) classifiable.getClass();
		if (this.classified.containsKey(exceptionClass)) {
			return this.classified.get(exceptionClass);
		}

		// check for subclasses
		C value = null;
		for (Class<?> cls = exceptionClass; !cls.equals(Object.class)
				&& value == null; cls = cls.getSuperclass()) {
			value = this.classified.get(cls);
		}

		// ConcurrentHashMap doesn't allow nulls
		if (value != null) {
			this.classified.put(exceptionClass, value);
		}

		if (value == null) {
			value = this.defaultValue;
		}

		return value;
	}
268051
public void assignManagedTypes(Map<Class<?>, EntityType<?>> managedTypes)
    {
        if (this.entityTypes == null)
        {
            this.entityTypes = managedTypes;
        }
        else
        {
            this.entityTypes.putAll(managedTypes);
        }
    }
653059
public void setIdpIdentifiers(java.util.Collection<String> idpIdentifiers) {
        if (idpIdentifiers == null) {
            this.idpIdentifiers = null;
            return;
        }

        this.idpIdentifiers = new java.util.ArrayList<String>(idpIdentifiers);
    }
455504
public String updateClassification(String classificationType) {
        Metadata metadata = new Metadata("enterprise", Metadata.CLASSIFICATION_TEMPLATE_KEY);
        metadata.add("/Box__Security__Classification__Key", classificationType);
        Metadata classification = this.updateMetadata(metadata);

        return classification.getString(Metadata.CLASSIFICATION_KEY);
    }
423936
private void validateRelationType(RelationType relationType) {
        ValidateGlobalRules.validateHasMinimumRoles(relationType).ifPresent(errorsFound::add);
        errorsFound.addAll(ValidateGlobalRules.validateRelationTypesToRolesSchema(relationType));
    }
361191
public function validateAssociations()
    {
        foreach ($this->associationMappings as $mapping) {
            if ( ! ClassLoader::classExists($mapping['targetEntity']) ) {
                throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']);
            }
        }
    }
1085796
public List<Classification> listAll(String classificationName) {
        assertArgumentNotNull("classificationName", classificationName);
        return findClassificationMeta(classificationName, () -> {
            return "listAll('" + classificationName + "')";
        }).listAll();
    }
473739
public void classifyIncremental() {
        if(as.isEmpty()) return;
        
        // Clear any state from previous incremental classifications
        newContexts.clear();
        affectedContexts.clear();

        int numNewConcepts = 0;

        // Determine which contexts are affected
        for (NF1a i : as.getNf1aAxioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF1b i : as.getNf1bAxioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF2 i : as.getNf2Axioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF3 i : as.getNf3Axioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF4 i : as.getNf4Axioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF5 i : as.getNf5Axioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF6 i : as.getNf6Axioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF7 i : as.getNf7Axioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        for (NF8 i : as.getNf8Axioms()) {
            numNewConcepts = processInclusion(numNewConcepts, i);
        }
        
        if(log.isInfoEnabled()) log.info("Added " + numNewConcepts + " new concepts to the ontology");

        // TODO: this is potentially slow
        IConceptMap<IConceptSet> subsumptions = getSubsumptions();

        rePrimeNF1(as, subsumptions);
        rePrimeNF2(as, subsumptions);
        rePrimeNF3(as, subsumptions);
        rePrimeNF4(as, subsumptions);
        rePrimeNF5(as, subsumptions);
        rePrimeNF6(as, subsumptions);
        rePrimeNF7(as, subsumptions);
        rePrimeNF8(as, subsumptions);

        // Classify
        if(log.isInfoEnabled())
            log.info("Classifying incrementally with " + numThreads + " threads");
        
        if(log.isInfoEnabled())
            log.info("Running saturation");
        ExecutorService executor = Executors.newFixedThreadPool(numThreads, THREAD_FACTORY);
        for (int j = 0; j < numThreads; j++) {
            Runnable worker = new Worker(todo);
            executor.execute(worker);
        }

        executor.shutdown();
        while (!executor.isTerminated()) {
            try {
                executor.awaitTermination(100, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        assert (todo.isEmpty());

        // Stop tracking changes in reactivated contexts
        for (Context ctx : affectedContexts) {
            ctx.endTracking();
        }

        affectedContexts.removeAll(newContexts);
        
        hasBeenIncrementallyClassified = true;
        as.clear();
        
        if(log.isTraceEnabled())
            log.trace("Processed " + contextIndex.size() + " contexts");
    }
31012
public function classify($uniqueid, \stored_file $dataset, $outputdir) {

        $classifier = $this->load_classifier($outputdir);

        $fh = $dataset->get_content_file_handle();

        // The first lines are var names and the second one values.
        $metadata = $this->extract_metadata($fh);

        // Skip headers.
        fgets($fh);

        $sampleids = array();
        $samples = array();
        $predictions = array();
        while (($data = fgetcsv($fh)) !== false) {
            $sampledata = array_map('floatval', $data);
            $sampleids[] = $data[0];
            $samples[] = array_slice($sampledata, 1, $metadata['nfeatures']);

            if (count($samples) === self::BATCH_SIZE) {
                // Prediction it batches to avoid running out of memory.

                // Append predictions incrementally, we want $sampleids keys in sync with $predictions keys.
                $newpredictions = $classifier->predict($samples);
                foreach ($newpredictions as $prediction) {
                    array_push($predictions, $prediction);
                }
                $samples = array();
            }
        }
        fclose($fh);

        // Finish the remaining predictions.
        if ($samples) {
            $predictions = $predictions + $classifier->predict($samples);
        }

        $resultobj = new \stdClass();
        $resultobj->status = \core_analytics\model::OK;
        $resultobj->info = array();

        foreach ($predictions as $index => $prediction) {
            $resultobj->predictions[$index] = array($sampleids[$index], $prediction);
        }

        return $resultobj;
    }
737352
public String setClassification(String classificationType) {
        Metadata metadata = new Metadata().add(Metadata.CLASSIFICATION_KEY, classificationType);
        Metadata classification = null;

        try {
            classification = this.createMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY, "enterprise", metadata);
        } catch (BoxAPIException e) {
            if (e.getResponseCode() == 409) {
                metadata = new Metadata("enterprise", Metadata.CLASSIFICATION_TEMPLATE_KEY);
                metadata.replace(Metadata.CLASSIFICATION_KEY, classificationType);
                classification = this.updateMetadata(metadata);
            } else {
                throw e;
            }
        }

        return classification.getString(Metadata.CLASSIFICATION_KEY);
    }
1089207
protected boolean checkCitationIds(List<String> citationIds, ItemDataProvider provider) {
		for (String id : citationIds) {
			if (provider.retrieveItem(id) == null) {
				String message = "unknown citation id: " + id;
				
				//find alternatives
				List<String> availableIds = Arrays.asList(provider.getIds());
				if (!availableIds.isEmpty()) {
					Collection<String> mins = Levenshtein.findSimilar(availableIds, id);
					if (mins.size() > 0) {
						if (mins.size() == 1) {
							message += "\n\nDid you mean this?";
						} else {
							message += "\n\nDid you mean one of these?";
						}
						for (String m : mins) {
							message += "\n\t" + m;
						}
					}
				}
				
				error(message);
				
				return false;
			}
		}
		return true;
	}