001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.nbio.ontology; 022 023import org.biojava.nbio.ontology.io.TabDelimParser; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027import java.io.BufferedReader; 028import java.io.InputStreamReader; 029 030/** 031 * Tools for manipulating ontologies. 032 * 033 * @author Matthew Pocock 034 */ 035public final class OntoTools { 036 037 private static final Logger logger = LoggerFactory.getLogger(OntoTools.class); 038 039 private static final Ontology CORE_ONTOLOGY; 040 private static final OntologyFactory DEFAULT_FACTORY; 041 private static final IntegerOntology CORE_INTEGER; 042 //private static final Ontology CORE_STRING; 043 044 // public static final Term TYPE; 045 public static final Term RELATION; 046 public static final Term ANY; 047 public static final Term NONE; 048 public static final Term IS_A; 049 public static final Term PART_OF; 050 // public static final Term SUB_TYPE_OF; 051 // public static final Term INSTANCE_OF; 052 // public static final Term DOMAIN; 053 // public static final Term CO_DOMAIN; 054 // public static final Term HAS_DOMAIN; 055 // public static final Term HAS_CO_DOMAIN; 056 057 // public static final Term BOOLEAN; 058 // public static final Term TRUE; 059 // public static final Term FALSE; 060 // public static final Term PREDICATE; 061 062 // public static final Term AND; 063 // public static final Term OR; 064 // public static final Term XOR; 065 // public static final Term EQUAL; 066 // public static final Term NOT_EQUAL; 067 // public static final Term IMPLIES; 068 069 public static final Term REFLEXIVE; 070 public static final Term SYMMETRIC; 071 public static final Term TRANSITIVE; 072 public static final Term EQUIVALENCE; 073 public static final Term PARTIAL_ORDER; 074 075 static { 076 DEFAULT_FACTORY = new OntologyFactory() { 077 @Override 078 public Ontology createOntology(String name, String desc) 079 throws OntologyException { 080 return new Ontology.Impl(name, desc); 081 } 082 }; 083 084 try { 085 BufferedReader reader = new BufferedReader( 086 new InputStreamReader( 087 OntoTools.class.getResourceAsStream( 088 "/ontology/core.onto" 089 ) 090 ) 091 ); 092 093 CORE_INTEGER = new IntegerOntology(); 094 CORE_ONTOLOGY = new TabDelimParser().parse( 095 reader, 096 DEFAULT_FACTORY 097 ); 098 099 // TYPE = CORE_ONTOLOGY.getTerm("type"); 100 RELATION = CORE_ONTOLOGY.getTerm("relation"); 101 ANY = CORE_ONTOLOGY.getTerm("any"); 102 NONE = CORE_ONTOLOGY.getTerm("none"); 103 IS_A = CORE_ONTOLOGY.getTerm("is-a"); 104 PART_OF = CORE_ONTOLOGY.getTerm("part-of"); 105 106 // SUB_TYPE_OF = CORE_ONTOLOGY.getTerm("sub_type_of"); 107 // INSTANCE_OF = CORE_ONTOLOGY.getTerm("instance_of"); 108 // DOMAIN = CORE_ONTOLOGY.getTerm("domain"); 109 // CO_DOMAIN = CORE_ONTOLOGY.getTerm("co_domain"); 110 // HAS_DOMAIN = CORE_ONTOLOGY.getTerm("has_domain"); 111 // HAS_CO_DOMAIN = CORE_ONTOLOGY.getTerm("has_co_domain"); 112 113 // BOOLEAN = CORE_ONTOLOGY.getTerm("boolean"); 114 // TRUE = CORE_ONTOLOGY.getTerm("true"); 115 // FALSE = CORE_ONTOLOGY.getTerm("false"); 116 // PREDICATE = CORE_ONTOLOGY.getTerm("predicate"); 117 118 // AND = CORE_ONTOLOGY.getTerm("and"); 119 // OR = CORE_ONTOLOGY.getTerm("or"); 120 // XOR = CORE_ONTOLOGY.getTerm("xor"); 121 // EQUAL = CORE_ONTOLOGY.getTerm("equal"); 122 // NOT_EQUAL = CORE_ONTOLOGY.getTerm("not_equal"); 123 // IMPLIES = CORE_ONTOLOGY.getTerm("implies"); 124 125 REFLEXIVE = CORE_ONTOLOGY.getTerm("reflexive"); 126 EQUIVALENCE = CORE_ONTOLOGY.getTerm("equivalence"); 127 SYMMETRIC = CORE_ONTOLOGY.getTerm("symmetric"); 128 TRANSITIVE = CORE_ONTOLOGY.getTerm("transitive"); 129 PARTIAL_ORDER = CORE_ONTOLOGY.getTerm("partial-order"); 130 131 } catch (Exception e) { 132 logger.error("Exception: ", e); 133 throw new RuntimeException("Could not initialize OntoTools", e); 134 } 135 } 136 137 138 private OntoTools() {} 139 140 /** 141 * Get the Ontology that defines our core "central dogma". 142 * 143 * <p>This contains definitions that we have to have, such as <code>any</code>, 144 * <code>predicate</code>, <code>is-a</code> and <code>transient</code>. These 145 * are our axioms, upon which the default interpreters build.</p> 146 * 147 * @return the "core" Ontology 148 */ 149 public static Ontology getCoreOntology() { 150 return CORE_ONTOLOGY; 151 } 152 153 /** 154 * Get the Ontology that defines integers. 155 * 156 * <p>This contains a term for each and every integer. I haven't decided yet 157 * if it contains terms for arithmatic.</p> 158 * 159 * @return the integer Ontology 160 */ 161 public static IntegerOntology getIntegerOntology() { 162 return CORE_INTEGER; 163 } 164 165 public static OntologyFactory getDefaultFactory() { 166 return DEFAULT_FACTORY; 167 } 168}