Loading histream-maven-plugin/src/main/java/de/sekmi/histream/maven/OntologyMojo.java +14 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public class OntologyMojo extends AbstractMojo { @Parameter(defaultValue="${project}", readonly=true, required=true) MavenProject project; @Parameter Map<String, String> prefixes; private void logWarning(String message){ getLog().warn(message); } Loading Loading @@ -117,6 +120,17 @@ public class OntologyMojo extends AbstractMojo { } catch (RepositoryException | IOException e) { throw new MojoExecutionException("Unable to load ontology", e); } if( prefixes != null ){ String[] ns = new String[prefixes.size()]; String[] pr = new String[ns.length]; int i=0; for( String key : prefixes.keySet() ){ pr[i] = key; ns[i] = prefixes.get(key); i++; } store.setNamespacePrefixes(ns, pr); } try { SQLGenerator gen = new SQLGenerator(metaSQL, dataSQL, map, overwrite); Loading histream-maven-plugin/src/test/java/de/sekmi/histream/maven/TestOntologyMojo.java +3 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package de.sekmi.histream.maven; import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Collections; import java.util.Properties; import org.apache.maven.shared.model.fileset.FileSet; Loading @@ -23,6 +24,7 @@ public class TestOntologyMojo { mojo.destination = new File("target/i2b2-aktin"); mojo.properties = new Properties(); mojo.overwrite = true; mojo.prefixes = Collections.singletonMap("a", "http://aktin.org/skos-cda#"); try( InputStream in = getClass().getResourceAsStream("/ontology.properties") ){ mojo.properties.load(in); } Loading histream-skos/src/main/java/de/sekmi/histream/ontology/skos/ConceptImpl.java +8 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ public class ConceptImpl implements Concept { } public String toString(){ return res.toString(); return getID(); } @Override Loading Loading @@ -135,8 +135,13 @@ public class ConceptImpl implements Concept { @Override public String getID() { URI me = (URI)res; String prefix = store.getNamespacePrefix(me.getNamespace()); if( prefix == null ){ // backward compatibility. this breaks the Ontology.getConceptById call. // TODO: use better namespace prefix instead of hashcode return Integer.toHexString(me.getNamespace().hashCode())+":"+me.getLocalName(); prefix = Integer.toHexString(me.getNamespace().hashCode()); } return prefix + ":" +me.getLocalName(); } Loading histream-skos/src/main/java/de/sekmi/histream/ontology/skos/HIStreamOntology.java +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ public class HIStreamOntology { DWH_ECMASCRIPT = f.createURI(DWH_NAMESPACE, "ECMAScript"); DWH_HAS_PART = f.createURI(DWH_NAMESPACE, "hasPart"); // TODO use correct names/URIs DWH_IS_PART_OF = f.createURI(DWH_NAMESPACE, "isPartOf"); // XXX see above // dwh:hasPart rdfs:subPropertyOf http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#hasPart } } histream-skos/src/main/java/de/sekmi/histream/ontology/skos/Store.java +50 −4 Original line number Diff line number Diff line Loading @@ -49,7 +49,8 @@ public class Store implements Ontology, Plugin { private Resource inferredContext; // SKOS scheme to enforce unique notations private Resource scheme; private Map<String, String> namespaceShortener; private String[] registeredPrefixes; private String[] registeredNamespaces; /// XXX namespace resolver /** Loading Loading @@ -142,7 +143,6 @@ public class Store implements Ontology, Plugin { return count; } private void initializeRepo(Iterable<File> files, Iterable<URL> urls, String baseURI) throws RepositoryException, IOException{ namespaceShortener = new HashMap<>(); repo = new SailRepository(new MemoryStore()); repo.initialize(); rc = repo.getConnection(); Loading Loading @@ -261,6 +261,49 @@ public class Store implements Ontology, Plugin { } public void setNamespacePrefixes(String[] namespaces, String prefixes[]){ // TODO order namespaces by length this.registeredNamespaces = namespaces; this.registeredPrefixes = prefixes; } private String expandIdPrefixes(String id){ if( registeredPrefixes == null ){ // no prefixes to expand return id; } for( int i=0; i<registeredPrefixes.length; i++ ){ String prefix = registeredPrefixes[i] + ":"; if( id.length() > prefix.length() && id.startsWith(prefix) ){ return registeredNamespaces[i] + id.substring(prefix.length()); } } return id; } String getNamespacePrefix(String namespace){ if( registeredNamespaces == null ){ return null; } for( int i=0; i<registeredNamespaces.length; i++ ){ if( namespace.equals(registeredNamespaces[i]) ){ return registeredPrefixes[i]; } } return null; } // // private String shortenIdNamespaces(String id){ // if( registeredNamespaces == null ){ // // no namespaces to shorten // return id; // } // for( int i=0; i<registeredNamespaces.length; i++ ){ // String ns = registeredNamespaces[i]; // if( id.length() > ns.length() && id.startsWith(ns) ){ // return registeredPrefixes[i] + ":" + id.substring(ns.length()); // } // } // return id; // } @Override public ConceptImpl getConceptByNotation(String id) throws OntologyException { Loading Loading @@ -494,7 +537,10 @@ public class Store implements Ontology, Plugin { } } @Override public Concept getConceptById(String id) throws OntologyException { public Concept getConceptById(String conceptId) throws OntologyException { // lookup namespaces String id = expandIdPrefixes(conceptId); URI uri = repo.getValueFactory().createURI(id); RepositoryResult<Statement> s = null; ConceptImpl ci = null; Loading Loading
histream-maven-plugin/src/main/java/de/sekmi/histream/maven/OntologyMojo.java +14 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public class OntologyMojo extends AbstractMojo { @Parameter(defaultValue="${project}", readonly=true, required=true) MavenProject project; @Parameter Map<String, String> prefixes; private void logWarning(String message){ getLog().warn(message); } Loading Loading @@ -117,6 +120,17 @@ public class OntologyMojo extends AbstractMojo { } catch (RepositoryException | IOException e) { throw new MojoExecutionException("Unable to load ontology", e); } if( prefixes != null ){ String[] ns = new String[prefixes.size()]; String[] pr = new String[ns.length]; int i=0; for( String key : prefixes.keySet() ){ pr[i] = key; ns[i] = prefixes.get(key); i++; } store.setNamespacePrefixes(ns, pr); } try { SQLGenerator gen = new SQLGenerator(metaSQL, dataSQL, map, overwrite); Loading
histream-maven-plugin/src/test/java/de/sekmi/histream/maven/TestOntologyMojo.java +3 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package de.sekmi.histream.maven; import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Collections; import java.util.Properties; import org.apache.maven.shared.model.fileset.FileSet; Loading @@ -23,6 +24,7 @@ public class TestOntologyMojo { mojo.destination = new File("target/i2b2-aktin"); mojo.properties = new Properties(); mojo.overwrite = true; mojo.prefixes = Collections.singletonMap("a", "http://aktin.org/skos-cda#"); try( InputStream in = getClass().getResourceAsStream("/ontology.properties") ){ mojo.properties.load(in); } Loading
histream-skos/src/main/java/de/sekmi/histream/ontology/skos/ConceptImpl.java +8 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ public class ConceptImpl implements Concept { } public String toString(){ return res.toString(); return getID(); } @Override Loading Loading @@ -135,8 +135,13 @@ public class ConceptImpl implements Concept { @Override public String getID() { URI me = (URI)res; String prefix = store.getNamespacePrefix(me.getNamespace()); if( prefix == null ){ // backward compatibility. this breaks the Ontology.getConceptById call. // TODO: use better namespace prefix instead of hashcode return Integer.toHexString(me.getNamespace().hashCode())+":"+me.getLocalName(); prefix = Integer.toHexString(me.getNamespace().hashCode()); } return prefix + ":" +me.getLocalName(); } Loading
histream-skos/src/main/java/de/sekmi/histream/ontology/skos/HIStreamOntology.java +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ public class HIStreamOntology { DWH_ECMASCRIPT = f.createURI(DWH_NAMESPACE, "ECMAScript"); DWH_HAS_PART = f.createURI(DWH_NAMESPACE, "hasPart"); // TODO use correct names/URIs DWH_IS_PART_OF = f.createURI(DWH_NAMESPACE, "isPartOf"); // XXX see above // dwh:hasPart rdfs:subPropertyOf http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#hasPart } }
histream-skos/src/main/java/de/sekmi/histream/ontology/skos/Store.java +50 −4 Original line number Diff line number Diff line Loading @@ -49,7 +49,8 @@ public class Store implements Ontology, Plugin { private Resource inferredContext; // SKOS scheme to enforce unique notations private Resource scheme; private Map<String, String> namespaceShortener; private String[] registeredPrefixes; private String[] registeredNamespaces; /// XXX namespace resolver /** Loading Loading @@ -142,7 +143,6 @@ public class Store implements Ontology, Plugin { return count; } private void initializeRepo(Iterable<File> files, Iterable<URL> urls, String baseURI) throws RepositoryException, IOException{ namespaceShortener = new HashMap<>(); repo = new SailRepository(new MemoryStore()); repo.initialize(); rc = repo.getConnection(); Loading Loading @@ -261,6 +261,49 @@ public class Store implements Ontology, Plugin { } public void setNamespacePrefixes(String[] namespaces, String prefixes[]){ // TODO order namespaces by length this.registeredNamespaces = namespaces; this.registeredPrefixes = prefixes; } private String expandIdPrefixes(String id){ if( registeredPrefixes == null ){ // no prefixes to expand return id; } for( int i=0; i<registeredPrefixes.length; i++ ){ String prefix = registeredPrefixes[i] + ":"; if( id.length() > prefix.length() && id.startsWith(prefix) ){ return registeredNamespaces[i] + id.substring(prefix.length()); } } return id; } String getNamespacePrefix(String namespace){ if( registeredNamespaces == null ){ return null; } for( int i=0; i<registeredNamespaces.length; i++ ){ if( namespace.equals(registeredNamespaces[i]) ){ return registeredPrefixes[i]; } } return null; } // // private String shortenIdNamespaces(String id){ // if( registeredNamespaces == null ){ // // no namespaces to shorten // return id; // } // for( int i=0; i<registeredNamespaces.length; i++ ){ // String ns = registeredNamespaces[i]; // if( id.length() > ns.length() && id.startsWith(ns) ){ // return registeredPrefixes[i] + ":" + id.substring(ns.length()); // } // } // return id; // } @Override public ConceptImpl getConceptByNotation(String id) throws OntologyException { Loading Loading @@ -494,7 +537,10 @@ public class Store implements Ontology, Plugin { } } @Override public Concept getConceptById(String id) throws OntologyException { public Concept getConceptById(String conceptId) throws OntologyException { // lookup namespaces String id = expandIdPrefixes(conceptId); URI uri = repo.getValueFactory().createURI(id); RepositoryResult<Statement> s = null; ConceptImpl ci = null; Loading