Skip to content

Commit 4affc9c

Browse files
committed
Load medic and NIFST ontologies from the classpath
1 parent 8205afa commit 4affc9c

6 files changed

Lines changed: 32 additions & 12 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
<resource>
276276
<directory>src</directory>
277277
<includes>
278+
<include>**/*.owl.gz</include>
278279
<include>**/*.properties</include>
279280
</includes>
280281
<filtering>false</filtering>
1.6 MB
Binary file not shown.
1.57 KB
Binary file not shown.

src/ontology.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ url.obiOntology=http://purl.obolibrary.org/obo/obi.owl
3434

3535

3636
# no longer actively used.
37-
url.nifstdOntology=http://ontology.neuinfo.org/NIF/nif-gemma.owl
3837
url.fmaOntology=http://purl.obolibrary.org/obo/fma.owl
3938

4039
ontology.index.dir=ontology.index.dir

src/ubic/basecode/ontology/providers/MedicOntologyService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.IOException;
2626
import java.io.InputStream;
27+
import java.util.zip.GZIPInputStream;
2728

2829
/**
2930
* MEDIC ONTOLOGY USED BY PHENOCARTA, its represents MESH terms as a tree so with can use the parent structure that a
@@ -39,7 +40,7 @@ public class MedicOntologyService extends AbstractOntologyService {
3940
/**
4041
* FIXME this shouldn't be hard-coded like this, we should load it like any other ontology service.
4142
*/
42-
private static final String MEDIC_ONTOLOGY_FILE = "/data/loader/ontology/medic.owl";
43+
private static final String MEDIC_ONTOLOGY_FILE = "/data/loader/ontology/medic.owl.gz";
4344

4445
@Override
4546
protected String getOntologyName() {
@@ -48,7 +49,7 @@ protected String getOntologyName() {
4849

4950
@Override
5051
protected String getOntologyUrl() {
51-
return MEDIC_ONTOLOGY_FILE;
52+
return "classpath:" + MEDIC_ONTOLOGY_FILE;
5253
}
5354

5455
@Override
@@ -57,7 +58,7 @@ protected OntModel loadModel() {
5758
if ( is == null ) {
5859
throw new RuntimeException( String.format( "The MEDIC ontology was not found in classpath at %s.", MEDIC_ONTOLOGY_FILE ) );
5960
}
60-
return loadModelFromStream( is );
61+
return loadModelFromStream( new GZIPInputStream( is ) );
6162
} catch ( IOException e ) {
6263
throw new RuntimeException( e );
6364
}
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
/*
22
* The baseCode project
3-
*
3+
*
44
* Copyright (c) 2011 University of British Columbia
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
77
* the License. You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
1212
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
* specific language governing permissions and limitations under the License.
1414
*/
1515
package ubic.basecode.ontology.providers;
1616

17+
import com.hp.hpl.jena.ontology.OntModel;
1718
import ubic.basecode.ontology.jena.AbstractOntologyMemoryBackedService;
18-
import ubic.basecode.util.Configuration;
19+
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.util.zip.GZIPInputStream;
1923

2024
/**
2125
* @author paul
22-
*
2326
*/
2427
public class NIFSTDOntologyService extends AbstractOntologyMemoryBackedService {
2528

26-
private static final String NIFSTD_ONTOLOGY_URL = "url.nifstdOntology";
29+
private static final String NIFSTD_ONTOLOGY_FILE = "/data/loader/ontology/nif-gemma.owl.gz";
2730

2831
@Override
2932
protected String getOntologyName() {
@@ -32,7 +35,23 @@ protected String getOntologyName() {
3235

3336
@Override
3437
protected String getOntologyUrl() {
35-
return Configuration.getString( NIFSTD_ONTOLOGY_URL );
38+
return "classpath:" + NIFSTD_ONTOLOGY_FILE;
39+
}
40+
41+
@Override
42+
protected boolean getProcessImport() {
43+
return false;
3644
}
3745

46+
@Override
47+
protected OntModel loadModel() {
48+
try ( InputStream stream = getClass().getResourceAsStream( NIFSTD_ONTOLOGY_FILE ) ) {
49+
if ( stream == null ) {
50+
throw new RuntimeException( String.format( "The NIF ontology was not found in classpath at %s.", NIFSTD_ONTOLOGY_FILE ) );
51+
}
52+
return loadModelFromStream( new GZIPInputStream( stream ) );
53+
} catch ( IOException e ) {
54+
throw new RuntimeException( e );
55+
}
56+
}
3857
}

0 commit comments

Comments
 (0)