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

📄 ontoeval.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package toocom.ocgl;

import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;

/**
 * This class includes tools dedicated to the verification and the validation of ontology. 
 * Using instance of OntoEval allows to display a Progress Bar (see TooCoMProgressBar).
 *
 * @author Fr閐閞ic F黵st
 */
public class OntoEval{
	
	/** This method performs the following tests : 
	 *  - Each concept type must have a parent in the hierarchy, and it must be a child of the 
	 *  Universal concept type (the Universal concept type can not have a parent). 
	 *  - A concept type can not be parent of itself (no circularity). 
	 *  - A concept type can not have only one child. */
	public static OntoTestResult conceptTypeHierarchyVerification(Ontology onto,Language l){
		OntoTestResult result = new OntoTestResult(onto,l);
		for(Iterator i = onto.getConceptTypes().iterator();i.hasNext();){
			ConceptType ct = (ConceptType) i.next();
			if(!ct.equals(onto.getUniversalConceptType())){
				// Child of Universal concept type
				if(!OntoEval.circularityTest(new LinkedList(),onto.getUniversalConceptType(),ct))
					result.addResult(CGConstants.ERROR_IN + CGConstants.CONCEPT_TYPES_HIERARCHY + " : " + CGConstants.CONCEPT_TYPE + ct.getTerm(l) + CGConstants.NOT_CHILD_OF_UNIVERSAL);
				// No circularity
				if(OntoEval.circularityTest(new LinkedList(),ct,ct))
					result.addResult(CGConstants.ERROR_IN + CGConstants.CONCEPT_TYPES_HIERARCHY + " : " + CGConstants.CIRCULARITY_FROM + ct.getTerm(l) + CGConstants.TO + ct.getTerm(l));
				// Not two concept types with the same name
				for(Iterator j = onto.getHomonymousCT(ct,l).iterator();j.hasNext();){
					result.addResult(CGConstants.WARNING_IN + CGConstants.CONCEPT_TYPES_HIERARCHY + " : " + CGConstants.CONCEPT_TYPE + ct.getTerm(l) + CGConstants.HAS_HOMONYM + ((ConceptType) j.next()).getTerm(l));
				}
				// At least one child for an abstract type
				if(ct.hasAxiomSchema("toocom.ocgl.ConceptAbstraction")){
					if(ct.getChildren().size() == 0)
						result.addResult(CGConstants.WARNING_IN + CGConstants.CONCEPT_TYPES_HIERARCHY + " : " + CGConstants.ABSTRACT + CGConstants.CONCEPT_TYPE + ct.getTerm(l) + CGConstants.HAS_NO_CHILD);
				}
				// Not only one child
				if(ct.getChildren().size() == 1)
					result.addResult(CGConstants.WARNING_IN + CGConstants.CONCEPT_TYPES_HIERARCHY + " : " + CGConstants.CONCEPT_TYPE + ct.getTerm(l) + CGConstants.HAS_ONLY_ONE_CHILD);
				// Not common child of two disjoints concept types
				for(Iterator j = ct.getParents().iterator();j.hasNext();){
					ConceptType parent = (ConceptType) j.next();
					for(Iterator k = parent.getAxiomSchemata("toocom.ocgl.ConceptDisjunction").iterator();k.hasNext();){
						ConceptDisjunction disj = (ConceptDisjunction) k.next();
						if(ct.getParents().contains((ConceptType) disj.getTheOtherPrimitive(parent)))  result.addResult(CGConstants.ERROR_IN + CGConstants.CONCEPT_TYPES_HIERARCHY + " : " + CGConstants.CONCEPT_TYPE + ct.getTerm(l) + CGConstants.HAS_DISJOINT_PARENTS + parent.getTerm(l) + CGConstants.AND_TEST + disj.getTerm(l));
					}
				}
				// At least one child for a partition
				if(ct.hasAxiomSchema("toocom.ocgl.ConceptPartition")){
					if(ct.getChildren().size() == 0)
						result.addResult(CGConstants.WARNING_IN + CGConstants.CONCEPT_TYPES_HIERARCHY + " : " + CGConstants.PARTITION + CGConstants.CONCEPT_TYPE + ct.getTerm(l) + CGConstants.HAS_NO_CHILD);
				}
			}
		}
		return result;
	}
	
