owlontbuilder.java

来自「Semantic Web Ontology Editor」· Java 代码 · 共 733 行 · 第 1/3 页

JAVA
733
字号
				alignEP.add(this.visitObjectProperty((OWLObjectProperty) prop));
		}
		OWLPropertyAxiom currentObject = currentDF.getOWLEquivalentPropertiesAxiom(alignEP);
		OntologyChange apx = null;
		if (addAxiom)
			apx = new AddPropertyAxiom(currentOnt, (OWLPropertyAxiom) currentObject, null);
		else 
			apx = new RemovePropertyAxiom(currentOnt, (OWLPropertyAxiom) currentObject, null);
		apx.accept((ChangeVisitor) currentOnt);
		this.changes.add(apx);
	}

	public void visit( OWLSubPropertyAxiom axiom ) throws OWLException {
		OWLProperty sub, sup;
		if (axiom.getSubProperty() instanceof OWLDataProperty) { 
			sub = this.visitDataProperty((OWLDataProperty) axiom.getSubProperty()); 
		}
		else {
			sub = this.visitObjectProperty((OWLObjectProperty) axiom.getSubProperty());
		}
		
		if (axiom.getSuperProperty() instanceof OWLDataProperty) {
			sup = this.visitDataProperty((OWLDataProperty) axiom.getSuperProperty()); 
		}
		else {
			sup = this.visitObjectProperty((OWLObjectProperty) axiom.getSuperProperty());
		}
		
		OWLPropertyAxiom currentObject = currentDF.getOWLSubPropertyAxiom(sub, sup);
		OntologyChange apx = null;
		if (addAxiom)
			apx = new AddPropertyAxiom(currentOnt, (OWLPropertyAxiom) currentObject, null);
		else 
			apx = new RemovePropertyAxiom(currentOnt, (OWLPropertyAxiom) currentObject, null);
		apx.accept((ChangeVisitor) currentOnt);
		this.changes.add(apx);
	}

	public void visit( OWLDifferentIndividualsAxiom ax) throws OWLException {
		Set alignDI = new HashSet();
		for ( Iterator it = ax.getIndividuals().iterator();
		it.hasNext(); ) {
			OWLIndividual desc = (OWLIndividual) it.next();
			alignDI.add(this.visitIndividual(desc));
		}
		OWLIndividualAxiom currentObject = currentDF.getOWLDifferentIndividualsAxiom(alignDI);
		OntologyChange aix = null;
		if (addAxiom)
			aix = new AddIndividualAxiom(currentOnt, (OWLIndividualAxiom) currentObject, null);
		else 
			aix = new RemoveIndividualAxiom(currentOnt, (OWLIndividualAxiom) currentObject, null);
		aix.accept((ChangeVisitor) currentOnt);
		this.changes.add(aix);
	}

	public void visit( OWLSameIndividualsAxiom ax) throws OWLException {
		Set alignDI = new HashSet();
		for ( Iterator it = ax.getIndividuals().iterator();
		it.hasNext(); ) {
			OWLIndividual desc = (OWLIndividual) it.next();
			alignDI.add(this.visitIndividual(desc));
		}
		OWLIndividualAxiom currentObject = currentDF.getOWLSameIndividualsAxiom(alignDI);
		OntologyChange aix = null;
		if (addAxiom)
			aix = new AddIndividualAxiom(currentOnt, (OWLIndividualAxiom) currentObject, null);
		else 
			aix = new RemoveIndividualAxiom(currentOnt, (OWLIndividualAxiom) currentObject, null);
		aix.accept((ChangeVisitor) currentOnt);
		this.changes.add(aix);
	}

	public OWLDataType visitDataType( OWLDataType ocdt ) throws OWLException {
		return currentDF.getOWLConcreteDataType(ocdt.getURI());
	}

	public void visit( OWLDataEnumeration enumeration ) throws OWLException {
		for ( Iterator it = enumeration.getValues().iterator();
		it.hasNext(); ) {
			OWLDataValue desc = (OWLDataValue) it.next();
			desc.accept( this );		
		}
	}
	
