Skip to content

Commit 14eb541

Browse files
committed
Move Uberon-related search tests under the providers package
1 parent 42aad23 commit 14eb541

3 files changed

Lines changed: 58 additions & 35 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ubic.basecode.ontology.providers;
2+
3+
import com.hp.hpl.jena.ontology.OntClass;
4+
import com.hp.hpl.jena.ontology.OntModel;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
import ubic.basecode.ontology.jena.OntologyLoader;
8+
import ubic.basecode.ontology.jena.search.OntologyIndexer;
9+
import ubic.basecode.ontology.jena.search.OntologySearch;
10+
import ubic.basecode.ontology.jena.search.SearchIndex;
11+
import ubic.basecode.ontology.search.OntologySearchException;
12+
import ubic.basecode.ontology.search.OntologySearchTest;
13+
14+
import java.io.IOException;
15+
import java.io.InputStream;
16+
import java.util.HashSet;
17+
import java.util.List;
18+
import java.util.Set;
19+
import java.util.zip.GZIPInputStream;
20+
21+
import static java.util.Objects.requireNonNull;
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertNotNull;
24+
25+
public class UberonOntologySearchTest {
26+
private static OntModel uberon;
27+
private static SearchIndex uberonIndex;
28+
29+
@BeforeClass
30+
public static void setUpUberon() throws IOException {
31+
try ( InputStream is = new GZIPInputStream( requireNonNull( OntologySearchTest.class.getResourceAsStream( "/data/uberon.owl.gz" ) ) ) ) {
32+
uberon = OntologyLoader.loadMemoryModel( is, "UBERON_TEST2" );
33+
uberonIndex = OntologyIndexer.indexOntology( "UBERON_TEST2", uberon, false );
34+
}
35+
}
36+
37+
@Test
38+
public void testOmitDefinition() throws OntologySearchException {
39+
OntClass brain = uberon.getOntClass( "http://purl.obolibrary.org/obo/UBERON_0000955" );
40+
assertNotNull( brain );
41+
Set<OntologySearch.SearchResult<OntClass>> searchResults = OntologySearch.matchClasses( uberon, uberonIndex, "brain" ).toSet();
42+
assertEquals( 128, searchResults.size() );
43+
}
44+
45+
@Test
46+
public void testScore() throws OntologySearchException {
47+
OntClass brain = uberon.getOntClass( "http://purl.obolibrary.org/obo/UBERON_0000955" );
48+
assertNotNull( brain );
49+
List<OntologySearch.SearchResult<OntClass>> searchResults = OntologySearch.matchClasses( uberon, uberonIndex, "brain" ).toList();
50+
assertEquals( 446, searchResults.size() );
51+
assertEquals( 3.33, searchResults.get( 0 ).score, 0.01 );
52+
assertEquals( 128, new HashSet<>( searchResults ).size() );
53+
}
54+
}

test/ubic/basecode/ontology/providers/UberonServiceTest.java renamed to test/ubic/basecode/ontology/providers/UberonOntologyServiceTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import static java.util.Objects.requireNonNull;
1818
import static org.junit.Assert.*;
19-
import static org.junit.Assert.assertTrue;
2019

21-
public class UberonServiceTest extends AbstractOntologyTest {
20+
public class UberonOntologyServiceTest extends AbstractOntologyTest {
2221

2322
private static OntologyService uberon;
2423

test/ubic/basecode/ontology/search/OntologySearchTest.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@
1717
import com.hp.hpl.jena.ontology.OntClass;
1818
import com.hp.hpl.jena.ontology.OntModel;
1919
import com.hp.hpl.jena.shared.JenaException;
20-
import org.junit.BeforeClass;
2120
import org.junit.Test;
2221
import ubic.basecode.ontology.AbstractOntologyTest;
2322
import ubic.basecode.ontology.jena.OntologyLoader;
2423
import ubic.basecode.ontology.jena.OntologyTermImpl;
25-
import ubic.basecode.ontology.jena.search.*;
24+
import ubic.basecode.ontology.jena.search.OntologyIndexer;
2625
import ubic.basecode.ontology.jena.search.OntologySearch;
26+
import ubic.basecode.ontology.jena.search.OntologySearchJenaException;
27+
import ubic.basecode.ontology.jena.search.SearchIndex;
2728

28-
import java.io.IOException;
2929
import java.io.InputStream;
3030
import java.util.Collection;
31-
import java.util.HashSet;
32-
import java.util.List;
3331
import java.util.Set;
3432
import java.util.zip.GZIPInputStream;
3533

@@ -45,17 +43,6 @@
4543
*/
4644
public class OntologySearchTest extends AbstractOntologyTest {
4745

48-
private static OntModel uberon;
49-
private static SearchIndex uberonIndex;
50-
51-
@BeforeClass
52-
public static void setUpUberon() throws IOException {
53-
try ( InputStream is = new GZIPInputStream( requireNonNull( OntologySearchTest.class.getResourceAsStream( "/data/uberon.owl.gz" ) ) ) ) {
54-
uberon = OntologyLoader.loadMemoryModel( is, "UBERON_TEST2" );
55-
uberonIndex = OntologyIndexer.indexOntology( "UBERON_TEST2", uberon, false );
56-
}
57-
}
58-
5946
@Test
6047
public final void testIndexing() throws Exception {
6148
InputStream is = new GZIPInputStream( requireNonNull( this.getClass().getResourceAsStream( "/data/mged.owl.gz" ) ) );
@@ -246,23 +233,6 @@ public final void testOmitDefinitions4() throws Exception {
246233
index.close();
247234
}
248235

249-
@Test
250-
public void testOmitDefinition() throws OntologySearchException {
251-
OntClass brain = uberon.getOntClass( "http://purl.obolibrary.org/obo/UBERON_0000955" );
252-
assertNotNull( brain );
253-
Set<OntologySearch.SearchResult<OntClass>> searchResults = OntologySearch.matchClasses( uberon, uberonIndex, "brain" ).toSet();
254-
assertEquals( 128, searchResults.size() );
255-
}
256-
257-
@Test
258-
public void testScore() throws OntologySearchException {
259-
OntClass brain = uberon.getOntClass( "http://purl.obolibrary.org/obo/UBERON_0000955" );
260-
assertNotNull( brain );
261-
List<OntologySearch.SearchResult<OntClass>> searchResults = OntologySearch.matchClasses( uberon, uberonIndex, "brain" ).toList();
262-
assertEquals( 446, searchResults.size() );
263-
assertEquals( 3.334063, searchResults.get( 0 ).score, 0.000001 );
264-
assertEquals( 128, new HashSet<>( searchResults ).size() );
265-
}
266236

267237
@Test
268238
public final void testPersistence() throws Exception {

0 commit comments

Comments
 (0)