	/** This method performs the following tests : 
	 *  - An instance has always a type.
	 *  - An abstract concept type can have instance.
	 *  - Two instances with the same concept type can not have the same label. 
	 *  - Two instances with different disjoint concept types can not have the same label.
	 *  - Two instances with different non disjoint concept types can not have the same label. */
	public static OntoTestResult instancesVerification(Ontology onto,Language l){
		OntoTestResult result = new OntoTestResult(onto,l);
		for(Iterator i = onto.getIndividuals().iterator();i.hasNext();){
			Individual ind = (Individual) i.next();
			// Instance without type
			if(ind.getType() == null) result.addResult(CGConstants.ERROR_IN + CGConstants.INSTANCES + " : " + CGConstants.INSTANCE + "[" + ind.toString(l) + "]" + CGConstants.HAS_NO_TYPE);
			LinkedList indList = onto.getHomonymousIndividual(ind,l);
			for(Iterator j = indList.iterator();j.hasNext();){
				Individual indBis = (Individual) j.next();
				if(indBis != null){
					if((ind.getType() != null) && (indBis.getType() != null)){
						if(ind.getType().equals(indBis.getType()))
							// Not homonymous individuals in the same concept type
							result.addResult(CGConstants.ERROR_IN + CGConstants.INSTANCES + " : " + CGConstants.INSTANCE + "[" + ind.toString(l) + "]" + CGConstants.HAS_HOMONYM_WITH_SAME_TYPE + "[" + indBis.toString(l) + "]");
						else{
							// Not homonymous individuals in disjoint concept types
							boolean test = false;
							for(Iterator k = ind.getType().getAxiomSchemata("toocom.ocgl.ConceptDisjunction").iterator();k.hasNext();){
								ConceptDisjunction disj = (ConceptDisjunction) k.next();
								if(indBis.getType().equals((ConceptType) disj.getTheOtherPrimitive(ind.getType()))){
									result.addResult(CGConstants.ERROR_IN + CGConstants.INSTANCES + " : " + CGConstants.INSTANCE + "[" + ind.toString(l) + "]" + CGConstants.HAS_HOMONYM_WITH_DISJOINT_TYPE + "[" + indBis.toString(l) + "]");
									test = true;
								}
							}
							// Not two homonymous individuals
							if(!test) result.addResult(CGConstants.WARNING_IN + CGConstants.INSTANCES + " : " + CGConstants.INSTANCE + "[" + ind.toString(l) + "]" + CGConstants.HAS_HOMONYM + "[" + indBis.toString(l) + "]");
						}
					}
				}
			}
		}
		return result;
	}
	
