Commit 1930a4ed authored by acoburn's avatar acoburn
Browse files

Rename 'validation' service to reflect what it actually does, namely: type inference

parent 4610c0f0
......@@ -24,12 +24,12 @@ Services
These modules provide particular services, independent of Fedora Resources.
* `acrepo-services-inference`: An OSGi-based structural typing service using owl inference
* `acrepo-services-jsonld`: This service creates expanded or compact JSON-LD representations of input documents
* `acrepo-services-ldcache`: This service dereferences and caches URIs, retrieving the `object` of particular triples on demand
* `acrepo-services-ldcache-file`: A file-based backend for the `acrepo-services-ldcache` service
* `acrepo-services-mint`: This mints random (public) URIs for use with Fedora resources
* `acrepo-services-pcdm`: This makes it easy to work with PCDM objects
* `acrepo-services-validation`: An OSGi-based validation service
Connectors
----------
......@@ -79,12 +79,12 @@ command from its shell:
feature:install acrepo-exts-serialize-xml
feature:install acrepo-exts-template
feature:install acrepo-services-inference
feature:install acrepo-services-jsonld
feature:install acrepo-services-ldcache
feature:install acrepo-services-ldcache-file
feature:install acrepo-services-mint
feature:install acrepo-services-pcdm
feature:install acrepo-services-validation
More information
----------------
......
......@@ -83,7 +83,7 @@ public class AcrepoServicesIT extends AbstractOSGiIT {
"acrepo-libs-jena", "acrepo-libs-sesame", "acrepo-libs-jsonld",
"acrepo-libs-jackson", "acrepo-libs-marmotta",
"acrepo-services-jsonld", "acrepo-services-ldcache",
"acrepo-services-mint", "acrepo-services-pcdm", "acrepo-services-validation",
"acrepo-services-mint", "acrepo-services-pcdm", "acrepo-services-inference",
"acrepo-connector-broadcast"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.fits.cfg", "rest.port", fitsPort),
......@@ -115,10 +115,10 @@ public class AcrepoServicesIT extends AbstractOSGiIT {
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-libs-jsonld")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-libs-marmotta")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-libs-sesame")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-inference")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-jsonld")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-ldcache")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-mint")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-pcdm")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-validation")));
}
}
......@@ -38,7 +38,7 @@
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-services-validation</artifactId>
<artifactId>acrepo-services-inference</artifactId>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
......
......@@ -108,14 +108,12 @@
<bundle>mvn:edu.amherst.acdc/acrepo-services-pcdm/${project.version}</bundle>
</feature>
<feature name="acrepo-services-validation" version="${project.version}">
<details>Installs the validation service</details>
<feature name="acrepo-services-inference" version="${project.version}">
<details>Installs the inference service</details>
<feature version="${project.version}">acrepo-libs-jena</feature>
<bundle>mvn:edu.amherst.acdc/acrepo-services-validation/${project.version}</bundle>
<configfile finalname="/etc/edu.amherst.acdc.services.validation.cfg">mvn:edu.amherst.acdc/acrepo-services-validation/${project.version}/cfg/configuration</configfile>
<bundle>mvn:edu.amherst.acdc/acrepo-services-inference/${project.version}</bundle>
</feature>
<feature name="acrepo-exts-serialize-xml" version="${project.version}">
......
......@@ -78,7 +78,7 @@ public class KarafIT {
final String version = cm.getProperty("project.version");
final String acrepoIdiomatic = getBundleUri("acrepo-connector-idiomatic", version);
final String acrepoPcdmSvc = getBundleUri("acrepo-services-pcdm", version);
final String acrepoValidationSvc = getBundleUri("acrepo-services-validation", version);
final String acrepoInferenceSvc = getBundleUri("acrepo-services-inference", version);
final String acrepoJsonLdSvc = getBundleUri("acrepo-services-jsonld", version);
final String acrepoJsonLd = getBundleUri("acrepo-exts-jsonld", version);
final String acrepoMintSvc = getBundleUri("acrepo-services-mint", version);
......@@ -113,14 +113,14 @@ public class KarafIT {
mavenBundle().groupId("com.github.andrewoma.dexx").artifactId("collection").versionAsInProject(),
CoreOptions.systemProperty("acdc.idiomatic-bundle").value(acrepoIdiomatic),
CoreOptions.systemProperty("acdc.validation-svc-bundle").value(acrepoValidationSvc),
CoreOptions.systemProperty("acdc.inference-svc-bundle").value(acrepoInferenceSvc),
CoreOptions.systemProperty("acdc.jsonld-bundle").value(acrepoJsonLd),
CoreOptions.systemProperty("acdc.jsonld-svc-bundle").value(acrepoJsonLdSvc),
CoreOptions.systemProperty("acdc.mint-svc-bundle").value(acrepoMintSvc),
CoreOptions.systemProperty("acdc.pcdm-svc-bundle").value(acrepoPcdmSvc),
bundle(acrepoIdiomatic).start(),
bundle(acrepoValidationSvc).start(),
bundle(acrepoInferenceSvc).start(),
bundle(acrepoJsonLd).start(),
bundle(acrepoJsonLdSvc).start(),
bundle(acrepoMintSvc).start(),
......@@ -144,7 +144,7 @@ public class KarafIT {
assertNotNull(bundleContext);
assertEquals(ACTIVE, bundleContext.getBundle(System.getProperty("acdc.idiomatic-bundle")).getState());
assertEquals(ACTIVE, bundleContext.getBundle(System.getProperty("acdc.validation-svc-bundle")).getState());
assertEquals(ACTIVE, bundleContext.getBundle(System.getProperty("acdc.inference-svc-bundle")).getState());
assertEquals(ACTIVE, bundleContext.getBundle(System.getProperty("acdc.jsonld-bundle")).getState());
assertEquals(ACTIVE, bundleContext.getBundle(System.getProperty("acdc.jsonld-svc-bundle")).getState());
assertEquals(ACTIVE, bundleContext.getBundle(System.getProperty("acdc.mint-svc-bundle")).getState());
......
Repository Validation Service
=============================
Repository Inference Service
============================
This OSGi service validates RDF documents using OWL restrictions.
This OSGi service can do structural typing of RDF graphs using OWL restrictions.
It does _not_ do validation!
Building
--------
......@@ -18,5 +19,5 @@ Each of these projects can be deployed in an OSGi container. For example using
command from its shell:
feature:repo-add mvn:edu.amherst.acdc/acrepo-karaf/LATEST/xml/features
feature:install acrepo-services-validation
feature:install acrepo-services-inference
......@@ -9,14 +9,14 @@
<version>1.0.1-SNAPSHOT</version>
</parent>
<artifactId>acrepo-services-validation</artifactId>
<artifactId>acrepo-services-inference</artifactId>
<packaging>bundle</packaging>
<name>RDF Validation service bundle</name>
<description>An OSGi service that validates an RDF document based on a set of OWL restrictions.</description>
<name>RDF inference service bundle</name>
<description>An OSGi service that does structural typing of RDF graphs based on a set of OWL restrictions.</description>
<properties>
<osgi.export.packages>edu.amherst.acdc.services.validation;version=${project.version}</osgi.export.packages>
<osgi.export.packages>edu.amherst.acdc.services.inference;version=${project.version}</osgi.export.packages>
</properties>
<dependencies>
......@@ -79,30 +79,6 @@
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<!-- add configuration file to artifact set for OSGi deployment -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>src/main/cfg/edu.amherst.acdc.services.validation.cfg</file>
<type>cfg</type>
<classifier>configuration</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.services.validation;
package edu.amherst.acdc.services.inference;
import java.io.InputStream;
......@@ -21,18 +21,19 @@ import java.io.InputStream;
* @author acoburn
* @since 6/16/16
*/
public interface ValidationService {
public interface InferenceService {
/**
* Determine whether an RDF graph is valid according to a set of OWL restrictions
* Determine whether an RDF graph has an inferred type, given a set of OWL restrictions
*
* @param subject The subject of the RDF graph
* @param type The inferred type
* @param input The input RDF graph
* @param contentType The mimeType of the input
* @param restrictions any OWL restrictions
* @param restrictionFormat the mimeType of the restriction graph
* @return whether the input document is valid
* @return given the RDF document and restiction set, does the given subject have the provided type
*/
boolean validate(final String subject, final InputStream input, final String contentType,
boolean hasType(final String subject, final String type, final InputStream input, final String contentType,
final InputStream restrictions, final String restrictionFormat);
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.services.validation;
package edu.amherst.acdc.services.inference;
import static org.apache.jena.rdf.model.ModelFactory.createDefaultModel;
import static org.apache.jena.rdf.model.ModelFactory.createInfModel;
......@@ -28,38 +28,21 @@ import java.io.InputStream;
import org.apache.jena.rdf.model.InfModel;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.reasoner.ValidityReport;
import org.slf4j.Logger;
/**
* @author acoburn
* @since 6/16/16
*/
public class ValidationServiceImpl implements ValidationService {
public class InferenceServiceImpl implements InferenceService {
private static final Logger LOGGER = getLogger(ValidationServiceImpl.class);
private static final Logger LOGGER = getLogger(InferenceServiceImpl.class);
private final Resource validationType;
/**
* Instantiate a ValidationService object
* @param validType a URI for the RDF type used for validation.
*/
public ValidationServiceImpl(final String validType) {
this.validationType = createResource(validType);
}
/**
* Generate a compact representation of the input stream
*
* @param input The input JSON document
* @param contextUrl the location of a context URL
* @return the compacted JSON Object
*/
@Override
public boolean validate(final String subject, final InputStream input, final String contentType,
final InputStream restrictions, final String restrictionFormat) {
public boolean hasType(final String subject, final String rdfType, final InputStream input,
final String contentType, final InputStream restrictions, final String restrictionFormat) {
final Resource inferredType = createResource(rdfType);
final Resource subjectResource = createResource(subject);
final Model model = createDefaultModel();
model.read(input, subject, contentTypeToLang(contentType).getName());
......@@ -68,17 +51,13 @@ public class ValidationServiceImpl implements ValidationService {
schema.read(restrictions, null,
contentTypeToLang(restrictionFormat).getName());
if (model.contains(subjectResource, type, inferredType)) {
return true;
}
final InfModel infmodel = createInfModel(getOWLReasoner(), model);
infmodel.add(schema);
final ValidityReport validity = infmodel.validate();
if (validity.isValid()) {
return infmodel.contains(subjectResource, type, validationType);
}
validity.getReports().forEachRemaining(report -> {
LOGGER.warn(report.toString());
});
return false;
return infmodel.contains(subjectResource, type, inferredType);
}
}
......@@ -7,19 +7,11 @@
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd"
default-activation="lazy">
<cm:property-placeholder persistent-id="edu.amherst.acdc.services.validation" update-strategy="reload" >
<cm:default-properties>
<cm:property name="validation.type" value="urn:validation#Valid"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="inferenceServiceBean" class="edu.amherst.acdc.services.inference.InferenceServiceImpl"/>
<bean id="validationServiceBean" class="edu.amherst.acdc.services.validation.ValidationServiceImpl">
<argument value="${validation.type}"/>
</bean>
<service ref="validationServiceBean" interface="edu.amherst.acdc.services.validation.ValidationService">
<service ref="inferenceServiceBean" interface="edu.amherst.acdc.services.inference.InferenceService">
<service-properties>
<entry key="osgi.jndi.service.name" value="validation"/>
<entry key="osgi.jndi.service.name" value="inference"/>
</service-properties>
</service>
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.services.validation;
package edu.amherst.acdc.services.inference;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
......@@ -24,69 +24,70 @@ import org.junit.Test;
* @author acoburn
* @since 6/16/16
*/
public class ValidationServiceTest {
public class InferenceServiceTest {
private final String TURTLE = "text/turtle";
private final String subject = "http://localhost:8080/fcrepo/rest/test";
private final ValidationService svc = new ValidationServiceImpl("urn:validation#Valid");
private final String appType = "urn:app#Complete";
private final InferenceService svc = new InferenceServiceImpl();
@Test
public void testValidateIsEquivalentClass() {
assertTrue(svc.validate(subject,
public void testIsEquivalentClass() {
assertTrue(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/isResource.ttl"), TURTLE));
}
@Test
public void testValidateIsNotEquivalentClass() {
assertFalse(svc.validate(subject,
public void testIsNotEquivalentClass() {
assertFalse(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/isBinary.ttl"), TURTLE));
}
@Test
public void testValidateHasValue() {
assertTrue(svc.validate(subject,
public void testHasValue() {
assertTrue(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/hasValue.ttl"), TURTLE));
}
@Test
public void testValidateCardinality() {
assertTrue(svc.validate(subject,
public void testCardinality() {
assertTrue(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/hasPrefLabel.ttl"), TURTLE));
}
@Test
public void testValidateResourceSubClass() {
assertTrue(svc.validate(subject,
public void testResourceSubClass() {
assertTrue(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/isResourceSubClass.ttl"), TURTLE));
}
@Test
public void testValidateIntersectionOf() {
assertTrue(svc.validate(subject,
public void testIntersectionOf() {
assertTrue(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/intersectionOf.ttl"), TURTLE));
}
@Test
public void testValidateUnionOf() {
assertTrue(svc.validate(subject,
public void testUnionOf() {
assertTrue(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/unionOf.ttl"), TURTLE));
}
@Test
public void testValidateApplicationProfile() {
assertTrue(svc.validate(subject,
public void testApplicationProfile() {
assertTrue(svc.hasType(subject, appType,
getClass().getResourceAsStream("/resource.ttl"), TURTLE,
getClass().getResourceAsStream("/applicationProfile.ttl"), TURTLE));
}
}
......@@ -2,11 +2,11 @@
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix fedora: <http://fedora.info/definitions/v4/repository#> .
@prefix validation: <urn:validation#> .
@prefix app: <urn:app#> .
@prefix pcdm: <http://pcdm.org/models#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
validation:Valid owl:equivalentClass [
app:Complete owl:equivalentClass [
owl:intersectionOf (
pcdm:Object
[ a owl:Restriction ;
......
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix validation: <urn:validation#> .
@prefix app: <urn:app#> .
validation:Valid owl:equivalentClass [ a owl:Restriction ;
app:Complete owl:equivalentClass [ a owl:Restriction ;
owl:onProperty skos:prefLabel ;
owl:minCardinality "1"^^xsd:nonNegativeInteger ] .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix fedora: <http://fedora.info/definitions/v4/repository#> .
@prefix validation: <urn:validation#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix app: <urn:app#> .
validation:Valid owl:equivalentClass [ a owl:Restriction ;
app:Complete owl:equivalentClass [ a owl:Restriction ;
owl:onProperty fedora:numberOfChildren ;
owl:hasValue "6"^^xsd:long ] .
......@@ -2,9 +2,9 @@
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix fedora: <http://fedora.info/definitions/v4/repository#> .
@prefix validation: <urn:validation#> .
@prefix app: <urn:app#> .
validation:Valid owl:equivalentClass [
app:Complete owl:equivalentClass [
owl:intersectionOf (
[ a owl:Restriction ;
owl:onProperty skos:prefLabel ;
......
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix fedora: <http://fedora.info/definitions/v4/repository#> .
@prefix validation: <urn:validation#> .
@prefix app: <urn:app#> .
validation:Valid owl:equivalentClass fedora:Binary .
app:Complete owl:equivalentClass fedora:Binary .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix fedora: <http://fedora.info/definitions/v4/repository#> .
@prefix validation: <urn:validation#> .
@prefix app: <urn:app#> .
validation:Valid owl:equivalentClass fedora:Resource .
app:Complete owl:equivalentClass fedora:Resource .
@prefix fedora: <http://fedora.info/definitions/v4/repository#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix validation: <urn:validation#> .
@prefix app: <urn:app#> .
fedora:Resource rdfs:subClassOf validation:Valid .
fedora:Resource rdfs:subClassOf app:Complete .
......@@ -7,7 +7,7 @@
</encoder>
</appender>
<logger name="edu.amherst.acdc.services.validation" additivity="false" level="INFO">
<logger name="edu.amherst.acdc.services.inference" additivity="false" level="INFO">
<appender-ref ref="STDOUT"/>
</logger>
<root additivity="false" level="INFO">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment