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

📄 conceptualprimitive.java

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

import java.util.*;
import java.awt.*;

/**
 * This class represents the conceptual primitive (Concept types and relation types) in the 
 * ontology. The conceptual primitives are included in hierarchies structured by the is-a relation.
 *
 * @author Fr閐閞ic F黵st
 */
public abstract class ConceptualPrimitive extends NamedGraphicalObject{

	private LinkedList parents;
	private LinkedList children;
	private LinkedList axiomSchemata;
	
	/** Creates the conceptual primitive class with the given set of terms. */
	public ConceptualPrimitive(Terms terms){
		super(terms);
		this.parents = new LinkedList();
		this.children = new LinkedList();
		this.axiomSchemata = new LinkedList();
	}
	
	/** This method adds parent to this primitive and adds child to the given one. */
	public void addParent(ConceptualPrimitive parent){
		if(!parents.contains(parent)){
			this.parents.add(parent);
			parent.addChild(this);
		}
	}
	
	/** This method removes parent to this primitive and removes child to the given one. */
	public void removeParent(ConceptualPrimitive parent){
		if(this.parents.remove(parent)){
			parent.removeChild(this);
		}
	}
	
	public LinkedList getParents(){
		return parents;
	}
	
	/** This method adds child to this primitive and adds parent to the given one. */
	public void addChild(ConceptualPrimitive child){
		if(!children.contains(child)){
			this.children.add(child);
			child.addParent(this);
		}
	}
	
	/** This method removes child to this primitive and removes parent to the given one. */
	public void removeChild(ConceptualPrimitive child){
		if(this.children.remove(child)){
			child.removeParent(this);
		}
	}
	
	public LinkedList getChildren(){
		return this.children;
	}
	
	/** Destroy the conceptual primitive and the link between it and others conceptual primitives. */
	public void destroy(Ontology onto){
		int parentsNumber = this.parents.size();
		for(int i = 0;i < parentsNumber;i ++){
			((ConceptualPrimitive) this.parents.remove(0)).removeChild(this);
		}
		int childrenNumber = this.children.size();
		for(int i = 0;i < childrenNumber;i ++){
			((ConceptualPrimitive) this.children.remove(0)).removeParent(this);
		}
		Object[] props = this.axiomSchemata.toArray();
		for(int cpt = 0;cpt < props.length;cpt ++){
			AxiomSchema as = (AxiomSchema) props[cpt];
			if(as != null)	as.destroy();
		}
	}
	
	/** Returns true if the primitive has the axiom schema that corresponds to the
	 *  class with the given name. */
	public boolean hasAxiomSchema(String axiomSchemaClassName){
		for(Iterator i = this.axiomSchemata.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			if(as.getClass().getName().equals(axiomSchemaClassName)) return true;	
		}
		return false;
	}
	
	/** Returns true if the primitive has, in common with the given primitive, the 
	 *  axiom schema that corresponds to the class with the given name. The axiom 
	 *  schema must be one that deals with two primitives. */
	public boolean hasAxiomSchemaTwo(String axiomSchemaClassName,ConceptualPrimitive cp){
		for(Iterator i = this.axiomSchemata.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			if(as.getClass().getName().equals(axiomSchemaClassName) && ((AxiomSchemaTwo) as).links(cp) && ((AxiomSchemaTwo) as).links(this)) return true;	
		}
		return false;
	}

	/** Returns true if the graphical representation of the is-a link between the two given
	 *  conceptual primitives contains the given point, returns false otherwise. */
	public static boolean isALinkContainsPoint(Graphics g,Point p,ConceptualPrimitive cp1,ConceptualPrimitive cp2,Language l){
		 return GraphicsToolkit.arrowLineContainsPoint(g,cp1.getCenter(),cp2.getCenter(),p);
	}
	
	/** Returns true if this concept type is a sort of the given one. */
	public boolean isA(ConceptualPrimitive cp){
		if(this.equals(cp)) return true;
		else{
			boolean result = false;
			for(Iterator i = parents.iterator();i.hasNext() && !result;){
				ConceptualPrimitive p = (ConceptualPrimitive) i.next();
				if(p.equals(cp)) return true;
				else result = p.isA(cp);
			}
			return result;
		}
	}
	
	public void addAxiomSchema(AxiomSchema as){
		this.axiomSchemata.add(as);
	}
	
	/** Removes the given axiom schema. */
	public void removeAxiomSchema(AxiomSchema as){
		this.axiomSchemata.remove(as);
	}
	
	/** Remove all axiom schemata than correspond to the class with the given name. For 
	 *  instance, to remove all disjunctions, set axiomSchemaClassName as 
	 *  "toocom.ocgl.ConceptDisjunction". */
	public void removeAxiomSchemata(String axiomSchemaClassName){
		LinkedList temp = (LinkedList) this.axiomSchemata.clone();
		for(Iterator i = temp.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			if(as.getClass().getName().equals(axiomSchemaClassName)){
				as.destroy();
			}
		}
	}
	
	/** Returns the axiom schemata specified by the name of the class. Returns null if
	 *  the primitive has no such axiom schema. */
	public LinkedList getAxiomSchemata(String axiomSchemaClassName){
		LinkedList result = new LinkedList();
		for(Iterator i = this.axiomSchemata.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			if(as.getClass().getName().equals(axiomSchemaClassName)){
				result.add(as);
			}
		}
		return result;
	}
	
	/** Returns the list of primitives linked to that primitive by the axiom schema. 
	 *  The axiom schema must be an AxiomSchemaTwo. */
	public LinkedList getLinkedPrimitives(String axiomSchemaClassName){
		LinkedList result = new LinkedList();
		for(Iterator i = this.axiomSchemata.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			if(as.getClass().getName().equals(axiomSchemaClassName)){
				result.add(((AxiomSchemaTwo) as).getTheOtherPrimitive(this));
			}
		}
		return result;
	}
	
	/** Returns all the axiom schemata of the primitive. */
	public LinkedList getAxiomSchemata(){
		return this.axiomSchemata;	
	}
	
	/** Returns the list of axiom schemata removed from this primitive. An axiom schemata  is removed if
	 *  this primitive can't have this axiom schemata. */
	public LinkedList updateAxiomSchemata(){
		LinkedList result = new LinkedList();
		LinkedList newList = new LinkedList();
		for(Iterator i = this.axiomSchemata.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			if(!((AxiomSchema) as).isValid()){
				result.add(as);
				as.destroy();
			}
			else newList.add(as);
		}
		this.axiomSchemata = newList;
		return result;
	}
	
	public void removeAllAxiomSchemata(){
		LinkedList temp = (LinkedList) this.axiomSchemata.clone();
		for(Iterator i = temp.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			as.destroy();
		}
		this.axiomSchemata.clear();
	}
	
	/** Paint the conceptual primitive with its label and properties symbol. */
	public void paintObject(Graphics g, Color objectColor, Color borderColor, Color selectedColor, Color highlightedColor, Color textColor,Language l){
		super.paintObject(g,objectColor,borderColor,selectedColor,highlightedColor,textColor,l);
		for(Iterator i = this.axiomSchemata.iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			as.paint(g,l);
		}
	}
	
}

⌨️ 快捷键说明

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