1 18 19 package com.hp.hpl.jena.ontology.daml.impl; 22 23 24 27 import com.hp.hpl.jena.vocabulary.*; 28 import com.hp.hpl.jena.rdf.model.*; 29 30 import java.util.*; 31 32 33 34 42 public class DAMLHierarchy 43 { 44 47 48 51 52 private static DAMLHierarchy s_instance = new DAMLHierarchy(); 53 54 55 58 62 public Resource[][] DAML_STANDARD_CLASS_HIERARCHY = new Resource[][] { 63 {DAML_OIL.Class, RDFS.Class}, 65 {DAML_OIL.Datatype, RDFS.Class}, 66 {DAML_OIL.Restriction, DAML_OIL.Class}, 67 {DAML_OIL.ObjectProperty, RDF.Property}, 68 {DAML_OIL.DatatypeProperty, RDF.Property}, 69 {DAML_OIL.TransitiveProperty, DAML_OIL.ObjectProperty}, 70 {DAML_OIL.UnambiguousProperty, DAML_OIL.ObjectProperty}, 71 {DAML_OIL.UniqueProperty, RDF.Property}, 72 {DAML_OIL.List, RDF.Seq}, 73 }; 74 75 76 79 public Resource[][] DAML_STANDARD_EQUIVALENCES = new Resource[][] { 80 {DAML_OIL.subClassOf, RDFS.subClassOf}, 81 {DAML_OIL.Literal, RDFS.Literal}, 82 {DAML_OIL.Property, RDF.Property}, 83 {DAML_OIL.type, RDF.type}, 84 {DAML_OIL.value, RDF.value}, 85 {DAML_OIL.subPropertyOf, RDFS.subPropertyOf}, 86 {DAML_OIL.domain, RDFS.domain}, 87 {DAML_OIL.range, RDFS.range}, 88 {DAML_OIL.label, RDFS.label}, 89 {DAML_OIL.comment, RDFS.comment}, 90 {DAML_OIL.seeAlso, RDFS.seeAlso}, 91 {DAML_OIL.isDefinedBy, RDFS.isDefinedBy}, 92 }; 93 94 95 96 public Property[] TRANSITIVE_PROPERTIES = new Property[] { 97 DAML_OIL.subClassOf, 98 DAML_OIL.subPropertyOf, 99 DAML_OIL.sameClassAs, 100 DAML_OIL.sameIndividualAs, 101 DAML_OIL.samePropertyAs, 102 DAML_OIL.equivalentTo, 103 104 RDFS.subClassOf, 105 RDFS.subPropertyOf 106 }; 107 108 109 protected Map m_classHierarchyMap = new HashMap(); 110 111 112 protected boolean m_initialised = false; 113 114 115 protected Map m_equivalenceMap = new HashMap(); 116 117 118 protected Map m_transitiveProperties = new HashMap(); 119 120 121 122 125 128 private DAMLHierarchy() { 129 } 130 131 132 135 140 public static DAMLHierarchy getInstance() { 141 return s_instance; 142 } 143 144 145 155 public boolean isDAMLSubClassOf( String uri0, String uri1 ) { 156 if ((uri0 == null) || (uri1 == null) || 159 (uri0.length() == 0) || (uri1.length() == 0)) { 160 return false; 161 } 162 163 initialiseMaps(); 165 166 String superClass = (String ) m_classHierarchyMap.get( uri0 ); 168 169 if (uri1.equals( superClass )) { 170 return true; 172 } 173 else { 174 return superClass == null ? false : isDAMLSubClassOf( superClass, uri1 ); 177 } 178 } 179 180 181 192 public boolean isTransitiveProperty( Resource res ) { 193 return (res instanceof Property && m_transitiveProperties.containsKey( res )); 194 } 195 196 197 204 public Iterator getEquivalentValues( Resource res ) { 205 initialiseMaps(); 207 208 LinkedList equivs = (LinkedList) m_equivalenceMap.get( res ); 209 return (equivs == null) ? new LinkedList().iterator() : equivs.iterator(); 210 } 211 212 213 214 217 222 private void initialiseMaps() { 223 if (!m_initialised) { 224 for (int i = 0; i < DAML_STANDARD_CLASS_HIERARCHY.length; i++) { 226 String subClass = DAML_STANDARD_CLASS_HIERARCHY[i][0].getURI(); 227 String superClass = DAML_STANDARD_CLASS_HIERARCHY[i][1].getURI(); 228 229 m_classHierarchyMap.put( subClass, superClass ); 230 } 231 232 for (int i = 0; i < DAML_STANDARD_EQUIVALENCES.length; i++) { 234 LinkedList l = (LinkedList) m_equivalenceMap.get( DAML_STANDARD_EQUIVALENCES[i][0] ); 236 237 if (l == null) { 238 l = new LinkedList(); 240 m_equivalenceMap.put( DAML_STANDARD_EQUIVALENCES[i][0], l ); 241 } 242 243 l.add( DAML_STANDARD_EQUIVALENCES[i][1] ); 244 245 l = (LinkedList) m_equivalenceMap.get( DAML_STANDARD_EQUIVALENCES[i][1] ); 247 248 if (l == null) { 249 l = new LinkedList(); 251 m_equivalenceMap.put( DAML_STANDARD_EQUIVALENCES[i][1], l ); 252 } 253 254 l.add( DAML_STANDARD_EQUIVALENCES[i][0] ); 255 } 256 257 for (int i = 0; i < TRANSITIVE_PROPERTIES.length; i++) { 259 m_transitiveProperties.put( TRANSITIVE_PROPERTIES[i], Boolean.TRUE ); 260 } 261 262 m_initialised = true; 263 } 264 } 265 266 267 268 272 273 } 274 275 276 305 306 | Popular Tags |