Search in sources :

Example 1 with AlgorithmState

use of org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState in project molgenis by molgenis.

the class MappingServiceController method getFirstAttributeMappingInfo.

/**
 * Find the firstattributeMapping skip the the algorithmStates that are given in the {@link AttributeMapping} to an
 * {@link EntityMapping}.
 *
 * @param mappingProjectId    ID of the mapping project
 * @param target              name of the target entity
 * @param skipAlgorithmStates the mapping algorithm states that should skip
 */
@PostMapping("/firstattributemapping")
@ResponseBody
public FirstAttributeMappingInfo getFirstAttributeMappingInfo(@RequestParam() String mappingProjectId, @RequestParam() String target, @RequestParam(value = "skipAlgorithmStates[]") List<AlgorithmState> skipAlgorithmStates, Model model) {
    MappingProject mappingProject = mappingService.getMappingProject(mappingProjectId);
    if (hasWritePermission(mappingProject)) {
        MappingTarget mappingTarget = mappingProject.getMappingTarget(target);
        List<String> sourceNames = mappingTarget.getEntityMappings().stream().map(i -> i.getSourceEntityType().getId()).collect(Collectors.toList());
        EntityType targetEntityMeta = mappingTarget.getTarget();
        for (Attribute attribute : targetEntityMeta.getAtomicAttributes()) {
            if (attribute.equals(targetEntityMeta.getIdAttribute())) {
                continue;
            }
            for (String source : sourceNames) {
                EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
                AttributeMapping attributeMapping = entityMapping.getAttributeMapping(attribute.getName());
                if (null != attributeMapping) {
                    AlgorithmState algorithmState = attributeMapping.getAlgorithmState();
                    if (null != skipAlgorithmStates) {
                        if (skipAlgorithmStates.contains(algorithmState)) {
                            continue;
                        }
                    }
                }
                return FirstAttributeMappingInfo.create(mappingProjectId, target, source, attribute.getName());
            }
        }
    }
    return null;
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) PluginController(org.molgenis.web.PluginController) MenuReaderService(org.molgenis.core.ui.menu.MenuReaderService) URISyntaxException(java.net.URISyntaxException) org.molgenis.semanticmapper.mapping.model(org.molgenis.semanticmapper.mapping.model) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AlgorithmService(org.molgenis.semanticmapper.service.AlgorithmService) CategoryMapping.createEmpty(org.molgenis.semanticmapper.mapping.model.CategoryMapping.createEmpty) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) AlgorithmState(org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState) Relation(org.molgenis.data.semantic.Relation) Valid(javax.validation.Valid) Href.concatEntityHref(org.molgenis.core.ui.data.support.Href.concatEntityHref) User(org.molgenis.data.security.auth.User) Model(org.springframework.ui.Model) RunAsSystemAspect(org.molgenis.security.core.runas.RunAsSystemAspect) MetaUtils.isSystemPackage(org.molgenis.data.meta.MetaUtils.isSystemPackage) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) URI(java.net.URI) com.google.common.collect(com.google.common.collect) org.molgenis.data(org.molgenis.data) DataExplorerController(org.molgenis.dataexplorer.controller.DataExplorerController) NameValidator.validateEntityName(org.molgenis.data.validation.meta.NameValidator.validateEntityName) SecurityUtils.getCurrentUsername(org.molgenis.security.core.utils.SecurityUtils.getCurrentUsername) MappingService(org.molgenis.semanticmapper.service.MappingService) JobsController(org.molgenis.core.ui.jobs.JobsController) MediaType(org.springframework.http.MediaType) UserAccountService(org.molgenis.security.user.UserAccountService) EntityTypeUtils(org.molgenis.data.support.EntityTypeUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) OntologyTagService(org.molgenis.semanticsearch.service.OntologyTagService) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SecurityUtils.currentUserIsSu(org.molgenis.security.core.utils.SecurityUtils.currentUserIsSu) MappingJobExecution(org.molgenis.semanticmapper.job.MappingJobExecution) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) JobExecutor(org.molgenis.jobs.JobExecutor) java.util(java.util) CategoryMapping.create(org.molgenis.semanticmapper.mapping.model.CategoryMapping.create) StringUtils.trim(org.apache.commons.lang3.StringUtils.trim) SemanticSearchService(org.molgenis.semanticsearch.service.SemanticSearchService) UserService(org.molgenis.data.security.user.UserService) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) MessageFormat.format(java.text.MessageFormat.format) AggregateResult(org.molgenis.data.aggregation.AggregateResult) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) StreamSupport(java.util.stream.StreamSupport) MappingJobExecutionFactory(org.molgenis.semanticmapper.job.MappingJobExecutionFactory) ImportWizardController(org.molgenis.core.ui.data.importer.wizard.ImportWizardController) GenerateAlgorithmRequest(org.molgenis.semanticmapper.data.request.GenerateAlgorithmRequest) AlgorithmEvaluation(org.molgenis.semanticmapper.service.impl.AlgorithmEvaluation) Logger(org.slf4j.Logger) MappingServiceRequest(org.molgenis.semanticmapper.data.request.MappingServiceRequest) URI(org.molgenis.semanticmapper.controller.MappingServiceController.URI) ResponseEntity.created(org.springframework.http.ResponseEntity.created) Streams.stream(com.google.common.collect.Streams.stream) Collectors.toList(java.util.stream.Collectors.toList) Package(org.molgenis.data.meta.model.Package) ResponseEntity(org.springframework.http.ResponseEntity) EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AlgorithmState(org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState)

