Beispiel #1
0
 /**
  * Checks if the resource has the provided RDF property set on it with the specified value.
  *
  * @param aProperty
  * @param aResource
  * @return
  */
 public boolean hasRDFPropertyWithValue(RDFProperty aProperty, OResource aResource) {
   List<OResource> resources = getRDFPropertyValues(aProperty);
   for (OResource r : resources) {
     if (r.equals(aResource)) return true;
   }
   return false;
 }
Beispiel #2
0
  /*
   * (non-Javadoc)
   *
   * @see gate.creole.ontology.OInstance#addRDFPropertyValue(gate.creole.ontology.RDFProperty,
   *      gate.creole.ontology.OResource)
   */
  public void addRDFPropertyValue(RDFProperty aProperty, OResource value)
      throws InvalidValueException {
    // we need to check if the current instance is a valid domain for
    // the property
    if (!aProperty.isValidDomain(this)) {
      Utils.error(
          this.getURI().toString()
              + " is not a valid domain for the property "
              + aProperty.getURI().toString());
      return;
    }

    // we need to check if the current instance is a valid domain for
    // the property
    if (!aProperty.isValidRange(value)) {
      Utils.error(
          value.getURI().toString()
              + " is not a valid range for the property "
              + aProperty.getURI().toString());
      return;
    }

    owlim.addRDFPropertyValue(
        this.repositoryID,
        this.uri.toString(),
        aProperty.getURI().toString(),
        value.getURI().toString());
    ontology.fireResourcePropertyValueChanged(
        this, aProperty, value, OConstants.RDF_PROPERTY_VALUE_ADDED_EVENT);
  }
  public void actionPerformed(ActionEvent actionevent) {
    OResource selectedNode = ((OResourceNode) selectedNodes.get(0).getUserObject()).getResource();
    String ns = selectedNode.getONodeID().getNameSpace();
    if (gate.creole.ontology.Utils.hasSystemNameSpace(selectedNode.getONodeID().toString())) {
      ns = ontology.getDefaultNameSpace();
    }
    nameSpace.setText(ns);

    nameSpace.setText(
        ontology.getDefaultNameSpace() == null
            ? "http://gate.ac.uk/example#"
            : ontology.getDefaultNameSpace());
    JOptionPane pane =
        new JOptionPane(
            mainPanel,
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION,
            MainFrame.getIcon("ontology-instance")) {
          public void selectInitialValue() {
            instanceName.requestFocusInWindow();
            instanceName.selectAll();
          }
        };
    pane.createDialog(MainFrame.getInstance(), "New Instance").setVisible(true);
    Object selectedValue = pane.getValue();
    if (selectedValue != null
        && selectedValue instanceof Integer
        && (Integer) selectedValue == JOptionPane.OK_OPTION) {
      String s = nameSpace.getText();
      if (!Utils.isValidNameSpace(s)) {
        JOptionPane.showMessageDialog(
            MainFrame.getInstance(),
            "Invalid Name Space: " + s + "\nExample: http://gate.ac.uk/example#");
        return;
      }
      if (!Utils.isValidOntologyResourceName(instanceName.getText())) {
        JOptionPane.showMessageDialog(
            MainFrame.getInstance(), "Invalid Instance: " + instanceName.getText());
        return;
      }
      if (Utils.getOResourceFromMap(ontology, s + instanceName.getText()) != null) {
        JOptionPane.showMessageDialog(
            MainFrame.getInstance(),
            "<html>" + "Resource <b>" + s + instanceName.getText() + "</b> already exists.");
        return;
      }

      for (int i = 0; i < selectedNodes.size(); i++) {
        Object obj = ((OResourceNode) selectedNodes.get(i).getUserObject()).getResource();
        if (obj instanceof OClass) {
          ontology.addOInstance(
              ontology.createOURI(nameSpace.getText() + instanceName.getText()), (OClass) obj);
        }
      }
    }
  }
Beispiel #4
0
 /*
  * (non-Javadoc)
  *
  * @see gate.creole.ontology.OInstance#removeRDFPropertyValue(gate.creole.ontology.RDFProperty,
  *      gate.creole.ontology.OResource)
  */
 public void removeRDFPropertyValue(RDFProperty aProperty, OResource value) {
   owlim.removeRDFPropertyValue(
       this.repositoryID,
       this.uri.toString(),
       aProperty.getURI().toString(),
       value.getURI().toString());
   ontology.fireResourcePropertyValueChanged(
       this, aProperty, value, OConstants.RDF_PROPERTY_VALUE_REMOVED_EVENT);
 }
 private void loadOntologyEntities() {
   for (OResource r : ruleStore.getOntology().getAllResources()) {
     entityNames.add(r.getURI().toString());
   }
 }