Exemplo n.º 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");
  }
Exemplo n.º 2
0
  @Override
  protected void doStart() throws Exception {

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

    /*
     * TODO setup web space
     */

  }
Exemplo n.º 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;
  }
Exemplo n.º 4
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);
      }
    }
  }
Exemplo n.º 5
0
 public AlgorithmValue() throws ThinklabException {
   super(KnowledgeManager.get().getTextType());
   value = "";
 }