Skip to content

Commit 3bd83fe

Browse files
committed
Merge branch 'hotfix-1.1.11'
2 parents 48ac3c8 + 84c10f7 commit 3bd83fe

File tree

13 files changed

+838
-983
lines changed

13 files changed

+838
-983
lines changed

pom.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>baseCode</name>
66
<groupId>baseCode</groupId>
77
<artifactId>baseCode</artifactId>
8-
<version>1.1.10</version>
8+
<version>1.1.11</version>
99
<inceptionYear>2003</inceptionYear>
1010
<description>
1111
<![CDATA[Data structures, math and statistics tools, and utilities that are often needed across projects.]]>
@@ -132,11 +132,6 @@
132132
<artifactId>mtj</artifactId>
133133
<version>1.0.4</version>
134134
</dependency>
135-
<dependency>
136-
<groupId>net.sourceforge.f2j</groupId>
137-
<artifactId>arpack_combined_all</artifactId>
138-
<version>0.1</version>
139-
</dependency>
140135

141136
<!-- Logging -->
142137
<dependency>
@@ -178,6 +173,10 @@
178173
<groupId>org.slf4j</groupId>
179174
<artifactId>slf4j-log4j12</artifactId>
180175
</exclusion>
176+
<exclusion>
177+
<artifactId>icu4j</artifactId>
178+
<groupId>com.ibm.icu</groupId>
179+
</exclusion>
181180
</exclusions>
182181
</dependency>
183182
<dependency>
@@ -378,7 +377,7 @@
378377
<artifactId>maven-surefire-plugin</artifactId>
379378
<version>2.22.2</version>
380379
<configuration>
381-
<argLine>-enableassertions -Xmx512m -Djava.awt.headless=true</argLine>
380+
<argLine>-enableassertions -Xmx1024m -Djava.awt.headless=true</argLine>
382381
<reportsDirectory>target/surefire-reports</reportsDirectory>
383382
<redirectTestOutputToFile>true</redirectTestOutputToFile>
384383
<includes>

src/ubic/basecode/ontology/OntologyLoader.java

Lines changed: 37 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* The baseCode project
3-
*
3+
*
44
* Copyright (c) 2010 University of British Columbia
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
@@ -18,49 +18,29 @@
1818
*/
1919
package ubic.basecode.ontology;
2020

21-
import java.io.BufferedReader;
22-
import java.io.File;
23-
import java.io.FileReader;
24-
import java.io.IOException;
25-
import java.io.InputStream;
26-
import java.io.InputStreamReader;
27-
import java.io.Reader;
28-
import java.net.HttpURLConnection;
29-
import java.net.URL;
30-
import java.net.URLConnection;
31-
import java.nio.file.Files;
32-
import java.nio.file.StandardCopyOption;
33-
import java.util.Collection;
34-
import java.util.HashSet;
35-
36-
import org.apache.commons.io.FileUtils;
37-
import org.apache.commons.lang3.StringUtils;
38-
import org.apache.commons.lang3.time.StopWatch;
39-
import org.slf4j.Logger;
40-
import org.slf4j.LoggerFactory;
41-
42-
import com.hp.hpl.jena.ontology.Individual;
43-
import com.hp.hpl.jena.ontology.OntClass;
4421
import com.hp.hpl.jena.ontology.OntModel;
4522
import com.hp.hpl.jena.ontology.OntModelSpec;
4623
import com.hp.hpl.jena.rdf.model.Model;
4724
import com.hp.hpl.jena.rdf.model.ModelFactory;
4825
import com.hp.hpl.jena.rdf.model.ModelMaker;
49-
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
50-
51-
import ubic.basecode.ontology.model.OntologyIndividual;
52-
import ubic.basecode.ontology.model.OntologyIndividualImpl;
53-
import ubic.basecode.ontology.model.OntologyProperty;
54-
import ubic.basecode.ontology.model.OntologyResource;
55-
import ubic.basecode.ontology.model.OntologyTerm;
56-
import ubic.basecode.ontology.model.OntologyTermImpl;
57-
import ubic.basecode.ontology.model.PropertyFactory;
26+
import org.apache.commons.io.FileUtils;
27+
import org.apache.commons.lang3.StringUtils;
28+
import org.apache.commons.lang3.time.StopWatch;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
5831
import ubic.basecode.util.Configuration;
5932

