Skip to content

Commit 52b1d6b

Browse files
sszuevafs
authored andcommitted
apacheGH-2160: introduce jena-ontapi (OWL2 support)
1 parent c93343b commit 52b1d6b

File tree

181 files changed

+67494
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+67494
-0
lines changed

jena-ontapi/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Apache Jena OWL2 Model
2+
3+
4+
### Summary
5+
6+
This is enhanced [Apache Jena](https://github.com/apache/jena) Inference [RDF](https://www.w3.org/TR/rdf11-concepts/) Model with [OWL2](https://www.w3.org/TR/owl2-syntax/) support.
7+
8+
### Major components
9+
10+
- [OntModel](src/main/java/org/apache/jena/ontapi/model/OntModel.java) - the main interface to work with OWL2 & OWL1 & RDFS ontologies
11+
- [OntModelFactory](src/main/java/org/apache/jena/ontapi/OntModelFactory.java) - factory for creating different `OntModel` types
12+
- [GraphRepository](src/main/java/org/apache/jena/ontapi/GraphRepository.java) - graph store accessor
13+
- [OntSpecification](src/main/java/org/apache/jena/ontapi/OntSpecification.java) - encapsulates `ReasonerFactory`, `OntConfig`, `OntPersonality`
14+
- [UnionGraph](src/main/java/org/apache/jena/ontapi/UnionGraph.java) - a Graph implementation with support hierarchy
15+
- [OntModelConfig](src/main/java/org/apache/jena/ontapi/OntModelControls.java) - model configuration, defines
16+
what a model can do and what it cannot do
17+
- [OntPersonality](src/main/java/org/apache/jena/ontapi/common/OntPersonality.java) - a configuration class
18+
to conduct Jena's polymorphism for `OntObject`s
19+
20+
### Supported specifications
21+
22+
- OWL2 DL & Full: NO_INF, RULES_INF, RDFS_INF, TRANS_INF + BUILTIN_INF (default)
23+
- OWL2 EL: NO_INF, RULES_INF, RDFS_INF, TRANS_INF
24+
- OWL2 QL: NO_INF, RULES_INF, RDFS_INF, TRANS_INF
25+
- OWL2 RL: NO_INF, RULES_INF, RDFS_INF, TRANS_INF
26+
- OWL1 DL & Full: NO_INF, RULES_INF, RDFS_INF, TRANS_INF, MICRO_RULES, MINI_RULES
27+
- OWL1 Lite: NO_INF, RULES_INF, RDFS_INF, TRANS_INF
28+
- RDFS: NO_INF, RDFS_INF, TRANS_INF
29+
30+
### Example
31+
32+
```java
33+
GraphRepository repository = GraphRepository.createGraphDocumentRepositoryMem();
34+
35+
OntModel m = OntModelFactory.createModel(OntSpecification.OWL2_DL_MEM_BUILTIN_INF, repository)
36+
.setNsPrefixes(OntModelFactory.STANDARD);
37+
38+
m.setID("ont").setVersionIRI("ont#v1");
39+
40+
OntObjectProperty p = m.createObjectProperty("p");
41+
OntClass a = m.createOntClass("a");
42+
OntIndividual i = a.createIndividual("i");
43+
OntClass b = m.createOntClass("b")
44+
.addSuperClass(m.createObjectIntersectionOf(a, m.createObjectHasValue(p, i)));
45+
46+
m.ontObjects(OntClass.class).forEach(System.out::println);
47+
m.ontObjects(OntIndividual.class).forEach(System.out::println);
48+
49+
m.write(System.out, "ttl");
50+
```

jena-ontapi/pom.xml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<artifactId>jena-ontapi</artifactId>
25+
<packaging>jar</packaging>
26+
<name>Apache Jena - ONTAPI</name>
27+
<parent>
28+
<groupId>org.apache.jena</groupId>
29+
<artifactId>jena</artifactId>
30+
<version>5.1.0-SNAPSHOT</version>
31+
<relativePath>..</relativePath>
32+
</parent>
33+
34+
<description>Ontology API for Apache Jena</description>
35+
36+
<properties>
37+
<build.time.xsd>${maven.build.timestamp}</build.time.xsd>
38+
<automatic.module.name>org.apache.jena.ontapi</automatic.module.name>
39+
</properties>
40+
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.apache.jena</groupId>
44+
<artifactId>jena-arq</artifactId>
45+
<version>5.1.0-SNAPSHOT</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter-engine</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter-params</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.logging.log4j</groupId>
59+
<artifactId>log4j-slf4j2-impl</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-compiler-plugin</artifactId>
69+
</plugin>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-source-plugin</artifactId>
73+
<executions>
74+
<execution>
75+
<id>attach-sources</id>
76+
<goals>
77+
<goal>jar-no-fork</goal>
78+
</goals>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-javadoc-plugin</artifactId>
85+
<executions>
86+
<execution>
87+
<id>attach-javadocs</id>
88+
<goals>
89+
<goal>jar</goal>
90+
</goals>
91+
</execution>
92+
</executions>
93+
</plugin>
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-jar-plugin</artifactId>
97+
<executions>
98+
<execution>
99+
<id>attache-tests</id>
100+
<goals>
101+
<goal>test-jar</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-surefire-plugin</artifactId>
109+
</plugin>
110+
</plugins>
111+
</build>
112+
113+
</project>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.jena.ontapi;
20+
21+
import org.apache.jena.ontapi.impl.repositories.DocumentGraphRepository;
22+
import org.apache.jena.graph.Graph;
23+
import org.apache.jena.graph.GraphMemFactory;
24+
import org.apache.jena.ontapi.model.OntID;
25+
26+
import java.util.Objects;
27+
import java.util.function.Supplier;
28+
import java.util.stream.Stream;
29+
30+
/**
31+
* Graph repository.
32+
* Each {@link Graph} is associated with ID.
33+
* For OWL Ontology Graphs, Graph ID can be {@link OntID#getImportsIRI()}.
34+
*
35+
* @see org.apache.jena.ontology.OntDocumentManager
36+
*/
37+
public interface GraphRepository {
38+
39+
/**
40+
* A factory method to creates {@link GraphRepository} instance
41+
* that loads graphs on demand from the location to memory.
42+
* The location is specified by the method {@link DocumentGraphRepository#addMapping(String, String)}.
43+
*
44+
* @return {@link DocumentGraphRepository}
45+
*/
46+
static DocumentGraphRepository createGraphDocumentRepositoryMem() {
47+
return createGraphDocumentRepository(GraphMemFactory::createDefaultGraph);
48+
}
49+
50+
/**
51+
* A factory method to creates {@link GraphRepository} instance
52+
* that loads graphs on demand from the location.
53+
* The location is specified by the method {@link DocumentGraphRepository#addMapping(String, String)}.
54+
*
55+
* @param factory {@link Supplier} to produce new {@link Graph}, {@code null} for default
56+
* @return {@link DocumentGraphRepository}
57+
*/
58+
static DocumentGraphRepository createGraphDocumentRepository(Supplier<Graph> factory) {
59+
return new DocumentGraphRepository(Objects.requireNonNull(factory, "Null graph factory"));
60+
}
61+
62+
/**
63+
* Gets Graph by ID.
64+
*
65+
* @param id {@code String} Graph's identifier
66+
* @return {@link Graph}
67+
*/
68+
Graph get(String id);
69+
70+
/**
71+
* @return {@code Stream} of Graph's identifiers
72+
*/
73+
Stream<String> ids();
74+
75+
/**
76+
* Associates the specified graph with the specified ID,
77+
* returning the previous association or {@code null} if there was no association.
78+
*
79+
* @param id {@code String} Graph's identifier
80+
* @param graph {@link Graph}
81+
* @return {@link Graph} or {@code null}
82+
*/
83+
Graph put(String id, Graph graph);
84+
85+
/**
86+
* Removes graph.
87+
*
88+
* @param id {@code String} Graph's identifier
89+
* @return {@link Graph}
90+
*/
91+
Graph remove(String id);
92+
93+
/**
94+
* Removes all graphs.
95+
*/
96+
void clear();
97+
98+
/**
99+
* @return number of graphs
100+
*/
101+
default long count() {
102+
return ids().count();
103+
}
104+
105+
/**
106+
* Lists all graphs.
107+
*
108+
* @return {@code Stream} of {@link Graph}s
109+
*/
110+
default Stream<Graph> graphs() {
111+
return ids().map(this::get).filter(Objects::nonNull);
112+
}
113+
114+
/**
115+
* @param id {@code String} Graph's identifier
116+
* @return boolean
117+
*/
118+
default boolean contains(String id) {
119+
Objects.requireNonNull(id);
120+
return ids().anyMatch(id::equals);
121+
}
122+
123+
}

0 commit comments

Comments
 (0)