예제 #1
0
  public void initialize() throws ThinklabException {

    /* link and initialize knowledge repository */
    knowledgeRepository.initialize();

    /* see if the preferences override the thinklab core ontology URL */
    String cont =
        LocalConfiguration.getProperties()
            .getProperty("thinklab.ontology.core", DEFAULT_CORE_ONTOLOGY);

    URL tco = Thinklab.get().getResourceURL(cont);
    knowledgeRepository.refreshOntology(tco, MiscUtilities.getNameFromURL(cont), true);

    /* initialize types before we register plugins */
    initializeThinklabTypes();

    /* initialize default blacklists */
    String blk = LocalConfiguration.getProperties().getProperty(IGNORE_PROPERTY_PROPERTY);

    if (blk != null) {
      String[] bk = blk.trim().split(",");
      for (String s : bk) {
        KnowledgeManager.get().blacklistProperty(s);
      }
    }

    blk = LocalConfiguration.getProperties().getProperty(IGNORE_CONCEPT_PROPERTY);

    if (blk != null) {
      String[] bk = blk.trim().split(",");
      for (String s : bk) {
        KnowledgeManager.get().blacklistConcept(s);
      }
    }

    commandManager = new CommandManager();

    Thinklab.get().logger().info("knowledge manager initialized successfully");
  }
예제 #2
0
  @Override
  protected void doStart() throws Exception {

    /*
     * tell thinklab to generate ThinkcapSessions
     */
    KnowledgeManager.get().setSessionManager(new ThinkcapSessionManager());

    /*
     * TODO setup web space
     */

  }
예제 #3
0
  public IValue execute(Command command, ISession session) throws ThinklabException {

    // TODO only handle ontologies for now
    String toload = command.getArgumentAsString("resource");
    String name = command.hasOption("name") ? command.getOptionAsString("name") : null;

    if (name == null) name = MiscUtilities.getNameFromURL(toload);

    name = KnowledgeManager.get().registerOntology(toload, name);

    session.getOutputStream().println("ontology " + name + " loaded");

    return null;
  }
예제 #4
0
  /**
   * Return the literal concept that represents the POD type of the object passed. Anything non-POD
   * will return null.
   *
   * @param value
   * @return
   */
  public static IConcept getConceptForObject(Object value) {

    IConcept ret = null;

    if (value instanceof Integer) {
      ret = KnowledgeManager.Integer();
    } else if (value instanceof Float) {
      ret = KnowledgeManager.Float();
    } else if (value instanceof Double) {
      ret = KnowledgeManager.Double();
    } else if (value instanceof Long) {
      ret = KnowledgeManager.Long();
    } else if (value instanceof String) {
      ret = KnowledgeManager.Text();
    } else if (value instanceof Boolean) {
      ret = KnowledgeManager.Boolean();
    }

    return ret;
  }
예제 #5
0
  @Override
  public void initialize(IInstance i) throws ThinklabException {

    super.initialize(i);

    /*
     * these should be in already through reflection, but let's keep
     * the OWL way supported just in case.
     */
    for (IRelationship r : i.getRelationships("modeltypes:hasClassifier")) {
      String[] rz = r.getValue().toString().split("->");
      Pair<GeneralClassifier, IConcept> cls =
          new Pair<GeneralClassifier, IConcept>(
              new GeneralClassifier(rz[1]), KnowledgeManager.get().requireConcept(rz[0]));
      classifiers.add(cls);
    }

    /*
     * we have no guarantee that the universal classifier, if there,
     * will be last, given that it may come from an OWL multiproperty where
     * the orderding isn't guaranteed.
     *
     * scan the classifiers and if we have a universal classifier make sure
     * it's the last one, to avoid problems.
     */
    int unidx = -1;
    int iz = 0;
    for (Pair<GeneralClassifier, IConcept> cls : classifiers) {
      if (cls.getFirst().isUniversal()) {
        unidx = iz;
      }
      iz++;
    }

    if (unidx >= 0 && unidx < classifiers.size() - 1) {
      ArrayList<Pair<GeneralClassifier, IConcept>> nc =
          new ArrayList<Pair<GeneralClassifier, IConcept>>();
      for (iz = 0; iz < classifiers.size(); iz++) {
        if (iz != unidx) nc.add(classifiers.get(iz));
      }
      nc.add(classifiers.get(unidx));
      classifiers = nc;
    }

    /*
     * check if we have a nil classifier; if we don't we don't bother classifying
     * nulls and save some work.
     */
    this.hasNilClassifier = false;
    for (Pair<GeneralClassifier, IConcept> cl : classifiers) {
      if (cl.getFirst().isNil()) {
        this.hasNilClassifier = true;
        break;
      }
    }

    IValue def = i.get(CoreScience.HAS_CONCEPTUAL_SPACE);
    if (def != null) cSpace = def.getConcept();

    def = i.get("modeltypes:encodesContinuousDistribution");
    if (def != null) continuousDistribution = MiscUtilities.parseDoubleVector(def.toString());

    // TODO remove?
    if (continuousDistribution != null
        && getDataSource() != null
        && (getDataSource() instanceof IState))
      ((IState) getDataSource())
          .getMetadata()
          .put(Metadata.CONTINUOS_DISTRIBUTION_BREAKPOINTS, continuousDistribution);

    if (continuousDistribution != null)
      metadata.put(Metadata.CONTINUOS_DISTRIBUTION_BREAKPOINTS, continuousDistribution);

    if (classifiers != null) {

      metadata.put(Metadata.CLASSIFIERS, classifiers);

      IConcept[] rnk = null;
      /*
       * remap the values to ranks and determine how to rewire the input
       * if necessary, use classifiers instead of lexicographic order to
       * infer the appropriate concept order
       */
      ArrayList<GeneralClassifier> cla = new ArrayList<GeneralClassifier>();
      ArrayList<IConcept> con = new ArrayList<IConcept>();
      for (Pair<GeneralClassifier, IConcept> op : classifiers) {
        cla.add(op.getFirst());
        con.add(op.getSecond());
      }

      Pair<double[], IConcept[]> pd = Metadata.computeDistributionBreakpoints(cSpace, cla, con);
      if (pd != null) {
        if (pd.getSecond()[0] != null) {
          rnk = pd.getSecond();
        }
      }

      HashMap<IConcept, Integer> ranks = null;
      if (rnk == null) {
        ranks = Metadata.rankConcepts(cSpace, metadata);
      } else {
        ranks = Metadata.rankConcepts(cSpace, rnk, metadata);
      }
    }
  }
예제 #6
0
 public TextValue(String s) {
   super(KnowledgeManager.Text());
   value = s;
 }
예제 #7
0
 public TextValue() {
   super(KnowledgeManager.Text());
   value = "";
 }
예제 #8
0
 public AlgorithmValue() throws ThinklabException {
   super(KnowledgeManager.get().getTextType());
   value = "";
 }