//	Uncomment for explanation
	
	public void visit( OWLFunctionalPropertyAxiom axiom ) throws OWLException {
		OWLProperty prop = null;
		if (axiom.getProperty() instanceof OWLDataProperty) 
			prop = this.visitDataProperty(((OWLDataProperty) axiom.getProperty()));
		else
			prop = this.visitObjectProperty(((OWLObjectProperty) axiom.getProperty()));
		// apply set functional change
		SetFunctional sf = new SetFunctional(currentOnt, prop, true, null);
		sf.accept((ChangeVisitor) currentOnt);
		this.changes.add(sf);
	}
	
	public void visit( OWLPropertyDomainAxiom axiom ) throws OWLException {
		OWLProperty prop = null;
		if (axiom.getProperty() instanceof OWLDataProperty) 
			prop = this.visitDataProperty(((OWLDataProperty) axiom.getProperty()));
		else
			prop = this.visitObjectProperty(((OWLObjectProperty) axiom.getProperty()));
		
		OWLDescription domain = this.visitDescription(axiom.getDomain());
		OntologyChange ad = null;
		if (addAxiom)
			ad = new AddDomain(currentOnt, prop, domain, null);
		else 
			ad = new RemoveDomain(currentOnt, prop, domain, null);
		ad.accept((ChangeVisitor) currentOnt);
		this.changes.add(ad);
	}
	
	public void visit( OWLObjectPropertyRangeAxiom axiom ) throws OWLException {
		OWLObjectProperty prop = this.visitObjectProperty(axiom.getProperty()); 
		OWLDescription range = this.visitDescription(axiom.getRange());
		OntologyChange ad = null;
		if (addAxiom)
			ad = new AddObjectPropertyRange(currentOnt, prop, range, null);
		else 
			ad = new RemoveObjectPropertyRange(currentOnt, prop, range, null);
		ad.accept((ChangeVisitor) currentOnt);
		this.changes.add(ad);
	}
	
	public void visit( OWLDataPropertyRangeAxiom axiom ) throws OWLException {
		OWLDataProperty prop = this.visitDataProperty(axiom.getProperty()); 
		OWLDataType range = this.visitDataType((OWLDataType) axiom.getRange());
		OntologyChange ad = null;
		if (addAxiom)
			ad = new AddDataPropertyRange(currentOnt, prop, range, null);
		else 
			ad = new RemoveDataPropertyRange(currentOnt, prop, range, null);
		ad.accept((ChangeVisitor) currentOnt);
		this.changes.add(ad);
	}
	
	/* (non-Javadoc)
	* @see org.mindswap.pellet.owlapi.OWLExtendedObjectVisitor#visit(org.mindswap.pellet.owlapi.OWLInverseFunctionalPropertyAxiom)
	*/
	public void visit(OWLInverseFunctionalPropertyAxiom axiom) throws OWLException {
		if (axiom instanceof OWLInversePropertyAxiomImpl) {
			visit((OWLInversePropertyAxiomImpl) axiom);
			return;
		}
		SetInverseFunctional sif = new SetInverseFunctional(currentOnt, this.visitObjectProperty(axiom.getProperty()), addAxiom, null);
		sif.accept((ChangeVisitor) currentOnt);
		this.changes.add(sif);
	}
	
	/* (non-Javadoc)
	* @see org.mindswap.pellet.owlapi.OWLExtendedObjectVisitor#visit(org.mindswap.pellet.owlapi.OWLTransitivePropertyAxiom)
	*/
	public void visit(OWLTransitivePropertyAxiom axiom) throws OWLException {
		SetTransitive st = new SetTransitive(currentOnt, this.visitObjectProperty((OWLObjectProperty) axiom.getProperty()), addAxiom, null);
		st.accept((ChangeVisitor) currentOnt);
		this.changes.add(st);
	}
	
	/* (non-Javadoc)
	* @see org.mindswap.pellet.owlapi.OWLExtendedObjectVisitor#visit(org.mindswap.pellet.owlapi.OWLSymmetricPropertyAxiom)
	*/
	public void visit(OWLSymmetricPropertyAxiom axiom) throws OWLException {
		SetSymmetric ss = new SetSymmetric(currentOnt, this.visitObjectProperty(axiom.getProperty()), addAxiom, null);
		ss.accept((ChangeVisitor) currentOnt);
		this.changes.add(ss);
	}
	
	/* (non-Javadoc)
	* @see org.mindswap.pellet.owlapi.OWLExtendedObjectVisitor#visit(org.mindswap.pellet.owlapi.OWLInversePropertyAxiom)
	*/
	public void visit(OWLInversePropertyAxiomImpl axiom) throws OWLException {
		OWLObjectProperty prop = this.visitObjectProperty(axiom.getProperty());
		OWLObjectProperty inv = this.visitObjectProperty(axiom.getInverseProperty());
		OntologyChange ai = null;
		if (addAxiom) {
			ai = new AddInverse(currentOnt, prop, inv, null);
			ai.accept((ChangeVisitor) currentOnt);
		}
		else {
			ai = new RemoveInverse(currentOnt, prop, inv, null);
			ai.accept((ChangeVisitor) currentOnt);
			ai = new RemoveInverse(currentOnt, inv, prop, null);
			ai.accept((ChangeVisitor) currentOnt);
		}
		this.changes.add(ai);
	}
	
	/* (non-Javadoc)
	* @see org.mindswap.pellet.owlapi.OWLExtendedObjectVisitor#visit(org.mindswap.pellet.owlapi.OWLObjectPropertyInstance)
	*/
	public void visit(OWLObjectPropertyInstance axiom) throws OWLException {
		OWLIndividual subj = this.visitIndividual(axiom.getSubject());
		OWLObjectProperty prop = this.visitObjectProperty(axiom.getProperty());
		OWLIndividual obj = this.visitIndividual(axiom.getObject());
		OntologyChange aopi = null;
		if (addAxiom)
			aopi = new AddObjectPropertyInstance(currentOnt, subj, prop, obj, null);
		else 
			aopi = new RemoveObjectPropertyInstance(currentOnt, subj, prop, obj, null);
		aopi.accept((ChangeVisitor) currentOnt);
		this.changes.add(aopi);
	}
	
	/* (non-Javadoc)
	* @see org.mindswap.pellet.owlapi.OWLExtendedObjectVisitor#visit(org.mindswap.pellet.owlapi.OWLDataPropertyInstance)
	*/
	public void visit(OWLDataPropertyInstance axiom) throws OWLException {
		OWLIndividual subj = this.visitIndividual(axiom.getSubject());
		OWLDataProperty prop = this.visitDataProperty(axiom.getProperty());
		OWLDataValue obj = axiom.getObject();
		OntologyChange adpi = null;
		if (addAxiom)
			adpi = new AddDataPropertyInstance(currentOnt, subj, prop, obj, null);
		else 
			adpi = new RemoveDataPropertyInstance(currentOnt, subj, prop, obj, null);
		adpi.accept((ChangeVisitor) currentOnt);
		this.changes.add(adpi);
	}
	
	public void visit(OWLIndividualTypeAssertion axiom) throws OWLException {
			OWLIndividual ind = this.visitIndividual(axiom.getIndividual());
			OWLDescription currentDesc = this.visitDescription(axiom.getType());
			OntologyChange aic = null;
			if (addAxiom)
				aic = new AddIndividualClass(currentOnt, ind, currentDesc, null);
			else 
				aic = new RemoveIndividualClass(currentOnt, ind, currentDesc, null);
			aic.accept((ChangeVisitor) currentOnt);
			this.changes.add(aic);
	}
	
	public void visit(OWLInversePropertyAxiom arg0) throws OWLException {
		visit((OWLInversePropertyAxiomImpl) arg0);
	}
	
	public void reset() {		
	}

}

⌨️ 快捷键说明

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