Skip to content

Commit

Permalink
ont-api: refactoring transformers subsystem (issue #4) - moving/renam…
Browse files Browse the repository at this point in the history
…ing/removing classes, changing docs
  • Loading branch information
sszuev committed Dec 31, 2019
1 parent 303f712 commit 93518ef
Show file tree
Hide file tree
Showing 31 changed files with 1,057 additions and 957 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.github.owlcs.ontapi;

import com.github.owlcs.ontapi.jena.utils.Graphs;
import com.github.owlcs.ontapi.transforms.TransformationModel;
import org.apache.jena.atlas.web.ContentType;
import org.apache.jena.graph.Graph;
import org.apache.jena.riot.Lang;
Expand Down Expand Up @@ -67,7 +68,7 @@ public abstract class OntGraphDocumentSource implements OWLOntologyDocumentSourc
* Answers if the graph must be put in order by the transformations mechanism.
*
* @return {@code true} if graph transformations is allowed
* @see com.github.owlcs.ontapi.transforms.Transform
* @see TransformationModel
* @since 1.3.2
*/
public boolean withTransforms() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/github/owlcs/ontapi/OntGraphUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.github.owlcs.ontapi.jena.model.OntModel;
import com.github.owlcs.ontapi.jena.utils.Graphs;
import com.github.owlcs.ontapi.jena.utils.Models;
import com.github.owlcs.ontapi.transforms.GraphTransformers;
import com.github.owlcs.ontapi.transforms.GraphStats;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.jena.graph.*;
import org.apache.jena.rdf.model.impl.ModelCom;
Expand Down Expand Up @@ -225,11 +225,11 @@ public static RDFLiteral literal(Node node) throws IllegalArgumentException {
* Auxiliary method to produce {@link OWLOntologyLoaderMetaData} object.
*
* @param graph {@link Graph}
* @param stats {@link GraphTransformers.Stats} transformation outcome, can be null for fake meta-data
* @param stats {@link GraphStats} transformation outcome, can be null for fake meta-data
* @return {@link OWLOntologyLoaderMetaData} object
* @throws IllegalArgumentException in case {@code graph} and {@code stats} are incompatible
*/
protected static OWLOntologyLoaderMetaData makeParserMetaData(Graph graph, GraphTransformers.Stats stats) {
protected static OWLOntologyLoaderMetaData makeParserMetaData(Graph graph, GraphStats stats) {
if (stats == null)
return OntologyMetaData.createParserMetaData(graph);
if (Graphs.getBase(graph) != stats.getGraph())
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/github/owlcs/ontapi/OntologyLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.github.owlcs.ontapi.jena.utils.Graphs;
import com.github.owlcs.ontapi.jena.utils.OntModels;
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
import com.github.owlcs.ontapi.transforms.GraphTransformers;
import com.github.owlcs.ontapi.transforms.GraphStats;
import com.github.owlcs.ontapi.transforms.TransformException;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.GraphUtil;
Expand Down Expand Up @@ -224,7 +224,7 @@ protected UnionGraph makeUnionGraph(GraphInfo info,
return graph;
}
// process transformations
GraphTransformers.Stats stats;
GraphStats stats;
Set<Graph> transformed = graphs.values().stream()
.filter(g -> !g.isFresh() || g.noTransforms())
.map(GraphInfo::getGraph)
Expand All @@ -237,8 +237,8 @@ protected UnionGraph makeUnionGraph(GraphInfo info,
throw new OntologyFactoryImpl.OWLTransformException(t);
}
info.setStats(stats);
stats.listStats(true)
.filter(GraphTransformers.Stats::isNotEmpty)
stats.stats(true)
.filter(GraphStats::isNotEmpty)
.forEach(s -> {
String uri = Graphs.getURI(s.getGraph());
if (uri == null) {
Expand Down Expand Up @@ -697,7 +697,7 @@ public static class GraphInfo {
private boolean fresh, transforms;
private Node ontology;
private Set<String> imports;
private GraphTransformers.Stats stats;
private GraphStats stats;

protected GraphInfo(Graph graph, OntFormat format, IRI source, boolean withTransforms) {
this.graph = graph;
Expand Down Expand Up @@ -755,11 +755,11 @@ protected IRI getSource() {
return source;
}

public GraphTransformers.Stats getStats() {
public GraphStats getStats() {
return stats;
}

protected void setStats(GraphTransformers.Stats stats) {
protected void setStats(GraphStats stats) {
this.stats = Objects.requireNonNull(stats, "Null transform stats");
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/github/owlcs/ontapi/OntologyMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.github.owlcs.ontapi.jena.utils.Graphs;
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
import com.github.owlcs.ontapi.jena.vocabulary.RDF;
import com.github.owlcs.ontapi.transforms.GraphTransformers;
import com.github.owlcs.ontapi.transforms.GraphStats;
import com.github.owlcs.ontapi.transforms.OWLIDTransform;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
Expand All @@ -43,12 +43,12 @@

/**
* Implementation of {@link OWLOntologyLoaderMetaData}.
* A wrapper for {@link GraphTransformers.Stats Transformation Stats} to satisfy OWL-API.
* A wrapper for {@link GraphStats Transformation Stats} to satisfy OWL-API.
* Constructed while loading to provide some additional information about runtime changes in the source.
* <p>
* Created by @szuev on 28.06.2018.
*
* @see GraphTransformers.Stats
* @see GraphStats
*/
@SuppressWarnings("WeakerAccess")
public class OntologyMetaData implements OWLOntologyLoaderMetaData {
Expand Down Expand Up @@ -94,26 +94,26 @@ public static OntologyMetaData createParserMetaData(Graph graph) {

/**
* A factory method.
* Creates {@link OWLOntologyLoaderMetaData} from the given {@link GraphTransformers.Stats Transformation Stats}.
* Creates {@link OWLOntologyLoaderMetaData} from the given {@link GraphStats Transformation Stats}.
*
* @param stats not null
* @return {@link OntologyMetaData} instance, not null
*/
public static OntologyMetaData createParserMetaData(GraphTransformers.Stats stats) {
public static OntologyMetaData createParserMetaData(GraphStats stats) {
Graph graph = Graphs.getBase(Objects.requireNonNull(stats, "Null graph").getGraph());
RDFOntologyHeaderStatus header = RDFOntologyHeaderStatus.PARSED_ONE_HEADER;
String idKey = OWLIDTransform.class.getSimpleName();
if (stats.hasTriples(GraphTransformers.Stats.Type.ADDED, idKey)) {
if (stats.hasTriples(GraphStats.Type.ADDED, idKey)) {
header = RDFOntologyHeaderStatus.PARSED_ZERO_HEADERS;
}
if (stats.hasTriples(GraphTransformers.Stats.Type.DELETED, idKey)) {
if (stats.hasTriples(GraphStats.Type.DELETED, idKey)) {
header = RDFOntologyHeaderStatus.PARSED_MULTIPLE_HEADERS;
}
Set<RDFTriple> unparsed = stats.triples(GraphTransformers.Stats.Type.UNPARSED)
Set<RDFTriple> unparsed = stats.triples(GraphStats.Type.UNPARSED)
.map(OntGraphUtils::triple)
.collect(Collectors.toSet());
ArrayListMultimap<IRI, Class<? extends OWLObject>> guessedDeclarations = ArrayListMultimap.create();
stats.triples(GraphTransformers.Stats.Type.ADDED)
stats.triples(GraphStats.Type.ADDED)
.collect(Collectors.toSet())
.forEach(t -> {
// note: anonymous subject also wrapped as iri
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/owlcs/ontapi/config/LoadControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ interface LoadControl<R> extends LoadSettings {
/**
* Sets {@code GraphTransformers.Store} collection.
*
* @param t {@link GraphTransformers.Store}, not {@code null}
* @param t {@link GraphTransformers}, not {@code null}
* @return {@link R} (this or copied instance)
* @see LoadSettings#getGraphTransformers()
* @see LoadSettings#isPerformTransformation()
*/
R setGraphTransformers(GraphTransformers.Store t);
R setGraphTransformers(GraphTransformers t);

/**
* Disables or enables the Graph Transformation mechanism depending on the given flag.
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/github/owlcs/ontapi/config/LoadSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.github.owlcs.ontapi.*;
import com.github.owlcs.ontapi.jena.impl.conf.OntPersonality;
import com.github.owlcs.ontapi.jena.model.OntModel;
import com.github.owlcs.ontapi.transforms.GraphFilter;
import com.github.owlcs.ontapi.transforms.GraphTransformers;
import org.apache.jena.graph.Graph;
import org.semanticweb.owlapi.model.IRI;
Expand Down Expand Up @@ -51,7 +52,7 @@ public interface LoadSettings {
OntPersonality getPersonality();

/**
* Gets {@link GraphTransformers.Store Transformers Store}.
* Gets {@link GraphTransformers Transformers Store}.
* <p>
* Transformers Store is a collection of actions that are performed on {@code Graph} before
* it enters into the main system.
Expand All @@ -61,22 +62,22 @@ public interface LoadSettings {
* or {@link Ontology Axiomatic Model}, but without a proper transformation
* you might not found valid {@link org.semanticweb.owlapi.model.OWLAxiom Axiom}s inside that data.
* Transformations can be simply disabled through
* the method {@link LoadControl#setGraphTransformers(GraphTransformers.Store)}.
* the method {@link LoadControl#setGraphTransformers(GraphTransformers)}.
* It is recommended to do this in case there is confidence that the data is OWL2,
* since transformations may take significant processor time.
* With the method {@link GraphTransformers.Store#setFilter(GraphTransformers.Filter)}
* With the method {@link GraphTransformers#setFilter(GraphFilter)}
* a whole graph family may be skipped from transformation process.
* And there is one more facility to selectively turn off transformations:
* the method {@link OntGraphDocumentSource#withTransforms()},
* which is used while passing externally loaded graph into the manager
* (see {@link OntologyManager#addOntology(Graph)}.
*
* @return {@link GraphTransformers.Store}
* @see LoadControl#setGraphTransformers(GraphTransformers.Store)
* @return {@link GraphTransformers}
* @see LoadControl#setGraphTransformers(GraphTransformers)
* @see LoadControl#setPerformTransformation(boolean)
* @see OntSettings#ONT_API_LOAD_CONF_TRANSFORMERS
*/
GraphTransformers.Store getGraphTransformers();
GraphTransformers getGraphTransformers();

/**
* Answers {@code true} if the mechanism of graph transformers is enabled, which is {@code true} by default.
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/github/owlcs/ontapi/config/OntConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

package com.github.owlcs.ontapi.config;

import org.semanticweb.owlapi.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.owlcs.ontapi.NoOpReadWriteLock;
import com.github.owlcs.ontapi.OntApiException;
import com.github.owlcs.ontapi.jena.impl.conf.OntPersonality;
import com.github.owlcs.ontapi.transforms.GraphTransformers;
import org.semanticweb.owlapi.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.io.IOException;
Expand All @@ -44,7 +44,7 @@
* <li>{@link #setModelCacheLevel(int, boolean)} (<b>since 1.4.2</b>), {@link #setModelCacheLevel(int)} (<b>since 1.4.0</b>)</li>
* <li>{@link #useContentCache()}, {@link #useComponentCache()}, {@link #useIteratorCache()} (<b>since 1.4.2</b>)</li>
* <li>{@link #getPersonality()} and {@link #setPersonality(OntPersonality)}</li>
* <li>{@link #getGraphTransformers()} amd {@link #setGraphTransformers(GraphTransformers.Store)}</li>
* <li>{@link #getGraphTransformers()} amd {@link #setGraphTransformers(GraphTransformers)}</li>
* <li>{@link #isPerformTransformation()} and {@link #setPerformTransformation(boolean)}</li>
* <li>{@link #isProcessImports()} and {@link #setProcessImports(boolean)} (<b>since 1.4.1</b>)</li>
* <li>{@link #getSupportedSchemes()} and {@link #setSupportedSchemes(List)}</li>
Expand Down Expand Up @@ -253,20 +253,20 @@ public OntConfig setPersonality(OntPersonality p) {
* {@inheritDoc}
*/
@Override
public GraphTransformers.Store getGraphTransformers() {
public GraphTransformers getGraphTransformers() {
return get(OntSettings.ONT_API_LOAD_CONF_TRANSFORMERS);
}

/**
* An ONT-API manager's load config setter.
* {@inheritDoc}
*
* @param t {@link com.github.owlcs.ontapi.transforms.GraphTransformers.Store}
* @param t {@link GraphTransformers}
* @return this instance
* @see OntLoaderConfiguration#setGraphTransformers(GraphTransformers.Store)
* @see OntLoaderConfiguration#setGraphTransformers(GraphTransformers)
*/
@Override
public OntConfig setGraphTransformers(GraphTransformers.Store t) {
public OntConfig setGraphTransformers(GraphTransformers t) {
return put(OntSettings.ONT_API_LOAD_CONF_TRANSFORMERS, t);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

package com.github.owlcs.ontapi.config;

import org.semanticweb.owlapi.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.owlcs.ontapi.OntApiException;
import com.github.owlcs.ontapi.jena.impl.conf.OntPersonality;
import com.github.owlcs.ontapi.transforms.GraphTransformers;
import org.semanticweb.owlapi.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.io.IOException;
Expand Down Expand Up @@ -145,19 +145,19 @@ public OntLoaderConfiguration setPerformTransformation(boolean b) {
* {@inheritDoc}
*/
@Override
public GraphTransformers.Store getGraphTransformers() {
public GraphTransformers getGraphTransformers() {
return get(OntSettings.ONT_API_LOAD_CONF_TRANSFORMERS);
}

/**
* An ONT-API config setter.
* {@inheritDoc}
*
* @param t {@link GraphTransformers.Store} new graph transformers store
* @param t {@link GraphTransformers} new graph transformers store
* @return {@link OntLoaderConfiguration}, a copied (new) or this instance in case no changes is made
*/
@Override
public OntLoaderConfiguration setGraphTransformers(GraphTransformers.Store t) {
public OntLoaderConfiguration setGraphTransformers(GraphTransformers t) {
return set(OntSettings.ONT_API_LOAD_CONF_TRANSFORMERS, t);
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/github/owlcs/ontapi/config/OntSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

package com.github.owlcs.ontapi.config;

import com.github.owlcs.ontapi.OntApiException;
import com.github.owlcs.ontapi.jena.impl.conf.OntModelConfig;
import com.github.owlcs.ontapi.jena.vocabulary.*;
import com.github.owlcs.ontapi.transforms.*;
import org.apache.jena.vocabulary.RDFS;
import org.semanticweb.owlapi.model.MissingImportHandlingStrategy;
import org.semanticweb.owlapi.model.MissingOntologyHeaderStrategy;
import org.semanticweb.owlapi.model.PriorityCollectionSorting;
import org.semanticweb.owlapi.model.parameters.ConfigurationOptions;
import com.github.owlcs.ontapi.OntApiException;
import com.github.owlcs.ontapi.jena.impl.conf.OntModelConfig;
import com.github.owlcs.ontapi.jena.vocabulary.*;
import com.github.owlcs.ontapi.transforms.*;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -133,20 +133,20 @@ OntModelConfig.StdMode getPersonalityMode() {
, SWRLTransform.class) {
@Override
public Object getDefaultValue() {
GraphTransformers.Store res = new GraphTransformers.Store();
for (Class<? extends Transform> c : getTransformTypes()) {
res = res.add(new GraphTransformers.DefaultMaker(c));
GraphTransformers res = new GraphTransformers();
for (Class<? extends TransformationModel> c : getTransformTypes()) {
res = res.addLast(Transform.Factory.create(c));
}
return res;
}

@SuppressWarnings("unchecked")
List<Class<? extends Transform>> getTransformTypes() {
List<Class<? extends TransformationModel>> getTransformTypes() {
List<?> res = PROPERTIES.getListProperty(key);
if (res == null) {
res = (List<?>) secondary;
}
return (List<Class<? extends Transform>>) res;
return (List<Class<? extends TransformationModel>>) res;
}
};

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/github/owlcs/ontapi/jena/OntVocabulary.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.github.owlcs.ontapi.jena.utils.Iter;
import com.github.owlcs.ontapi.jena.vocabulary.*;
import com.github.owlcs.ontapi.transforms.GraphTransformers;
import org.apache.jena.datatypes.BaseDatatype;
import org.apache.jena.datatypes.RDFDatatype;
import org.apache.jena.datatypes.TypeMapper;
Expand Down Expand Up @@ -194,7 +195,7 @@ default Set<Resource> getBuiltinOWLEntities() {
* from the packages {@link com.github.owlcs.ontapi.jena.vocabulary} and {@link org.apache.jena.vocabulary}
* (such as {@link OWL}).
* In ONT-API, a {@link OntVocabulary} is used to build {@link com.github.owlcs.ontapi.jena.impl.conf.OntPersonality}
* and in {@link com.github.owlcs.ontapi.transforms.GraphTransformers} subsystem.
* and in {@link GraphTransformers} subsystem.
* <p>
* Created by @szuev on 21.12.2016.
*/
Expand Down Expand Up @@ -355,6 +356,7 @@ private static <X> Set<X> toUnmodifiableSet(Collection<X> input) {
*/
@SuppressWarnings("WeakerAccess")
protected static class OWLImpl extends Impl {
private static final Class<?>[] VOCABULARIES = new Class<?>[]{XSD.class, RDF.class, RDFS.class, OWL.class};
/**
* The list of datatypes from owl-2 specification (35 types)
* (see <a href='https://www.w3.org/TR/owl2-quick-reference/'>Quick References, 3.1 Built-in Datatypes</a>).
Expand Down Expand Up @@ -383,7 +385,6 @@ protected static class OWLImpl extends Impl {
Stream.of(OWL.topDataProperty, OWL.bottomDataProperty).collect(Iter.toUnmodifiableSet());
public static final Set<Property> OBJECT_PROPERTIES =
Stream.of(OWL.topObjectProperty, OWL.bottomObjectProperty).collect(Iter.toUnmodifiableSet());
private static final Class<?>[] VOCABULARIES = new Class<?>[]{XSD.class, RDF.class, RDFS.class, OWL.class};
public static final Set<Property> PROPERTIES = getConstants(Property.class, VOCABULARIES);
public static final Set<Resource> RESOURCES = getConstants(Resource.class, VOCABULARIES);

Expand Down Expand Up @@ -453,8 +454,8 @@ protected SKOSImpl() {
* @see SWRLB
*/
protected static class SWRLImpl extends Impl {
public static final Set<Resource> BUILTINS = getConstants(Property.class, SWRLB.class);
private static final Class<?>[] VOCABULARIES = new Class<?>[]{SWRL.class, SWRLB.class};
public static final Set<Resource> BUILTINS = getConstants(Property.class, SWRLB.class);
public static final Set<Property> PROPERTIES = getConstants(Property.class, VOCABULARIES);
public static final Set<Resource> RESOURCES = getConstants(Resource.class, VOCABULARIES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* The collection of base methods for {@link ManifestDeclarator} and {@link ReasonerDeclarator}
*/
@SuppressWarnings({"WeakerAccess", "UnusedReturnValue"})
public abstract class BaseDeclarator extends Transform {
public abstract class BaseDeclarator extends TransformationModel {
private static final List<Property> RESTRICTION_PROPERTY_MARKERS = Stream.of(OWL.onProperty, OWL.allValuesFrom,
OWL.someValuesFrom, OWL.hasValue, OWL.onClass,
OWL.onDataRange, OWL.cardinality, OWL.qualifiedCardinality,
Expand Down
Loading

0 comments on commit 93518ef

Please sign in to comment.