📄 swoopmodel.java
字号:
* @param ont * @param ent * @param parent */ public void addEntity(OWLOntology ont, OWLEntity ent, OWLEntity parent) { try { AddEntity change = new AddEntity(ont, ent, null); change.accept((ChangeVisitor) ont); // add parent entity change if parent!=null if (parent!=null) { if (parent instanceof OWLClass) { if (ent instanceof OWLClass) { // add super class OWLClass parentCla = (OWLClass) parent; // OWLOntology parentOnt = (OWLOntology) parentCla.getOntologies().iterator().next(); AddSuperClass supChange = new AddSuperClass(this.selectedOntology, (OWLClass) ent, parentCla, null); supChange.accept((ChangeVisitor) this.selectedOntology); } else if (ent instanceof OWLIndividual){ // add instance type AddIndividualClass indChange = new AddIndividualClass(this.selectedOntology, (OWLIndividual) ent, (OWLClass) parent, null); indChange.accept((ChangeVisitor) this.selectedOntology); } } else if (parent instanceof OWLProperty) { // add super class OWLProperty parentProp = (OWLProperty) parent; // OWLOntology parentOnt = (OWLOntology) parentCla.getOntologies().iterator().next(); AddSuperProperty supChange = new AddSuperProperty(this.selectedOntology, (OWLProperty) ent, parentProp, null); supChange.accept((ChangeVisitor) this.selectedOntology); } } // use SwingWorker to process ontology using reasoner this.useSwingWorker(new ModelChangeEvent(this, ModelChangeEvent.ADDED_ENTITY), false, ent, change); } catch (OWLException ex) { ex.printStackTrace(); } } /** * Add a General Concept Inclusion (GCI) axiom to an Ontology * Pass the LHS/RHS Class Descriptions of the GCI * Reasoner is refreshed and listeners are notified */ public void addGCI(OWLOntology ont, OWLDescription lhs, OWLDescription rhs) { try { OWLSubClassAxiom axiom = ont.getOWLDataFactory().getOWLSubClassAxiom(lhs, rhs); AddClassAxiom change = new AddClassAxiom(ont, axiom, null); change.accept((ChangeVisitor) ont); // use SwingWorker to process ontology using reasoner this.useSwingWorker(new ModelChangeEvent(this, ModelChangeEvent.ADDED_ENTITY), false, null, null); //TODO: also record add GCI as a change// this.addCommittedChange(change); } catch (OWLException ex) { ex.printStackTrace(); } } /** * Remove an OWL Entity from the ontology * i.e. Remove all references of the entity from the ontology. This feature * is not available in the OWL-API which only removes the type assertion * @param ont * @param ent * @param allReferences */ public void removeEntity(OWLOntology ont, OWLEntity ent, boolean allReferences) { try { RemoveEntity change = new RemoveEntity(ont, ent, null); if (!allReferences) { change.accept((ChangeVisitor) ont); } else { OWLEntityRemover remover = new OWLEntityRemover(ont); remover.removeEntity(ent); } this.selectedEntity = null; this.selectedOntology = ont; this.selectedOWLObject = ont; // use SwingWorker to process ontology using reasoner this.useSwingWorker(new ModelChangeEvent(this, ModelChangeEvent.REMOVED_ENTITY), false, null, change); } catch (OWLException ex) { ex.printStackTrace(); } } /* * Remove a set of GCIs from the ontology */ public void removeGCI(OWLOntology ont, Object[] gcis, boolean warning) { try { int result = -1; if (warning) { String title = "Remove GCI(s) from Ontology"; int options = JOptionPane.YES_NO_OPTION; result = JOptionPane.showConfirmDialog(null, "This is going to remove all selected GCIs from the Ontology. Continue?", title, options); } if(result==JOptionPane.YES_OPTION || !warning) { for (int i=0; i<gcis.length; i++) { OWLSubClassAxiom remGCI = (OWLSubClassAxiom) gcis[i]; RemoveClassAxiom remAxiom = new RemoveClassAxiom(ont, remGCI, null); remAxiom.accept((ChangeVisitor) ont); } this.selectedEntity = null; this.selectedOntology = ont; this.selectedOWLObject = ont; // use SwingWorker to process ontology using reasoner this.useSwingWorker(new ModelChangeEvent(this, ModelChangeEvent.REMOVED_ENTITY), false, null, null); //TODO: also record remove GCI as a change// this.addCommittedChange(change); } } catch (OWLException ex) { ex.printStackTrace(); } } /** * * Set the flag for showing ontologies imported by the selected ontology. The selected * reasoner is automatically refreshed by this function to load/unload the imported * ontologies based on the given parameter. an exception is thrown if the reasoner * fails with the new setting * * @param value * @throws OWLException */ public void setShowImports(boolean value) throws OWLException { show_imports = value; // use SwingWorker to process ontology using reasoner this.useSwingWorker(new ModelChangeEvent(this, ModelChangeEvent.IMPORTS_VIEW_CHANGED), true, null, null); } public boolean getShowImports() { return show_imports; } public String shortForm(URI uri) { if (uri==null) return "Anonymous Individual"; if (this.useLabels) { LabelShortFormProvider lsfp = new LabelShortFormProvider(this); return lsfp.shortForm(uri); } else return shortForms.shortForm(uri); } public ShortFormProvider getShortForms() { return shortForms; } public void notifyListeners(ModelChangeEvent event) { Iterator i = listeners.iterator(); while(i.hasNext()) { SwoopModelListener sml = (SwoopModelListener) i.next(); sml.modelChanged(event); } } /** * * Changes the current selected ontology. The reasoner is loaded with this new ontology. * an exception is thrown if the reasoner cannot process this ontology. * * @param ontology * @throws OWLException */ public void setSelectedOntology(OWLOntology ontology) throws OWLException { // save ontology settings before changing selection to new ontology this.saveCurrentOntSettings(); this.selectedOntology = ontology; this.selectedEntity = null; // load ontology settings after selection has changed loadOntSettings(ontology); // notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.ONTOLOGY_SEL_CHANGED)); } /** * Clear swoopModel selections i.e. selected Ontology, Entity and OWLObject * also notify listeners via CLEAR_SELECTIONS ModelChange event * */ public void clearSelections() { this.selectedOntology = null; this.selectedEntity = null; this.selectedOWLObject = null; ModelChangeEvent event = new ModelChangeEvent(this, ModelChangeEvent.CLEAR_SELECTIONS); notifyListeners(event); } public OWLOntology getSelectedOntology() { return selectedOntology; } public void setSelectedEntity(OWLEntity entity) { this.selectedEntity = entity; ModelChangeEvent event = new ModelChangeEvent(this, ModelChangeEvent.ENTITY_SEL_CHANGED); notifyListeners(event); } public OWLEntity getSelectedEntity() { return selectedEntity; } /** * Sets the SwoopModel reasoner. * Also classifies the currently selected ontology * @param reasoner * @throws OWLException */ public void setReasoner(SwoopReasoner selReasoner) throws Exception { // when changing reasoner selection for an ontology in the UI // first save current reasoner selection if( selectedOntology != null && reasoner!=null) reasonerCache.putReasoner(selectedOntology, this.reasoner.getName(), this.reasoner); final SwoopReasoner previousReasoner = this.reasoner; // now select new reasoner boolean loadedReasonerFromCache = false; // check if reasoner already exists in cache SwoopReasoner newReasoner = ( selectedOntology != null ) ? reasonerCache.getReasoner(selectedOntology, selReasoner.getName()) : null; if (newReasoner!=null) { loadedReasonerFromCache = true; System.out.println("Loaded "+newReasoner.getName()+" reasoner from cache.."); } else { // else create new instance of selected reasoner Class cls = selReasoner.getClass(); newReasoner = (SwoopReasoner) cls.newInstance(); System.out.println("Created new "+newReasoner.getName()+" reasoner.."); } try { if(selectedOntology != null && !loadedReasonerFromCache) { newReasoner.setDoExplanation(enableDebugging); newReasoner.setLoadImports(this.show_imports, false); //don't refresh here final SwoopModel model = this; final SwoopReasoner reas = newReasoner; // use SwingWorker to process ontology using reasoner SwingWorker worker = new SwingWorker() { boolean fail = false; public Object construct() { try { reas.setOntology(selectedOntology); } catch (Exception ex) { fail = true; if( ex != null ) throw new RuntimeException(ex); else throw new RuntimeException( "Unexpected error" ); } return null; } public void finished() { // do the UI update after reasoner processes the ontology if (fail) { // remove pellet from cache model.reasonerCache.removeReasonerOntology(model.selectedOntology, reas.getName()); // set reasoner to previous one model.reasoner = previousReasoner; // make reasonerCombo select previous one notifyListeners(new ModelChangeEvent(model, ModelChangeEvent.REASONER_FAIL)); } else { // set new reasoner model.reasoner = reas; // add reasoner to cache reasonerCache.putReasoner(selectedOntology, reas.getName(), reas); notifyListeners(new ModelChangeEvent(model, ModelChangeEvent.REASONER_SEL_CHANGED)); } } }; worker.start(); } else { // notify regardless (if loaded from cache) this.reasoner = newReasoner; notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.REASONER_SEL_CHANGED)); } } catch (Throwable e) {// this.clearSelections(); e.printStackTrace(); throw new OWLException(e.getMessage()); } } public SwoopReasoner getReasoner() { return reasoner; } public boolean getShowQNames() { return showQNames; } public void setShowQNames(boolean showQNames) { this.showQNames = showQNames; if(showQNames) shortForms = new QNameShortFormProvider(); else shortForms = new DefaultShortFormProvider(); ModelChangeEvent event = new ModelChangeEvent(this, ModelChangeEvent.QNAME_VIEW_CHANGED); notifyListeners(event); } public boolean getUseLabels() { return this.useLabels; } public void setUseLabels(boolean useLabels) { this.useLabels = useLabels; ModelChangeEvent event = new ModelChangeEvent(this, ModelChangeEvent.QNAME_VIEW_CHANGED); notifyListeners(event); } public boolean getShowIcons() { return this.showIcons; } public void setShowInherited(boolean showInherited) { this.showInherited = showInherited; notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.SHOW_INHERITED, selectedOntology)); } public boolean getShowInherited() { return this.showInherited; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -