⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swoopmodel.java

📁 Semantic Web Ontology Editor
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
								SwoopReasoner noReasoner = (SwoopReasoner) SwoopToldReasoner.class.newInstance();								// select No-Reasoner								model.setReasoner(noReasoner);							} 							catch (Exception e) {								e.printStackTrace();							}							notifyListeners(new ModelChangeEvent(model, ModelChangeEvent.REASONER_FAIL));						}						else {							// proceed as normal - logging changes if no cancellation/exception							if (loggerF && model.isLogChanges()) committedChanges.addAll(uncommittedChanges);				    		uncommittedChanges = new ArrayList();				    						    		if (notifyF) notifyListeners(new ModelChangeEvent(model, ModelChangeEvent.ONTOLOGY_CHANGED, changedOntologies));				    		bufferedChanges = new ArrayList();						}					}				};				worker.start();    		}    		    		    	}    	catch (Exception ex) {    		ex.printStackTrace();    	}				    }        public List getCommittedChanges() {    	return committedChanges;    }        /* Note: set*Changes(..) should not add to changesCache, only add*Changes(..) should */     public void setCommittedChanges(Collection allChanges) {    	committedChanges.clear();    	committedChanges.addAll(allChanges);    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.RESET_CHANGE, null));    }        /**     * Adds an arbitrary set of ontologies to the SwoopModel     * Currently used by the partitioning code to add the partitions back to Swoop     * @param onts     */    public void addOntologies(Collection onts) {    	Iterator i = onts.iterator();    	while(i.hasNext()) {			OWLOntology ont = (OWLOntology) i.next();			try {				ontologies.put(ont.getURI(), ont);			} catch (OWLException e) {				e.printStackTrace();			}		}    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.ONTOLOGY_LOADED, null));    }        /**	 * Add an ontology to the SwoopModel Also adds the imports closure of the	 * ontology to the SwoopModel Saves current ontology-specific user settings	 * (imports, qnames, reasoner) Also loads settings if any (should load	 * defaults always if the ontology being added is a new one)	 * 	 * @param onto	 * @throws OWLException	 */	public void addOntology(OWLOntology onto) throws OWLException {		// get imports closure		Iterator i = OntologyHelper.importClosure(onto).iterator();		while(i.hasNext()) {			OWLOntology ont = (OWLOntology) i.next();						OWLOntology current = (OWLOntology) ontologies.get(ont.getLogicalURI());			if ((current != null ) && !(current.getPhysicalURI().equals(ont.getPhysicalURI()))) {				handleExistingOntology(ont, ont.getLogicalURI());			} else {				ontologies.put(ont.getURI(), ont);				// update imported ontology settings in this case as well				this.updateImportSettings(ont);			}		}				// save ontology settings before changing selection to new ontology		this.saveCurrentOntSettings();				this.selectedOntology = onto;		this.selectedEntity = null;		this.selectedOWLObject = onto;				// load ontology settings after selection has changed		// dont need to loadOntSettings here because it will be done when		// selection changes to loaded ontology later//		loadOntSettings(onto); // this should always load defaults		//*** instead set default settings for new ontology ***/		this.show_imports = true;		this.showQNames = false;		this.reasoner = getDefaultReasoner();;				notifyListeners(new ModelChangeEvent(this,				ModelChangeEvent.ONTOLOGY_LOADED, onto));	}        public OWLOntology addOntology(URI uri) throws OWLException {    	    		OWLOntology ontology = this.loadOntology(uri);		addOntology(ontology);		return ontology;    }    /**     * Generic function to load an ontology given a URI (web or local)     * It checks the file extension (.txt, .rdf..) and calls the appropriate     * OWL API lexer/parser (Abstract Syntax, RDF/XML) to parse the OWL Ontology     * @param uri     * @return     */    public OWLOntology loadOntology(URI uri) throws OWLException {    	OWLOntology ontology = null;    	    	if (uri.toString().endsWith(".txt")) {  		    		ontology = this.loadOntologyInAbstractSyntax(null, uri);    	} else if (uri.toString().endsWith(".wsp")) { //ws-policy extension    		// if it is a ws-policy file, use the XSLT to convert it to OWL    		    		//pass the reader and the URI    		//need to check whether it's a ws-policy file    		    		Reader reader = WSPolicy.transformPolicyFile(uri);    		    		    		ontology = this.loadOntologyInRDF(reader, uri);    	}    	else {    		ontology = this.loadOntologyInRDF(null, uri);    	}    	return ontology;    }        /**     * Given an ontology, and a type of entity (OWLClass/ObjProp/DataProp/Individual),     * return a set of these entities from the ontology (BASE_ONT) or its imported ontologies (IMPORTED_ONT) or its imports closure (TRANSCLOSE_ONT).     * @param ont     * @param ont_type     * @param entity_type     * @return     */	public Set getEntitySet(OWLOntology ont, int ont_type, int entity_type) {				Set entitySet = new HashSet();		try {			if(ont.getIncludedOntologies() != null) {	        				Set inclOntSet = new HashSet();				if (ont_type == TRANSCLOSE_ONT) inclOntSet = OntologyHelper.importClosure(ont);				else if (ont_type == BASE_ONT) inclOntSet.add(ont);				else if (ont_type == IMPORTED_ONT) {					inclOntSet = OntologyHelper.importClosure(ont);					inclOntSet.remove(ont);									}						            Iterator iter = inclOntSet.iterator();	            while(iter.hasNext()) {	            	OWLOntology inclOnt = (OWLOntology) iter.next();	            	switch (entity_type) {	            		case ALL: 	            		case CLASSES:	            			Iterator claIter = inclOnt.getClasses().iterator();	        				while (claIter.hasNext()) {	        					OWLDescription desc = (OWLDescription) claIter.next();	        					if (desc instanceof OWLClass) entitySet.add(desc);	        				}	            				            			if (entity_type==CLASSES) break;	            				            		case DATAPROPERTIES:	            			entitySet.addAll(inclOnt.getDataProperties());	            			if (entity_type==DATAPROPERTIES) break;	            				            		case OBJPROPERTIES:	            			entitySet.addAll(inclOnt.getObjectProperties());	            			if (entity_type==OBJPROPERTIES) break;	            			            		case PROPERTIES:	            			entitySet.addAll(inclOnt.getObjectProperties());	            			entitySet.addAll(inclOnt.getDataProperties());	            			entitySet.addAll(inclOnt.getAnnotationProperties());//	            			********************************************************	    					//Added for Econnections	    					//*********************************************************	    					//Whenever an ontology A imports another ontology B, and A is	    					// Econencted to B, then all the links from B to A have to be shown	    					// As object properties in A, not as links	    					//*******************************************************	    					Iterator it = inclOnt.getObjectProperties().iterator();	    					while (it.hasNext()){	    						OWLEntity ent = (OWLEntity)it.next();	    						if (ent instanceof OWLObjectProperty){	    							if(((OWLObjectProperty)(ent)).isLink()){	    							   	if(((OWLObjectProperty)(ent)).getLinkTarget().equals(ont.getURI())){	    							   		OWLObjectProperty aux = (OWLObjectProperty)ent;	    							   		aux.setLinkTarget(null);	    							   	    entitySet.remove(ent);	    							   	    entitySet.add(aux);	    							   	}	    							   		    							}	    						}	    							    					}	    						    					//*********************************************************	            			if (entity_type==PROPERTIES) break;	            				            		case INDIVIDUALS:	            			Iterator indIter = inclOnt.getIndividuals().iterator();	        				while (indIter.hasNext()) {	        					OWLIndividual ind = (OWLIndividual) indIter.next();//	        					if (ind.getURI()!=null) 	        					    entitySet.add(ind);	        				}	            			break;	            				            		case GCI:	            			for (iter = inclOnt.getClassAxioms().iterator(); iter.hasNext();) {	            				OWLClassAxiom axiom = (OWLClassAxiom) iter.next();	            				if (axiom instanceof OWLSubClassAxiom) {	            					if (!(((OWLSubClassAxiom) axiom).getSubClass() instanceof OWLClass)) {	            						entitySet.add(axiom);	            					}	            				}	            			}	            			break;	            				            		//*****************************************************		            		//Added for Econnections		            		//*****************************************************	            		case FOREIGN_ENT:		            			Iterator foreignIter = this.getSelectedOntology().getForeignEntities().keySet().iterator();	            			while(foreignIter.hasNext()){	            				OWLEntity ent = (OWLEntity)foreignIter.next();	            				if(ent.getURI()!=null) entitySet.add(ent);	            			}	            			break;	            	}	            	  //*********************************************************	            }			}		}		catch (OWLException e) {			e.printStackTrace();		}		return entitySet;	}    	/**	 * Load an OWL Ontology serialized in the OWL Abstract Syntax format given	 * a reader (optional) and a URI (compulsory)	 * @param reader	 * @param uri	 * @return	 * @throws OWLException 	 */    public OWLOntology loadOntologyInAbstractSyntax(Reader reader, URI uri) throws OWLException {    	OWLOntology ontology;    	    	    	OWLConnection connection = new OWLConnectionImpl();    	AbstractOWLParser parser = new AbstractOWLParser(connection);	    	if (reader!=null) {    		ontology = parser.parseOntology(reader, uri);			    	} else {    		ontology = parser.parseOntology(uri);    	}    	    	return ontology;    }    //*************************************************    //Added for Econnections    //*************************************************    public boolean isEconnectedOntology(OWLOntology ont){    	boolean b = false;    	    	try {			Iterator it = ont.getObjectProperties().iterator();			while(it.hasNext()){				OWLObjectProperty prop = (OWLObjectProperty)it.next();				if(prop.isLink())					b=true;			}		} catch (OWLException e) {			e.printStackTrace();		}    	    	if(!ont.getForeignEntities().isEmpty()){    		b=true;    	}    		    	return b;    }     /**     * Remove an ontology from the swoopModel given its uri.     * Remove it from the ontologies hashMap     * @param uri     */    public void removeOntology(URI uri) {    	OWLOntology onto = getOntology(uri);    	    	this.selectedOntology = null;    	    	if(onto != null) {    		ontologies.remove(uri);    		clearCaches(onto);    		this.changesCache.removeOntology(onto);    	   	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.ONTOLOGY_REMOVED, uri));    	}    	    	this.clearSelections();    }        /*     * Clear the reasoner, change (maybe annotations?) cache     * of SwoopModel for a specific ontology     */    public void clearCaches(OWLOntology ont) {    	this.reasonerCache.removeReasoners(ont);//		this.changesCache.removeOntology(ont);//		this.annotationCache.remove(ont);		this.removeOntStats(ont);    }        public OWLOntology getOntology(URI uri) {    	return (OWLOntology) ontologies.get(uri);    }        public Hashtable getOntologiesMap() {    	return (Hashtable) ontologies;    }        public Collection getOntologies() {    	return ontologies.values();    }        public Set getOntologyURIs() {    	return ontologies.keySet();    }        public void addListener(SwoopModelListener sml) {    	listeners.add(sml);    }        public void removeListener(SwoopModelListener sml) {    	listeners.remove(sml);    }        /**     * Add an OWL entity (OWL Class/Property/Individual) to the ontology passed as arguments.     * Also make the new entity a subclass/subproperty/instanceOf of an existing entity (parent)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -