PropertiesHandler { public void addProperties(NamedResource subject, Map<Assertion, Set<Value<?>>> properties) { new AxiomSaver(adapter, snapshot).persistAxioms(subject, properties); } PropertiesHandler(OwlapiAdapter adapter, OntologySnapshot snapshot); Collection<Axiom<?>> getProperties(NamedResource subject, boolean includeInferred); void addProperties(NamedResource subject, Map<Assertion, Set<Value<?>>> properties); void removeProperties(NamedResource subject, Map<Assertion, Set<Value<?>>> properties);  }
@Test public void addPropertiesForExistingDataPropertyAddsAssertionsToOntology() { final Assertion assertion = Assertion.createDataPropertyAssertion(DP_ONE, false); final Set<Value<?>> values = new HashSet<>( Arrays.asList(new Value<>("One"), new Value<>("Two"), new Value<>("Three"))); manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLDataProperty(IRI.create(DP_ONE))))); propertiesHandler.addProperties(INDIVIDUAL, Collections.singletonMap(assertion, values)); verifyAddedDataPropertyAxioms(values); }
@Test public void addPropertiesForExistingDataPropertyAddsValuesOfCorrespondingTypes() { final Assertion assertion = Assertion.createDataPropertyAssertion(DP_ONE, false); final Set<Object> baseValues = new HashSet<>(Arrays.asList(false, 1, new Date())); final Set<Value<?>> values = baseValues.stream().map(Value::new).collect(Collectors.toSet()); manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLDataProperty(IRI.create(DP_ONE))))); propertiesHandler.addProperties(INDIVIDUAL, Collections.singletonMap(assertion, values)); verifyAddedDataPropertyAxioms(values); }
@Test public void addPropertiesForExistingObjectPropertyAddsAssertionsToOntology() { final Assertion assertion = Assertion.createObjectPropertyAssertion(OP_ONE, false); final Set<Value<?>> values = new HashSet<>(Arrays.asList( new Value<>(NamedResource.create("http: new Value<>(NamedResource.create("http: manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLObjectProperty(IRI.create(OP_ONE))))); propertiesHandler.addProperties(INDIVIDUAL, Collections.singletonMap(assertion, values)); verifyAddedObjectPropertyAxioms(values); }
@Test public void addPropertiesForExistingObjectPropertyHandlesIndividualsAsStringAndUri() { final Assertion assertion = Assertion.createObjectPropertyAssertion(OP_ONE, false); final Set<Value<?>> values = new HashSet<>(Arrays.asList( new Value<>("http: new Value<>(URI.create("http: manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLDataProperty(IRI.create(DP_ONE))))); propertiesHandler.addProperties(INDIVIDUAL, Collections.singletonMap(assertion, values)); verifyAddedObjectPropertyAxioms(values); }
@Test public void addPropertiesInfersDataPropertyAndLiteralsFromValuesForUnknownProperty() { final Assertion assertion = Assertion.createPropertyAssertion(DP_ONE, false); final Set<Object> typedValues = new HashSet<>(Arrays.asList(true, 117L, new Date())); final Set<Value<?>> values = typedValues.stream().map(Value::new).collect(Collectors.toSet()); propertiesHandler.addProperties(INDIVIDUAL, Collections.singletonMap(assertion, values)); manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLDataProperty(IRI.create(DP_ONE))))); }
@Test public void addPropertiesInfersObjectPropertyAndIrisFromValuesForUnknownProperty() throws Exception { final Assertion assertion = Assertion.createPropertyAssertion(OP_ONE, false); final Set<Object> typedValues = new HashSet<>( Arrays.asList("http: new URL("http: final Set<Value<?>> values = typedValues.stream().map(Value::new).collect(Collectors.toSet()); propertiesHandler.addProperties(INDIVIDUAL, Collections.singletonMap(assertion, values)); verifyAddedObjectPropertyAxioms(values); }
@Test public void addPropertiesAddsValuesOfKnownAnnotationProperty() { final Assertion assertion = Assertion.createPropertyAssertion(OP_ONE, false); final Set<Object> individualValues = new HashSet<>(Collections.singletonList("http: final Set<Object> literalValues = new HashSet<>(Arrays.asList("label", 1)); final Set<Value<?>> values = literalValues.stream().map(Value::new).collect(Collectors.toSet()); values.addAll(individualValues.stream().map(Value::new).collect(Collectors.toSet())); manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLAnnotationProperty(IRI.create(OP_ONE))))); propertiesHandler.addProperties(INDIVIDUAL, Collections.singletonMap(assertion, values)); verifyAddedAnnotationtPropertyAxioms(values); }