Example 2 with AlgorithmState

use of org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState in project molgenis by molgenis.

the class AlgorithmGeneratorServiceImpl method generate.

@Override
public GeneratedAlgorithm generate(Attribute targetAttribute, Map<Attribute, ExplainedAttribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) {
    String algorithm = StringUtils.EMPTY;
    AlgorithmState algorithmState = null;
    Set<Attribute> mappedSourceAttributes = null;
    if (sourceAttributes.size() > 0) {
        AlgorithmTemplate algorithmTemplate = algorithmTemplateService.find(sourceAttributes).findFirst().orElse(null);
        if (algorithmTemplate != null) {
            algorithm = algorithmTemplate.render();
            mappedSourceAttributes = AlgorithmGeneratorHelper.extractSourceAttributesFromAlgorithm(algorithm, sourceEntityType);
            algorithm = convertUnitForTemplateAlgorithm(algorithm, targetAttribute, targetEntityType, mappedSourceAttributes, sourceEntityType);
            algorithmState = GENERATED_HIGH;
        } else {
            Entry<Attribute, ExplainedAttribute> firstEntry = sourceAttributes.entrySet().stream().findFirst().get();
            Attribute sourceAttribute = firstEntry.getKey();
            algorithm = generate(targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType);
            mappedSourceAttributes = AlgorithmGeneratorHelper.extractSourceAttributesFromAlgorithm(algorithm, sourceEntityType);
            algorithmState = firstEntry.getValue().isHighQuality() ? GENERATED_HIGH : GENERATED_LOW;
        }
    }
    return GeneratedAlgorithm.create(algorithm, mappedSourceAttributes, algorithmState);
}
Also used : ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AlgorithmState(org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState) AlgorithmTemplate(org.molgenis.semanticmapper.service.impl.AlgorithmTemplate)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)2 AlgorithmState (org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState)2 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)2 com.google.common.collect (com.google.common.collect)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Streams.stream (com.google.common.collect.Streams.stream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 MessageFormat.format (java.text.MessageFormat.format)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Valid (javax.validation.Valid)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.trim (org.apache.commons.lang3.StringUtils.trim)1 ImportWizardController (org.molgenis.core.ui.data.importer.wizard.ImportWizardController)1 Href.concatEntityHref (org.molgenis.core.ui.data.support.Href.concatEntityHref)1 JobsController (org.molgenis.core.ui.jobs.JobsController)1