Ejemplo n.º 1
0
 @Override
 public void initialise() throws Exception {
   editorKit = (OWLEditorKit) getEditorKit();
   workspace = editorKit.getWorkspace();
   owlManager = editorKit.getOWLModelManager();
   modelManager = ((OBDAModelManager) editorKit.get(OBDAModelImpl.class.getName()));
 }
Ejemplo n.º 2
0
 public SearchManager(OWLEditorKit editorKit, SearchMetadataImportManager importManager) {
   this.editorKit = editorKit;
   this.importManager = importManager;
   categories.add(SearchCategory.DISPLAY_NAME);
   categories.add(SearchCategory.IRI);
   categories.add(SearchCategory.ANNOTATION_VALUE);
   categories.add(SearchCategory.LOGICAL_AXIOM);
   ontologyChangeListener = changes -> markCacheAsStale();
   modelManagerListener = this::handleModelManagerEvent;
   editorKit.getModelManager().addListener(modelManagerListener);
   editorKit.getOWLModelManager().addOntologyChangeListener(ontologyChangeListener);
 }
 /**
  * Renders the annotation property into a paragraph in the page.
  *
  * @param page The page to insert the paragraph into.
  * @param annotation The annotation containing the property to be rendered.
  * @param defaultForeground The default foreground color.
  * @param defaultBackground The default background color.
  * @param isSelected Specifies whether the associated cell is selected or not.
  */
 private Paragraph renderAnnotationProperty(
     Page page,
     OWLAnnotation annotation,
     Color defaultForeground,
     Color defaultBackground,
     boolean isSelected) {
   OWLAnnotationProperty property = annotation.getProperty();
   String rendering = editorKit.getOWLModelManager().getRendering(property);
   Paragraph paragraph = page.addParagraph(rendering);
   Color foreground = getAnnotationPropertyForeground(defaultForeground, isSelected);
   paragraph.setForeground(foreground);
   //        if (isReferenceOntologyActive()) {
   //            paragraph.setBold(true);
   //        }
   if (annotation.getValue() instanceof OWLLiteral) {
     OWLLiteral literalValue = (OWLLiteral) annotation.getValue();
     paragraph.append("    ", foreground);
     appendTag(paragraph, literalValue, foreground, isSelected);
   }
   switch (annotationRenderingStyle) {
     case COMFORTABLE:
       paragraph.setMarginBottom(4);
       break;
     case COSY:
       paragraph.setMarginBottom(2);
       break;
     case COMPACT:
       paragraph.setMarginBottom(1);
       break;
   }
   return paragraph;
 }
Ejemplo n.º 4
0
 private void selectEntity() {
   Optional<OWLEntity> selectedEntity = searchPanel.getSelectedEntity();
   if (selectedEntity.isPresent()) {
     editorKit.getOWLWorkspace().getOWLSelectionModel().setSelectedEntity(selectedEntity.get());
     editorKit.getOWLWorkspace().displayOWLEntity(selectedEntity.get());
   }
 }
