Commit 247cf35f authored by rwm's avatar rwm
Browse files

scheme support for concepts/ontologies

parent 10f3c337
...@@ -84,6 +84,7 @@ dwh:String a owl:Restriction ; ...@@ -84,6 +84,7 @@ dwh:String a owl:Restriction ;
:OtherSub a skos:Concept ; :OtherSub a skos:Concept ;
skos:inScheme :OtherScheme ; skos:inScheme :OtherScheme ;
skos:inScheme :TestScheme ;
skos:broader :OtherTop ; skos:broader :OtherTop ;
skos:prefLabel "OtherSub_label_en"@en ; skos:prefLabel "OtherSub_label_en"@en ;
skos:notation "other" . skos:notation "other" .
...@@ -120,6 +120,17 @@ public class ConceptImpl implements Concept { ...@@ -120,6 +120,17 @@ public class ConceptImpl implements Concept {
throw new OntologyException(e); throw new OntologyException(e);
} }
} }
@Override
public String[] getSchemes() throws OntologyException {
ArrayList<String> ids = new ArrayList<>();
try {
store.forEachObject(this.res, SKOS.IN_SCHEME, scheme -> ids.add(scheme.stringValue()));
} catch (RepositoryException e) {
throw new OntologyException(e);
}
return ids.toArray(new String[ids.size()]);
}
......
...@@ -170,8 +170,10 @@ public class Store implements Ontology, Plugin { ...@@ -170,8 +170,10 @@ public class Store implements Ontology, Plugin {
// if this.scheme is null, top concepts of all schemes are returned // if this.scheme is null, top concepts of all schemes are returned
return getRelatedConcepts(this.scheme, SKOS.HAS_TOP_CONCEPT); return getRelatedConcepts(this.scheme, SKOS.HAS_TOP_CONCEPT);
} }
public Concept[] getTopConcepts(String schemeURI)throws OntologyException{
return getRelatedConcepts(repo.getValueFactory().createURI(schemeURI), SKOS.HAS_TOP_CONCEPT); @Override
public Concept[] getTopConcepts(String scheme)throws OntologyException{
return getRelatedConcepts(repo.getValueFactory().createURI(scheme), SKOS.HAS_TOP_CONCEPT);
} }
private Concept[] getRelatedConcepts(Resource subject, URI predicate)throws OntologyException{ private Concept[] getRelatedConcepts(Resource subject, URI predicate)throws OntologyException{
RepositoryResult<Statement> rr; RepositoryResult<Statement> rr;
......
...@@ -24,6 +24,16 @@ public class OntologyTest { ...@@ -24,6 +24,16 @@ public class OntologyTest {
store.setConceptScheme(NS_PREFIX+"TestScheme"); store.setConceptScheme(NS_PREFIX+"TestScheme");
} }
@Test
public void testGetSchemes() throws OntologyException{
Concept c = store.getConceptByNotation("other");
Assert.assertNotNull(c);
String[] schemes = c.getSchemes();
Assert.assertNotNull(schemes);
Assert.assertEquals(2, schemes.length);
// TODO verify scheme set (order is irrelevant)
}
@Test @Test
public void getConceptByIdTest() throws OntologyException{ public void getConceptByIdTest() throws OntologyException{
Assert.assertNull(store.getConceptByNotation("notfound")); Assert.assertNull(store.getConceptByNotation("notfound"));
...@@ -126,7 +136,6 @@ public class OntologyTest { ...@@ -126,7 +136,6 @@ public class OntologyTest {
Concept c = store.getConceptByNotation("Type"); Concept c = store.getConceptByNotation("Type");
System.out.println("Concept:"+c); System.out.println("Concept:"+c);
} }
} }
} }
...@@ -41,6 +41,14 @@ public interface Concept { ...@@ -41,6 +41,14 @@ public interface Concept {
*/ */
String[] getIDs() throws OntologyException; String[] getIDs() throws OntologyException;
/**
* Get the schemes to which this concept belongs.
* A concept may belong to no scheme. In this case an empty array is returned.
* @return scheme URIs
* @throws OntologyException on error
*/
String[] getSchemes() throws OntologyException;
/** /**
* Get the concept's preferred label for a given locale. * Get the concept's preferred label for a given locale.
* *
......
...@@ -23,6 +23,13 @@ public interface Ontology extends Closeable{ ...@@ -23,6 +23,13 @@ public interface Ontology extends Closeable{
* @throws OntologyException for ontology errors * @throws OntologyException for ontology errors
*/ */
public Concept[] getTopConcepts() throws OntologyException; public Concept[] getTopConcepts() throws OntologyException;
/**
* Return the top concepts of this ontology in the specified scheme
* @param scheme scheme to which all returned top concepts belong
* @return top concepts
* @throws OntologyException for ontology errors
*/
public Concept[] getTopConcepts(String scheme) throws OntologyException;
/** /**
* Returns the time when this ontology was last modified. * Returns the time when this ontology was last modified.
......
Supports Markdown
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