Skip to content

Commit 3fc74ca

Browse files
authored
Merge pull request #45 from VisualDataWeb/33-anonymous-inverse-property
Set Domain/Range of inverse properties to same as the inverse.
2 parents 7433650 + e524ca7 commit 3fc74ca

File tree

10 files changed

+186
-24
lines changed

10 files changed

+186
-24
lines changed

src/main/java/de/uni_stuttgart/vis/vowl/owl2vowl/converter/InputStreamConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class InputStreamConverter extends AbstractConverter {
1818
private static final Logger logger = LogManager.getLogger(InputStreamConverter.class);
1919

2020
public InputStreamConverter(InputStream ontology) {
21-
this(ontology, Collections.<InputStream>emptyList());
21+
this(ontology, Collections.emptyList());
2222
}
2323

2424
public InputStreamConverter(InputStream ontology, Collection<InputStream> necessaryExternals) {

src/main/java/de/uni_stuttgart/vis/vowl/owl2vowl/parser/owlapi/EntityCreationVisitor.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.nodes.datatypes.VowlLiteral;
88
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlDatatypeProperty;
99
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlObjectProperty;
10-
import org.semanticweb.owlapi.model.*;
10+
import org.apache.logging.log4j.LogManager;
11+
import org.apache.logging.log4j.Logger;
12+
import org.semanticweb.owlapi.model.OWLClass;
13+
import org.semanticweb.owlapi.model.OWLDataProperty;
14+
import org.semanticweb.owlapi.model.OWLDatatype;
15+
import org.semanticweb.owlapi.model.OWLLiteral;
16+
import org.semanticweb.owlapi.model.OWLObjectProperty;
17+
import org.semanticweb.owlapi.model.OWLObjectVisitor;
1118

1219
public class EntityCreationVisitor implements OWLObjectVisitor {
1320

1421
private VowlData vowlData;
22+
private Logger logger = LogManager.getLogger(EntityCreationVisitor.class);
1523

1624
public EntityCreationVisitor(VowlData vowlData) {
1725
this.vowlData = vowlData;
@@ -28,6 +36,7 @@ public void visit(OWLClass ce) {
2836
clazz = new VowlClass(ce.getIRI());
2937
} else {
3038
// TODO Anonymous behaviour undefined
39+
logger.info("Anonymous OWLClass " + ce);
3140
return;
3241
}
3342

@@ -52,10 +61,11 @@ public void visit(OWLDatatype node) {
5261
public void visit(OWLObjectProperty property) {
5362
VowlObjectProperty prop;
5463

55-
if(!property.isAnonymous()) {
64+
if (!property.isAnonymous()) {
5665
prop = new VowlObjectProperty(property.getIRI());
5766
} else {
5867
// TODO anonymous behaviour
68+
logger.info("Anonymous OWLObjectProperty " + property);
5969
return;
6070
}
6171

@@ -66,10 +76,11 @@ public void visit(OWLObjectProperty property) {
6676
public void visit(OWLDataProperty property) {
6777
VowlDatatypeProperty prop;
6878

69-
if(!property.isAnonymous()) {
79+
if (!property.isAnonymous()) {
7080
prop = new VowlDatatypeProperty(property.getIRI());
7181
} else {
7282
// TODO anonymous behaviour
83+
logger.info("Anonymous OWLDataProperty " + property);
7384
return;
7485
}
7586

src/main/java/de/uni_stuttgart/vis/vowl/owl2vowl/parser/vowl/classes/OwlClassAxiomVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public void visit(OWLObjectIntersectionOf ce) {
285285
node.addAttribute(VowlAttribute.INTERSECTION);
286286
} else {
287287
// TODO Anonymous undefined behaviour
288-
logger.info("Anonymous exists in intersections.");
288+
logger.info("Anonymous exists in intersections. " + operand);
289289
}
290290
}
291291
}

src/main/java/de/uni_stuttgart/vis/vowl/owl2vowl/parser/vowl/property/DomainRangeFiller.java

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlDatatypeProperty;
1111
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlObjectProperty;
1212
import de.uni_stuttgart.vis.vowl.owl2vowl.model.visitor.VowlPropertyVisitor;
13-
13+
import java.util.Collection;
14+
import java.util.Set;
1415
import org.apache.logging.log4j.LogManager;
1516
import org.apache.logging.log4j.Logger;
1617
import org.semanticweb.owlapi.model.IRI;
1718

18-
import java.util.Collection;
19-
import java.util.Set;
20-
2119
/**
2220
* Class which is responsible to fill the Domain/Range of properties regarding the VOWL specification.
21+
*
2322
* @author Eduard
2423
*/
2524
public class DomainRangeFiller implements VowlPropertyVisitor {
@@ -37,23 +36,28 @@ public DomainRangeFiller(VowlData vowlData, Collection<? extends AbstractPropert
3736
public void execute() {
3837
fillEmpty();
3938
mergeMulti();
39+
processInverseProperties();
4040
}
4141

4242
private void fillEmpty() {
43-
values.forEach(element -> {
44-
if (element instanceof HasReference) {
45-
//Ignore references cause they do not need generated Domain/Range
46-
return;
47-
}
48-
try {
49-
element.accept(this);
50-
} catch (Exception e){
51-
logger.info(" DomainRange Filler faild to accept element");
52-
logger.info(" Element: "+element);
53-
logger.info(" Reason: "+e);
54-
logger.info(" SKIPPING THIS ELEMENT *****");
55-
}
56-
});
43+
values.stream()
44+
// Only process props which have empty domain/range
45+
.filter(property -> property.getDomains().isEmpty() || property.getRanges().isEmpty())
46+
// skip inverse properties
47+
.filter(property -> property.getInverse() == null)
48+
.forEach(this::processProperty);
49+
}
50+
51+
private void processProperty(AbstractProperty property) {
52+
if (property instanceof HasReference) {
53+
//Ignore references cause they do not need generated Domain/Range
54+
return;
55+
}
56+
try {
57+
property.accept(this);
58+
} catch (Exception e) {
59+
logger.error("Exception during processing property: " + e + " with message: " + e.getMessage() + " | Skip");
60+
}
5761
}
5862

5963
private VowlThing searchForConnectedThing(Set<IRI> value) {
@@ -79,6 +83,29 @@ private void mergeMulti() {
7983
}
8084
}
8185

86+
private void processInverseProperties() {
87+
values.stream()
88+
.filter(property -> property.getInverse() != null)
89+
.filter(property -> property.getDomains().isEmpty() || property.getRanges().isEmpty())
90+
.peek(this::fillWithInverse)
91+
.filter(property -> property.getDomains().isEmpty() || property.getRanges().isEmpty())
92+
.forEach(this::processProperty);
93+
}
94+
95+
private void fillWithInverse(AbstractProperty property) {
96+
AbstractProperty inverse = vowlData.getPropertyForIri(property.getInverse());
97+
98+
if (property.getDomains().isEmpty() && inverse.getJsonRange() != null) {
99+
property.getDomains().add(inverse.getJsonRange());
100+
logger.debug("Filled inverse property domain " + property + " with " + inverse.getJsonRange());
101+
}
102+
103+
if (property.getRanges().isEmpty() && inverse.getJsonDomain() != null) {
104+
property.getRanges().add(inverse.getJsonDomain());
105+
logger.debug("Filled inverse property range " + property + " with " + inverse.getJsonDomain());
106+
}
107+
}
108+
82109
@Override
83110
public void visit(VowlObjectProperty vowlObjectProperty) {
84111
classBehaviour(vowlObjectProperty);

src/test/java/de/uni_stuttgart/vis/vowl/owl2vowl/CompleteTestSuite.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
@RunWith(Suite.class)
99
@Suite.SuiteClasses({
10+
ComparisonHelperTest.class,
1011
ConsoleMainTest.class,
1112
OntobenchTest.class,
12-
ComparisonHelperTest.class
13+
PropertyTest.class
1314
})
1415
public class CompleteTestSuite extends TestSuite {
1516

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.uni_stuttgart.vis.vowl.owl2vowl;
2+
3+
import org.semanticweb.owlapi.model.IRI;
4+
5+
public class Constants {
6+
7+
public static final String OWL2VOWL_NAMESPACE = "https://owl2vowl.de/";
8+
9+
public static IRI getIRIWithTestNamespace(String entityIRI) {
10+
return IRI.create(OWL2VOWL_NAMESPACE + entityIRI);
11+
}
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.uni_stuttgart.vis.vowl.owl2vowl;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.is;
5+
6+
import de.uni_stuttgart.vis.vowl.owl2vowl.model.data.VowlData;
7+
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.AbstractProperty;
8+
import org.junit.Test;
9+
10+
11+
public class PropertyTest {
12+
13+
@Test
14+
public void shouldProcessAnonymousInverseRelationCorrectly() {
15+
TestConverter converter = new TestConverter(getClass().getResourceAsStream("/inverse-anonym-test.ttl"));
16+
VowlData data = converter.getConvertedData();
17+
18+
AbstractProperty propertyA = data.getPropertyForIri(Constants.getIRIWithTestNamespace("propertyA"));
19+
AbstractProperty propertyB = data.getPropertyForIri(Constants.getIRIWithTestNamespace("propertyB"));
20+
21+
assertThat(propertyA.getJsonDomain(), is(Constants.getIRIWithTestNamespace("classA")));
22+
assertThat(propertyA.getJsonRange(), is(Constants.getIRIWithTestNamespace("classB")));
23+
24+
assertThat(propertyB.getJsonDomain(), is(Constants.getIRIWithTestNamespace("classB")));
25+
assertThat(propertyB.getJsonRange(), is(Constants.getIRIWithTestNamespace("classA")));
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package de.uni_stuttgart.vis.vowl.owl2vowl;
2+
3+
import de.uni_stuttgart.vis.vowl.owl2vowl.converter.InputStreamConverter;
4+
import de.uni_stuttgart.vis.vowl.owl2vowl.model.data.VowlData;
5+
import java.io.InputStream;
6+
7+
public class TestConverter extends InputStreamConverter {
8+
9+
public TestConverter(InputStream ontology) {
10+
super(ontology);
11+
}
12+
13+
public VowlData getConvertedData() {
14+
if (!this.initialized) {
15+
this.convert();
16+
}
17+
return this.vowlData;
18+
}
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#################################PREFIXES################################
2+
3+
@prefix : <https://owl2vowl.de/> .
4+
@prefix this: <https://owl2vowl.de/> .
5+
@prefix dcterms: <http://purl.org/dc/terms/> .
6+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
7+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
8+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
9+
@prefix schema: <http://schema.org/> .
10+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
11+
12+
#################################ONTOLOGY#################################
13+
14+
this:schema
15+
a owl:Ontology ;
16+
dcterms:title "OWL2VOWL Testing" ;
17+
.
18+
19+
#################################ENTITIES##################################
20+
21+
:propertyA
22+
a owl:ObjectProperty ;
23+
rdfs:domain :classA ;
24+
rdfs:range :classB ;
25+
.
26+
:propertyB
27+
owl:inverseOf :propertyA ;
28+
.

src/test/resources/log4j2.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration>
3+
<Properties>
4+
<Property name="PID">????</Property>
5+
<Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
6+
<Property name="LOG_LEVEL_PATTERN">%5p</Property>
7+
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{${LOG_LEVEL_PATTERN}} %clr{${sys:PID}}{magenta} %clr{---}{faint}
8+
%clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}
9+
</Property>
10+
<Property name="FILE_LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN} ${sys:PID} --- [%t] %-40.40c{1.} :
11+
%m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}
12+
</Property>
13+
</Properties>
14+
<Appenders>
15+
<Console name="Console" target="SYSTEM_OUT" follow="true">
16+
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}"/>
17+
</Console>
18+
</Appenders>
19+
<Loggers>
20+
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error"/>
21+
<Logger name="org.apache.catalina.util.LifecycleBase" level="error"/>
22+
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn"/>
23+
<logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
24+
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn"/>
25+
<Logger name="org.crsh.plugin" level="warn"/>
26+
<logger name="org.crsh.ssh" level="warn"/>
27+
<Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error"/>
28+
<Logger name="org.hibernate.validator.internal.util.Version" level="warn"/>
29+
<logger name="org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration" level="warn"/>
30+
<logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
31+
<logger name="org.thymeleaf" level="warn"/>
32+
<logger name="de.uni_stuttgart.vis.vowl.owl2vowl" level="debug"/>
33+
<Root level="info">
34+
<AppenderRef ref="Console"/>
35+
</Root>
36+
</Loggers>
37+
</Configuration>

0 commit comments

Comments
 (0)