Skip to content

Commit 638975e

Browse files
committed
Store code for loading ontologies for future use
1 parent e69c0cd commit 638975e

6 files changed

Lines changed: 362 additions & 1 deletion

File tree

federated-catalog/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ dependencies {
5555

5656
// upgrade 14.1
5757
implementation(libs.edc.fc.core.v2025)
58+
59+
// vocabulary
60+
implementation(libs.net.sourceforge.owlapi)
61+
62+
// test
63+
testImplementation(libs.edc.junit)
64+
5865
}
5966

6067
application {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2025 Universidad de Alicante
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Apache License, Version 2.0 which is available at
6+
* https://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Contributors:
11+
* LdE - Universidad de Alicante - initial implementation
12+
*
13+
*/
14+
15+
package org.eclipse.edc.heleade.federated.catalog.extension.vocabulary;
16+
17+
import org.semanticweb.owlapi.apibinding.OWLManager;
18+
import org.semanticweb.owlapi.model.IRI;
19+
import org.semanticweb.owlapi.model.OWLClass;
20+
import org.semanticweb.owlapi.model.OWLDataFactory;
21+
import org.semanticweb.owlapi.model.OWLOntology;
22+
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
23+
import org.semanticweb.owlapi.model.OWLOntologyManager;
24+
import org.semanticweb.owlapi.util.AutoIRIMapper;
25+
26+
import java.io.File;
27+
28+
import static org.semanticweb.owlapi.search.EntitySearcher.getAnnotationObjects;
29+
30+
public class VocabularyManager {
31+
32+
public static OWLOntologyManager create() {
33+
OWLOntologyManager m =
34+
OWLManager.createOWLOntologyManager();
35+
m.getIRIMappers().add(new AutoIRIMapper(
36+
new File("materializedOntologies"), true));
37+
return m;
38+
}
39+
40+
public static String loadOntology(String ontologyIri) {
41+
42+
StringBuilder output = new StringBuilder();
43+
44+
OWLDataFactory df = OWLManager.getOWLDataFactory();
45+
OWLOntologyManager m = create();
46+
47+
try {
48+
IRI iri;
49+
50+
if (isPath(ontologyIri)) {
51+
File file = new File(ontologyIri);
52+
iri = IRI.create(file);
53+
} else {
54+
iri = IRI.create(ontologyIri);
55+
}
56+
57+
OWLOntology o = m.loadOntologyFromOntologyDocument(iri);
58+
59+
output.append(" ONTOLOGY: ").append(o.getOntologyID().getOntologyIRI().toString()).append("\n");
60+
if (o.getOntologyID().getVersionIRI().isPresent()) {
61+
output.append(" VERSION: ").append(o.getOntologyID().getVersionIRI().get()).append("\n");
62+
}
63+
64+
output.append("\n getAnnotations");
65+
for (var a : o.getAnnotations()) {
66+
output.append(a.getProperty().getIRI().toString()).append(" ").append(a.getValue().toString()).append("\n");
67+
}
68+
69+
output.append("\n getClassesInSignature");
70+
71+
for (OWLClass cls : o.getClassesInSignature()) {
72+
output.append(cls.getIRI().toString()).append(" ").append(cls.getIRI().getFragment()).append("\n");
73+
var annotations = getAnnotationObjects(cls, o, df.getRDFSLabel());
74+
annotations.forEach(a -> output.append("\t - ").append(a.getValue().asLiteral().get().getLang()).append(": ").append(a.getValue().asLiteral().get().getLiteral()).append("\n"));
75+
var comments = getAnnotationObjects(cls, o, df.getRDFSComment());
76+
comments.forEach(a -> output.append("\t * ").append(a.getValue().asLiteral().get().getLang()).append(": ").append(a.getValue().asLiteral().get().getLiteral()).append("\n"));
77+
}
78+
output.append("\n getDataPropertiesInSignature");
79+
o.getDataPropertiesInSignature().forEach(p -> output.append(p).append("\n"));
80+
output.append("\n getObjectPropertiesInSignature");
81+
o.getObjectPropertiesInSignature().forEach(p -> output.append(p).append("\n"));
82+
output.append("\n getIndividualsInSignature");
83+
o.getIndividualsInSignature().forEach(p -> output.append(p).append("\n"));
84+
85+
} catch (OWLOntologyCreationException e) {
86+
throw new RuntimeException(e);
87+
}
88+
return output.toString();
89+
}
90+
91+
private static boolean isPath(String ontologyIri) {
92+
return !ontologyIri.startsWith("http://") && !ontologyIri.startsWith("https://");
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 Universidad de Alicante
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Apache License, Version 2.0 which is available at
6+
* https://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Contributors:
11+
* LdE - Universidad de Alicante - initial implementation
12+
*
13+
*/
14+
15+
package org.eclipse.edc.heleade.federated.catalog.extension.vocabulary;
16+
17+
import org.eclipse.edc.junit.testfixtures.TestUtils;
18+
import org.junit.jupiter.api.Test;
19+
20+
import java.io.File;
21+
22+
23+
public class VocabularyManagerTest {
24+
25+
// public static final String SEGITTUR_ONTOLOGY_IRI = "https://ontologia.segittur.es/turismo/def/core/ontology.rdf";
26+
private static final String TEST_OWL_PATH = "federated-catalog/src/test/resources/test.owl";
27+
28+
// @Test
29+
// void shouldLoadOntologyFromRemoteLocation() {
30+
// VocabularyManager.loadOntology(SEGITTUR_ONTOLOGY_IRI);
31+
// }
32+
33+
@Test
34+
void shouldLoadOntologyFromFile() {
35+
var fileFromRelativePath = new File(TestUtils.findBuildRoot(), TEST_OWL_PATH);
36+
String filePath = fileFromRelativePath.getAbsolutePath();
37+
String output = VocabularyManager.loadOntology(filePath);
38+
assert !output.isEmpty();
39+
assert output.contains("Rock");
40+
}
41+
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<rdf:RDF
2+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
3+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
4+
xmlns:owl ="http://www.w3.org/2002/07/owl#">
5+
<owl:Ontology rdf:about="xml:base"/>
6+
7+
<owl:Class rdf:ID="genero">
8+
<rdfs:comment>Generos musicales.</rdfs:comment>
9+
</owl:Class>
10+
11+
<owl:Class rdf:ID="rock">
12+
<rdfs:comment>Rock \m/ </rdfs:comment>
13+
<rdfs:subClassOf rdf:resource="#genero"/>
14+
15+
</owl:Class>
16+
17+
<owl:Class rdf:ID="clasico">
18+
<rdfs:comment>
19+
Rock clasico
20+
</rdfs:comment>
21+
22+
<owl:intersectionOf rdf:parseType="Collection">
23+
<owl:Class rdf:about="#rock"/>
24+
<owl:Restriction>
25+
<owl:onProperty rdf:resource="#subgenero"/>
26+
<owl:allValuesFrom rdf:resource="#rock"/>
27+
</owl:Restriction>
28+
<owl:Restriction>
29+
<owl:onProperty rdf:resource="#toca"/>
30+
<owl:allValuesFrom rdf:resource="#cuerdas"/>
31+
</owl:Restriction>
32+
<owl:Restriction>
33+
<owl:onProperty rdf:resource="#toca"/>
34+
<owl:allValuesFrom rdf:resource="#percusion"/>
35+
</owl:Restriction>
36+
37+
</owl:intersectionOf>
38+
</owl:Class>
39+
40+
<owl:Class rdf:ID="metal">
41+
<rdfs:comment>
42+
Heavy metal
43+
</rdfs:comment>
44+
45+
<owl:intersectionOf rdf:parseType="Collection">
46+
<owl:Class rdf:about="#rock"/>
47+
<owl:Restriction>
48+
<owl:onProperty rdf:resource="#subgenero"/>
49+
<owl:allValuesFrom rdf:resource="#rock"/>
50+
</owl:Restriction>
51+
<owl:Restriction>
52+
<owl:onProperty rdf:resource="#toca"/>
53+
<owl:allValuesFrom rdf:resource="#cuerdas"/>
54+
</owl:Restriction>
55+
<owl:Restriction>
56+
<owl:onProperty rdf:resource="#toca"/>
57+
<owl:allValuesFrom rdf:resource="#percusion"/>
58+
</owl:Restriction>
59+
60+
</owl:intersectionOf>
61+
</owl:Class>
62+
63+
<owl:Class rdf:ID="ska">
64+
<rdfs:comment>
65+
Ska
66+
</rdfs:comment>
67+
68+
<owl:intersectionOf rdf:parseType="Collection">
69+
<owl:Class rdf:about="#rock"/>
70+
<owl:Restriction>
71+
<owl:onProperty rdf:resource="#subgenero"/>
72+
<owl:allValuesFrom rdf:resource="#rock"/>
73+
</owl:Restriction>
74+
<owl:Restriction>
75+
<owl:onProperty rdf:resource="#toca"/>
76+
<owl:allValuesFrom rdf:resource="#viento"/>
77+
</owl:Restriction>
78+
<owl:Restriction>
79+
<owl:onProperty rdf:resource="#toca"/>
80+
<owl:allValuesFrom rdf:resource="#percusion"/>
81+
</owl:Restriction>
82+
</owl:intersectionOf>
83+
</owl:Class>
84+
85+
<owl:Class rdf:ID="pop">
86+
<rdfs:comment>Musica Pop</rdfs:comment>
87+
<rdfs:subClassOf rdf:resource="#genero"/>
88+
</owl:Class>
89+
90+
<owl:Class rdf:ID="balada">
91+
<rdfs:comment>Balada</rdfs:comment>
92+
<owl:intersectionOf rdf:parseType="Collection">
93+
<owl:Class rdf:about="#pop"/>
94+
<owl:Restriction>
95+
<owl:onProperty rdf:resource="#subgenero"/>
96+
<owl:allValuesFrom rdf:resource="#pop"/>
97+
</owl:Restriction>
98+
</owl:intersectionOf>
99+
</owl:Class>
100+
101+
<owl:Class rdf:ID="dance">
102+
<rdfs:comment>Dance</rdfs:comment>
103+
<owl:intersectionOf rdf:parseType="Collection">
104+
<owl:Class rdf:about="#pop"/>
105+
<owl:Restriction>
106+
<owl:onProperty rdf:resource="#subgenero"/>
107+
<owl:allValuesFrom rdf:resource="#pop"/>
108+
</owl:Restriction>
109+
</owl:intersectionOf>
110+
</owl:Class>
111+
112+
113+
114+
<owl:Class rdf:ID="instrumento">
115+
<rdfs:comment>Instrumentos musicales.</rdfs:comment>
116+
<owl:disjointWith rdf:resource="#genero"/>
117+
</owl:Class>
118+
119+
<owl:Class rdf:ID="cuerdas">
120+
<rdfs:comment>Instrumentos de cuerdas</rdfs:comment>
121+
<rdfs:subClassOf rdf:resource="#instrumento"/>
122+
</owl:Class>
123+
124+
<owl:Class rdf:ID="guitarra">
125+
<rdfs:comment>Guitarra</rdfs:comment>
126+
<rdfs:subClassOf rdf:resource="#cuerdas"/>
127+
</owl:Class>
128+
129+
<owl:Class rdf:ID="bajo">
130+
<rdfs:comment>Bajo</rdfs:comment>
131+
<rdfs:subClassOf rdf:resource="#cuerdas"/>
132+
</owl:Class>
133+
134+
<owl:Class rdf:ID="percusion">
135+
<rdfs:comment>Instrumentos de percusion</rdfs:comment>
136+
<rdfs:subClassOf rdf:resource="#instrumento"/>
137+
</owl:Class>
138+
139+
<owl:Class rdf:ID="bateria">
140+
<rdfs:comment>Bateria</rdfs:comment>
141+
<rdfs:subClassOf rdf:resource="#percusion"/>
142+
</owl:Class>
143+
144+
<owl:Class rdf:ID="timbales">
145+
<rdfs:comment>Timbales</rdfs:comment>
146+
<rdfs:subClassOf rdf:resource="#percusion"/>
147+
</owl:Class>
148+
149+
<owl:Class rdf:ID="viento">
150+
<rdfs:comment>Instrumentos de viento</rdfs:comment>
151+
<rdfs:subClassOf rdf:resource="#instrumento"/>
152+
</owl:Class>
153+
154+
<owl:Class rdf:ID="saxofon">
155+
<rdfs:comment>Sax</rdfs:comment>
156+
<rdfs:subClassOf rdf:resource="#viento"/>
157+
</owl:Class>
158+
159+
<owl:Class rdf:ID="trompeta">
160+
<rdfs:comment>Trompeta</rdfs:comment>
161+
<rdfs:subClassOf rdf:resource="#viento"/>
162+
</owl:Class>
163+
164+
<owl:Class rdf:ID="teclado">
165+
<rdfs:comment>Instrumentos con teclas</rdfs:comment>
166+
<rdfs:subClassOf rdf:resource="#instrumento"/>
167+
</owl:Class>
168+
169+
<owl:Class rdf:ID="sintetizador">
170+
<rdfs:comment>Sintetizador</rdfs:comment>
171+
<rdfs:subClassOf rdf:resource="#teclado"/>
172+
</owl:Class>
173+
174+
<owl:Class rdf:ID="organo">
175+
<rdfs:comment>Organo</rdfs:comment>
176+
<rdfs:subClassOf rdf:resource="#teclado"/>
177+
</owl:Class>
178+
179+
180+
<owl:Class rdf:ID="artista">
181+
<rdfs:comment>Artista.</rdfs:comment>
182+
183+
</owl:Class>
184+
185+
<owl:Class rdf:ID="guitarrista">
186+
<rdfs:comment>Guitarrista</rdfs:comment>
187+
<owl:intersectionOf rdf:parseType="Collection">
188+
<owl:Class rdf:about="#artista"/>
189+
<owl:Restriction>
190+
<owl:onProperty rdf:resource="#toca"/>
191+
<owl:allValuesFrom rdf:resource="#cuerdas"/>
192+
</owl:Restriction>
193+
</owl:intersectionOf>
194+
</owl:Class>
195+
196+
<rdf:Description rdf:ID="tommorello">
197+
<rdfs:comment>Tom Morello Guitarrista de RATM</rdfs:comment>
198+
<rdf:type rdf:resource="#guitarrista"/>
199+
</rdf:Description>
200+
201+
<owl:TransitiveProperty rdf:ID="subgenero"/>
202+
203+
<owl:ObjectProperty rdf:ID="toca">
204+
<rdfs:domain rdf:resource="#instrumento"/>
205+
<rdfs:range rdf:resource="#artista"/>
206+
<rdfs:range rdf:resource="#genero"/>
207+
</owl:ObjectProperty>
208+
209+
<owl:ObjectProperty rdf:ID="tocadoPor">
210+
<owl:inverseOf rdf:resource="#toca"/>
211+
</owl:ObjectProperty>
212+
213+
214+
215+
</rdf:RDF>

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ edc-oauth2-client = { module = "org.eclipse.edc:oauth2-client", version.ref = "e
168168
edc-ih-api-did = { module = "org.eclipse.edc:did-api", version.ref = "edc" }
169169
edc-ih-api-participants = { module = "org.eclipse.edc:participant-context-api", version.ref = "edc" }
170170

171+
# vocabulary hub
172+
net-sourceforge-owlapi = { module = "net.sourceforge.owlapi:owlapi-distribution", version = "5.5.1" }
173+
174+
171175
[bundles]
172176
edc-sqlstores = ["edc-sql-assetindex", "edc-sql-contract-definition", "edc-sql-contract-negotiation", "edc-sql-transferprocess", "edc-sql-policydef", "edc-sql-policy-monitor", "edc-sql-edrindex"]
173177

providers/provider-base/resources/configuration/provider-base-configuration.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ edc.heleade.service.dataservice.credentials.default={\"description\": \"Default.
4141
edc.participant.registry.url=http://localhost:39191/api/
4242
edc.participant.claims=providers/provider-base/resources/identity/claims.json
4343
edc.participant.private.key=providers/provider-base/resources/identity/ed25519_private.pem
44-
edc.participant.public.key=providers/provider-base/resources/identity/ed25519_public.pem
44+
edc.participant.public.key=providers/provider-base/resources/identity/ed25519_public.pem

0 commit comments

Comments
 (0)