示例#1
0
  @Override
  public void initialise() throws Exception {
    editorKit = (OWLEditorKit) getEditorKit();
    owlManager = editorKit.getOWLModelManager();
    //		currentOnto = owlManager.getActiveOntology();

  }
示例#2
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);
    }
  }
 /**
  * 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;
 }
  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);
  }
  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());
  }
示例#6
0
 @Override
 public void initialise() throws Exception {
   editorKit = (OWLEditorKit) getEditorKit();
   workspace = editorKit.getWorkspace();
   owlManager = editorKit.getOWLModelManager();
   modelManager = ((OBDAModelManager) editorKit.get(OBDAModelImpl.class.getName()));
 }
示例#7
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);
 }
 /**
  * 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;
 }
示例#9
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;
 }
示例#11
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);
   //        }
 }
 /**
  * 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);
 }
 public String getRendering(OWLObject object) {
   return editorKit.getOWLModelManager().getRendering(object);
 }
 public OWLOntology getActiveOntology() {
   return editorKit.getOWLModelManager().getActiveOntology();
 }
 public void dispose() {
   editorKit.getOWLModelManager().removeOntologyChangeListener(ontChangeListener);
 }
示例#17
0
 public void dispose() {
   OWLModelManager modelMan = editorKit.getOWLModelManager();
   modelMan.removeOntologyChangeListener(ontologyChangeListener);
   modelMan.removeListener(modelManagerListener);
 }
 /**
  * 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());
 }
 public Set<OWLOntology> getOntologies() {
   return editorKit.getOWLModelManager().getActiveOntologies();
 }