| 1 | // Work with namespaces in local ontologies |
|---|
| 2 | /** |
|---|
| 3 | * Copyright (c) 2010 - 2011 European Molecular Biology Laboratory and University of Groningen |
|---|
| 4 | * |
|---|
| 5 | * Contact: ontocat-users@lists.sourceforge.net |
|---|
| 6 | * |
|---|
| 7 | * This file is part of OntoCAT |
|---|
| 8 | * |
|---|
| 9 | * OntoCAT is free software: you can redistribute it and/or modify it under |
|---|
| 10 | * the terms of the GNU Lesser General Public License as published by the Free |
|---|
| 11 | * Software Foundation; either version 3 of the License, or (at your option) any |
|---|
| 12 | * later version. |
|---|
| 13 | * |
|---|
| 14 | * OntoCAT is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|---|
| 17 | * details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU Lesser General Public License along |
|---|
| 20 | * with OntoCAT. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 21 | */ |
|---|
| 22 | package uk.ac.ebi.ontocat.examples; |
|---|
| 23 | |
|---|
| 24 | import java.net.URI; |
|---|
| 25 | import java.net.URISyntaxException; |
|---|
| 26 | import java.util.List; |
|---|
| 27 | |
|---|
| 28 | import uk.ac.ebi.ontocat.OntologyServiceException; |
|---|
| 29 | import uk.ac.ebi.ontocat.OntologyTerm; |
|---|
| 30 | import uk.ac.ebi.ontocat.file.FileOntologyService; |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * Example 18 |
|---|
| 34 | * |
|---|
| 35 | * The tricky namespaces |
|---|
| 36 | */ |
|---|
| 37 | public class Example18 { |
|---|
| 38 | public static void main(String[] args) throws OntologyServiceException, URISyntaxException { |
|---|
| 39 | // OWL API arbitrary assigns one to OBO ontologies as they are not supported |
|---|
| 40 | // natively by OBO format |
|---|
| 41 | // OWL ontologies can have multiple namespaces if they import terms directly (e.g. EFO). |
|---|
| 42 | // In practice anything that comes up in the file minus URI fragment can be used as |
|---|
| 43 | // ontology accession, but it is good practice to specify one yourself in alternative |
|---|
| 44 | // constructor, see below: |
|---|
| 45 | |
|---|
| 46 | // Instantiate a FileOntologyService(URI, ontologyAccession) |
|---|
| 47 | FileOntologyService os = new FileOntologyService(new URI("http://www.co-ode.org/ontologies/pizza/2007/02/12/pizza.owl"), |
|---|
| 48 | "http://pizza/namespace/"); |
|---|
| 49 | |
|---|
| 50 | // Try to find a term |
|---|
| 51 | List<OntologyTerm> list = os.searchAll("Cajun"); |
|---|
| 52 | |
|---|
| 53 | System.out.println(list.get(0).getOntologyAccession()); |
|---|
| 54 | // http://www.co-ode.org/ontologies/pizza/pizza.owl# |
|---|
| 55 | |
|---|
| 56 | System.out.println(os.getOntologies().get(0).getOntologyAccession()); |
|---|
| 57 | // http://www.co-ode.org/ontologies/pizza/pizza.owl |
|---|
| 58 | |
|---|
| 59 | // Those work |
|---|
| 60 | System.out.println("\nThose work:"); |
|---|
| 61 | System.out.println(os.getAllTerms("http://www.co-ode.org/ontologies/pizza/pizza.owl#").size()); |
|---|
| 62 | System.out.println(os.getAllTerms("http://www.co-ode.org/ontologies/pizza/pizza.owl").size()); |
|---|
| 63 | System.out.println(os.getAllTerms("http://pizza/namespace/").size()); |
|---|
| 64 | |
|---|
| 65 | System.out.println(os.getRootTerms("http://www.co-ode.org/ontologies/pizza/pizza.owl#").size()); |
|---|
| 66 | System.out.println(os.getRootTerms("http://www.co-ode.org/ontologies/pizza/pizza.owl").size()); |
|---|
| 67 | System.out.println(os.getRootTerms("http://pizza/namespace/").size()); |
|---|
| 68 | |
|---|
| 69 | // Those don't |
|---|
| 70 | System.out.println("\nThose don't:"); |
|---|
| 71 | System.out.println(os.getAllTerms("some/random/namespace").size()); |
|---|
| 72 | System.out.println(os.getRootTerms("some/random/namespace").size()); |
|---|
| 73 | } |
|---|
| 74 | } |
|---|