Ejemplo n.º 5
0
  @Override
  public void initialise() throws Exception {
    editorKit = (OWLEditorKit) getEditorKit();
    owlManager = editorKit.getOWLModelManager();
    //		currentOnto = owlManager.getActiveOntology();

  }
  public void setOntology(OWLOntology ont) {
    this.ont = ont;
    List<Object> data = new ArrayList<>();
    data.add(directImportsHeader);

    // @@TODO ordering
    for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) {
      data.add(new OntologyImportItem(ont, decl, editorKit));
    }
    data.add(indirectImportsHeader);
    // @@TODO ordering
    try {
      for (OWLOntology ontRef :
          editorKit.getOWLModelManager().getOWLOntologyManager().getImportsClosure(ont)) {
        if (!ontRef.equals(ont)) {
          for (OWLImportsDeclaration dec : ontRef.getImportsDeclarations()) {
            if (!data.contains(dec)) {
              data.add(new OntologyImportItem(ontRef, dec, editorKit));
            }
          }
        }
      }
    } catch (UnknownOWLOntologyException e) {
      throw new OWLRuntimeException(e);
    }
    setListData(data.toArray());
  }
  public OntologyImportsList(OWLEditorKit editorKit) {
    this.editorKit = editorKit;
    setFixedCellHeight(-1);
    setCellRenderer(new OntologyImportsItemRenderer(editorKit));

    directImportsHeader =
        new MListSectionHeader() {
          public String getName() {
            return "Direct Imports";
          }

          public boolean canAdd() {
            return true;
          }
        };

    indirectImportsHeader =
        new MListSectionHeader() {
          public String getName() {
            return "Indirect Imports";
          }

          public boolean canAdd() {
            return false;
          }
        };

    editorKit.getOWLModelManager().addOntologyChangeListener(ontChangeListener);
  }
Ejemplo n.º 8
0
  /**
   * * Protege wont trigger a save action unless it detects that the OWLOntology currently opened
   * has suffered a change. The OBDA plugin requires that protege triggers a save action also in the
   * case when only the OBDA model has suffered chagnes. To acomplish this, this method will "fake"
   * an ontology change by inserting and removing a class into the OWLModel.
   */
  private void triggerOntologyChanged() {
    if (loadingData) {
      return;
    }
    OWLModelManager owlmm = owlEditorKit.getOWLModelManager();
    OWLOntology ontology = owlmm.getActiveOntology();

    if (ontology == null) {
      return;
    }

    OWLClass newClass =
        owlmm
            .getOWLDataFactory()
            .getOWLClass(IRI.create("http://www.unibz.it/krdb/obdaplugin#RandomClass6677841155"));
    OWLAxiom axiom = owlmm.getOWLDataFactory().getOWLDeclarationAxiom(newClass);

    try {
      AddAxiom addChange = new AddAxiom(ontology, axiom);
      owlmm.applyChange(addChange);
      RemoveAxiom removeChange = new RemoveAxiom(ontology, axiom);
      owlmm.applyChange(removeChange);
    } catch (Exception e) {
      log.warn(
          "Exception forcing an ontology change. Your OWL model might contain a new class that you need to remove manually: {}",
          newClass.getIRI());
      log.warn(e.getMessage());
      log.debug(e.getMessage(), e);
    }
  }
 public boolean setEditedObject(OWLAnonymousIndividual object) {
   if (object == null) {
     String id = "genid-" + UUID.randomUUID().toString();
     final OWLOntologyID ontologyID =
         editorKit.getModelManager().getActiveOntology().getOntologyID();
     if (!ontologyID.isAnonymous()) {
       id = ontologyID.getOntologyIRI().get() + "#" + id;
     }
     object = editorKit.getModelManager().getOWLDataFactory().getOWLAnonymousIndividual(id);
   }
   frameList.setRootObject(object);
   mainComponent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
   annotationValueLabel.setIcon(OWLIcons.getIcon("individual.png"));
   annotationValueLabel.setText(editorKit.getModelManager().getRendering(object));
   return true;
 }
Ejemplo n.º 10
0
 /**
  * * Called from ModelManager dispose method since this object is setup as the
  * APIController.class.getName() property with the put method.
  */
 public void dispose() throws Exception {
   try {
     owlEditorKit.getModelManager().removeListener(getModelManagerListener());
     connectionManager.dispose();
   } catch (Exception e) {
     log.warn(e.getMessage());
   }
 }
Ejemplo n.º 11
0
 public static void showDialog(OWLEditorKit editorKit, Set<OWLOntology> ontologies) {
   SaveConfirmationPanel panel = new SaveConfirmationPanel(editorKit, ontologies);
   JOptionPaneEx.showConfirmDialog(
       editorKit.getWorkspace(),
       "Saved ontologies",
       panel,
       JOptionPane.PLAIN_MESSAGE,
       JOptionPane.DEFAULT_OPTION,
       null);
 }
