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

📄 conceptualimplication.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	public boolean hasHypothesisConcept(Concept c){
		return (hypothesisConcepts.indexOf(c) != -1);
	}
	
	/** Returns true if the concept is explicitly specified as conclusion concept or if it
	 *  is linked to a relation specified as conclusion relation. */
	public boolean hasConclusionConcept(Concept c){
		if(conclusionConcepts.indexOf(c) != -1){
			return true;
		}
		else{
			if(hypothesisConcepts.indexOf(c) != -1){
				for(Iterator i = conclusionRelations.iterator();i.hasNext();){
					if(((Relation) i.next()).hasLinkedConcept(c)) return true;
				}
				return false;
			}
			else return false;
		}
	}
	
	/** Returns true if the concept is explicitly specified as conclusion concept. */
	public boolean hasPureConclusionConcept(Concept c){
		return (conclusionConcepts.indexOf(c) != -1);
	}
	
	/** Returns true if the concept is in the hypothesis part of the axiom and linked to a relation
	 *  of the conclusion part of the axiom. */
	public boolean hasHypothesisConclusionConcept(Concept c){
		return (this.hasConclusionConcept(c) && (hypothesisConcepts.indexOf(c) != -1));
	}
	
	/** Returns true if the axiom contains the given relation in its hypothesis part. */
	public boolean hasHypothesisRelation(Relation r){
		return (hypothesisRelations.indexOf(r) != -1);
	}
	
	/** Returns true if the axiom contains the given relation in its conclusion part. */
	public boolean hasConclusionRelation(Relation r){
		return (conclusionRelations.indexOf(r) != -1);
	}
	
	/** Add the given concept to the hypothesis of the axiom if it does not already appears 
	 *  in the list and returns true, returns false otherwise. Returns false if the axiom is 
	 *  finalized and can not be modified. */
	public boolean addHypothesisConcept(Concept c){
		if(!this.hypothesisConcepts.contains(c)){
			this.hypothesisConcepts.add(c);
			return true;
		}
		else return false;
	}
	
	/** Add the given concept to the conclusion of the axiom if it does not already appears 
	 *  in the list and returns true, returns false otherwise. Returns false if the axiom is 
	 *  finalized and can not be modified. */
	public boolean addConclusionConcept(Concept c){
		if(!this.conclusionConcepts.contains(c)){
			this.conclusionConcepts.add(c);
			return true;
		}
		else return false;
	}
	
	/** Put the concept c in the hypothesis part of the axiom if it was in the conclusion part. */
	public void convertInHypothesis(Concept c){
		if(this.conclusionConcepts.remove(c)) this.hypothesisConcepts.add(c);
	}
	
	/** Put the concept c in the conclusion part of the axiom if it was in the hypothesis part. */
	public void convertInConclusion(Concept c){
		if(this.hypothesisConcepts.remove(c)) this.conclusionConcepts.add(c);
	}
	
	/** Add the given relation to the hypothesis of the axiom if it does not already appears 
	 *  in the list and returns true, returns false otherwise. Returns false if the axiom is 
	 *  finalized and can not be modified. */
	public boolean addHypothesisRelation(Relation r){
		if(!this.hypothesisRelations.contains(r)){
			this.hypothesisRelations.add(r);
			return true;
		}
		else return false;
	}
	
	/** Add the given relation to the conclusion of the axiom if it does not already appears 
	 *  in the list and returns true, returns false otherwise. Returns false if the axiom is 
	 *  finalized and can not be modified. */
	public boolean addConclusionRelation(Relation r){
		if(!this.conclusionRelations.contains(r)){
			this.conclusionRelations.add(r);
			return true;
		}
		else return false;
	}
	
	/** Remove the given concept and returns true if the concept is in the list, returns false
	  * otherwise. */
	public boolean removeConcept(Concept c){
		boolean result = (this.hypothesisConcepts.remove(c) || this.conclusionConcepts.remove(c));
		if(result){
			for(Iterator i = this.hypothesisRelations.iterator();i.hasNext();){
				((Relation) i.next()).removeLinkedConcept(c);
			}
			for(Iterator i = this.conclusionRelations.iterator();i.hasNext();){
				((Relation) i.next()).removeLinkedConcept(c);
			}
		}
		return result;
	}
	
	/** Remove the given relation and returns true if the relation is in the list, returns false
	  * otherwise. */
	public boolean removeRelation(Relation r){
		return (this.hypothesisRelations.remove(r) || this.conclusionRelations.remove(r));
	}
	
	/** Remove the given object and returns true if the object is in the list, returns false
	  * otherwise. */
	public boolean removeObject(NamedGraphicalObject no){
		if(no instanceof Concept) return this.removeConcept((Concept) no); 
		if(no instanceof Relation) return this.removeRelation((Relation) no);
		return false;
	}
	
	/** Returns all the concepts which are not generic (ie with an individual marker different
	 *  from *. */
	public LinkedList getNonGenericConcepts(){
		LinkedList result = new LinkedList();
		for(Iterator i = hypothesisConcepts.iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(!c.isGenericConcept()) result. add(c);
		}
		for(Iterator i = conclusionConcepts.iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(!c.isGenericConcept()) result. add(c);
		}
		return result;
	}
	
	/** Returns the other concept if the implication contains another concept like c (same type and same individual), $
	 *  null otherwise. */
	public Concept containsAnotherConceptLike(Concept c){
		for(Iterator i = this.getAllConcepts().iterator();i.hasNext();){
			Concept con = (Concept) i.next();
			if((!con.equals(c)) && (con.getType() != null) && (c.getType() != null) && con.getType().equals(c.getType()) &&
			  (((con.getIndividual() == null) && (c.getIndividual() == null)) || 
			  ((con.getIndividual() != null) && (c.getIndividual() != null) && (c.getIndividual().equals(con.getIndividual()))))) return con;
		}
		return null;
	}
	
	/** Returns the different relation if it exists between c1 and c2, null otherwise. */
	public Relation containsDifferentRelationBetween(Concept c1,Concept c2, Ontology onto){
		for(Iterator i = this.getAllRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			if((r.getType() != null) && (r.getType().equals(onto.getDifferenceRelationType())) &&
			  r.hasLinkedConcept(c1) && r.hasLinkedConcept(c2)) return r;
		}
		return null;
	}
	
	/** Returns one of the relation of the implication incompatible (or exclusive) with r, if it exists, null otherwise. */
	public Relation getIncompatibleRelation(Relation r){
		RelationExclusivity exclu = (RelationExclusivity) r.getType().getAxiomSchemata("toocom.ocgl.RelationExclusivity").getFirst();
		LinkedList incomp = r.getType().getAxiomSchemata("toocom.ocgl.RelationIncompatibility");
		for(Iterator i = this.getAllRelations().iterator();i.hasNext();){
			Relation rbis = (Relation) i.next();
			if((exclu != null) && (exclu.getTheOtherPrimitive(r.getType()).equals(rbis.getType()))) return rbis;
			else{
				for(Iterator j = incomp.iterator();j.hasNext();){
					RelationIncompatibility relin = (RelationIncompatibility) j.next();
					if(relin.getTheOtherPrimitive(r.getType()).equals(rbis.getType())) return rbis;
				}
			}
		}
		return null;
	}
	
	public void destroy(Ontology onto){}
	
	public ConceptualImplication cloneConceptualImplication(){
		Hashtable conLinks = new Hashtable();
		Hashtable conRel = new Hashtable();
		ConceptualImplication result = new ConceptualImplication(this.getTerms());
		for(Iterator i = this.getHypothesisConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			Concept cBis = c.cloneConcept();
			result.addHypothesisConcept(cBis);
			conLinks.put(c,cBis);
		}
		for(Iterator i = this.getPureConclusionConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			Concept cBis = c.cloneConcept();
			result.addConclusionConcept(cBis);
			conLinks.put(c,cBis);
		}
		for(Iterator i = this.getHypothesisRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			Relation rBis = r.cloneRelation();
			result.addHypothesisRelation(rBis);
			for(int index = 1;index <= rBis.getType().getArity();index ++){
				Concept cTemp = r.getLinkedConcept(index);
				if(cTemp != null){
					rBis.setLinkedConcept((Concept) conLinks.get(cTemp),index);
				}
			}	
		}
		for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			Relation rBis = r.cloneRelation();
			result.addConclusionRelation(rBis);
			for(int index = 1;index <= rBis.getType().getArity();index ++){
				Concept cTemp = r.getLinkedConcept(index);
				if(cTemp != null){
					rBis.setLinkedConcept((Concept) conLinks.get(cTemp),index);
				}
			}	
		}
		return result;
	}
			
	/** Returns the bounds of the image according to the font size of the given Graphics. */
	public RectangularShape getBounds(Graphics g,Language l){
		int xmin = -1;
		int xmax = -1;
		int ymin = -1;
		int ymax = -1;
		for(Iterator i = this.getAllConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(xmin == -1) xmin = (int) c.getBounds(g,l).getX();
			else xmin = Math.min(xmin,(int) c.getBounds(g,l).getX());
			if(xmax == -1) xmax = (int) (c.getBounds(g,l).getX() + c.getBounds(g,l).getWidth());
			else xmax = Math.max(xmax,(int) (c.getBounds(g,l).getX() + c.getBounds(g,l).getWidth()));
			if(ymin == -1) ymin = (int) c.getBounds(g,l).getY();
			else ymin = Math.min(ymin,(int) c.getBounds(g,l).getY());
			if(ymax == -1) ymax = (int) (c.getBounds(g,l).getY() + c.getBounds(g,l).getHeight());
			else ymax = Math.max(ymax,(int) (c.getBounds(g,l).getY() + c.getBounds(g,l).getHeight()));
		}
		for(Iterator i = this.getAllRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			if(xmin == -1) xmin = (int) r.getBounds(g,l).getX();
			else xmin = Math.min(xmin,(int) r.getBounds(g,l).getX());
			if(xmax == -1) xmax = (int) (r.getBounds(g,l).getX() + r.getBounds(g,l).getWidth());
			else xmax = Math.max(xmax,(int) (r.getBounds(g,l).getX() + r.getBounds(g,l).getWidth()));
			if(ymin == -1) ymin = (int) r.getBounds(g,l).getY();
			else ymin = Math.min(ymin,(int) r.getBounds(g,l).getY());
			if(ymax == -1) ymax = (int) (r.getBounds(g,l).getY() + r.getBounds(g,l).getHeight());
			else ymax = Math.max(ymax,(int) (r.getBounds(g,l).getY() + r.getBounds(g,l).getHeight()));
		}
		return new Rectangle(xmin,ymin,xmax - xmin,ymax - ymin);
	}
	
	/** Paint the implication. */
	public void paintObject(Graphics g,Language l){
		for(Iterator i = this.getHypothesisRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			r.paintLinks(g,l);
		}
		for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			r.paintLinks(g,l);
		}
		for(Iterator i = this.getHypothesisRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			r.paintObject(g,l);
		}
		for(Iterator i = this.getHypothesisConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			c.paintObject(g,l);
		}
		for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			r.paintObjectAsConclusion(g,l);
		}
		for(Iterator i = this.getConclusionConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(this.hasHypothesisConclusionConcept(c)) c.paintObject(g,l);
			else c.paintObjectAsConclusion(g,l);
		}
	}
	
}

⌨️ 快捷键说明

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