annotate NCBO_services/get_ontology_view.java @ 20:1910c878378c

get_ontology menu improved (Automatically generated), source added, readme improved
author Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Wed, 25 Jan 2012 19:49:20 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
1 package es.upm.fi.dia.oeg.ncbo.galaxy;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
2
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
3 import java.io.BufferedReader;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
4 import java.io.BufferedWriter;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
5 import java.io.IOException;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
6 import java.io.InputStream;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
7 import java.io.InputStreamReader;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
8 import java.io.OutputStreamWriter;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
9
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
10 import org.apache.http.HttpEntity;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
11 import org.apache.http.HttpResponse;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
12 import org.apache.http.client.ClientProtocolException;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
13 import org.apache.http.client.HttpClient;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
14 import org.apache.http.client.methods.HttpGet;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
15 import org.apache.http.client.methods.HttpPost;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
16 import org.apache.http.impl.client.DefaultHttpClient;
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
17
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
18 public class get_ontology_view {
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
19
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
20 /**
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
21 * @param args
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
22 * @throws IOException
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
23 * @throws ClientProtocolException
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
24 */
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
25 public static void main(String[] args) throws ClientProtocolException, IOException {
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
26 // http://www.bioontology.org/wiki/index.php/BioPortal_REST_services#Download_a_specific_ontology_view_based_on_the_ontology_view_version_id
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
27 // Download a specific ontology view based on the ontology view version id
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
28
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
29 String api_key = args [0];
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
30 String ontology_view_id = args [1];
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
31
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
32 HttpClient client = new DefaultHttpClient();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
33 // http://rest.bioontology.org/bioportal/ontologies/download/43072?apikey=YourAPIKey
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
34 HttpGet get = new HttpGet("http://rest.bioontology.org/bioportal/ontologies/download/" + ontology_view_id + "?apikey=" + api_key);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
35
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
36 HttpResponse response = client.execute(get);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
37 HttpEntity entity = response.getEntity();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
38 if (entity != null) {
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
39 InputStream instream = entity.getContent();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
40 InputStreamReader is=new InputStreamReader(instream);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
41 BufferedReader br=new BufferedReader(is);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
42 String read=br.readLine();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
43 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
44 while(read!=null){
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
45 // System.out.println(read);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
46 bw.write(read);
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
47 bw.newLine();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
48 read=br.readLine();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
49 }
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
50 bw.close();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
51 instream.close();
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
52 }
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
53 }
1910c878378c get_ontology menu improved (Automatically generated), source added, readme improved
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
54 }