00001
00002
00003
00004
00005
00006
00007 package edu.tum.cs.srl.taxonomy;
00008
00009 import java.util.HashMap;
00010 import java.util.Vector;
00011
00012 public class Taxonomy {
00013 protected HashMap<String,Concept> concepts = new HashMap<String, Concept>();
00014
00015 public Taxonomy() {
00016 }
00017
00018 public void addConcept(Concept c) {
00019 concepts.put(c.name, c);
00020 }
00021
00022 public Concept getConcept(String name) {
00023 return concepts.get(name);
00024 }
00025
00032 public Vector<Concept> getDescendants(String conceptName) throws Exception {
00033 Concept c = getConcept(conceptName);
00034 if(c == null)
00035 throw new Exception("Concept '" + conceptName + "' not in taxonomy.");
00036 return c.getDescendants();
00037 }
00038
00039 public boolean query_isa(String subtype, String type) throws Exception {
00040 Concept c = getConcept(type);
00041 Concept sc = getConcept(subtype);
00042 if(c == null)
00043 throw new Exception("Concept '" + type + "' unknown.");
00044 if(sc == null)
00045 throw new Exception("Concept '" + subtype + "' unknown.");
00046 Vector<Concept> p1 = sc.getAncestors();
00047 Vector<Concept> p2 = c.getAncestors();
00048 if(!(p1.size() > p2.size()))
00049 return false;
00050 return p1.contains(c);
00051 }
00052 }