Skip to content

Commit

Permalink
Set Domain/Range of inverse properties to same as the inverse.
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
BlackDark committed Feb 25, 2018
1 parent 7433650 commit e524ca7
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class InputStreamConverter extends AbstractConverter {
private static final Logger logger = LogManager.getLogger(InputStreamConverter.class);

public InputStreamConverter(InputStream ontology) {
this(ontology, Collections.<InputStream>emptyList());
this(ontology, Collections.emptyList());
}

public InputStreamConverter(InputStream ontology, Collection<InputStream> necessaryExternals) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.nodes.datatypes.VowlLiteral;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlDatatypeProperty;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlObjectProperty;
import org.semanticweb.owlapi.model.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectVisitor;

public class EntityCreationVisitor implements OWLObjectVisitor {

private VowlData vowlData;
private Logger logger = LogManager.getLogger(EntityCreationVisitor.class);

public EntityCreationVisitor(VowlData vowlData) {
this.vowlData = vowlData;
Expand All @@ -28,6 +36,7 @@ public void visit(OWLClass ce) {
clazz = new VowlClass(ce.getIRI());
} else {
// TODO Anonymous behaviour undefined
logger.info("Anonymous OWLClass " + ce);
return;
}

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

if(!property.isAnonymous()) {
if (!property.isAnonymous()) {
prop = new VowlObjectProperty(property.getIRI());
} else {
// TODO anonymous behaviour
logger.info("Anonymous OWLObjectProperty " + property);
return;
}

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

if(!property.isAnonymous()) {
if (!property.isAnonymous()) {
prop = new VowlDatatypeProperty(property.getIRI());
} else {
// TODO anonymous behaviour
logger.info("Anonymous OWLDataProperty " + property);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void visit(OWLObjectIntersectionOf ce) {
node.addAttribute(VowlAttribute.INTERSECTION);
} else {
// TODO Anonymous undefined behaviour
logger.info("Anonymous exists in intersections.");
logger.info("Anonymous exists in intersections. " + operand);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlDatatypeProperty;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlObjectProperty;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.visitor.VowlPropertyVisitor;

import java.util.Collection;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.semanticweb.owlapi.model.IRI;

import java.util.Collection;
import java.util.Set;

/**
* Class which is responsible to fill the Domain/Range of properties regarding the VOWL specification.
*
* @author Eduard
*/
public class DomainRangeFiller implements VowlPropertyVisitor {
Expand All @@ -37,23 +36,28 @@ public DomainRangeFiller(VowlData vowlData, Collection<? extends AbstractPropert
public void execute() {
fillEmpty();
mergeMulti();
processInverseProperties();
}

private void fillEmpty() {
values.forEach(element -> {
if (element instanceof HasReference) {
//Ignore references cause they do not need generated Domain/Range
return;
}
try {
element.accept(this);
} catch (Exception e){
logger.info(" DomainRange Filler faild to accept element");
logger.info(" Element: "+element);
logger.info(" Reason: "+e);
logger.info(" SKIPPING THIS ELEMENT *****");
}
});
values.stream()
// Only process props which have empty domain/range
.filter(property -> property.getDomains().isEmpty() || property.getRanges().isEmpty())
// skip inverse properties
.filter(property -> property.getInverse() == null)
.forEach(this::processProperty);
}

private void processProperty(AbstractProperty property) {
if (property instanceof HasReference) {
//Ignore references cause they do not need generated Domain/Range
return;
}
try {
property.accept(this);
} catch (Exception e) {
logger.error("Exception during processing property: " + e + " with message: " + e.getMessage() + " | Skip");
}
}

private VowlThing searchForConnectedThing(Set<IRI> value) {
Expand All @@ -79,6 +83,29 @@ private void mergeMulti() {
}
}

private void processInverseProperties() {
values.stream()
.filter(property -> property.getInverse() != null)
.filter(property -> property.getDomains().isEmpty() || property.getRanges().isEmpty())
.peek(this::fillWithInverse)
.filter(property -> property.getDomains().isEmpty() || property.getRanges().isEmpty())
.forEach(this::processProperty);
}

private void fillWithInverse(AbstractProperty property) {
AbstractProperty inverse = vowlData.getPropertyForIri(property.getInverse());

if (property.getDomains().isEmpty() && inverse.getJsonRange() != null) {
property.getDomains().add(inverse.getJsonRange());
logger.debug("Filled inverse property domain " + property + " with " + inverse.getJsonRange());
}

if (property.getRanges().isEmpty() && inverse.getJsonDomain() != null) {
property.getRanges().add(inverse.getJsonDomain());
logger.debug("Filled inverse property range " + property + " with " + inverse.getJsonDomain());
}
}

@Override
public void visit(VowlObjectProperty vowlObjectProperty) {
classBehaviour(vowlObjectProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

@RunWith(Suite.class)
@Suite.SuiteClasses({
ComparisonHelperTest.class,
ConsoleMainTest.class,
OntobenchTest.class,
ComparisonHelperTest.class
PropertyTest.class
})
public class CompleteTestSuite extends TestSuite {

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/de/uni_stuttgart/vis/vowl/owl2vowl/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.uni_stuttgart.vis.vowl.owl2vowl;

import org.semanticweb.owlapi.model.IRI;

public class Constants {

public static final String OWL2VOWL_NAMESPACE = "https://owl2vowl.de/";

public static IRI getIRIWithTestNamespace(String entityIRI) {
return IRI.create(OWL2VOWL_NAMESPACE + entityIRI);
}
}
27 changes: 27 additions & 0 deletions src/test/java/de/uni_stuttgart/vis/vowl/owl2vowl/PropertyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.uni_stuttgart.vis.vowl.owl2vowl;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import de.uni_stuttgart.vis.vowl.owl2vowl.model.data.VowlData;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.AbstractProperty;
import org.junit.Test;


public class PropertyTest {

@Test
public void shouldProcessAnonymousInverseRelationCorrectly() {
TestConverter converter = new TestConverter(getClass().getResourceAsStream("/inverse-anonym-test.ttl"));
VowlData data = converter.getConvertedData();

AbstractProperty propertyA = data.getPropertyForIri(Constants.getIRIWithTestNamespace("propertyA"));
AbstractProperty propertyB = data.getPropertyForIri(Constants.getIRIWithTestNamespace("propertyB"));

assertThat(propertyA.getJsonDomain(), is(Constants.getIRIWithTestNamespace("classA")));
assertThat(propertyA.getJsonRange(), is(Constants.getIRIWithTestNamespace("classB")));

assertThat(propertyB.getJsonDomain(), is(Constants.getIRIWithTestNamespace("classB")));
assertThat(propertyB.getJsonRange(), is(Constants.getIRIWithTestNamespace("classA")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.uni_stuttgart.vis.vowl.owl2vowl;

import de.uni_stuttgart.vis.vowl.owl2vowl.converter.InputStreamConverter;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.data.VowlData;
import java.io.InputStream;

public class TestConverter extends InputStreamConverter {

public TestConverter(InputStream ontology) {
super(ontology);
}

public VowlData getConvertedData() {
if (!this.initialized) {
this.convert();
}
return this.vowlData;
}
}
28 changes: 28 additions & 0 deletions src/test/resources/inverse-anonym-test.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#################################PREFIXES################################

@prefix : <https://owl2vowl.de/> .
@prefix this: <https://owl2vowl.de/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

#################################ONTOLOGY#################################

this:schema
a owl:Ontology ;
dcterms:title "OWL2VOWL Testing" ;
.

#################################ENTITIES##################################

:propertyA
a owl:ObjectProperty ;
rdfs:domain :classA ;
rdfs:range :classB ;
.
:propertyB
owl:inverseOf :propertyA ;
.
37 changes: 37 additions & 0 deletions src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Properties>
<Property name="PID">????</Property>
<Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
<Property name="LOG_LEVEL_PATTERN">%5p</Property>
<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}
%clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}
</Property>
<Property name="FILE_LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN} ${sys:PID} --- [%t] %-40.40c{1.} :
%m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}
</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error"/>
<Logger name="org.apache.catalina.util.LifecycleBase" level="error"/>
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn"/>
<logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn"/>
<Logger name="org.crsh.plugin" level="warn"/>
<logger name="org.crsh.ssh" level="warn"/>
<Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error"/>
<Logger name="org.hibernate.validator.internal.util.Version" level="warn"/>
<logger name="org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration" level="warn"/>
<logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
<logger name="org.thymeleaf" level="warn"/>
<logger name="de.uni_stuttgart.vis.vowl.owl2vowl" level="debug"/>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

0 comments on commit e524ca7

Please sign in to comment.