Ejemplo n.º 12
0
  /**
   * This method makes sure is used to setup a new/fresh OBDA model. This is done by replacing the
   * instance this.obdacontroller (the OBDA model) with a new object. On creation listeners for the
   * datasources, mappings and queries are setup so that changes in these trigger and ontology
   * change.
   *
   * <p>Additionally, this method configures all available OBDAOWLReasonerFacotry objects to have a
   * reference to the newly created OBDA model and to the global preference object. This is
   * necessary so that the factories are able to pass the OBDA model to the reasoner instances when
   * they are created.
   */
  private void setupNewOBDAModel() {
    OBDAModel activeOBDAModel = getActiveOBDAModel();

    if (activeOBDAModel != null) {
      return;
    }
    activeOBDAModel = dfac.getOBDAModel();

    activeOBDAModel.addSourcesListener(dlistener);
    activeOBDAModel.addMappingsListener(mlistener);
    queryController.addListener(qlistener);

    OWLModelManager mmgr = owlEditorKit.getOWLWorkspace().getOWLModelManager();

    Set<OWLOntology> ontologies = mmgr.getOntologies();
    for (OWLOntology ontology : ontologies) {
      // Setup the entity declarations
      for (OWLClass c : ontology.getClassesInSignature()) {
        OClass pred = ofac.createClass(c.getIRI().toString());
        activeOBDAModel.declareClass(pred);
      }
      for (OWLObjectProperty r : ontology.getObjectPropertiesInSignature()) {
        ObjectPropertyExpression pred = ofac.createObjectProperty(r.getIRI().toString());
        activeOBDAModel.declareObjectProperty(pred);
      }
      for (OWLDataProperty p : ontology.getDataPropertiesInSignature()) {
        DataPropertyExpression pred = ofac.createDataProperty(p.getIRI().toString());
        activeOBDAModel.declareDataProperty(pred);
      }
    }

    // Setup the prefixes
    PrefixOWLOntologyFormat prefixManager =
        PrefixUtilities.getPrefixOWLOntologyFormat(mmgr.getActiveOntology());
    //		addOBDACommonPrefixes(prefixManager);

    PrefixManagerWrapper prefixwrapper = new PrefixManagerWrapper(prefixManager);
    activeOBDAModel.setPrefixManager(prefixwrapper);

    OWLOntology activeOntology = mmgr.getActiveOntology();

    String defaultPrefix = prefixManager.getDefaultPrefix();
    if (defaultPrefix == null) {
      OWLOntologyID ontologyID = activeOntology.getOntologyID();
      defaultPrefix = ontologyID.getOntologyIRI().toURI().toString();
    }
    activeOBDAModel.getPrefixManager().addPrefix(PrefixManager.DEFAULT_PREFIX, defaultPrefix);

    // Add the model
    URI modelUri = activeOntology.getOntologyID().getOntologyIRI().toURI();
    obdamodels.put(modelUri, activeOBDAModel);
  }
Ejemplo n.º 13
0
  protected void handleAdd() {
    // don't need to check the section as only the direct imports can be added
    OntologyImportWizard wizard =
        new OntologyImportWizard(
            (Frame) SwingUtilities.getAncestorOfClass(Frame.class, editorKit.getWorkspace()),
            editorKit);
    int ret = wizard.showModalDialog();

    if (ret == Wizard.FINISH_RETURN_CODE) {
      AddImportsStrategy strategy = new AddImportsStrategy(editorKit, ont, wizard.getImports());
      strategy.addImports();
    }
  }
 /**
  * Renderes a set of entities as an annotation value. The idea is that the annotation value is an
  * IRI that corresponds to the IRI of entities in the imports closure of the active ontology.
  *
  * @param page The page that the entities will be rendered into.
  * @param entities The entities.
  * @return A list of paragraphs that represents the rendering of the entities.
  */
 private List<Paragraph> renderEntities(Page page, Set<OWLEntity> entities) {
   List<Paragraph> paragraphs = new ArrayList<>();
   for (OWLEntity entity : entities) {
     Icon icon = getIcon(entity);
     OWLModelManager modelManager = editorKit.getOWLModelManager();
     Paragraph paragraph =
         new Paragraph(modelManager.getRendering(entity), new OWLEntityLink(editorKit, entity));
     paragraph.setIcon(icon);
     page.add(paragraph);
     paragraphs.add(paragraph);
   }
   return paragraphs;
 }
