@Override
  public Polylist conceptualize() throws ThinklabException {

    return Polylist.list(
        CoreScience.CONTEXTUALIZED_DATASOURCE,
        Polylist.list("@", new DatasourceStateAdapter(this)));
  }
  @Override
  public IValue execute(Command command, ISession session) throws ThinklabException {

    String concept = command.getArgumentAsString("concept");

    IKBox kbox = KBoxManager.get();
    if (command.hasOption("kbox"))
      kbox = KBoxManager.get().requireGlobalKBox(command.getOptionAsString("kbox"));

    ArrayList<Topology> extents = new ArrayList<Topology>();

    IContext context = null;
    if (!command.getArgumentAsString("context").equals("_NONE_")) {
      context = ModelFactory.get().requireContext(command.getArgumentAsString("context"));
    }

    Constraint c = new Constraint(CoreScience.Observation());

    IInstance inst = session.createObject(Polylist.list(concept));
    c =
        c.restrict(
            new Restriction(
                CoreScience.HAS_OBSERVABLE, new DefaultConformance().getConstraint(inst)));

    if (context != null) {

      ArrayList<Restriction> er = new ArrayList<Restriction>();
      for (IExtent o : context.getExtents()) {
        Restriction r = o.getConstraint("intersects");
        if (r != null) er.add(r);
      }

      if (er.size() > 0) {
        c =
            c.restrict(
                er.size() == 1
                    ? er.get(0)
                    : Restriction.AND(er.toArray(new Restriction[er.size()])));
      }
    }

    IQueryResult r = kbox.query(c);

    session.getOutputStream().print(r.getTotalResultCount() + " possible observation(s) found");

    for (int i = 0; i < r.getTotalResultCount(); i++) {
      Polylist o = r.getResultAsList(i, null);
      session.print(" --- Observation " + i + " ----------------\n");
      session.print(Polylist.prettyPrint(o));
      session.print("\n");
    }

    return null;
  }
示例#3
0
  public void setObservable(Object observableOrModel) throws ThinklabException {

    if (observableOrModel instanceof IConcept) {
      this.observable = (IConcept) observableOrModel;
      this.observableSpecs = Polylist.list(this.observable);
      this.observableId = this.observable.toString();
    } else if (observableOrModel instanceof Polylist) {
      this.observableSpecs = (Polylist) observableOrModel;
      this.observableId = this.observableSpecs.first().toString();
    } else {
      this.observableId = observableOrModel.toString();
    }
  }