conciseformatentityrenderer.java

来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,805 行 · 第 1/5 页

JAVA
1,805
字号
		return this.isExplicit(subj, code, obj, null);	}		/**	 * Given a subject (OWL entity) and an object (OWL entity) and a type of relation	 * checks if the relation is explicitly defined in the ontology or not	 * If not, it is either inferred by the reasoner or imported and hence is	 * displayed in italics	 * @param subj - subject of the relationship	 * @param code - type of relationship	 * @param obj - object of the relationship	 * @param value - value only specified for ind-prop-value assertions	 * @return	 * @throws OWLException	 */	private boolean isExplicit(OWLObject subj, String code, OWLObject obj, Object value) throws OWLException {				OWLOntology ontology = reasoner.getOntology();		OWLDataFactory factory = ontology.getOWLDataFactory();				if (code.equals("C-INT")) {			if (subj instanceof OWLClass) {				OWLClass cla = (OWLClass) subj;				Iterator iter = cla.getEquivalentClasses(ontology).iterator();				while (iter.hasNext()) {					Object equ = iter.next();					if (equ instanceof OWLAnd) {						OWLAnd inter = (OWLAnd) equ;						if (inter.getOperands().contains(obj)) return true;					}				}				return false;			}		}		else if (code.equals("C-UNI")) {			if (subj instanceof OWLClass) {				OWLClass cla = (OWLClass) subj;				Iterator iter = cla.getEquivalentClasses(ontology).iterator();				while (iter.hasNext()) {					Object equ = iter.next();					if (equ instanceof OWLOr) {						OWLOr union = (OWLOr) equ;						if (union.getOperands().contains(obj)) return true;					}				}				return false;			}		}		else if (code.equals("I-ONE")) {			if (subj instanceof OWLClass && obj instanceof OWLIndividual) {				OWLClass cla = (OWLClass) subj;				Iterator iter = cla.getEnumerations(ontology).iterator();				while (iter.hasNext()) {					OWLEnumeration enumer = (OWLEnumeration) iter.next();					for (Iterator iter2 = enumer.getIndividuals().iterator(); iter2.hasNext(); ) {						OWLIndividual ind = (OWLIndividual) iter2.next();						if (ind.equals(obj)) return true;						}								}			}			return false;		}		else if (code.equals("C-DIS")) {			Iterator iter = ontology.getClassAxioms().iterator();			while (iter.hasNext()) {				OWLClassAxiom axiom = (OWLClassAxiom) iter.next(); 				if (axiom instanceof OWLDisjointClassesAxiom) {					OWLDisjointClassesAxiom disjAxiom = (OWLDisjointClassesAxiom) axiom;					if (disjAxiom.getDisjointClasses().contains(subj) && disjAxiom.getDisjointClasses().contains(obj)) return true;				}			}			return false;		}		else if(code.equals("C-SUB")) {			boolean asserted = false;			if(subj instanceof OWLClass)				asserted = ((OWLClass) subj).getSuperClasses(ontology).contains(obj);			OWLSubClassAxiom subClassAxiom = factory.getOWLSubClassAxiom((OWLDescription)subj, (OWLDescription)obj);			if (!asserted) asserted = (ontology.getClassAxioms().contains(subClassAxiom));			return asserted;					}		else if(code.equals("C-SUP")) {			boolean asserted = false;			if(obj instanceof OWLClass)				asserted = ((OWLClass) obj).getSuperClasses(ontology).contains(subj);			OWLSubClassAxiom subClassAxiom = factory.getOWLSubClassAxiom((OWLDescription)obj, (OWLDescription)subj);			if (!asserted) asserted = (ontology.getClassAxioms().contains(subClassAxiom));							return asserted;		}		else if(code.equals("C-EQU")) {			if(subj instanceof OWLClass)				return ((OWLClass) subj).getEquivalentClasses(reasoner.getOntologies()).contains(obj);			if(obj instanceof OWLClass)				return ((OWLClass) obj).getEquivalentClasses(reasoner.getOntologies()).contains(subj);			else {				Set set = new HashSet();				set.add(subj);				set.add(obj);				OWLEquivalentClassesAxiom eqClassAxiom = factory.getOWLEquivalentClassesAxiom(set);				return (ontology.getClassAxioms().contains(eqClassAxiom));							}		}		else if(code.equals("C-NOT")) {			if(subj instanceof OWLClass)				return OWLDescriptionFinder.getComplements((OWLClass) subj, reasoner.getOntologies()).contains(obj);			if(obj instanceof OWLClass)				return OWLDescriptionFinder.getComplements((OWLClass) obj, reasoner.getOntologies()).contains(subj);		}		else if(code.equals("P-DOM")) {			if((subj instanceof OWLClass) && (obj instanceof OWLProperty)) {				OWLClass cla = (OWLClass) subj;				OWLProperty prop = (OWLProperty) obj;				return (prop.getDomains(ontology).contains(cla));				//return (getPropertiesWithDomain(cla, false).contains(prop));			}		}		else if(code.equals("P-INV")) {			if((subj instanceof OWLProperty) && (obj instanceof OWLProperty)) {				OWLProperty p1 = (OWLProperty) subj;				OWLProperty p2 = (OWLProperty) obj;				return (((OWLObjectProperty) p1).getInverses(ontology).contains(p2));				//return (getPropertiesWithDomain(cla, false).contains(prop));			}		}		else if(code.equals("C-HASDOM")) {			if((obj instanceof OWLClass) && (subj instanceof OWLProperty)) {				OWLClass cla = (OWLClass) obj;				OWLProperty prop = (OWLProperty) subj;				return (prop.getDomains(ontology).contains(cla));			}		}		else if(code.equals("P-RAN")) {			if((subj instanceof OWLClass) && (obj instanceof OWLProperty)) {				OWLClass cla = (OWLClass) subj;				OWLProperty prop = (OWLProperty) obj;				return (prop.getRanges(ontology).contains(cla));				//return (getPropertiesWithRange(cla, false).contains(prop));			}		}		else if(code.equals("C-HASRAN")) {			if((obj instanceof OWLClass) && (subj instanceof OWLProperty)) {				OWLClass cla = (OWLClass) obj;				OWLProperty prop = (OWLProperty) subj;				return (prop.getRanges(ontology).contains(cla));			}		}		else if(code.equals("C-TYP")) {		    OWLIndividual ind = (OWLIndividual) subj;		    OWLDescription desc = (OWLDescription) obj;		    if(desc instanceof OWLClass)		        		    	return ind.getTypes(ontology).contains(desc);		    else		        return true;		}		else if(code.equals("I-INS")) {		    OWLIndividual ind = (OWLIndividual) obj;		    OWLClass c = (OWLClass) subj;		    return ind.getTypes(ontology).contains(c);		}		else if(code.equals("I-SAM")) {			// get individual axioms for the ontology			for (Iterator iter = ontology.getIndividualAxioms().iterator(); iter.hasNext(); ){				OWLIndividualAxiom indAxiom = (OWLIndividualAxiom) iter.next();				// get the set of individuals participating in each axiom				Set inds = indAxiom.getIndividuals();				if(!(indAxiom instanceof OWLSameIndividualsAxiom))				    continue;				if(inds.contains(subj) && inds.contains(obj))				    return true;						}		    return false;		}				else if(code.equals("I-DIF")) {			// get individual axioms for the ontology			for (Iterator iter = ontology.getIndividualAxioms().iterator(); iter.hasNext(); ){				OWLIndividualAxiom indAxiom = (OWLIndividualAxiom) iter.next();				// get the set of individuals participating in each axiom				Set inds = indAxiom.getIndividuals();				if(!(indAxiom instanceof OWLDifferentIndividualsAxiom))				    continue;				if(inds.contains(subj) && inds.contains(obj))				    return true;						}		    return false;		}					else if(code.equals("P-INSD")) {			OWLIndividual ind = (OWLIndividual) subj;			OWLDataProperty prop = (OWLDataProperty) obj;			Set allValues = (Set) ind.getDataPropertyValues(ontology).get( prop );			OWLDataValue val = (OWLDataValue) value;			// Evren: if the values are defined in another ontology then allValues will be null			if( allValues != null ) {				for (Iterator iter = allValues.iterator(); iter.hasNext();) {					OWLDataValue v = (OWLDataValue) iter.next();					if(v.equals(val))						return true;				}			}			return false;		}		else if(code.equals("P-INSO")) {			OWLIndividual ind = (OWLIndividual) subj;			OWLObjectProperty prop = (OWLObjectProperty) obj;			OWLIndividual val = (OWLIndividual) value;			Set allValues = (Set) ind.getObjectPropertyValues(ontology).get( prop );			return (allValues != null) && allValues.contains( val );		}		return true;	}		/**	 * Check if a property attribute removal change is currently in the	 * swoopModel.unCommittedChanges and return the change if found	 * @param prop - property on which attribute is to be changed	 * @param code - code for the attribute (functional, inversefunctional..)	 * @return	 */	private OntologyChange isDeleted(OWLProperty prop, String code) {//		 isDeleted function for property-attribues		Iterator i = changes.iterator();		while(i.hasNext()) {			OntologyChange oc = (OntologyChange) i.next();			if (oc instanceof SetFunctional && code.equals("P-FUN")) {				SetFunctional change = (SetFunctional) oc;				if (change.getProperty().equals(prop) && !change.isFunctional()) return oc;			}			if (oc instanceof SetInverseFunctional && code.equals("P-IFUN")) {				SetInverseFunctional change = (SetInverseFunctional) oc;				if (change.getProperty().equals(prop) && !change.isInverseFunctional()) return oc;			}			if (oc instanceof SetTransitive && code.equals("P-TRA")) {				SetTransitive change = (SetTransitive) oc;				if (change.getProperty().equals(prop) && !change.isTransitive()) return oc;			}			if (oc instanceof SetSymmetric && code.equals("P-SYM")) {				SetSymmetric change = (SetSymmetric) oc;				if (change.getProperty().equals(prop) && !change.isSymmetric()) return oc;			}		}		return null;	}		/**	 * Function to check instance' property-value axioms that are deleted	 * If an ontology change is returned, corresponding axiom is striked out in the HTML renderer	 * @param prop	 * @param value	 * @return	 */	private OntologyChange isDeleted(OWLProperty prop, OWLObject value) {				// isDeleted function for instance' property-value pairs only		Iterator i = changes.iterator();		while(i.hasNext()) {			OntologyChange oc = (OntologyChange) i.next();						if (oc instanceof RemoveDataPropertyInstance && prop instanceof OWLDataProperty) {				RemoveDataPropertyInstance rem = (RemoveDataPropertyInstance) oc;				if (rem.getSubject().equals((OWLIndividual) displayedEntity) 				&& rem.getProperty().equals((OWLDataProperty) prop)				&& rem.getObject().equals((OWLDataValue) value))					return oc;			}						if (oc instanceof RemoveObjectPropertyInstance && prop instanceof OWLObjectProperty) {				RemoveObjectPropertyInstance rem = (RemoveObjectPropertyInstance) oc;				if (rem.getSubject().equals((OWLIndividual) displayedEntity) 				&& rem.getProperty().equals((OWLObjectProperty) prop)				&& rem.getObject().equals((OWLIndividual) value))					return oc;			}		}		return null;	}		/**	 * Given a subject (OWL entity) and an object (OWL entity) and a relationship code,	 * check if the relationship axiom is deleted by the user or not	 * If an ontology change is returned, corresponding axiom is striked out in the HTML renderer	 * @param subj - subject of the relationship axiom	 * @param code - relation type code 	 * @param obj - object of the relationship axiom	 * @return	 * @throws OWLException	 */	private OntologyChange isDeleted(OWLObject subj, String code, OWLObject obj) throws OWLException {		OntologyChange deleted = null;				Iterator i = changes.iterator();		while(i.hasNext()) {			OntologyChange oc = (OntologyChange) i.next();						if(oc instanceof RemoveDomain) {				RemoveDomain rem = (RemoveDomain) oc;				if ((code.equals("C-HASDOM")) && (rem.getProperty().equals((OWLProperty) subj)) && (rem.getDomain().equals((OWLDescription) obj))) {					deleted = oc;				}				if ((code.equals("P-DOM")) && (rem.getProperty().equals((OWLProperty) obj)) && (rem.getDomain().equals((OWLDescription) subj))) {					deleted = oc;				}			}			else if(oc instanceof RemoveInverse) {				RemoveInverse rem = (RemoveInverse) oc;				if ((code.equals("P-INV")) && (rem.getProperty().equals((OWLObjectProperty) subj)) && (rem.getInverse().equals((OWLObjectProperty) obj))) {					deleted = oc;				}				// also inverse is deleted				if ((code.equals("P-INV")) && (rem.getProperty().equals((OWLObjectProperty) obj)) && (rem.getInverse().equals((OWLObjectProperty) subj))) {					deleted = oc;				}			}			else if(oc instanceof RemoveObjectPropertyRange) {				RemoveObjectPropertyRange rem = (RemoveObjectPropertyRange) oc;				if (subj instanceof OWLObjectProperty) {					if ((code.equals("C-HASRAN")) && (rem.getProperty().equals((OWLObjectProperty) subj)) && (rem.getRange().equals((OWLDescription) obj))) {						deleted = oc;					}				}				if (obj instanceof OWLObjectProperty) {					if ((code.equals("P-RAN")) && (rem.getProperty().equals((OWLObjectProperty) obj)) && (rem.getRange().equals((OWLDescription) subj))) {						deleted = oc;					}				}			}			else if(oc instanceof RemoveDataPropertyRange) {								if (subj instanceof OWLDataProperty && obj instanceof OWLDataRange) {					RemoveDataPropertyRange rem = (RemoveDataPropertyRange) oc;					if ((code.equals("C-HASRAN")) && (rem.getProperty().equals((OWLDataProperty) subj)) && (rem.getRange().equals((OWLDataRange) obj))) {						deleted = oc;					}				}			}			else if(oc instanceof RemovePropertyAxiom) {				RemovePropertyAxiom rem = (RemovePropertyAxiom) oc;				if (rem.getAxiom() instanceof OWLEquivalentPropertiesAxiom) {					OWLEquivalentPropertiesAxiom epAxiom = (OWLEquivalentPropertiesAxiom) rem.getAxiom();					if (code.equals("P-EQU")					&& epAxiom.getProperties().contains((OWLProperty) obj)					&& epAxiom.getProperties().contains((OWLProperty) subj)) {						deleted = oc;					}				}				else if (rem.getAxiom() instanceof OWLSubPropertyAxiom) {					OWLSubPropertyAxiom subPAxiom = (OWLSubPropertyAxiom) rem.getAxiom();					if (code.equals("P-SUB") 						&& subPAxiom.getSubProperty().equals((OWLProperty) subj) 						&& subPAxiom.getSuperProperty().equals((OWLProperty) obj)) {						deleted = oc;					}					else if (code.equals("P-SUP") 						&& subPAxiom.getSubProperty().equals((OWLProperty) obj) 						&& subPAxiom.getSuperProperty().equals((OWLProperty) subj)) {						deleted = oc;					}				}			}			else if(oc instanceof RemoveSuperProperty) {				RemoveSuperProperty rem = (RemoveSuperProperty) oc;				if (code.equals("P-SUB") 

⌨️ 快捷键说明

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