Search in sources :

Example 1 with Name

use of com.opensimulationplatform.core.model.modeldescription.Name in project osp-validator by open-simulation-platform.

the class OspOwlBuilder method removeNakedVariablesFromOntology.

private void removeNakedVariablesFromOntology() {
    for (Map.Entry<OWLIndividual, Variable> entries : context.variables.entrySet()) {
        OWLIndividual variableIndividual = entries.getKey();
        Variable variable = entries.getValue();
        Optional<Map.Entry<OWLIndividual, Name>> nameOptional = context.names.entrySet().stream().filter(e -> e.getValue().equals(variable.getName())).findFirst();
        if (!variableExistsInVariableGroup(variable) && !variableExistsInConnection(variable)) {
            OWLEntityRemover remover = new OWLEntityRemover(context.owl.manager, Collections.singleton(context.owl.ontology));
            remover.visit((OWLNamedIndividual) variableIndividual);
            if (nameOptional.isPresent()) {
                OWLIndividual nameIndividual = nameOptional.get().getKey();
                remover.visit((OWLNamedIndividual) nameIndividual);
            }
            context.owl.manager.applyChanges(remover.getChanges());
            context.individuals.remove(variableIndividual);
            if (nameOptional.isPresent()) {
                OWLIndividual nameIndividual = nameOptional.get().getKey();
                context.individuals.remove(nameIndividual);
            }
        }
    }
}
Also used : Name(com.opensimulationplatform.core.model.modeldescription.Name) InferenceType(org.semanticweb.owlapi.reasoner.InferenceType) VariableGroup(com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) java.util(java.util) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) OWLEntityRemover(org.semanticweb.owlapi.util.OWLEntityRemover) ValidationError(com.opensimulationplatform.gen.owl.model.OntologyClasses.ValidationError) OWLClass(org.semanticweb.owlapi.model.OWLClass) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) OWLEntityRemover(org.semanticweb.owlapi.util.OWLEntityRemover) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 2 with Name

use of com.opensimulationplatform.core.model.modeldescription.Name in project osp-validator by open-simulation-platform.

the class VE_Name_1_Test method invalid.

@Test
public void invalid() {
    Variable v1 = new Variable();
    v1.setName("not-a-unique-name");
    Variable v2 = new Variable();
    v2.setName("not-a-unique-name");
    builder.build(v1);
    builder.build(v2);
    builder.complete();
    List<ValidationDiagnostic<Name>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    Name invalidName = diagnostics.get(0).getValidatedObject();
    assertEquals(invalidName.get(), v1.getName().get());
    assertEquals(invalidName.get(), v2.getName().get());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Name(com.opensimulationplatform.core.model.modeldescription.Name) Test(org.junit.Test)

Example 3 with Name

use of com.opensimulationplatform.core.model.modeldescription.Name in project osp-validator by open-simulation-platform.

the class VE_Name_2_Test method invalid.

@Test
public void invalid() {
    Simulator s1 = new Simulator();
    s1.setName("not-a-unique-name");
    Simulator s2 = new Simulator();
    s2.setName("not-a-unique-name");
    builder.build(s1);
    builder.build(s2);
    builder.complete();
    List<ValidationDiagnostic<Name>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    Name invalidName = diagnostics.get(0).getValidatedObject();
    assertEquals(invalidName.get(), s1.getName().get());
    assertEquals(invalidName.get(), s2.getName().get());
}
Also used : ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Name(com.opensimulationplatform.core.model.modeldescription.Name) Test(org.junit.Test)

Example 4 with Name

use of com.opensimulationplatform.core.model.modeldescription.Name in project osp-validator by open-simulation-platform.

the class VE_Name_3_Test method invalid.

@Test
public void invalid() {
    Generic vg1 = new Generic();
    vg1.setName("not-a-unique-name");
    Generic vg2 = new Generic();
    vg2.setName("not-a-unique-name");
    builder.build(vg1);
    builder.build(vg2);
    builder.complete();
    List<ValidationDiagnostic<Name>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    Name invalidName = diagnostics.get(0).getValidatedObject();
    assertEquals(invalidName.get(), vg1.getName().get());
    assertEquals(invalidName.get(), vg2.getName().get());
}
Also used : Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Name(com.opensimulationplatform.core.model.modeldescription.Name) Test(org.junit.Test)

Aggregations

Name (com.opensimulationplatform.core.model.modeldescription.Name)4 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)3 Test (org.junit.Test)3 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)2 VariableGroup (com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup)1 Generic (com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic)1 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)1 VariableConnection (com.opensimulationplatform.core.model.systemstructure.VariableConnection)1 ValidationError (com.opensimulationplatform.gen.owl.model.OntologyClasses.ValidationError)1 java.util (java.util)1 OWLClass (org.semanticweb.owlapi.model.OWLClass)1 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)1 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)1 InferenceType (org.semanticweb.owlapi.reasoner.InferenceType)1 OWLEntityRemover (org.semanticweb.owlapi.util.OWLEntityRemover)1