$search
00001 package edu.tum.cs.ias.knowrob.owl; 00002 00003 import java.util.Hashtable; 00004 00005 public class OWLThing implements Comparable<OWLThing> { 00006 00007 00011 protected static Hashtable<String, OWLThing> identifiers = new Hashtable<String, OWLThing>(); 00012 00016 protected String iri; 00017 00021 protected String label; 00022 00026 protected boolean readFromProlog = false; 00027 00028 00032 protected boolean saveToProlog = false; 00033 00034 00035 00045 public static OWLThing getOWLThing(String iri, String label) { 00046 00047 if(identifiers.containsKey(iri)) { 00048 00049 if(identifiers.get(iri).label != label) 00050 identifiers.get(iri).setLabel(label); 00051 00052 return identifiers.get(iri); 00053 00054 } else { 00055 OWLThing res = new OWLThing(iri, label); 00056 identifiers.put(iri, res); 00057 return res; 00058 } 00059 } 00060 00061 00069 protected OWLThing(String iri, String label) { 00070 00071 this.iri = iri; 00072 00073 if(label!=null) 00074 this.label = label; 00075 else 00076 this.label = getShortName(); 00077 00078 } 00079 00080 00089 public static OWLThing getOWLThingByShortname(String shortname) { 00090 00091 for(String iri : identifiers.keySet()) { 00092 if(iri.endsWith(shortname)) { 00093 return identifiers.get(iri); 00094 } 00095 } 00096 return null; 00097 } 00098 00104 public static void removeOWLThing(String iri) { 00105 identifiers.remove(iri); 00106 } 00107 00108 00113 public String getIRI() { 00114 return iri; 00115 } 00116 00117 00122 public void setIri(String iri) { 00123 this.iri = iri; 00124 } 00125 00130 public String getLabel() { 00131 return label; 00132 } 00133 00138 public void setLabel(String label) { 00139 this.label = label; 00140 } 00141 00142 00149 public String getIRIPrefix(){ 00150 return getPrefixOfIRI(iri); 00151 } 00152 00153 00154 00161 public String getShortName(){ // name after hash sign 00162 return getShortNameOfIRI(iri); 00163 } 00164 00165 00172 public String getIRIFilename(){ // after last '/', before hash 00173 return getFilenameOfIRI(iri); 00174 } 00175 00176 00177 00184 @Override 00185 public int compareTo(OWLThing o) { 00186 return this.iri.compareTo(o.getIRI()); 00187 } 00188 00189 00196 public boolean equals(Object b) { 00197 if (b instanceof OWLThing) { 00198 if(this.iri.equals(((OWLThing) b).getIRI())) 00199 return true; 00200 else 00201 return false; 00202 } 00203 return false; 00204 } 00205 00209 @Override 00210 public String toString() { 00211 return this.iri; 00212 } 00213 00214 00224 public static String removeSingleQuotes(String str) { 00225 if(str.startsWith("'")) 00226 str = str.substring(1); 00227 00228 if(str.endsWith("'")) 00229 str = str.substring(0, str.length()-1); 00230 return str; 00231 } 00232 00233 00243 public static String addSingleQuotes(String str) { 00244 return "'"+removeSingleQuotes(str)+"'"; 00245 } 00246 00247 00254 public static String getShortNameOfIRI(String iri) { 00255 00256 String[] elem = iri.split("#"); 00257 if(elem.length>1) { 00258 String res = elem[1].replaceAll("'", ""); 00259 return res; 00260 } 00261 else return iri; 00262 } 00263 00264 00265 public static String getPrefixOfIRI(String iri) { 00266 00267 String[] elem = iri.split("#"); 00268 if(elem.length>1) { 00269 String res = elem[0].replaceAll("'", ""); 00270 return res; 00271 } 00272 else return iri; 00273 } 00274 00275 public static String getFilenameOfIRI(String iri) { 00276 00277 String[] elem = iri.split("/"); 00278 if(elem.length>1) { 00279 00280 String after_slash = elem[elem.length-1].replaceAll("'", ""); 00281 String[] elem2 = after_slash.split("#"); 00282 00283 if(elem2.length>1) { 00284 String res = elem2[0]; 00285 return res; 00286 } 00287 else return after_slash; 00288 } 00289 else return iri; 00290 } 00291 00292 00293 public boolean isReadFromProlog() { 00294 return readFromProlog; 00295 } 00296 00297 00298 public void setReadFromProlog(boolean readFromProlog) { 00299 this.readFromProlog = readFromProlog; 00300 } 00301 00302 00303 public boolean needsSaveToProlog() { 00304 return saveToProlog; 00305 } 00306 00307 00308 public void setSaveToProlog(boolean saveToProlog) { 00309 this.saveToProlog = saveToProlog; 00310 } 00311 00312 }