	/** This method performs the following tests : 
	 *  - A relation type can not be parent of itself (no circularity)
	 *	- The signature of a relation type is coherent with those of its parent type 
	 *  - The signature of a reflexive relation type must be coherent with this property 
	 *  - The signatures of two symmetric relation types must be the same. */
	public static OntoTestResult relationTypeHierarchyVerification(Ontology onto,Language l){
		OntoTestResult result = new OntoTestResult(onto,l);
		for(Iterator i = onto.getRelationTypes().iterator();i.hasNext();){
			RelationType rt = (RelationType) i.next();
			// No circularity
			if(OntoEval.circularityTest(new LinkedList(),rt,rt))
				result.addResult(CGConstants.ERROR_IN + CGConstants.RELATION_TYPES_HIERARCHY + " : " + CGConstants.CIRCULARITY_FROM + rt.getTerm(l) + CGConstants.TO + rt.getTerm(l));
			// Not two relation types with the same name
			for(Iterator j = onto.getHomonymousRT(rt,l).iterator();j.hasNext();){
				result.addResult(CGConstants.WARNING_IN + CGConstants.RELATION_TYPES_HIERARCHY + " : " + CGConstants.RELATION_TYPE + rt.getTerm(l) + CGConstants.HAS_HOMONYM + ((RelationType) j.next()).getTerm(l));
			}
			// Signature must be specified
			boolean test = true;
			for(int index = 1;index <= rt.getArity();index ++){
				if(rt.getSignature().getConceptType(index) == null) test = false;
			}	
			if(test){
				// Signature coherent with those of the parents types
				for(Iterator j = rt.getParents().iterator();j.hasNext();){
					RelationType parent = (RelationType) j.next();
					if(!rt.getSignature().isA(parent.getSignature())) result.addResult(CGConstants.ERROR_IN + CGConstants.RELATION_TYPES_HIERARCHY + " : " + CGConstants.SIGNATURE_OF + CGConstants.RELATION_TYPE + rt.getTerm(l) + CGConstants.NOT_COHERENT_WITH_THOSE_OF_PARENT_TYPE + parent.getTerm(l));
				}
				// The signature of the relation type must be coherent with those of the incompatible
				// relation types 
				for(Iterator j = rt.getAxiomSchemata("toocom.ocgl.RelationIncompatibility").iterator();j.hasNext();){
					RelationIncompatibility incAxiom = (RelationIncompatibility) j.next();
					RelationType incomp = (RelationType) incAxiom.getTheOtherPrimitive(rt);
					if(!incomp.getSignature().equals(rt.getSignature()))
					result.addResult(CGConstants.ERROR_IN + CGConstants.RELATION_TYPES_HIERARCHY + " : " + CGConstants.SIGNATURES_OF + CGConstants.INCOMPATIBLE + CGConstants.RELATION_TYPES + rt.getTerm(l) + CGConstants.AND_TEST + incomp.getTerm(l) + CGConstants.ARE_NOT_THE_SAME);
				}
				// The signature of the relation type must be coherent with those of the exclusive
				// relation type
				for(Iterator j = rt.getAxiomSchemata("toocom.ocgl.RelationExclusivity").iterator();j.hasNext();){
					RelationExclusivity incAxiom = (RelationExclusivity) j.next();
					RelationType incomp = (RelationType) incAxiom.getTheOtherPrimitive(rt);
					if(!incomp.getSignature().equals(rt.getSignature()))
					result.addResult(CGConstants.ERROR_IN + CGConstants.RELATION_TYPES_HIERARCHY + " : " + CGConstants.SIGNATURES_OF + CGConstants.EXCLUSIVE + CGConstants.RELATION_TYPES + rt.getTerm(l) + CGConstants.AND_TEST + incomp.getTerm(l) + CGConstants.ARE_NOT_THE_SAME);
				}
			}
			else result.addResult(CGConstants.ERROR_IN + CGConstants.RELATION_TYPES_HIERARCHY + " : " + CGConstants.SIGNATURE_OF + CGConstants.RELATION_TYPE + rt.getTerm(l) + CGConstants.IS_NOT_COMPLETE);
		}
		return result;
	}
	
	/** This method performs the following tests :  
	 *  - Each concept and relation must have a type.
	 *  - In each axiom, each relation must be linked to so many concepts with appropriate types than its arity.
	 *  - There must be no redundancy of concept or relation in an axiom. 
	 *  - Any incompatible or exclusive relation can link the same concepts.  
	 *  - Difference relation can not link the same concept.
	 *  - Each hypothesis relation must link only hypothesis concepts.
	 *  - Hypothesis and conclusion of each axiom must respect all constraints induced by the 
	 *  other axioms.*/
	public static OntoTestResult axiomsVerification(Ontology onto,Language l,CogitantClient client){
		OntoTestResult result = new OntoTestResult(onto,l);
		for(Iterator i = onto.getAxioms().iterator();i.hasNext();){
			Axiom a = (Axiom) i.next();
			// The axiom must produce knowledge, ie it must have at least one node in its conclusion part

⌨️ 快捷键说明

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