/**
   * Adds all of the temporal relationships in the given Protege complex abstraction instance
   * (specified with the <code>withRelationships</code> slot) to the given PROTEMPA complex
   * abstraction definition.
   *
   * @param instance a Protege complex abstraction <code>Instance</code>.
   * @param cad a PROTEMPA <code>ComplexAbstractionDefinition</code> instance.
   */
  private static void addRelationships(
      Map<Instance, TemporalExtendedPropositionDefinition> extendedParameterCache,
      Instance instance,
      HighLevelAbstractionDefinition cad,
      ProtegeKnowledgeSourceBackend backend)
      throws KnowledgeSourceReadException {
    ConnectionManager cm = backend.getConnectionManager();
    for (Iterator<?> itr =
            instance
                .getOwnSlotValues(instance.getKnowledgeBase().getSlot("withRelations"))
                .iterator();
        itr.hasNext(); ) {
      Instance relationInstance = (Instance) itr.next();

      Instance lhsExtendedParameter =
          (Instance) cm.getOwnSlotValue(relationInstance, cm.getSlot("lhs"));
      Instance rhsExtendedParameter =
          (Instance) cm.getOwnSlotValue(relationInstance, cm.getSlot("rhs"));

      Relation relation = Util.instanceToRelation(relationInstance, cm, backend);

      TemporalExtendedPropositionDefinition lhsEP =
          extendedParameterCache.get(lhsExtendedParameter);

      TemporalExtendedPropositionDefinition rhsEP =
          extendedParameterCache.get(rhsExtendedParameter);

      cad.setRelation(lhsEP, rhsEP, relation);
    }
  }
Пример #2
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));
         }
       }
     }
   }
 }
Пример #3
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;
  }