Commit 389a46d0 authored by R.W.Majeed's avatar R.W.Majeed

get ontology concepts by ID (IRI)

parent 1921119e
......@@ -43,7 +43,7 @@ public interface Concept {
/**
* Get id identifying this concept which is unique to the ontology
* For RDF, this will be the rdf:about URI which can have abbreviated namespace prefix.
* For RDF, this will be the rdf:about IRI which can have abbreviated namespace prefix.
* @return unique id
*/
String getID();
......
......@@ -10,12 +10,20 @@ import java.io.Closeable;
*/
public interface Ontology extends Closeable{
/**
* Find a concept by it's id value. In SKOS terms, the id is equivalent to the concept's notation.
* @param id concept id
* @return concept
* Find a concept by it's notation. In SKOS terms, the id is equivalent to the concept's notation.
* @param notation concept id
* @return concept or {@code null} if not found
* @throws OntologyException for ontology errors
*/
public Concept getConceptByNotation(String id) throws OntologyException;
public Concept getConceptByNotation(String notation) throws OntologyException;
/**
* Find a concept by its ID / IRI
* @param id unique concept id
* @return concept or {@code null} if not found
* @throws OntologyException for ontology errors
*/
public Concept getConceptById(String id)throws OntologyException;
/**
* Return the top concepts of this ontology
......
......@@ -467,5 +467,21 @@ public class Store implements Ontology, Plugin {
throw new SKOSException(r, "dwh:mapFact must contain one of dwh:condition, dwh:choose, dwh:value");
}
}
@Override
public Concept getConceptById(String id) throws OntologyException {
URI uri = repo.getValueFactory().createURI(id);
RepositoryResult<Statement> s = null;
ConceptImpl ci = null;
try{
s = rc.getStatements(uri, RDF.TYPE, SKOS.CONCEPT, false);
if( s.hasNext() ){
ci = new ConceptImpl(this, s.next().getSubject());
}
s.close();
} catch (RepositoryException e) {
throw new OntologyException(e);
}
return ci;
}
}
......@@ -124,6 +124,16 @@ public class OntologyTest {
Assert.assertEquals("Description_de", c.getDescription(Locale.GERMAN));
}
@Test
public void verifyGetByIRI() throws OntologyException{
Concept c = store.getConceptById("http://sekmi.de/histream/skos/tests#OtherSub");
Assert.assertNotNull(c);
String[] n = c.getNotations();
Assert.assertNotNull(n);
Assert.assertEquals(1,n.length);
Assert.assertEquals("other",n[0]);
}
@After
public void closeOntology() throws IOException{
store.close();
......
Markdown is supported
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