Exemplo n.º 1
0
  private boolean containInstance(Instance sel, Slot slot, Instance instance) {
    if (itsInstance == null) return false;
    Collection instances = sel.getOwnSlotValues(slot);
    Iterator i = instances.iterator();
    while (i.hasNext()) {

      Instance tmpInstance = (Instance) i.next();
      if (tmpInstance.equals(instance)) return true;
    }
    return false;
  }
Exemplo n.º 2
0
 // This is used for Query test
 public Collection search(Collection instances, Slot slot, String operation, Object obj) {
   ArrayList resultInstances = new ArrayList();
   Iterator i = instances.iterator();
   String value = (String) (((Instance) obj).getBrowserText());
   while (i.hasNext()) {
     Instance instance = (Instance) i.next();
     if (testInstance(getTestIndex(operation), instance, slot, value))
       resultInstances.add(instance);
   }
   return resultInstances;
 }
 public String getInvalidValuesText(
     Frame frame, Slot slot, Collection slotValues, Collection facetValues) {
   String result = null;
   Number n = (Number) CollectionUtilities.getFirstItem(facetValues);
   if (n != null) {
     double max = n.doubleValue();
     Iterator i = slotValues.iterator();
     while (result == null && i.hasNext()) {
       Object value = i.next();
       result = getInvalidValueText(max, value);
     }
   }
   return result;
 }
Exemplo n.º 4
0
  public Collection search() {
    if (specification.getType() == null) return null;
    String slotType = specification.getType();
    if (!slotType.toLowerCase().equals("cls")) return null;

    // Here we first test the function based on the simplest Instance cases
    ArrayList resultInstances = new ArrayList();
    Collection instances = itsInstances;
    Iterator i = instances.iterator();
    Slot slot = itsWidget.getKB().getSlot(specification.getName());
    while (i.hasNext()) {
      Instance instance = (Instance) i.next();
      if (testInstance(getTestIndex(specification.getConstraint()), instance, slot))
        resultInstances.add(instance);
    }
    return resultInstances;
  }
Exemplo n.º 5
0
 public void addForwardReferences() {
   KnowledgeBase kb = this.getKnowledgeBase();
   Collection transitions = getOwnSlotValues(kb.getSlot("transitions"));
   Slot fromSlot = kb.getSlot(":FROM");
   Slot toSlot = kb.getSlot(":TO");
   Instance from = null;
   Instance to = null;
   Slot branches = kb.getSlot("branches");
   Slot followed_by = kb.getSlot("followed_by");
   Slot label = kb.getSlot("label");
   for (Iterator transition = transitions.iterator(); transition.hasNext(); ) {
     Instance inst = (Instance) transition.next();
     from = (Instance) inst.getOwnSlotValue(fromSlot);
     if (from != null) {
       to = (Instance) inst.getOwnSlotValue(toSlot);
       if (to != null) {
         try {
           if (from.hasOwnSlot(branches)) {
             /*logger.debug("addForwardReferences: "+ from.getOwnSlotValue(label)+
             " has branches"); */
             if ((from.getOwnSlotValues(branches) == null)
                 || (!from.getOwnSlotValues(branches).contains(to)))
               from.addOwnSlotValue(branches, to);
           } else if (from.hasOwnSlot(followed_by)) {
             /*logger.debug("addForwardReferences: "+ from.getOwnSlotValue(label)+
             " has followed by");*/
             if (!(to.equals(from.getOwnSlotValue(followed_by))))
               from.setOwnSlotValue(followed_by, to);
           } else
             logger.error(
                 "addForwardReferences: "
                     + from.getOwnSlotValue(label)
                     + "has no followed_by or branches slot");
         } catch (Exception e) {
           logger.error(
               "Exception adding "
                   + to.getOwnSlotValue(label)
                   + " to "
                   + from.getOwnSlotValue(label));
         }
       }
     }
   }
 }
Exemplo n.º 6
0
  public void removeForwardReferences() {
    KnowledgeBase kb = this.getKnowledgeBase();
    Slot branches = kb.getSlot("branches");
    Slot followed_by = kb.getSlot("followed_by");
    // logger.debug("Slot "+branches.getName());
    // logger.debug("Slot "+followed_by.getName());
    Slot label = kb.getSlot("label");
    Collection steps = getOwnSlotValues(kb.getSlot("steps"));
    for (Iterator iterater = steps.iterator(); iterater.hasNext(); ) {
      Instance step = (Instance) iterater.next();
      // logger.debug("removeForwardReferences: node ="+step.getOwnSlotValue(label));
      /*for (Iterator slots=step.getOwnSlots().iterator(); slots.hasNext();){
      	logger.debug("has slot "+((Slot)slots.next()).getName());
      }*/
      try {
        if (step.hasOwnSlot(branches)) {
          /*logger.debug("removeForwardReferences: "+ step.getOwnSlotValue(label)+
          " has branches"); */
          step.setOwnSlotValues(branches, new ArrayList());
        } else if (step.hasOwnSlot(followed_by)) {
          /* logger.debug("removeForwardReferences: "+ step.getOwnSlotValue(label)+
          " has followed_by value "+step.getOwnSlotValue(followed_by));*/
          step.setOwnSlotValue(followed_by, null);
        } else
          logger.error(
              "removeForwardReferences: "
                  + step.getOwnSlotValue(label)
                  + "has no followed_by or branches slot");
      } catch (Exception e) {

        logger.error(
            "Exception making " + step.getOwnSlotValue(label) + " null, Message: " + e.getMessage(),
            e);
      }
    }
  }
Exemplo n.º 7
0
 public void printContent(PrintWriter itsWriter, String delimiter) {
   Collection steps = getstepsValue();
   if (steps != null) {
     for (Iterator i = steps.iterator(); i.hasNext(); ) {
       Object step = i.next();
       if (step instanceof Scenario) {
         ((Scenario) step).printContent(itsWriter, delimiter);
       }
     }
     itsWriter.println();
     for (Iterator j = steps.iterator(); j.hasNext(); ) {
       Object step = j.next();
       if (step instanceof Action_Choice) {
         ((Action_Choice) step).printContent(itsWriter, delimiter);
       }
     }
   }
 }