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

📄 ontoeval.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if(a.getConclusionPart().isEmpty())
				result.addResult(CGConstants.WARNING_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.NO_CONCLUSION);			
			for(Iterator j = a.getAllConcepts().iterator();j.hasNext();){
				Concept c = (Concept) j.next();
				// All concepts must have a type
				if(c.getType() == null) result.addResult(CGConstants.ERROR_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.CONCEPT + "[" + c.toString(l) + "]" + CGConstants.HAS_NO_TYPE);
				// No redundancy of concept in an axiom (concepts with same type and same individual different 
				// from * or concepts with same type and * and no different relation between them)
				Concept tempCon = a.containsAnotherConceptLike(c);
				if(tempCon != null){
					if(c.getIndividual() != null) result.addResult(CGConstants.WARNING_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.TWO + CGConstants.CONCEPTS + "[" + c.toString(l) + "]" + CGConstants.EXIST);
					else{
						if(a.containsDifferentRelationBetween(c,tempCon,onto) == null) result.addResult(CGConstants.WARNING_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.TWO + CGConstants.CONCEPTS + "[" + c.toString(l) + "]" + CGConstants.EXIST + CGConstants.WITHOUT_DIFFERENCE_RELATION_BETWEEN_THEM);
					}
				}
			}
			// Test of relations
			for(Iterator j = a.getAllRelations().iterator();j.hasNext();){
				Relation r = (Relation) j.next();
				// All relations must have a type
				if(r.getType() == null) result.addResult(CGConstants.ERROR_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.HAS_NO_TYPE);
				else{
					// All relations must be linked to as many concepts as its arity, 
					// concepts with types corresponding to the signature of the type of the relation
					for(int k = 1;k <= r.getType().getArity();k ++){
						Concept c = r.getLinkedConcept(k);
						if(c == null) result.addResult(CGConstants.ERROR_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.NOT_LINKED_TO + CGConstants.CONCEPT + k);
						else{
							if((c.getType() != null) && !c.getType().isA(r.getType().getSignature().getConceptType(k)))
							result.addResult(CGConstants.ERROR_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.TYPE_OF_CONCEPT + "[" + c.toString(l) + "]" + CGConstants.IS_NOT_COMPATIBLE_WITH_THE_LINKED_RELATION + "(" + r.getTerm(l) + ")");
						}
					}
					// Any incompatible or exclusive relations can not exist in an axiom
					Relation ex = a.getIncompatibleRelation(r);
					if((ex != null) && r.linksSameConcepts(ex)) result.addResult(CGConstants.WARNING_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.INCOMPATIBLE_WITH + CGConstants.RELATION + "(" + ex.getTerm(l) + ")" );
					// Difference relation can not link a concept and the same concept
					if(r.getType().equals(onto.getDifferenceRelationType()) && (r.getLinkedConcept(1) != null) && 
					  (r.getLinkedConcept(2) != null) && r.getLinkedConcept(1).equals(r.getLinkedConcept(2))) 
					  result.addResult(CGConstants.WARNING_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.LINKS_A_CONCEPT_TO_ITSELF);
				}
			}
			// All relations in hypothesis must be linked to concepts that belong to hypothesis
			for(Iterator j = a.getHypothesisRelations().iterator();j.hasNext();){
				Relation r = (Relation) j.next();
				for(Iterator k = r.getLinkedConcepts().iterator();k.hasNext();){
					Concept c = (Concept) k.next();
					if((c != null) && !a.hasHypothesisConcept(c)) result.addResult(CGConstants.ERROR_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.HYPOTHESIS + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.LINKED_TO + CGConstants.CONCLUSION + CGConstants.CONCEPT + "[" + c.toString(l) + "]");
				}
			}
			// Coherence between axioms
			try{
				client.createServerSupport(onto,l);
				for(Iterator j = onto.getAxioms().iterator();j.hasNext();){
					Axiom axiom = (Axiom) j.next();
					if(!axiom.equals(a)){
						for(Iterator k = axiom.getInducedConstraints(l).iterator();k.hasNext();){
							Constraint cons = (Constraint) k.next();
							// The hypothesis must respect all constraints induced by the other axioms, otherwise 
							// the axiom can not be applied
							if(cons.getConstraintProjections(a.getHypothesisPart(),client,onto,l).size() != 0)
						 	result.addResult(CGConstants.WARNING_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.AXIOM + CGConstants.HYPOTHESIS + CGConstants.BREAKS + CGConstants.AXIOM + axiom.getTerm(l));
						 	// The conclusion must respect all constraints induced by the other axioms, otherwise
							// the axiom produce an inconsistency
							if(cons.getConstraintProjections(a.getConclusionPart(),client,onto,l).size() != 0)
						 	result.addResult(CGConstants.WARNING_IN + CGConstants.AXIOM + a.getTerm(l) + " : " + CGConstants.AXIOM + CGConstants.CONCLUSION + CGConstants.BREAKS + CGConstants.AXIOM + axiom.getTerm(l));							
						}						
					}
				}
			}
			catch(Exception e){
				System.out.println(e.getMessage());
			}
		}
		return result;
	}
	
	/** Returns true if a chain of axioms from a to b exist in the axiom set of the ontology, 
	 *  with at most level axioms in the chain. */
	/*private boolean axiomCircularity(Ontology onto,Language l,CogitantClient client,Axiom a, Axiom b, int level){
		
	}*/
	
	/** This method performs the tests of concept types hierarchy, relation types hierarchy and axioms. */
	public static OntoTestResult ontologyVerification(Ontology onto,Language l,CogitantClient client){
		OntoTestResult otr1 = OntoEval.conceptTypeHierarchyVerification(onto,l);
		OntoTestResult otr2 = OntoEval.relationTypeHierarchyVerification(onto,l);
		OntoTestResult otr3 = OntoEval.axiomsVerification(onto,l,client);
		otr1.addResults(otr2);
		otr1.addResults(otr3);
		return otr1;
	}
	
	/** This method returns true if cp1 is a direct or indirect parent of cp2 in the hierarchy,
	 *  false otherwise. The LinkedList must be empty at the beginning of the test. */
	private static boolean circularityTest(LinkedList encounteredCP, ConceptualPrimitive cp1, ConceptualPrimitive cp2){
		for(Iterator i = cp2.getParents().iterator();i.hasNext();){
			ConceptualPrimitive parent = (ConceptualPrimitive) i.next();
			if(parent.equals(cp1)) return true;
			if(!encounteredCP.contains(parent)){
				LinkedList next = (LinkedList) encounteredCP.clone();
				next.add(parent);
				if(OntoEval.circularityTest(next,cp1,parent)) return true;
			}
		}
		return false;
	}
	
	/** Returns the results of following tests on the graph : 
	 *  - Each concept and relation must have a type.
	 *  - A non generic concept can have an abstract type except if it is an ontological instance.
	 *  - 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.*/	
	public static OntoTestResult graphVerification(Graph g,Ontology onto,Language l){
		OntoTestResult result = new OntoTestResult(onto,l);
		// Test of concepts
		for(Iterator j = g.getConcepts().iterator();j.hasNext();){
			Concept c = (Concept) j.next();
			// All concepts must have a type
			if(c.getType() == null) result.addResult(CGConstants.ERROR_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.CONCEPT + "[" + c.toString(l) + "]" + CGConstants.HAS_NO_TYPE);
			// A non generic concept that is not an ontological individual must be of a non abstract type
			if((c.getType() != null) && (c.getType().hasAxiomSchema("toocom.ocgl.ConceptAbstraction")) && (c.getIndividual() == null)
			  && (!c.getTerm(l).equals(""))) result.addResult(CGConstants.ERROR_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.NON_GENERIC_CONCEPT + "[" + c.toString(l) + "]" + CGConstants.HAS_ABSTRACT_TYPE);
			// No redundancy of concept in a graph (concepts with same type and same individual different 
			// from * or concepts with same type and * and no different relation between them)
			Concept tempCon = g.containsAnotherConceptLike(c);
			if(tempCon != null){
				if(c.getIndividual() != null) result.addResult(CGConstants.WARNING_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.TWO + CGConstants.CONCEPTS + "[" + c.toString(l) + "]" + CGConstants.EXIST);
				else{
					if(g.containsDifferentRelationBetween(c,tempCon,onto) == null) result.addResult(CGConstants.WARNING_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.TWO + CGConstants.CONCEPTS + "[" + c.toString(l) + "]" + CGConstants.EXIST + CGConstants.WITHOUT_DIFFERENCE_RELATION_BETWEEN_THEM);
				}
			}
		}
		// Test of relations
		for(Iterator j = g.getRelations().iterator();j.hasNext();){
			Relation r = (Relation) j.next();
			// All relations must have a type
			if(r.getType() == null) result.addResult(CGConstants.ERROR_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.HAS_NO_TYPE);
			else{
				// All relations must be linked to as many concepts as its arity, 
				// concepts with types corresponding to the signature of the type of the relation
				for(int k = 1;k <= r.getType().getArity();k ++){
					Concept c = r.getLinkedConcept(k);
					if(c == null) result.addResult(CGConstants.ERROR_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.NOT_LINKED_TO + CGConstants.CONCEPT + k);
					else{
						if((c.getType() != null) && !c.getType().isA(r.getType().getSignature().getConceptType(k)))
						result.addResult(CGConstants.ERROR_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.TYPE_OF_CONCEPT + "[" + c.toString(l) + "]" + CGConstants.IS_NOT_COMPATIBLE_WITH_THE_LINKED_RELATION + "(" + r.getTerm(l) + ")");
					}
				}
				// Any incompatible or exclusive relations can not exist in an axiom
				Relation ex = g.getIncompatibleRelation(r);
				if((ex != null) && r.linksSameConcepts(ex)) result.addResult(CGConstants.WARNING_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.INCOMPATIBLE_WITH + CGConstants.RELATION + "(" + ex.getTerm(l) + ")" );
				// Difference relation can not link a concept and the same concept
				if(r.getType().equals(onto.getDifferenceRelationType()) && (r.getLinkedConcept(1) != null) && 
				  (r.getLinkedConcept(2) != null) && r.getLinkedConcept(1).equals(r.getLinkedConcept(2))) 
				  result.addResult(CGConstants.WARNING_IN + CGConstants.GRAPH + g.getTerm(l) + " : " + CGConstants.RELATION + "(" + r.getTerm(l) + ")" + CGConstants.LINKS_A_CONCEPT_TO_ITSELF);
			}
		}
		return result;
	}
	
}

⌨️ 快捷键说明

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