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

📄 conceptualimplication.java

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

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

/**
 * This class represents a conceptual implication, that is a couple of conceptual graphs. The
 * first graph is the antecedent, the second one the consequent.
 * 
 * @author Fr閐閞ic F黵st
 */
public class ConceptualImplication extends NamedGraphicalObject{
	
	protected LinkedList hypothesisConcepts;
	protected LinkedList conclusionConcepts;
	protected LinkedList hypothesisRelations;
	protected LinkedList conclusionRelations;
	
	public ConceptualImplication(Terms terms){
		super(terms);
		this.hypothesisConcepts = new LinkedList();
		this.conclusionConcepts = new LinkedList();
		this.hypothesisRelations = new LinkedList();
		this.conclusionRelations = new LinkedList();
	}
	
	public ConceptualImplication(){
		super(Terms.getUndefinedTerms());
		this.hypothesisConcepts = new LinkedList();
		this.conclusionConcepts = new LinkedList();
		this.hypothesisRelations = new LinkedList();
		this.conclusionRelations = new LinkedList();
	}
	
	
	/** Returns the textual representation of the axiom in first order logic. */
	public String toString(Language l){
		String result = "";
		Hashtable variables = new Hashtable();
		int cpt = 1;
		String forAll = CGConstants.FOR_ALL + " ";
		for(Iterator i = this.hypothesisConcepts.iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(c.isGenericConcept()){
				String var = new String("x" + cpt);
				variables.put(c,var);
				forAll += var + ",";
				cpt ++;
				if(c.getType() != null) result += c.getType().getTerm(l) + "(" + var + ") " + CGConstants.AND + " ";
				else result += CGConstants.UNDEFINED_ELEMENT + "(" + var + ") " + CGConstants.AND + " ";
			}
			else{
				if(c.getType() != null) result += c.getType().getTerm(l) + "(" + c.getIndividual().getTerm(l) + ") " + CGConstants.AND + " ";
				else result += CGConstants.UNDEFINED_ELEMENT + "(" + c.getIndividual().getTerm(l) + ") " + CGConstants.AND + " ";
			}
		}	
		forAll = forAll.substring(0,forAll.length() - 1);
		forAll += " " + CGConstants.SUCH_AS + " ";
		result = forAll + result;
		for(Iterator i = this.hypothesisRelations.iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			result += r.getTerm(l) + "(";
			for(Iterator j = r.getLinkedConcepts().iterator();j.hasNext();){
				Concept c = (Concept) j.next();
				if(c != null){
					if(c.isGenericConcept()) result += (String) variables.get(c);
					else result += c.getIndividual().getTerm(l);
				}
				else result += CGConstants.UNDEFINED_ELEMENT;
				if(j.hasNext()) result += ",";
			}
			result += ") " + CGConstants.AND + " ";
		}	
		result = result.substring(0,result.length() - CGConstants.AND.length() - 1);
		cpt = 1;
		String vars = "";
		String formula = "";
		for(Iterator i = this.getPureConclusionConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(c.isGenericConcept()){
				String var = new String("y" + cpt);
				variables.put(c,var);
				cpt ++;
				if(c.getType() != null) formula += c.getType().getTerm(l) + "(" + var + ") " + CGConstants.AND + " ";
				else formula += CGConstants.UNDEFINED_ELEMENT + "(" + var + ") " + CGConstants.AND + " ";
				if(vars.length() == 0) vars = var;
				else vars += "," + var;
			}
			else{
				if(c.getType() != null) formula += c.getType().getTerm(l) + "(" + c.getIndividual().getTerm(l) + ") " + CGConstants.AND + " ";
				else formula += CGConstants.UNDEFINED_ELEMENT + "(" + c.getIndividual().getTerm(l) + ") " + CGConstants.AND + " ";
			}
		}
		if(vars.length() > 0) result += " , " + CGConstants.THEN + " " + CGConstants.THERE_EXISTS + " " + vars + " " + CGConstants.SUCH_AS + " ";
		else result += " , " + CGConstants.THEN + " ";
		result += formula;
		for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			result += r.getTerm(l) + "(";
			for(Iterator j = r.getLinkedConcepts().iterator();j.hasNext();){
				Concept c = (Concept) j.next();
				if(c != null){
					if(c.isGenericConcept()) result += (String) variables.get(c);
					else result += c.getIndividual().getTerm(l);
				}
				else result += CGConstants.UNDEFINED_ELEMENT;
				if(j.hasNext()) result += ",";
			}
			if(i.hasNext()) result += ") " + CGConstants.AND + " ";
			else result += ") ";
		}
		result = result.substring(0,result.length());
		return result;
	}
	
	/** Returns the node (concept or relation) with the given id, null if any such node
	 *  exists in the implication. */
	public Node getNode(int id){
		for(Iterator i = this.getAllConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(c.getId() == id) return c;
		}
		for(Iterator i = this.getAllRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			if(r.getId() == id) return r;
		}
		return null;
	}
	
	/** Returns the name of the axiom in the given language and statistic about the number of
	 *  vertices of the axiom. */
	public String getStatistics(Language l){
		return (this.getTerm(l) + "(" + this.hypothesisConcepts.size() + "," + this.hypothesisRelations.size() + "," + this.conclusionConcepts.size() + "," + this.conclusionRelations.size() + ")");
	}
	
	/** Returns the number of vertices (concepts and relations) of the hypothesis part 
	 *  of the axiom. */
	public int getHypothesisVertexCount(){
		return (hypothesisConcepts.size() + hypothesisRelations.size());
	}
	
	/** Returns the hypothesis part of the axiom as a Graph. */
	public Graph getHypothesisPart(){
		Graph result = new Graph(this.getTerms().appendAndCopy(" - " + CGConstants.getHypothesisTerms()));
		for(Iterator i = this.getHypothesisConcepts().iterator();i.hasNext();){
			result.addConcept((Concept) i.next());
		}
		for(Iterator i = this.getHypothesisRelations().iterator();i.hasNext();){
			result.addRelation((Relation) i.next());
		}
		return result;
	}
	
	/** Returns the conclusion part of the axiom as a Graph. */
	public Graph getConclusionPart(){
		Graph result = new Graph(this.getTerms().appendAndCopy(" - " + CGConstants.getConclusionTerms()));
		for(Iterator i = this.getConclusionConcepts().iterator();i.hasNext();){
			result.addConcept((Concept) i.next());
		}
		for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
			result.addRelation((Relation) i.next());
		}
		return result;
	}
	
	/** Returns the number of vertices (concepts and relations) of the conclusion part 
	 *  of the axiom. */
	public int getConclusionVertexCount(){
		return (this.getConclusionConcepts().size() + conclusionRelations.size());
	}
	
	/** Returns the concept with the given id, null if any such concept exists in the axiom. */
	public Concept getConcept(int id){
		for(Iterator i = this.getAllConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(c.getId() == id) return c;
		}
		return null;
	}
	
	/** Returns the relation with the given id, null if any such relation exists in the axiom. */
	public Relation getRelation(int id){
		for(Iterator i = this.getAllRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			if(r.getId() == id) return r;
		}
		return null;
	}
	
	/** Returns the list of relation linked to the concept c in the hypothesis of the axiom. If*
	 *  c is a conclusion concept or not a concept of the axiom, the returned list is empty. */
	public LinkedList getLinkedHypothesisRelations(Concept c){
		LinkedList result = new LinkedList();
		if(this.hasHypothesisConcept(c)){
			for(Iterator i = this.getHypothesisRelations().iterator();i.hasNext();){
				Relation r = (Relation) i.next();
				if(r.hasLinkedConcept(c)) result.add(r);
			}
		}
		return result;
	}

	/** Returns the list of relation linked to the concept c in the conclusion of the axiom. If*
	 *  c is not a concept of the axiom, the returned list is empty. */
	public LinkedList getLinkedConclusionRelations(Concept c){
		LinkedList result = new LinkedList();
		if(this.hasConclusionConcept(c)){
			for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
				Relation r = (Relation) i.next();
				if(r.hasLinkedConcept(c)) result.add(r);
			}
		}
		return result;
	}
	
	/** Returns the conclusion concepts, including those that are specified as hypothesis
	 *  concepts but which are linked to conclusion relation. */
	public LinkedList getConclusionConcepts(){
		LinkedList result = new LinkedList(conclusionConcepts);
		for(Iterator i = hypothesisConcepts.iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(this.hasConclusionConcept(c)){
				result.add(c);
			} 
		}
		return result;
	}
	
	/** Returns the concepts which only appear in the conclusion part of the axiom. */
	public LinkedList getPureConclusionConcepts(){
		return conclusionConcepts;
	}
	
	/** Returns the concepts which are both in the hypothesis part and in the conclusion part of
	 *  the axiom (that is linked to a relation of the conclusion part of the axiom). */
	public LinkedList getHypothesisConclusionConcepts(){
		LinkedList result = new LinkedList();
		for(Iterator i = this.getConclusionConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			if(hypothesisConcepts.contains(c)) result.add(c);
		}
		return result;
	}
	
	public LinkedList getHypothesisConcepts(){
		return hypothesisConcepts;
	}
	
	public LinkedList getHypothesisRelations(){
		return hypothesisRelations;
	}
	
	public LinkedList getConclusionRelations(){
		return conclusionRelations;
	}
	
	/** Returns the list of both hypothesis concepts and conclusion concepts. */
	public LinkedList getAllConcepts(){
		LinkedList result = new LinkedList();
		for(Iterator i = hypothesisConcepts.iterator();i.hasNext();){
			result.add(i.next());
		}
		for(Iterator i = conclusionConcepts.iterator();i.hasNext();){
			result.add(i.next());
		}
		return result;
	}

	/** Returns the list of both hypothesis relations and conclusion relations. */
	public LinkedList getAllRelations(){
		LinkedList result = new LinkedList();
		for(Iterator i = hypothesisRelations.iterator();i.hasNext();){
			result.add(i.next());
		}
		for(Iterator i = conclusionRelations.iterator();i.hasNext();){
			result.add(i.next());
		}
		return result;
	}
	
	/** Returns true if the axiom contains the given concept in its hypothesis part. */

⌨️ 快捷键说明

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