示例#1
0
  /**
   * constructs an empty database for the given model
   *
   * @param model
   * @throws Exception
   */
  public GenericDatabase(RelationalModel model) throws Exception {
    this.model = model;
    entries = new HashMap<String, VariableType>();
    domains = new HashMap<String, HashSet<String>>();
    functionalDependencies = new HashMap<RelationKey, HashMap<String, String[]>>();
    taxonomy = model.getTaxonomy();
    paramHandler = new ParameterHandler(this);
    paramHandler.add("debug", "setDebug");
    paramHandler.add("debug", "setVerbose");

    // initialize domains
    if (taxonomy != null) {
      entity2type = new HashMap<String, String>();
      multiDomains = new HashMap<String, MultiIterator<String>>();
      for (Concept c : model.getTaxonomy().getConcepts()) {
        domains.put(c.name, new HashSet<String>());
      }
    }

    // fill domains with guaranteed domain elements
    for (Entry<String, ? extends Collection<String>> e :
        model.getGuaranteedDomainElements().entrySet()) {
      for (String element : e.getValue()) fillDomain(e.getKey(), element);
    }

    Collection<String> prologRules = model.getPrologRules();
    prolog = new PrologKnowledgeBase();
    if (prologRules != null && !prologRules.isEmpty()) {
      System.out.println("building Prolog knowledge base... ");
      for (String rule : prologRules) {
        try {
          System.out.println("telling " + rule);
          prolog.tell(rule);
        } catch (Throwable e) {
          System.out.println("DID catch");
          throw new Exception("Error processing rule '" + rule + "'", e);
        }
      }
    }
  }