Commit 4169fab0 authored by rwm's avatar rwm

Concept.getIDs renamed to getNotations. Added method for Concept.getID.

i2b2 import uses unique ids.
parent 4c18fcdb
......@@ -5,6 +5,7 @@ import java.util.Locale;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.vocabulary.DC;
import org.openrdf.model.vocabulary.SKOS;
......@@ -52,7 +53,7 @@ public class ConceptImpl implements Concept {
}
@Override
public String[] getIDs() throws OntologyException {
public String[] getNotations() throws OntologyException {
ArrayList<String> ids = new ArrayList<>();
try{
RepositoryResult<Statement> s = store.getConnection().getStatements(res, SKOS.NOTATION, null, true);
......@@ -131,6 +132,13 @@ public class ConceptImpl implements Concept {
}
return ids.toArray(new String[ids.size()]);
}
@Override
public String getID() {
URI me = (URI)res;
// TODO: use better namespace prefix instead of hashcode
return Integer.toHexString(me.getNamespace().hashCode())+":"+me.getLocalName();
}
......
......@@ -63,7 +63,6 @@ public class Store implements Ontology, Plugin {
* @param conf configuration parameters
* @throws FileNotFoundException if one of the specified files can not be found
* @throws IOException for i/o exceptions while reading the files
* @throws RDFParseException if rdf files can not be parsed
* @throws RepositoryException for any other exceptions during ontology initialisation
*/
public Store(Map<String,String> conf) throws RepositoryException, IOException{
......
......@@ -142,7 +142,7 @@ public class RDFTransformation implements Transformation {
}
// map to target
String[] ids = target.getIDs();
String[] ids = target.getNotations();
if( ids.length == 0 )throw new TransformationException("No notation found in target concept "+target);
fact.replaceConcept(ids[0]);
// TODO: is there a way to specify which notation should be used if there are multiple notations?
......
......@@ -39,8 +39,8 @@ public class OntologyTest {
Assert.assertNull(store.getConceptByNotation("notfound"));
Concept c = store.getConceptByNotation("T:type:int");
Assert.assertNotNull(c);
Assert.assertEquals(1, c.getIDs().length);
Assert.assertEquals("T:type:int", c.getIDs()[0]);
Assert.assertEquals(1, c.getNotations().length);
Assert.assertEquals("T:type:int", c.getNotations()[0]);
ValueRestriction rest = c.getValueRestriction();
Assert.assertNotNull(rest);
}
......@@ -108,7 +108,7 @@ public class OntologyTest {
Concept[] narrower = top[0].getNarrower();
Assert.assertNotNull(narrower);
Assert.assertEquals(1, narrower.length);
String[] ids = narrower[0].getIDs();
String[] ids = narrower[0].getNotations();
Assert.assertEquals(1, ids.length);
Assert.assertEquals("other", ids[0]);
}
......
......@@ -251,21 +251,17 @@ public class Import implements AutoCloseable{
private void insertMeta(int level, String path_prefix, Concept concept, boolean accessRoot) throws SQLException, OntologyException{
insertMeta.setInt(1, level);
String label = concept.getPrefLabel(locale);
String path_part = label; // TODO unique key sufficient, e.g. try label.hashCode()
String path_part = concept.getID(); // TODO unique key sufficient, e.g. try label.hashCode()
if( label == null ){
// no label for language, try to get neutral label
label = concept.getPrefLabel(null);
path_part = label;
if( label == null ){
// concept does not have a label
label = concept.toString();
path_part = label;//Integer.toHexString(concept.hashCode());
log.warning("Missing prefLabel for concept "+concept+" substituted with hashCode:"+label);
label = concept.getID();
log.warning("Missing prefLabel for concept "+concept+" substituted with ID");
}
}
// TODO find better way to generate path_part
path_part = Integer.toHexString(label.hashCode());
// use hashcode
String path = path_prefix + path_part+"\\";
......@@ -277,7 +273,7 @@ public class Import implements AutoCloseable{
// c_visualattributes and c_basecode
Concept[] subConcepts = concept.getNarrower();
String[] conceptIds = concept.getIDs();
String[] conceptIds = concept.getNotations();
if( conceptIds.length == 0 ){
......
......@@ -39,8 +39,14 @@ public interface Concept {
* @return String array containing all id's assigned to this concept
* @throws OntologyException for ontology errors
*/
String[] getIDs() throws OntologyException;
String[] getNotations() throws OntologyException;
/**
* 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.
* @return unique id
*/
String getID();
/**
* Get the schemes to which this concept belongs.
* A concept may belong to no scheme. In this case an empty array is returned.
......@@ -60,6 +66,7 @@ public interface Concept {
* @throws OntologyException for ontology errors
*/
String getPrefLabel(Locale locale) throws OntologyException;
// TODO: allow specification of multiple locales in order of preference
/**
* Get the concept's description for a given locale.
......
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