Exemple #1
0
 protected void loadInstance(Instance instance) {
   String s = instance.getBrowserText();
   setMainText(s);
   setMainIcon(instance.getIcon());
   appendType(instance);
   setBackgroundSelectionColor(Colors.getInstanceSelectionColor());
 }
 private static boolean isInTrash(ProjectInstance projectInstance) {
   Instance protegeInstance = projectInstance.getProtegeInstance();
   KnowledgeBase kb = protegeInstance.getKnowledgeBase();
   Slot inTrashSlot = getInTrashSlot(kb);
   Object ownSlotValue = protegeInstance.getOwnSlotValue(inTrashSlot);
   return ownSlotValue != null && ownSlotValue.equals(Boolean.TRUE);
 }
  /**
   * 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);
    }
  }
  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;
  }
 /*
  * ToDo This test should pass but currently the undo manager is broken.
  *
  */
 public void testUndoDeleteSimpleInstance() {
   String value = "hello";
   Cls clsA = createCls();
   Slot slotA = createSlot();
   clsA.addDirectTemplateSlot(slotA);
   Instance i1 = clsA.createDirectInstance("i1");
   i1.setDirectOwnSlotValue(slotA, value);
   assertEquals(value, i1.getDirectOwnSlotValue(slotA));
   _frameStore.deleteSimpleInstance((SimpleInstance) i1);
   _frameStore.undo();
   assertEquals(value, i1.getDirectOwnSlotValue(slotA));
 }
 /**
  * Adds a new project to the metaproject. This sets up the name of the project and the description
  * of the project in the metaproject. (Location is not set/used by this implementation - not all
  * implementations use pprj files anymore).
  *
  * @param newProjectSettings The info about the new project
  */
 private void addProjectToMetaProject(ProjectId projectId, NewProjectSettings newProjectSettings) {
   MetaProject mp = getMetaProject();
   ProjectInstance pi = mp.createProject(projectId.getId());
   pi.setDescription(newProjectSettings.getProjectDescription());
   final Instance protegeInstance = pi.getProtegeInstance();
   final KnowledgeBase kb = protegeInstance.getKnowledgeBase();
   final Slot displayNameSlot = kb.getSlot("displayName");
   protegeInstance.setOwnSlotValue(displayNameSlot, newProjectSettings.getDisplayName());
   User user = mp.getUser(newProjectSettings.getProjectOwner().getUserName());
   pi.setOwner(user);
   OWLAPIMetaProjectStore.getStore().saveMetaProject(this);
 }
 public void testUndoCreateSimpleInstance() {
   Cls cls = createCls();
   Instance instance = createSimpleInstance(cls);
   String name = instance.getName();
   assertNotNull("name", name);
   Frame frame = getFrame(name);
   assertEquals("created", instance, frame);
   assertTrue("can undo", _frameStore.canUndo());
   _frameStore.undo();
   frame = getFrame(name);
   assertNull("undone", frame);
   _frameStore.redo();
   instance = (Instance) getFrame(name);
   assertEquals("recreated", instance.getName(), name);
 }
 public void setInTrash(ProjectId projectId, boolean b) {
   try {
     WRITE_LOCK.lock();
     ProjectInstance pi = getProjectInstance(projectId);
     Instance instance = pi.getProtegeInstance();
     KnowledgeBase knowledgeBase = instance.getKnowledgeBase();
     Slot inTrashSlot = knowledgeBase.getSlot(IN_TRASH_SLOT_NAME);
     if (inTrashSlot != null) {
       instance.setOwnSlotValue(inTrashSlot, b);
     }
     save();
   } finally {
     WRITE_LOCK.unlock();
   }
 }
 @Override
 public HighLevelAbstractionDefinition convert(
     Instance complexAbstractionInstance, ProtegeKnowledgeSourceBackend backend)
     throws KnowledgeSourceReadException {
   HighLevelAbstractionDefinition result =
       new HighLevelAbstractionDefinition(complexAbstractionInstance.getName());
   ConnectionManager cm = backend.getConnectionManager();
   Util.setNames(complexAbstractionInstance, result, cm);
   Util.setInDataSource(complexAbstractionInstance, result, cm);
   Util.setProperties(complexAbstractionInstance, result, cm);
   Util.setTerms(complexAbstractionInstance, result, cm);
   Util.setGap(complexAbstractionInstance, result, backend, cm);
   Util.setSolid(complexAbstractionInstance, result, cm);
   Util.setConcatenable(complexAbstractionInstance, result, cm);
   Util.setReferences(complexAbstractionInstance, result, cm);
   result.setAccessed(new Date());
   Map<Instance, TemporalExtendedPropositionDefinition> extendedParameterCache = new HashMap<>();
   addComponentAbstractionDefinitions(
       complexAbstractionInstance, result, extendedParameterCache, backend);
   addRelationships(extendedParameterCache, complexAbstractionInstance, result, backend);
   Util.setInverseIsAs(complexAbstractionInstance, result, cm);
   result.setTemporalOffset(
       Util.temporalOffsets(complexAbstractionInstance, backend, extendedParameterCache));
   result.setSourceId(DefaultSourceId.getInstance(backend.getId()));
   return result;
 }
 private boolean testInstance(int testIndex, Instance instance, Slot slot) {
   String value;
   if (specification.getValue() == null) return false;
   if (((String) specification.getValue()).length() < 1) return false;
   value = instance.getBrowserText();
   return testInstance(testIndex, instance, slot, value);
 }
 private DropData convertEventIntoDropData(DropTargetDropEvent dropTargetDropEvent) {
   Transferable transferable = dropTargetDropEvent.getTransferable();
   Point tableLocation = getTableLocationForEvent(dropTargetDropEvent);
   if (null != _underlyingTable.getValueAt(tableLocation.x, tableLocation.y)) {
     return null;
   }
   Instance entry;
   try {
     entry = (Instance) transferable.getTransferData(_flavor);
   } catch (Exception e) {
     return null;
   }
   if ((null == entry) || !entry.hasType(_entryCls)) {
     return null;
   }
   return new DropData(tableLocation, entry);
 }
 public boolean isInTrash(ProjectId projectId) {
   try {
     READ_LOCK.lock();
     ProjectInstance pi = getProjectInstance(projectId);
     Instance instance = pi.getProtegeInstance();
     KnowledgeBase knowledgeBase = instance.getKnowledgeBase();
     Slot inTrashSlot = knowledgeBase.getSlot(IN_TRASH_SLOT_NAME);
     if (inTrashSlot == null) {
       return false;
     }
     Object val = instance.getOwnSlotValue(inTrashSlot);
     if (!(val instanceof Boolean)) {
       return false;
     }
     return (Boolean) val;
   } finally {
     READ_LOCK.unlock();
   }
 }
  /** Main test subroutine for Instance slot. */
  private boolean testInstance(int testIndex, Instance instance, Slot slot, String value) {

    boolean testResult = false;
    if (instance == null) return testResult;
    if (slot == null) {
      return false;
    }

    Instance tmpInstance = (Instance) instance.getOwnSlotValue(slot);
    if (tmpInstance == null && testIndex == 0) return false;
    if (tmpInstance == null && testIndex == 1) return true;

    switch (testIndex) {
      case 0: // is equal to
        return containInstance(instance, slot, itsInstance);
      case 1: // is not equal to
        return (!containInstance(instance, slot, itsInstance));
      default:
        break;
    }
    return testResult;
  }
  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);
      }
    }
  }
Exemple #15
0
 private void appendType(Instance instance) {
   if (_displayType) {
     String type = instance.getDirectType().getBrowserText();
     appendText("  (" + type + ")");
   }
 }
 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));
         }
       }
     }
   }
 }