33+
import java.io.*;
34+
import java.net.HttpURLConnection;
35+
import java.net.URL;
36+
import java.net.URLConnection;
37+
import java.nio.file.Files;
38+
import java.nio.file.StandardCopyOption;
39+
6040
/**
6141
* Reads ontologies from OWL resources
62-
*
63-
* @author paul
42+
*
43+
* @author paul
6444
*/
6545
public class OntologyLoader {
6646

@@ -69,133 +49,37 @@ public class OntologyLoader {
6949
private static final String OLD_CACHE_SUFFIX = ".old";
7050
private static final String TMP_CACHE_SUFFIX = ".tmp";
7151

72-
/**
73-
* @param url
74-
* @param model
75-
* @return
76-
*/
77-
public static Collection<OntologyResource> initialize( String url, OntModel model ) {
78-
79-
Collection<OntologyResource> result = new HashSet<>();
80-
81-
ExtendedIterator<OntClass> classIt = model.listClasses();
82-
int count = 0;
83-
log.debug( "Reading classes for ontology: " + url );
84-
while ( classIt.hasNext() ) {
85-
OntClass element = classIt.next();
86-
if ( element.isAnon() ) continue;
87-
OntologyTerm ontologyTerm = new OntologyTermImpl( element );
88-
result.add( ontologyTerm );
89-
if ( ++count % 1000 == 0 ) {
90-
log.debug( "Loaded " + count + " terms, last was " + ontologyTerm );
91-
}
92-
}
93-
94-
log.debug( "Loaded " + count + " terms" );
95-
96-
ExtendedIterator<com.hp.hpl.jena.ontology.ObjectProperty> propIt = model.listObjectProperties();
97-
count = 0;
98-
log.debug( "Reading object properties..." );
99-
while ( propIt.hasNext() ) {
100-
com.hp.hpl.jena.ontology.ObjectProperty element = propIt.next();
101-
OntologyProperty ontologyTerm = PropertyFactory.asProperty( element );
102-
if ( ontologyTerm == null ) continue; // couldn't be converted for some reason.
103-
result.add( ontologyTerm );
104-
if ( ++count % 1000 == 0 ) {
105-
log.debug( "Loaded " + count + " object properties, last was " + ontologyTerm );
106-
}
107-
}
108-
109-
ExtendedIterator<com.hp.hpl.jena.ontology.DatatypeProperty> dtPropIt = model.listDatatypeProperties();
110-
log.debug( "Reading datatype properties..." );
111-
while ( dtPropIt.hasNext() ) {
112-
com.hp.hpl.jena.ontology.DatatypeProperty element = dtPropIt.next();
113-
OntologyProperty ontologyTerm = PropertyFactory.asProperty( element );
114-
if ( ontologyTerm == null ) continue; // couldn't be converted for some reason.
115-
result.add( ontologyTerm );
116-
if ( ++count % 1000 == 0 ) {
117-
log.debug( "Loaded " + count + " datatype properties, last was " + ontologyTerm );
118-
}
119-
}
120-
121-
log.debug( "Loaded " + count + " properties" );
122-
123-
ExtendedIterator<Individual> indiIt = model.listIndividuals();
124-
count = 0;
125-
log.debug( "Reading individuals..." );
126-
while ( indiIt.hasNext() ) {
127-
Individual element = indiIt.next();
128-
if ( element.isAnon() ) continue;
129-
OntologyIndividual ontologyTerm = new OntologyIndividualImpl( element );
130-
result.add( ontologyTerm );
131-
if ( ++count % 1000 == 0 ) {
132-
log.debug( "Loaded " + count + " individuals, last was " + ontologyTerm );
133-
}
134-
}
135-
log.debug( "Loaded " + count + " individuals" );
136-
return result;
137-
}
138-
13952
/**
14053
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available.
141-
*
142-
* @param is
143-
* @param url, used as a key
144-
* @param spec
145-
* @return
14654
*/
147-
public static OntModel loadMemoryModel( InputStream is, String url, OntModelSpec spec ) {
148-
OntModel model = getMemoryModel( url, spec );
55+
public static OntModel loadMemoryModel( InputStream is, String url ) {
56+
OntModel model = getMemoryModel( url );
14957
model.read( is, null );
15058
return model;
15159
}
15260

153-
/**
154-
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available. Uses
155-
* OWL_MEM_TRANS_INF
156-
*
157-
* @param url
158-
* @return
159-
*/
160-
public static OntModel loadMemoryModel( String url ) {
161-
return loadMemoryModel( url, OntModelSpec.OWL_MEM_TRANS_INF );
162-
}
163-
164-
/**
165-
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available. Uses
166-
* OWL_MEM_TRANS_INF
167-
* If load from URL fails, attempt to load from disk cache under @cacheName.
168-
*
169-
* @param url
170-
* @return
171-
*/
172-
public static OntModel loadMemoryModel( String url, String cacheName ) {
173-
return loadMemoryModel( url, OntModelSpec.OWL_MEM_TRANS_INF, cacheName );
174-
}
175-
17661
/**
17762
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available.
178-
*
179-
* @param url
180-
* @return
63+
*
64+
* @see #loadMemoryModel(String, String)
18165
*/
182-
public static OntModel loadMemoryModel( String url, OntModelSpec spec ) {
183-
return loadMemoryModel( url, spec, null );
66+
public static OntModel loadMemoryModel( String url ) {
67+
return loadMemoryModel( url, null );
18468
}
18569

18670
/**
18771
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available.
18872
* If load from URL fails, attempt to load from disk cache under @cacheName.
189-
*
190-
* @param url
191-
* @param spec e.g. OWL_MEM_TRANS_INF
192-
* @param cacheName unique name of this ontology, will be used to load from disk in case of failed url connection
193-
* @return
73+
* <p>
74+
* Uses {@link OntModelSpec#OWL_MEM_TRANS_INF}.
75+
*
76+
* @param url a URL where the OWL file is stored
77+
* @param cacheName unique name of this ontology, will be used to load from disk in case of failed url connection
19478
*/
195-
public static OntModel loadMemoryModel( String url, OntModelSpec spec, String cacheName ) {
79+
public static OntModel loadMemoryModel( String url, String cacheName ) {
19680
StopWatch timer = new StopWatch();
19781
timer.start();
198-
OntModel model = getMemoryModel( url, spec );
82+
OntModel model = getMemoryModel( url );
19983

20084
URLConnection urlc = null;
20185
int tries = 0;
@@ -242,7 +126,7 @@ public static OntModel loadMemoryModel( String url, OntModelSpec spec, String ca
242126
}
243127

244128
if ( urlc != null ) {
245-
try (InputStream in = urlc.getInputStream();) {
129+
try ( InputStream in = urlc.getInputStream(); ) {
246130
Reader reader;
247131
if ( cacheName != null ) {
248132
// write tmp to disk
@@ -261,7 +145,7 @@ public static OntModel loadMemoryModel( String url, OntModelSpec spec, String ca
261145
}
262146

263147
assert reader != null;
264-
try (BufferedReader buf = new BufferedReader( reader );) {
148+
try ( BufferedReader buf = new BufferedReader( reader ); ) {
265149
model.read( buf, url );
266150
}
267151

@@ -286,7 +170,7 @@ public static OntModel loadMemoryModel( String url, OntModelSpec spec, String ca
286170
}
287171

288172
if ( f.exists() && !f.isDirectory() ) {
289-
try (BufferedReader buf = new BufferedReader( new FileReader( f ) );) {
173+
try ( BufferedReader buf = new BufferedReader( new FileReader( f ) ); ) {
290174
model.read( buf, url );
291175
// We successfully loaded the cached ontology. Copy the loaded ontology to oldFile
292176
// so that we don't recreate indices during initialization based on a false change in
@@ -359,25 +243,14 @@ public static boolean deleteOldCache( String cacheName ) {
359243
return false;
360244
}
361245

362-
/**
363-
* Get model that is entirely in memory with default OntModelSpec.OWL_MEM_RDFS_INF.
364-
*
365-
* @param url
366-
* @return
367-
*/
368-
static OntModel getMemoryModel( String url ) {
369-
return getMemoryModel( url, OntModelSpec.OWL_MEM_RDFS_INF );
370-
}
371-
372246
/**
373247
* Get model that is entirely in memory.
374-
*
375-
* @param url
376-
* @param specification
248+
*
249+
* @param url
377250
* @return
378251
*/
379-
static OntModel getMemoryModel( String url, OntModelSpec specification ) {
380-
OntModelSpec spec = new OntModelSpec( specification );
252+
private static OntModel getMemoryModel( String url ) {
253+
OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_MEM_TRANS_INF );
381254
ModelMaker maker = ModelFactory.createMemModelMaker();
382255
Model base = maker.createModel( url, false );
383256
spec.setImportModelMaker( maker );
@@ -389,7 +262,7 @@ static OntModel getMemoryModel( String url, OntModelSpec specification ) {
389262
}
390263

391264
/**
392-
* @param name
265+
* @param name
393266
* @return
394267
*/
395268
public static File getDiskCachePath( String name ) {

0 commit comments

Comments
 (0)