Skip to content

Commit

Permalink
ont-api: split into jena & ontapi modules (issue #44), related refact…
Browse files Browse the repository at this point in the history
…oring, cleanup (code, javadocs, test-resources)
  • Loading branch information
sszuev committed Dec 10, 2022
1 parent 764c101 commit ecb5ca9
Show file tree
Hide file tree
Showing 969 changed files with 18,821 additions and 8,560 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ nohup.out

/out/
/target/
/jena/.flattened-pom.xml
/.flattened-pom.xml
/ontapi/.flattened-pom.xml
60 changes: 60 additions & 0 deletions jena/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ This file is part of the ONT API.
~ The contents of this file are subject to the LGPL License, Version 3.0.
~ Copyright (c) 2022, owl.cs group.
~
~ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
~ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
~
~ Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0 in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
~ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.owlcs</groupId>
<artifactId>ontapi-parent</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>jena</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the ONT API.
* The contents of this file are subject to the LGPL License, Version 3.0.
* Copyright (c) 2019, The University of Manchester, owl.cs group.
* Copyright (c) 2022, owl.cs group.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void init() {
* Creates default (in-memory) graph implementation.
*
* @return {@code GraphMem}
* @see org.apache.jena.graph.Factory#createGraphMem()
* @see Factory#createGraphMem()
*/
public static Graph createDefaultGraph() {
return Factory.createDefaultGraph();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the ONT API.
* The contents of this file are subject to the LGPL License, Version 3.0.
* Copyright (c) 2021, owl.cs group.
* Copyright (c) 2022, owl.cs group.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand All @@ -14,7 +14,11 @@

package com.github.owlcs.ontapi.jena;

import com.github.owlcs.ontapi.jena.vocabulary.*;
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
import com.github.owlcs.ontapi.jena.vocabulary.RDF;
import com.github.owlcs.ontapi.jena.vocabulary.SWRL;
import com.github.owlcs.ontapi.jena.vocabulary.SWRLB;
import com.github.owlcs.ontapi.jena.vocabulary.XSD;
import org.apache.jena.datatypes.BaseDatatype;
import org.apache.jena.datatypes.RDFDatatype;
import org.apache.jena.datatypes.TypeMapper;
Expand All @@ -27,7 +31,14 @@

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -36,11 +47,11 @@
* This is a generic interface that simply maps an {@code uri}-key to a {@code Set} of
* {@link Resource RDF Resources} or {@link Property RDF Properties},
* that are defined in vocabulary schemas and represent some family determined by that key.
* A schema is an java class containing public static final constants.
* A schema is a java class containing public static final constants.
* Schemas are usually located inside the packages
* {@link com.github.owlcs.ontapi.jena.vocabulary} and {@link org.apache.jena.vocabulary}.
* There are two kind of property/resources described by this vocabulary: system and builtin.
* A system resource/property is simply an URI defined in any scheme.
* A system resource/property is simply a URI defined in any scheme.
* A builtin resource/property is a URI with known type, that does not require explicit declaration.
* Note that all methods of this interface return unmodifiable {@code Set}s.
* <p>
Expand All @@ -52,7 +63,7 @@ public interface OntVocabulary {

/**
* Answers a {@code Set} of system/builtin {@link Resource}s for the specified URI-{@code key}.
* An URI-{@code key} - is a schema URI that determines a family of desired resources.
* A URI-{@code key} - is a schema URI that determines a family of desired resources.
* For example to get all resources a key {@link RDFS#Resource rdfs:Resource} should be used,
* because it is a supertype of everything.
*
Expand Down Expand Up @@ -175,25 +186,14 @@ default Set<Property> getBuiltinOWLProperties() {
.collect(Collectors.toUnmodifiableSet());
}

/**
* Answers a {@code Set} containing all builtin entity resources.
*
* @return {@code Set} of {@link Resource Resources}
*/
default Set<Resource> getBuiltinOWLEntities() {
return Stream.of(getBuiltinClasses(), getBuiltinDatatypes(), getBuiltinOWLProperties())
.flatMap(Collection::stream)
.collect(Collectors.toUnmodifiableSet());
}

/**
* A factory-helper to work with {@link OntVocabulary} instances, that wrap constant-holders
* from the packages {@link com.github.owlcs.ontapi.jena.vocabulary}
* and {@link org.apache.jena.vocabulary} (such as {@link OWL}).
* <p>
* In ONT-API, a {@link OntVocabulary} singleton is used
* to build {@link com.github.owlcs.ontapi.jena.impl.conf.OntPersonality}
* and, also, in {@link com.github.owlcs.ontapi.transforms} subsystem.
* and, also, in {@code com.github.owlcs.ontapi.transforms} subsystem.
* <p>
* Created by @szuev on 21.12.2016.
*/
Expand Down Expand Up @@ -356,7 +356,7 @@ 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>).
* (see <a href="https://www.w3.org/TR/owl2-quick-reference/">Quick References, 3.1 Built-in Datatypes</a>).
* It seems it is not full:
*/
public static final Set<Resource> OWL2_DATATYPES =
Expand Down Expand Up @@ -423,8 +423,8 @@ protected static class SKOSImpl extends Impl {
SKOS.narrower, SKOS.narrowerTransitive, SKOS.related,
SKOS.relatedMatch, SKOS.semanticRelation, SKOS.topConceptOf);
/**
* NOTE: In the {@link org.semanticweb.owlapi.vocab.SKOSVocabulary} there is also skos:TopConcept
* But in fact there is no such resource in the <a href='https://www.w3.org/2009/08/skos-reference/skos.htm'>specification</a>.
* NOTE: In the OWLAPI-api {@code org.semanticweb.owlapi.vocab.SKOSVocabulary} there is also skos:TopConcept
* But in fact there is no such resource in the <a href="https://www.w3.org/2009/08/skos-reference/skos.htm">specification</a>.
*/
public static final Set<Resource> CLASSES =
Set.of(SKOS.Collection, SKOS.Concept, SKOS.ConceptScheme, SKOS.OrderedCollection);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the ONT API.
* The contents of this file are subject to the LGPL License, Version 3.0.
* Copyright (c) 2021, owl.cs group.
* Copyright (c) 2022, owl.cs group.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand All @@ -15,7 +15,7 @@
package com.github.owlcs.ontapi.jena;

import com.github.owlcs.ontapi.jena.utils.Graphs;
import com.github.owlcs.ontapi.jena.utils.Iter;
import com.github.owlcs.ontapi.jena.utils.Iterators;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.GraphListener;
import org.apache.jena.graph.Triple;
Expand All @@ -25,11 +25,19 @@
import org.apache.jena.util.CollectionFactory;
import org.apache.jena.util.iterator.ExtendedIterator;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.stream.Stream;

/**
* An Union Graph.
* A Union Graph.
* It consists of two parts: a {@link #base base} graph and an {@link #sub Underlying} graphs collection.
* The difference between {@link org.apache.jena.graph.compose.MultiUnion MultiUnion} and this implementation is that
* this graph explicitly requires primary base graph which is the only one that can be modified directly.
Expand Down Expand Up @@ -226,7 +234,7 @@ protected void resetGraphsCache() {
* @see UnionGraph#getBaseGraph()
*/
public ExtendedIterator<Graph> listBaseGraphs() {
return Iter.create(graphs == null ? graphs = collectBaseGraphs() : graphs);
return Iterators.create(graphs == null ? graphs = collectBaseGraphs() : graphs);
}

/**
Expand All @@ -235,7 +243,7 @@ public ExtendedIterator<Graph> listBaseGraphs() {
* @return <b>distinct</b> {@link ExtendedIterator} of {@link UnionGraph}s
*/
public ExtendedIterator<UnionGraph> listUnionGraphs() {
return Iter.create(collectUnionGraphs());
return Iterators.create(collectUnionGraphs());
}

/**
Expand Down Expand Up @@ -283,7 +291,7 @@ public int graphBaseSize() {
public boolean isEmpty() {
// the default implementation use size(), which is extremely ineffective in general,
// since implies iterating over whole graph
return Iter.findFirst(find()).isEmpty();
return Iterators.findFirst(find()).isEmpty();
}

/**
Expand All @@ -300,14 +308,14 @@ protected ExtendedIterator<Triple> createFindIterator(Triple m) {
return base.find(m);
}
if (!distinct) {
return Iter.flatMap(listBaseGraphs(), x -> x.find(m));
return Iterators.flatMap(listBaseGraphs(), x -> x.find(m));
}
// The logic and the comment below have been copy-pasted from the org.apache.jena.graph.compose.Union:
// To find in the union, find in the components, concatenate the results, and omit duplicates.
// That last is a performance penalty,
// but I see no way to remove it unless we know the graphs do not overlap.
Set<Triple> seen = createSet();
return Iter.flatMap(listBaseGraphs(), x -> recording(rejecting(x.find(m), seen), seen));
return Iterators.flatMap(listBaseGraphs(), x -> recording(rejecting(x.find(m), seen), seen));
}

/**
Expand All @@ -334,15 +342,15 @@ public void close() {
}

/**
* Generic dependsOn, returns {@code true} iff this graph or any its sub-graphs depend on the specified graph.
* Generic dependsOn, returns {@code true} iff this graph or any sub-graphs depend on the specified graph.
*
* @param other {@link Graph}
* @return boolean
*/
@Override
public boolean dependsOn(Graph other) {
return (other instanceof UnionGraph && collectUnionGraphs().contains(other))
|| Iter.anyMatch(listBaseGraphs(), x -> Graphs.dependsOn(x, other));
|| Iterators.anyMatch(listBaseGraphs(), x -> Graphs.dependsOn(x, other));
}

/**
Expand All @@ -367,7 +375,7 @@ protected Set<Graph> collectBaseGraphs() {
* Recursively collects all base {@link Graph graph}s
* that are present in this collection or anywhere under the hierarchy.
*
* @param res a {@code Set} of non-union {@link Graph}s to return
* @param res a {@code Set} of non-union {@link Graph}s to return
* @param seen {@code Set} of {@link UnionGraph}s to control recursion
*/
private void collectBaseGraphs(Set<Graph> res, Set<UnionGraph> seen) {
Expand Down Expand Up @@ -467,7 +475,7 @@ protected Underlying(Collection<Graph> graphs) {
* @return {@link ExtendedIterator} of sub-{@link Graph graph}s
*/
public ExtendedIterator<Graph> listGraphs() {
return Iter.create(graphs);
return Iterators.create(graphs);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the ONT API.
* The contents of this file are subject to the LGPL License, Version 3.0.
* Copyright (c) 2019, The University of Manchester, owl.cs group.
* Copyright (c) 2022, owl.cs group.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand All @@ -14,8 +14,19 @@

package com.github.owlcs.ontapi.jena.impl;

import com.github.owlcs.ontapi.jena.impl.conf.*;
import com.github.owlcs.ontapi.jena.model.*;
import com.github.owlcs.ontapi.jena.impl.conf.ObjectFactory;
import com.github.owlcs.ontapi.jena.impl.conf.OntFilter;
import com.github.owlcs.ontapi.jena.impl.conf.OntFinder;
import com.github.owlcs.ontapi.jena.impl.conf.OntMaker;
import com.github.owlcs.ontapi.jena.impl.conf.OntPersonality;
import com.github.owlcs.ontapi.jena.impl.conf.Vocabulary;
import com.github.owlcs.ontapi.jena.model.OntAnnotationProperty;
import com.github.owlcs.ontapi.jena.model.OntClass;
import com.github.owlcs.ontapi.jena.model.OntDataProperty;
import com.github.owlcs.ontapi.jena.model.OntDataRange;
import com.github.owlcs.ontapi.jena.model.OntEntity;
import com.github.owlcs.ontapi.jena.model.OntIndividual;
import com.github.owlcs.ontapi.jena.model.OntObjectProperty;
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
import com.github.owlcs.ontapi.jena.vocabulary.RDF;
import org.apache.jena.enhanced.EnhGraph;
Expand All @@ -26,7 +37,12 @@
import org.apache.jena.util.iterator.ExtendedIterator;
import org.apache.jena.vocabulary.RDFS;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

/**
Expand Down Expand Up @@ -74,8 +90,7 @@ private boolean filterType(Node n, EnhGraph g) {
if (hasDeclaration) {
return true;
}
// In general, owl:NamedIndividual declaration is optional,
// see https://github.com/avicomp/ont-api/issues/73
// In general, owl:NamedIndividual declaration is optional
for (Node c : candidates) {
if (PersonalityModel.canAs(OntClass.class, c, g)) return true;
}
Expand Down
Loading

0 comments on commit ecb5ca9

Please sign in to comment.