예제 #1
0
 protected String getInstanceCountString(Cls cls) {
   int count;
   switch (_instanceCountType) {
     case NONE:
       count = 0;
       break;
     case DIRECT:
       count = cls.getDirectInstanceCount();
       break;
     case ALL:
       count = cls.getInstanceCount();
       break;
     default:
       Assert.fail("bad type: " + _instanceCountType);
       count = 0;
       break;
   }
   String s;
   if (count > 0) {
     s = "  (" + count + ")";
   } else {
     s = "";
   }
   return s;
 }
 public void doMove(Collection paths) {
   Iterator i = paths.iterator();
   while (i.hasNext()) {
     TreePath path = (TreePath) i.next();
     LazyTreeNode draggedNode = (LazyTreeNode) path.getLastPathComponent();
     LazyTreeNode draggedNodeParent = (LazyTreeNode) draggedNode.getParent();
     Cls draggedCls = (Cls) draggedNode.getUserObject();
     Cls draggedClsParent = (Cls) draggedNodeParent.getUserObject();
     if (draggedCls instanceof OWLNamedClass) {
       OWLNamedClass namedClass = (OWLNamedClass) draggedCls;
       if (namedClass.isDefinedClass()) {
         for (Iterator it = namedClass.getEquivalentClasses().iterator(); it.hasNext(); ) {
           RDFSClass equi = (RDFSClass) it.next();
           if (equi instanceof OWLIntersectionClass) {
             if (((OWLIntersectionClass) equi)
                 .hasOperandWithBrowserText(draggedClsParent.getBrowserText())) {
               return;
             }
           }
         }
       }
     }
     draggedCls.removeDirectSuperclass(draggedClsParent);
   }
 }
 private void removeValueTypeOverride(RDFSNamedClass cls, Slot slot) {
   if (slot != null && ((Cls) cls).hasDirectlyOverriddenTemplateFacet(slot, valueTypeFacet)) {
     ((Cls) cls).setTemplateSlotAllowedClses(slot, Collections.EMPTY_LIST);
     ((Cls) cls).setTemplateFacetValues(slot, valueTypeFacet, Collections.EMPTY_LIST);
     if (log.isLoggable(Level.FINE)) {
       log.fine("- Removed :VALUE-TYPE override from " + cls.getName() + "." + slot.getName());
     }
   }
 }