Ejemplo n.º 15
0
 public OBDAModel getActiveOBDAModel() {
   OWLOntology ontology = owlEditorKit.getOWLModelManager().getActiveOntology();
   if (ontology != null) {
     OWLOntologyID ontologyID = ontology.getOntologyID();
     IRI ontologyIRI = ontologyID.getOntologyIRI();
     URI uri = null;
     if (ontologyIRI != null) {
       uri = ontologyIRI.toURI();
     } else {
       uri = URI.create(ontologyID.toString());
     }
     return obdamodels.get(uri);
   }
   return null;
 }
 /**
  * Renderes an annotation value that is an IRI
  *
  * @param page The page that the value will be rendered into.
  * @param iri The IRI that is the annotation value.
  * @param defaultForeground The default foreground color.
  * @param defaultBackgound The default background color.
  * @param isSelected Whether or not the cell containing the annotation is selected.
  * @param hasFocus Whether or not the cell containing the annotation has the focus.
  * @return A list of paragraphs that represent the rendering of the annotation value.
  */
 private List<Paragraph> renderIRI(
     Page page,
     IRI iri,
     Color defaultForeground,
     Color defaultBackgound,
     boolean isSelected,
     boolean hasFocus) {
   OWLModelManager modelManager = editorKit.getOWLModelManager();
   Set<OWLEntity> entities = modelManager.getOWLEntityFinder().getEntities(iri);
   List<Paragraph> paragraphs;
   if (entities.isEmpty()) {
     paragraphs = renderExternalIRI(page, iri);
   } else {
     paragraphs = renderEntities(page, entities);
   }
   return paragraphs;
 }
Ejemplo n.º 17
0
 public void handleSave() throws Exception {
   if (DBG) System.out.println("HG handleSave ");
   OWLOntology ont = getModelManager().getActiveOntology();
   if (ont instanceof HGDBOntologyImpl) {
     String message =
         "This ontology is database backed and does not need to be saved to the database again.\n"
             + "All changes to it are instantly persisted in the Hypergraph Ontology Repository.";
     System.err.println(message);
     // logger.warn(message);
     JOptionPane.showMessageDialog(
         getWorkspace(),
         message,
         "Hypergraph Database Backed Ontology",
         JOptionPane.ERROR_MESSAGE);
   } else {
     super.handleSave();
   }
 }
  public static OWLIndividual showDialog(OWLEditorKit owlEditorKit) {
    SKOSConceptSchemeSelectorPanel panel =
        new SKOSConceptSchemeSelectorPanel(
            owlEditorKit,
            true,
            owlEditorKit.getModelManager().getOntologies(),
            ListSelectionModel.SINGLE_SELECTION);

    int ret =
        new UIHelper(owlEditorKit)
            .showDialog("Create a new SKOS Concept Scheme", panel, panel.viewComponent);

    if (ret == JOptionPane.OK_OPTION) {
      OWLIndividual ind = panel.getSelectedObject();
      panel.viewComponent.dispose();
      return ind;
    } else {
      panel.viewComponent.dispose();
      return null;
    }
  }
