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

📄 swoopmodel.java

📁 Semantic Web Ontology Editor
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public void setEnableRules(boolean mode) {		enableRules = mode;		notifyListeners(new ModelChangeEvent(this,				ModelChangeEvent.RULES_CHANGED, selectedOntology));	}    public boolean getShowDivisions() {    	return showDivisions;    }        public URI getCurrentlyLoadingURI() {    	return currentlyLoadingURI;    }        public void setCurrentlyLoadingURI(URI uri) {    	this.currentlyLoadingURI = uri;    }        public void setEditorEnabled(boolean mode) {    	editorEnabled = mode;    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.EDITABLE_CHANGED, selectedOntology));    	    }        public void setEnableDebugging(boolean mode) {    	enableDebugging = mode;    	    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.DEBUGGING_CHANGED, selectedOntology));    	    }        public void setShowIcons(boolean mode, boolean notify) {    	showIcons = mode;    	if (notify) notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.EDITABLE_CHANGED, selectedOntology));    	    }        public void setShowDivisions(boolean mode) {    	showDivisions = mode;    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.EDITABLE_CHANGED, selectedOntology));    	    }        public List getUncommittedChanges() {    	if (uncommittedChanges==null) uncommittedChanges = new ArrayList();    	return uncommittedChanges;    }        public Set getEntityAnnotations(OWLEntity entity) {    	return (HashSet) ResourceAnnotHash.get(entity);    }        public void setEntityAnnotations(OWLEntity entity, Set annotations) {    	ResourceAnnotHash.put(entity, annotations);    }        /* Note: set*Changes(..) should not add to changesCache, only add*Changes(..) should */    public List setUncommittedChanges(Collection changes) {    	uncommittedChanges.clear();    	uncommittedChanges.addAll(changes);    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.RESET_CHANGE, null));    	return uncommittedChanges;    }        public List addUncommittedChanges(Collection changes) {    	return addUncommittedChanges(changes, true);    }        public List addUncommittedChanges(Collection changes, boolean notify) {    	uncommittedChanges.addAll(changes);    	for (Iterator iter = changes.iterator(); iter.hasNext();) {    		OntologyChange change = (OntologyChange) iter.next();    		processChange(change, false);    	}    	if (notify) notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.ADDED_CHANGE, null));    	return uncommittedChanges;    	    }        public List addUncommittedChange(OntologyChange change) {    	uncommittedChanges.add(change);    	    	processChange(change, false);    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.ADDED_CHANGE, null));    	return uncommittedChanges;    }        /**     * Process the ontology change using ChangeLog.java to obtain      * a string description of the change and URIs of subjects of the change.     * Then create an instance of SwoopChange and add author/timestamp     * and if committed or not.     * Finally add swoopChange to changesCache     */    public void processChange(OntologyChange change, boolean isCommitted) {    	try {	    	// create instance of ChangeLog	    	ChangeLog clog = new ChangeLog(null, this);	    		    	// call method to obtain description of change and subject URIs of change	    	List subjURIs = new ArrayList();	    	List extraSubj = new ArrayList();	    	String desc = clog.getChangeInformation(change, ChangeLog.CHANGE_DESCRIPTION, null, subjURIs, null).toString();	    	/* also add ontology of change to subjURIs */	    	if (change.getOntology()!=null) {	    		if (!subjURIs.contains(change.getOntology().getURI())) subjURIs.add(change.getOntology().getURI());	    		// but save copy of uris minus ontology to be used below		    	extraSubj = new ArrayList(subjURIs);		    	extraSubj.remove(change.getOntology().getURI());	    	}	    		    	// add timestamp and author from SwoopModel	    	String ts = this.getTimeStamp();	    	String author = this.getUserName();	    		    	// create new instance of SwoopChange for each subject of change	    	for (Iterator iter = subjURIs.iterator(); iter.hasNext();) {	    			    		URI owlObjectURI = (URI) iter.next();	    			    		// determine if change is checkpoint related or not	    		boolean chkptRelated = false;	    		if (change instanceof SaveCheckpointChange || change instanceof RevertCheckpointChange) {	    			chkptRelated = true;	    		}	    			    		/* create instanceof SwoopChange passing necessary args */	    		SwoopChange swc = new SwoopChange(author, owlObjectURI, change, ts, desc, isCommitted, chkptRelated);	    			    		// add extra subject URIs for all changes	    		// by removing current entity name	    		List extra = new ArrayList(extraSubj);	    		extra.remove(owlObjectURI);	    		swc.setExtraSubjects(extra);	    			    		changesCache.addChange(owlObjectURI, swc);	    			    		// also if change is committed, remove any matching uncommited changes if any	    		//TODO make this faster	    		if (isCommitted) {	    			changesCache.removeOntologyChange(owlObjectURI, change, false);	    		}	    	}    	}    	catch (OWLException ex) {    		ex.printStackTrace();    	}    }        public List addCommittedChange(OntologyChange change) {    	if (isLogChanges()) {	    	committedChanges.add(change);	    	// process change to get subject and description and create a new instance of swoopchange	    	processChange(change, true);	    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.ADDED_CHANGE, null));    	}    	return committedChanges;    }        public List addCommittedChanges(List changes) {    	if (isLogChanges()) {	    	committedChanges.addAll(changes);	    	for (int i=0; i<changes.size(); i++) {	    		processChange((OntologyChange) changes.get(i), true);	    	}	    	notifyListeners(new ModelChangeEvent(this, ModelChangeEvent.ADDED_CHANGE, null));    	}    	return committedChanges;    }    /**     * Apply a boolean element change i.e. Add/Remove a Intersection/Union/Not element     * Useful since it allows changes to these sets at a greater granularity than the default OWL-API (add/remove entire intersection/..)     * @param oc     */    public boolean applyBooleanElementChange(OntologyChange oc) {    	    	try {    		BooleanElementChange change = (BooleanElementChange) oc;    		    		// break up composite change into components    		OWLOntology ont = change.getOntology();    		changedOntologies.add(ont);    				    		OWLClass cla = change.getOWLClass();    		OWLDescription desc = change.getOWLDescription();    		Class type = change.getType();    		    		if (type.equals(OWLNot.class)) {    			// handle ADD/REMOVE of complements    			    			if (change.getChangeType().equals("Add")) {    				// add complement class    				OWLNot compClass = ont.getOWLDataFactory().getOWLNot(desc);    				AddEquivalentClass chng = new AddEquivalentClass(ont, cla, compClass, null);    				chng.accept((ChangeVisitor) ont);    			}    			else {    				// remove complement class    				// iterate through current complements and remove it    				    				Set nots = cla.getEquivalentClasses(ont);    				Iterator iter = nots.iterator();    				RemoveEquivalentClass chng = null;    				while (iter.hasNext()) {    					OWLDescription equClass = (OWLDescription) iter.next();    					if (equClass instanceof OWLNot) {    						if (((OWLNot) equClass).getOperand().equals(desc)) {    							chng = new RemoveEquivalentClass(ont, cla, equClass, null);        						break;    						}    					}    				}    				     				if (chng!=null) chng.accept((ChangeVisitor) ont);    			}    		}    		else {    			// handle ADD/REMOVE of intersections/unions    				    		// and create two atomic changes using components	    		// first delete any existing boolean set	    		// while storing existing boolean set operands	    		Set newBoolSet = new HashSet();	    		Set set = type.equals(OWLAnd.class) ?	    				OWLDescriptionFinder.getIntersections(cla, cla.getOntologies()):	    				OWLDescriptionFinder.getUnions(cla, cla.getOntologies());    							    		if(!set.isEmpty()) {	    			OWLNaryBooleanDescription boolDesc = (OWLNaryBooleanDescription) set.iterator().next();	    			if (type.equals(OWLAnd.class)) newBoolSet.addAll(((OWLAnd) boolDesc).getOperands());	    			else newBoolSet.addAll(((OWLOr) boolDesc).getOperands());	    			RemoveEquivalentClass change1 = new RemoveEquivalentClass(ont, cla, boolDesc, null);	    			change1.accept((ChangeVisitor) ont);	    		}	    			    		// now add desc to set and create new boolean    					    		if (change.getChangeType().equals("Add")) newBoolSet.add(desc);	    		else if (newBoolSet.contains(desc)) newBoolSet.remove(desc);	    			    		//*** Only add description if new boolean set has *some* element	    		if (newBoolSet.size()>0) {		    		OWLDataFactory ontDF = ont.getOWLDataFactory();	    				    		OWLBooleanDescription newBool = null;		    		if (type.equals(OWLAnd.class)) newBool = ontDF.getOWLAnd(newBoolSet);		    		else newBool = ontDF.getOWLOr(newBoolSet);		    		AddEquivalentClass change2 = new AddEquivalentClass(ont, cla, newBool, null);		    		change2.accept((ChangeVisitor) ont);	    		}    		}    		return true;    	}    	catch (OWLException e) {    		e.printStackTrace();    	}    	return false;    }        /**     * Same as ApplyBooleanElementChange except this handles enumerations (owl:oneOf)     * @param oc     */    public boolean applyEnumElementChange(OntologyChange oc) {    	    	try {    		EnumElementChange change = (EnumElementChange) oc;    		    		// break up composite change into components    		OWLOntology ont = change.getOntology();    		changedOntologies.add(ont);    				    		OWLClass cla = change.getOWLClass();    		OWLIndividual ind = change.getOWLIndividual();    		    		// and create two atomic changes using components    		// first delete any existing enumeration    		// while storing existing enum set operands    		Set newEnumSet = new HashSet();    		Set set = OWLDescriptionFinder.getEnumerations(cla, cla.getOntologies());    		    						    		if(!set.isEmpty()) {    			OWLEnumeration enumElem = (OWLEnumeration) set.iterator().next();    			newEnumSet.addAll(enumElem.getIndividuals());    			RemoveEnumeration change1 = new RemoveEnumeration(ont, cla, enumElem, null);    			change1.accept((ChangeVisitor) ont);    		}    		    		// now add ind to set and create new enumSet    		if (change.getChangeType().equals("Add")) newEnumSet.add(ind);    		else if (newEnumSet.contains(ind)) newEnumSet.remove(ind);    		    		if (newEnumSet.size()>0) {	    		OWLDataFactory ontDF = ont.getOWLDataFactory();	    		OWLEnumeration newEnum = null;	    		newEnum = ontDF.getOWLEnumeration(newEnumSet);	    		AddEnumeration change2 = new AddEnumeration(ont, cla, newEnum, null);	    		change2.accept((ChangeVisitor) ont);    		}    		return true;    	}    	catch (OWLException e) {    		e.printStackTrace();    	}    	return false;    }            public void applyOntologyChanges() {    	this.applyOntologyChanges(true, true);    }        public void applyOntologyChanges(boolean notify, boolean logger) {    	    	try {    		Iterator i = uncommittedChanges.iterator();    		changedOntologies = new HashSet();    		bufferedChanges = new ArrayList(uncommittedChanges);    		    		while(i.hasNext()) {    			OntologyChange oc = (OntologyChange) i.next();     			    			// handle special composite changes separately    			if (oc instanceof BooleanElementChange) {     				applyBooleanElementChange(oc);    			}    			else if (oc instanceof EnumElementChange) {     				applyEnumElementChange(oc);    			}    			else {    				OWLOntology ont = oc.getOntology();    				oc.accept((ChangeVisitor) ont);        			changedOntologies.add(ont);    			}    			    			processChange(oc, true);    			    			//*** need to remove all associated reasoner instances for that ontology    			// when a change occurs..        		reasonerCache.removeReasoners(oc.getOntology());        		// also remove ontStats so that it is automatically recomputed        		this.removeOntStats(oc.getOntology());    		}    		    		if(reasoner != null && selectedOntology != null) {    			final SwoopModel model = this;    			final boolean notifyF = notify;    			final boolean loggerF = logger;				    			SwingWorker worker = new SwingWorker() {					boolean fail = false;					public Object construct() {						try {							reasoner.setOntology(model.selectedOntology);													} catch (Exception ex) {							fail = true;							if( ex != null )							    throw new RuntimeException(ex.getMessage());							else							    throw new RuntimeException( "Unexpected error" );						}							return null;					}					public void finished() {						if (fail) {							try {								// remove all reasoners from cache								model.reasonerCache.removeReasoners(model.selectedOntology);								reasoner = null; // this will prevent it from being added to the cache again in call to model.setReasoner() below

⌨️ 快捷键说明

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