예제 #4
0
 /*
  * 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));
 }
 private void setAllowedClses(RDFSNamedClass cls, Slot slot, Collection newAllowedClses) {
   if (log.isLoggable(Level.FINE)) {
     log.fine("+ Setting allowed clses of " + cls.getName() + "." + slot.getName());
   }
   for (Iterator it = newAllowedClses.iterator(); it.hasNext(); ) {
     Cls ac = (Cls) it.next();
     if (log.isLoggable(Level.FINE)) {
       log.fine("  - " + ac.getBrowserText());
     }
   }
   ((Cls) cls).setTemplateSlotAllowedClses(slot, newAllowedClses);
 }
 private void addAllRestriction(Cls cls, RDFProperty property, Cls allCls) {
   OWLAllValuesFrom restriction = owlModel.createOWLAllValuesFrom(property, (RDFSClass) allCls);
   cls.addDirectSuperclass(restriction);
   if (log.isLoggable(Level.FINE)) {
     log.fine(
         "+ OWLAllValuesFrom "
             + restriction.getBrowserText()
             + " to "
             + cls.getName()
             + "."
             + property.getName());
   }
 }
예제 #7
0
 public void testGetProject() {
   if (!Server_Test.isServerRunning()) {
     return;
   }
   Project p =
       RemoteProjectManager.getInstance()
           .getProject(Server_Test.HOST, USER, PASSWORD, PROJECT_NAME, true);
   assertNotNull(p);
   OWLModel kb = (OWLModel) p.getKnowledgeBase();
   Cls cls = kb.getOWLNamedClass(kb.getNamespaceManager().getDefaultNamespace() + "Pizza");
   Log.getLogger().info("found " + cls + " with frame id = " + cls.getFrameID());
   assertNotNull(cls);
   p.dispose();
 }
예제 #8
0
 public void testUndocreateCls() {
   Cls cls = createCls();
   String name = cls.getName();
   assertNotNull("name", name);
   Frame frame = getFrame(name);
   assertEquals("created", cls, frame);
   assertTrue("can undo", _frameStore.canUndo());
   _frameStore.undo();
   frame = getFrame(name);
   assertNull("undone", frame);
   _frameStore.redo();
   frame = getFrame(name);
   assertEquals("recreated", frame.getName(), name);
 }
예제 #9
0
 protected void loadCls(Cls cls) {
   setMainIcon(getIcon(cls));
   setMainText(cls.getBrowserText());
   appendText(getInstanceCountString(cls));
   appendType(cls);
   setBackgroundSelectionColor(Colors.getClsSelectionColor());
 }
예제 #10
0
 public int addRow(Cls cls) {
   if (cls.equals(tableModel.getEditedCls())) {
     tableModel.displaySemanticError("Cannot assign " + cls.getBrowserText() + " to itself.");
     return -1;
   } else {
     RDFSClass rdfsClass = (RDFSClass) cls;
     if (tableModel.addRow(rdfsClass, getSelectedRow())) {
       setSelectedRow(rdfsClass);
       return tableModel.getClassRow(rdfsClass);
     } else {
       tableModel.displaySemanticError("Could not add " + cls.getBrowserText() + ".");
       if (rdfsClass instanceof OWLAnonymousClass) {
         rdfsClass.delete();
       }
       return -1;
     }
   }
 }
  private void updateValueTypeFacet(
      RDFSNamedClass cls, Slot slot, OWLQuantifierRestriction restriction) {
    ValueType oldValueType = ((Cls) cls).getTemplateSlotValueType(slot);
    ValueType newValueType = oldValueType;
    Collection oldAllowedClses = ((Cls) cls).getTemplateSlotAllowedClses(slot);
    Collection newAllowedClses = oldAllowedClses;
    Collection oldAllowedValues = ((Cls) cls).getTemplateSlotAllowedValues(slot);
    Collection newAllowedValues = oldAllowedValues;
    RDFResource filler = restriction.getFiller();
    if (filler instanceof RDFSClass) {
      RDFSClass quantifierClass = (RDFSClass) filler;
      if (RDFSNames.Cls.LITERAL.equals(quantifierClass.getName())) {
        newValueType = ValueType.ANY;
      } else {
        newValueType = ValueType.INSTANCE;
        newAllowedClses = getQuantifierClsClses(quantifierClass);
      }
    } else {
      if (filler instanceof OWLDataRange) {
        newAllowedValues = ((OWLDataRange) filler).getOneOf().getValues();
        newValueType = ValueType.SYMBOL;
      } else {
        RDFSDatatype datatype = (RDFSDatatype) filler;
        if (datatype.equals(owlModel.getRDFXMLLiteralType())) {
          newValueType = ValueType.STRING;
        } else {
          String uri = XMLSchemaDatatypes.getXSDDatatype(datatype).getURI();
          newValueType = XMLSchemaDatatypes.getValueType(uri);
        }
      }
    }

    if (oldValueType == newValueType) {
      if (newValueType == ValueType.INSTANCE && !oldAllowedClses.equals(newAllowedClses)) {
        setAllowedClses(cls, slot, newAllowedClses);
      } else if (newValueType == ValueType.SYMBOL && !oldAllowedValues.equals(newAllowedValues)) {
        setAllowedValues(cls, slot, newAllowedValues);
      }
    } else {
      if (log.isLoggable(Level.FINE)) {
        log.fine(
            "+ Setting :VALUE-TYPE of "
                + cls.getName()
                + "."
                + slot.getName()
                + " to "
                + newValueType);
      }
      ((Cls) cls).setTemplateSlotValueType(slot, newValueType);
      if (newValueType == ValueType.INSTANCE) {
        setAllowedClses(cls, slot, newAllowedClses);
      } else if (newValueType == ValueType.SYMBOL) {
        setAllowedValues(cls, slot, newAllowedValues);
      }
    }
  }
예제 #12
0
 public void testUndoSimpleTransaction() {
   Cls cls = createCls();
   Slot slot1 = createSlot();
   Slot slot2 = createSlot();
   cls.addDirectTemplateSlot(slot1);
   cls.addDirectTemplateSlot(slot2);
   Instance instance = cls.createDirectInstance(null);
   _frameStore.beginTransaction("simple nonsense");
   _frameStore.setDirectOwnSlotValues(instance, slot1, makeList("foo1"));
   _frameStore.setDirectOwnSlotValues(instance, slot2, makeList("foo2"));
   _frameStore.commitTransaction();
   assertEqualsList(makeList("foo1"), _frameStore.getDirectOwnSlotValues(instance, slot1));
   assertEqualsList(makeList("foo2"), _frameStore.getDirectOwnSlotValues(instance, slot2));
   _frameStore.undo();
   assertEqualsList(makeList(), _frameStore.getDirectOwnSlotValues(instance, slot1));
   assertEqualsList(makeList(), _frameStore.getDirectOwnSlotValues(instance, slot2));
   _frameStore.redo();
   assertEqualsList(makeList("foo1"), _frameStore.getDirectOwnSlotValues(instance, slot1));
   assertEqualsList(makeList("foo2"), _frameStore.getDirectOwnSlotValues(instance, slot2));
 }
 protected void updateAllRestrictions(Cls cls, RDFProperty property) {
   if (cls.hasDirectlyOverriddenTemplateFacet(property, valueTypeFacet)) {
     ValueType valueType = cls.getTemplateSlotValueType(property);
     if (valueType == ValueType.INSTANCE) {
       Collection clses = cls.getTemplateSlotAllowedClses(property);
       if (clses.size() == 0) {
         removeRestrictions(cls, property, metaCls);
         addAllRestriction(cls, property, owlModel.createOWLEnumeratedClass());
       } else {
         ensureNoSurvivingClsesAreDeleted(cls, property, clses, metaCls);
         if (clses.size() == 1) {
           Cls allCls = (Cls) clses.iterator().next();
           removeRestrictions(cls, property, metaCls);
           addAllRestriction(cls, property, allCls);
         } else {
           OWLUnionClass unionCls = owlModel.createOWLUnionClass(clses);
           removeRestrictions(cls, property, metaCls);
           addAllRestriction(cls, property, unionCls);
         }
       }
     } else if (valueType != ValueType.SYMBOL && valueType != ValueType.CLS) {
       removeRestrictions(cls, property, metaCls);
       RDFSDatatype datatype =
           owlModel.getRDFSDatatypeByURI(
               XMLSchemaDatatypes.getDefaultXSDDatatype(valueType).getURI());
       OWLAllValuesFrom restriction = owlModel.createOWLAllValuesFrom(property, datatype);
       cls.addDirectSuperclass(restriction);
       if (log.isLoggable(Level.FINE)) {
         log.fine(
             "+ OWLAllValuesFrom "
                 + restriction.getBrowserText()
                 + " to "
                 + cls.getName()
                 + "."
                 + property.getName());
       }
     }
   } else {
     removeRestrictions(cls, property, metaCls);
   }
 }
예제 #14
0
  public void testUndoDeleteSlot() {
    String templateSlotValue = "restricted";
    String slotValue = "something";
    Cls cls = createCls();
    Slot slot = createSlot();
    cls.addDirectTemplateSlot(slot);
    _frameStore.setDirectTemplateSlotValues(cls, slot, Collections.singleton(templateSlotValue));
    SimpleInstance i = createSimpleInstance(cls);
    i.setDirectOwnSlotValue(slot, slotValue);

    assertTrue(_frameStore.getTemplateSlotValues(cls, slot).size() == 1);
    assertTrue(_frameStore.getTemplateSlotValues(cls, slot).contains(templateSlotValue));
    assertTrue(i.getDirectOwnSlotValues(slot).size() == 1);
    assertTrue(i.getDirectOwnSlotValue(slot).equals(slotValue));

    _frameStore.deleteSlot(slot);
    _frameStore.undo();

    assertTrue(_frameStore.getTemplateSlotValues(cls, slot).size() == 1);
    assertTrue(_frameStore.getTemplateSlotValues(cls, slot).contains(templateSlotValue));
    assertTrue(i.getDirectOwnSlotValues(slot).size() == 1);
    assertTrue(i.getDirectOwnSlotValue(slot).equals(slotValue));
  }
예제 #15
0
 private void setCls(Cls cls) {
   selectedCls = cls;
   name = tab.getWrapper().getInternalName(selectedCls);
   value_field.setText(cls.getBrowserText());
 }
예제 #16
0
  public JPanel createPanel() {
    JPanel panel = new JPanel();
    panel.setLocation(450, 300);
    panel.setLayout(new GridLayout(2, 1));

    LabeledComponent lc = null;
    JPanel definingPanel = new JPanel();
    definingPanel.setLayout(new BorderLayout());
    JLabel definingLabel = new JLabel("  Defining");
    definingCheckBox = new JCheckBox();
    definingCheckBox.setSelected(defining);
    definingCheckBox.setEnabled(definingEditable);

    definingPanel.add(definingCheckBox, BorderLayout.WEST);
    definingPanel.add(definingLabel, BorderLayout.CENTER);

    panel.add(definingPanel);

    value_field = new JTextField("");
    value_field.setEditable(false);

    String pt = selectedCls != null ? selectedCls.getBrowserText() : "";
    value_field.setText(pt);

    value_field.setPreferredSize(new Dimension(300, 20));
    lc = new LabeledComponent("Select a superclass", value_field);

    Action SelectPropertyValueAction =
        new AbstractAction("Select a superclass...", OWLIcons.getAddIcon("PrimitiveClass")) {
          private static final long serialVersionUID = 123456009L;

          public void actionPerformed(ActionEvent e) {
            // java.awt.TextField textfield = new TextField();
            String label = "Select a named class";

            Collection clses = tab.getOWLWrapper().getSelectableRoots();

            boolean ok = false;

            while (!ok) {

              final NCISelectClsesPanel p = new NCISelectClsesPanel(owlModel, clses);
              int result = ModalDialog.showDialog(tab, p, label, ModalDialog.MODE_OK_CANCEL);
              if (result == ModalDialogFactory.OPTION_OK) {
                Collection c = p.getSelection();
                if (c != null && c.size() > 0) {
                  Iterator it = c.iterator();
                  Object obj = it.next();
                  String clsName = ((OWLNamedClass) obj).getPrefixedName();
                  // tab.getOWLWrapper()
                  // .getInternalName((Cls) obj);
                  if (clsName.compareTo("owl:Thing") == 0) {

                  } else {
                    setCls((Cls) obj);
                    ok = true;
                  }
                }

              } else {
                // user cancelled
                ok = true;
              }
            }
          }
        };

    lc.addHeaderButton(SelectPropertyValueAction);
    panel.add(lc);

    return panel;
  }
예제 #17
0
 // ESCA-JAVA0130
 protected Icon getIcon(Cls cls) {
   return cls.getIcon();
 }