Ejemplo n.º 19
0
  public OBDAModelManager(EditorKit editorKit) {
    super();

    if (!(editorKit instanceof OWLEditorKit)) {
      throw new IllegalArgumentException("The OBDA PLugin only works with OWLEditorKit instances.");
    }
    this.owlEditorKit = (OWLEditorKit) editorKit;
    mmgr = ((OWLModelManager) owlEditorKit.getModelManager()).getOWLOntologyManager();
    OWLModelManager owlmmgr = (OWLModelManager) editorKit.getModelManager();
    owlmmgr.addListener(modelManagerListener);
    obdaManagerListeners = new LinkedList<OBDAModelManagerListener>();
    obdamodels = new HashMap<URI, OBDAModel>();

    // Adding ontology change listeners to synchronize with the mappings
    mmgr.addOntologyChangeListener(new OntologyRefactoringListener());

    // Initialize the query controller
    queryController = new QueryController();

    // Printing the version information to the console
    //	System.out.println("Using " + VersionInfo.getVersionInfo().toString() + "\n");
  }
Ejemplo n.º 20
0
 /** @param k k */
 public OWLEntitySelector(OWLEditorKit k) {
   super(new BorderLayout());
   kit = k;
   facetClasses.addAll(LocalityChecker.collectEntities(k.getOWLModelManager().getOntologies()));
   facetClassView.setCellRenderer(new RenderableObjectCellRenderer(kit));
   facetClassView.setModel(facetClassesModel);
   setOK(false);
   facetClassesModel.init();
   JScrollPane spobjf = ComponentFactory.createScrollPane(facetClassView);
   spobjf.setBorder(ComponentFactory.createTitledBorder("Entity selection"));
   this.add(spobjf);
   facetClassView.addListSelectionListener(
       new ListSelectionListener() {
         @Override
         public void valueChanged(ListSelectionEvent e) {
           if (!e.getValueIsAdjusting()) {
             // then status is OK
             OWLEntitySelector.this.setOK(true);
           }
         }
       });
 }
 private void appendTag(
     Paragraph tagParagraph, OWLLiteral literal, Color foreground, boolean isSelected) {
   Color tagColor = isSelected ? foreground : Color.GRAY;
   Color tagValueColor = isSelected ? foreground : Color.GRAY;
   if (literal.hasLang()) {
     tagParagraph.append("[language: ", tagColor);
     tagParagraph.append(literal.getLang(), tagValueColor);
     tagParagraph.append("]", tagColor);
   } else if (datatypeRendering == RENDER_DATATYPE_INLINE && !literal.isRDFPlainLiteral()) {
     tagParagraph.append("[type: ", tagColor);
     tagParagraph.append(
         editorKit.getOWLModelManager().getRendering(literal.getDatatype()), tagValueColor);
     tagParagraph.append("]", tagColor);
   }
   //        if (ontology != null) {
   //            tagParagraph.append("    ", foreground);
   //            tagParagraph.append("[in: ", tagColor);
   //            String ontologyRendering = editorKit.getOWLModelManager().getRendering(ontology);
   //            tagParagraph.append(ontologyRendering, tagColor);
   //            tagParagraph.append("]", tagColor);
   //        }
 }
 public SKOSConceptSchemeSelectorPanel(OWLEditorKit eKit, boolean editable) {
   this(eKit, editable, eKit.getModelManager().getActiveOntologies());
 }
