Revision 8717
Added by ben leinfelder over 10 years ago
test/edu/ucsb/nceas/metacat/annotation/BioPortalServiceTest.java | ||
---|---|---|
1 |
/** '$RCSfile$' |
|
2 |
* Copyright: 2010 Regents of the University of California and the |
|
3 |
* National Center for Ecological Analysis and Synthesis |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; either version 2 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
*/ |
|
19 |
package edu.ucsb.nceas.metacat.annotation; |
|
20 |
|
|
21 |
import com.hp.hpl.jena.ontology.OntClass; |
|
22 |
import com.hp.hpl.jena.ontology.OntModel; |
|
23 |
import com.hp.hpl.jena.rdf.model.ModelFactory; |
|
24 |
import com.hp.hpl.jena.rdf.model.Resource; |
|
25 |
|
|
26 |
import junit.framework.Test; |
|
27 |
import junit.framework.TestSuite; |
|
28 |
import edu.ucsb.nceas.MCTestCase; |
|
29 |
|
|
30 |
public class BioPortalServiceTest extends MCTestCase { |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* constructor for the test |
|
35 |
*/ |
|
36 |
public BioPortalServiceTest(String name) { |
|
37 |
super(name); |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Establish a testing framework by initializing appropriate objects |
|
42 |
*/ |
|
43 |
public void setUp() throws Exception { |
|
44 |
super.setUp(); |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Release any objects after tests are complete |
|
49 |
*/ |
|
50 |
public void tearDown() { |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Create a suite of tests to be run together |
|
55 |
*/ |
|
56 |
public static Test suite() { |
|
57 |
TestSuite suite = new TestSuite(); |
|
58 |
suite.addTest(new BioPortalServiceTest("testLookup")); |
|
59 |
return suite; |
|
60 |
} |
|
61 |
|
|
62 |
public void testLookup() { |
|
63 |
// set up our simple model for testing: Characteristic <- Temperature |
|
64 |
OntModel m = ModelFactory.createOntologyModel(); |
|
65 |
OntClass characteristicClass = m.createClass(DatapackageSummarizer.oboe_core + "Characteristic"); |
|
66 |
OntClass temperatureClass = m.createClass(DatapackageSummarizer.oboe_characteristics + "Temperature"); |
|
67 |
temperatureClass.addSuperClass(characteristicClass); |
|
68 |
|
|
69 |
// look up the annotation recommendation from BioPortal |
|
70 |
String text = "Air temperature"; |
|
71 |
Resource retClass = BioPortalService.lookupAnnotationClass(characteristicClass, text, DatapackageSummarizer.OBOE_SBC); |
|
72 |
assertEquals(DatapackageSummarizer.oboe_characteristics + "Temperature", retClass.getURI()); |
|
73 |
} |
|
74 |
|
|
75 |
} |
|
0 | 76 |
src/edu/ucsb/nceas/metacat/annotation/DatapackageSummarizer.java | ||
---|---|---|
54 | 54 |
public static String owl = "http://www.w3.org/2002/07/owl#"; |
55 | 55 |
public static String oboe = "http://ecoinformatics.org/oboe/oboe.1.0/oboe.owl#"; |
56 | 56 |
public static String oboe_core = "http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#"; |
57 |
public static String oboe_characteristics = "http://ecoinformatics.org/oboe/oboe.1.0/oboe-characteristics.owl#"; |
|
57 | 58 |
public static String oa = "http://www.w3.org/ns/oa#"; |
58 | 59 |
public static String oa_source = "http://www.w3.org/ns/oa.rdf"; |
59 | 60 |
public static String dcterms = "http://purl.org/dc/terms/"; |
... | ... | |
64 | 65 |
public static String prov_source = "http://www.w3.org/ns/prov.owl"; |
65 | 66 |
public static String cito = "http://purl.org/spar/cito/"; |
66 | 67 |
|
68 |
public static String OBOE_SBC = "OBOE-SBC"; |
|
69 |
|
|
67 | 70 |
// package visibility for testing only |
68 | 71 |
boolean randomize = false; |
69 | 72 |
|
... | ... | |
246 | 249 |
} |
247 | 250 |
} |
248 | 251 |
// try to look it up if we got this far |
249 |
return BioPortalService.lookupAnnotationClass(standardClass, unit); |
|
252 |
return BioPortalService.lookupAnnotationClass(standardClass, unit, OBOE_SBC);
|
|
250 | 253 |
} |
251 | 254 |
|
252 | 255 |
private Resource lookupCharacteristic(OntClass characteristicClass, Attribute attribute) { |
... | ... | |
280 | 283 |
} |
281 | 284 |
|
282 | 285 |
// try to look it up if we got this far |
283 |
return BioPortalService.lookupAnnotationClass(characteristicClass, attribute.getDefinition()); |
|
286 |
return BioPortalService.lookupAnnotationClass(characteristicClass, attribute.getDefinition(), OBOE_SBC);
|
|
284 | 287 |
|
285 | 288 |
} |
286 | 289 |
|
src/edu/ucsb/nceas/metacat/annotation/BioPortalService.java | ||
---|---|---|
30 | 30 |
* @param text |
31 | 31 |
* @return |
32 | 32 |
*/ |
33 |
public static Resource lookupAnnotationClass(OntClass superClass, String text) { |
|
33 |
public static Resource lookupAnnotationClass(OntClass superClass, String text, String ontologies) {
|
|
34 | 34 |
|
35 | 35 |
try { |
36 | 36 |
|
37 | 37 |
String urlParameters = "apikey=" + API_KEY; |
38 | 38 |
urlParameters += "&format=xml"; |
39 |
urlParameters += "&ontologies=OBOE-SBC"; |
|
40 |
// urlParameters += "&ontologies=SWEET"; |
|
39 |
if (ontologies != null) { |
|
40 |
urlParameters += "&ontologies=" + ontologies; |
|
41 |
} |
|
41 | 42 |
urlParameters += "&text=" + URLEncoder.encode(text, "UTF-8"); |
42 | 43 |
|
43 | 44 |
String url = REST_URL + "/annotator?" + urlParameters ; |
Also available in: Unified diff
add test for BioPortal annotator service.