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

📄 concept.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
字号:
package toocom.ocgl;

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.font.*;

/**
 * This class represents the concepts in the ontology. In an axiom, a concept can be painted 
 * as hypothesis concept or conclusion concept. A concept can be an ontological instance 
 * (then the getIndividual() method returns a non null Individual) or a non ontological
 * instance (then the getIndividual() method returns null but the getTerms() method returns
 * terms that are not equals to "".
 *
 * @author Fr閐閞ic F黵st
 */
public class Concept extends Node{

	private ConceptType type;
	private Individual i;
	
	/** Creates a generic Concept object. */
	public Concept(){
		super(Terms.getGenericConceptTerms());
	}
	
	public Concept(int x, int y){
		super(Terms.getGenericConceptTerms(),x,y);
	}
	
	/** Creates the Concept object with the given concept type and the given individual.*/
	public Concept(Individual i, ConceptType ct){
		super(i.getTerms());
		this.i = i;
		this.type = ct;
	}
	
	/** Creates the generic Concept object with the given concept type. */
	public Concept(ConceptType ct){
		super(Terms.getGenericConceptTerms());
		this.type = ct;
	}
	
	/** Returns a concept with an undefined type and a generic marker. */
	public static Concept getUndefinedConcept(){
		return new Concept(null);
		//return new Concept(ConceptType.getUndefinedConceptType());
	}
	
	/** Returns true if the concept is generic, that is without specific term to identify it. */
	public boolean isGenericConcept(){
		return ((this.getTerms() == null) || this.getTerms().equals(Terms.getGenericConceptTerms()) 
		|| (this.getIndividual() == null));
	}
	
	public Individual getIndividual(){
		return i;
	}
	
	/** Set the identity of the concept. If i == null, the concept is set as a generic
	 *  concept. */
	public void setIndividual(Individual i){
		if(i != null){
			this.setTerms(i.getTerms());
			if(i.getType() != null) this.setType(i.getType());
		}
		else this.setTerms(Terms.getGenericConceptTerms());
		this.i = i;
	}
	
	public void setType(ConceptType type){
		if((this.type != null) && !this.type.equals(type)) this.setIndividual(null);
		if(type == null) this.setIndividual(null);
		this.type = type;
	}
	
	public ConceptType getType(){
		return type;
	}
	
	/** Returns a Concept with the same properties than this Concept but with an other id. The
	 *  new concept is not linked to any relation. */
	public Concept cloneConcept(){
		Concept result;
		if(this.i == null){
			result = new Concept(this.getType());
			result.setTerms((Terms) this.getTerms().cloneTerms());
		}
		else result = new Concept(this.getIndividual(),this.getType());
		result.setLocation(this.x,this.y);
		return result;
	}
	
	public String toString(Language l){
		if(this.type == null){
			return CGConstants.UNDEFINED_ELEMENT + " : " + CGConstants.GENERIC_CONCEPT_LABEL;
		}
		else{
			if(i == null) return (this.type.getTerm(l) + " : " + this.getTerm(l));
			else return (this.type.getTerm(l) + " : " + i.getTerm(l));
		}
	}
	
	/** Remove all links between this concept and relations in the ontology. */
	public void destroy(Ontology onto){
		Iterator it = onto.getRelations().iterator();
		boolean control = true;
		while(it.hasNext() && control){
			Relation r = (Relation) it.next();
			if(r.removeLinkedConcept(this) != -1) control = false;
		}
	}
	
	/** Returns the bounds of the image according to the font size of the given Graphics. */
	public RectangularShape getBounds(Graphics g,Language l){
		String s = this.toString(l);
		return GraphicsToolkit.getRectangularBounds(g,s,new Point(this.x,this.y));
	}
		
	/** Paint the concept with its label in a rectangular shape. */
	public void paintObject(Graphics g,Language l){
		this.paintObject(g,CGConstants.CONCEPT_COLOR,CGConstants.CONCEPT_BORDER_COLOR,CGConstants.SELECTED_CONCEPT_BORDER_COLOR,CGConstants.HIGHLIGHTED_CONCEPT_COLOR,CGConstants.CONCEPT_TEXT_COLOR,l);
	}
	
	/** Paint the concept with its label in a rectangular shape as element of the 
	 *  conclusion of an axiom. */
	public void paintObjectAsConclusion(Graphics g,Language l){
		this.paintObject(g,CGConstants.CONCLUSION_CONCEPT_COLOR,CGConstants.CONCLUSION_CONCEPT_BORDER_COLOR,CGConstants.CONCLUSION_SELECTED_CONCEPT_BORDER_COLOR,CGConstants.HIGHLIGHTED_CONCEPT_COLOR,CGConstants.CONCLUSION_CONCEPT_TEXT_COLOR,l);
	}

}

⌨️ 快捷键说明

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