Ejemplo n.º 23
0
  @Override
  protected void initialiseOWLView() throws Exception {

    // Retrieve the editor kit.
    final OWLEditorKit editor = getOWLEditorKit();

    controller = (OBDAModelManager) editor.get(OBDAModelImpl.class.getName());
    controller.addListener(this);

    OBDAModel obdaModel = controller.getActiveOBDAModel();

    TargetQueryVocabularyValidator validator = new TargetQueryValidator(obdaModel);

    // Init the Mapping Manager panel.
    mappingPanel = new MappingManagerPanel(obdaModel, validator);

    editor
        .getOWLWorkspace()
        .getOWLSelectionModel()
        .addListener(
            new OWLSelectionModelListener() {
              @Override
              public void selectionChanged() throws Exception {
                OWLEntity entity =
                    editor.getOWLWorkspace().getOWLSelectionModel().getSelectedEntity();
                if (entity == null) return;
                if (!entity.isTopEntity()) {
                  String shortf = entity.getIRI().getFragment();
                  if (shortf == null) {
                    String iri = entity.getIRI().toString();
                    shortf = iri.substring(iri.lastIndexOf("/"));
                  }
                  mappingPanel.setFilter("pred:" + shortf);
                } else {
                  mappingPanel.setFilter("");
                }
              }
            });

    datasourceSelector = new DatasourceSelector(controller.getActiveOBDAModel());
    datasourceSelector.addDatasourceListListener(mappingPanel);

    // Construt the layout of the panel.
    JPanel selectorPanel = new JPanel();
    selectorPanel.setLayout(new GridBagLayout());

    JLabel label = new JLabel("Select datasource: ");
    label.setFont(new Font("Dialog", Font.BOLD, 12));
    label.setForeground(new Color(53, 113, 163));
    // label.setBackground(new java.awt.Color(153, 153, 153));
    // label.setFont(new java.awt.Font("Arial", 1, 11));
    // label.setForeground(new java.awt.Color(153, 153, 153));
    label.setPreferredSize(new Dimension(119, 14));

    GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
    selectorPanel.add(label, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
    selectorPanel.add(datasourceSelector, gridBagConstraints);

    selectorPanel.setBorder(new TitledBorder("Datasource selection"));
    mappingPanel.setBorder(new TitledBorder("Mapping manager"));

    setLayout(new BorderLayout());
    add(mappingPanel, BorderLayout.CENTER);
    add(selectorPanel, BorderLayout.NORTH);
  }
Ejemplo n.º 24
0
 public void dispose() {
   OWLModelManager modelMan = editorKit.getOWLModelManager();
   modelMan.removeOntologyChangeListener(ontologyChangeListener);
   modelMan.removeListener(modelManagerListener);
 }
 public OWLProtegeEntityResolver(@Nonnull OWLEditorKit editorKit) {
   checkNotNull(editorKit);
   modelManager = editorKit.getModelManager();
   entityFinder = modelManager.getOWLEntityFinder();
   entityFactory = modelManager.getOWLEntityFactory();
 }
Ejemplo n.º 26
0
 public void dispose() {
   editorKit.getOWLModelManager().removeOntologyChangeListener(ontChangeListener);
 }
 /**
  * Determines if the reference ontology (if set) is equal to the active ontology.
  *
  * @return <code>true</code> if the reference ontology is equal to the active ontology, otherwise
  *     <code>false</code>.
  */
 public boolean isReferenceOntologyActive() {
   return ontology != null && ontology.equals(editorKit.getOWLModelManager().getActiveOntology());
 }
 /**
  * Renders an annotation value that is an anonymous individual.
  *
  * @param page The page that the individual should be rendered into.
  * @param individual The individual.
  * @return A list of paragraphs that represent the rendering of the individual.
  */
 private List<Paragraph> renderAnonymousIndividual(Page page, OWLAnonymousIndividual individual) {
   String rendering = editorKit.getOWLModelManager().getRendering(individual);
   Paragraph paragraph = page.addParagraph(rendering);
   paragraph.setIcon(getIcon(individual));
   return Arrays.asList(paragraph);
 }
 /**
  * Gets the icon for an entity.
  *
  * @param entity The entity.
  * @return The icon or null if the entity does not have an icon.
  */
 private Icon getIcon(OWLObject entity) {
   return editorKit.getOWLWorkspace().getOWLIconProvider().getIcon(entity);
 }
Ejemplo n.º 30
0
 protected void initialiseCompleted() {
   super.initialiseCompleted();
 }