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

📄 matchingalgorithm.java

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

import java.util.*;
import java.io.*;
import toocom.ocgl.*;
import toocom.iotools.*;
import toocom.exceptions.*;
import toocom.ui.*;
import org.semanticweb.owl.io.*;

/**
 * This class contains parameters used in the matching algorithm.
 *
 * @author Fr閐閞ic F黵st
 */
public class MatchingAlgorithm{
	
	protected static int symmetryWeight = 1;
	protected static int transitivityWeight = 1;
	protected static int reflexivityWeight = 1;
	protected static int irreflexivityWeight = 1;
	protected static int antisymmetryWeight = 1;
	protected static int cminWeight = 1;
	protected static int cmaxWeight = 1;
	protected static int topoWeight = 1;
	protected static int topoPlusWeight = 1;
	protected static int disjunctionWeight = 1;
	protected static int incompatibilityWeight = 1;
	protected static int exclusivityWeight = 1;
	protected static int signatureWeight = 1;
	protected static int isaWeight = 1;
	protected static int abstractionWeight = 1;

	/** Find matching between ontologies stored in the files. */
	public static MatchingList match(File o1, File o2, Language l, CogitantClient cc, boolean trace) throws OntologyFileLoadingException,IOException,WrongSignatureException{ 
		Ontology onto1 = IOInterface.loadOntology(o1,l,trace);
		Ontology onto2 = IOInterface.loadOntology(o2,l,trace);
		return MatchingAlgorithm.matchOntos(onto1,onto2,l,cc,trace);
	}
	
	/** Returns the meta projection from a1 to a2 and from a2 to a1, if it exists, 
	 *  null otherwise. The metasupport (metaOCGL) must have been created on the server and
	 *  the metaOCGL ontology must be given as parameter. */
	public static IdTable getMetaProj(Axiom a1, Axiom a2, Language l,Ontology metaOCGL, CogitantClient cc) throws FileNotFoundException,IOException,WrongSignatureException{
		// Building the first metaGraph
		Graph metaA1 = new Graph(new Terms("meta-" + a1.getTerm(l)));
		Hashtable table1 = new Hashtable();
		// Id table : metaA1 -> A1
		IdTable id1 = new IdTable();
		for(Iterator j = a1.getHypothesisConcepts().iterator();j.hasNext();){
			Concept c = (Concept) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Antecedent_C",l));
			table1.put(c,cTemp);
			metaA1.addConcept(cTemp);
			id1.put(cTemp.getId(),c.getId());
		}
		for(Iterator j = a1.getHypothesisRelations().iterator();j.hasNext();){
			Relation r = (Relation) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Antecedent_BR",l));
			if(r.getArity() == 3) cTemp.setType(metaOCGL.getConceptType("Antecedent_TR",l));
			table1.put(r,cTemp);
			metaA1.addConcept(cTemp);
			id1.put(cTemp.getId(),r.getId());
			for(int index = 1;index <= r.getArity();index ++){
				Concept c = (Concept) r.getLinkedConcept(index);
				if(c != null){
					if(index == 1){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role1",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table1.get(c),2);
						metaA1.addRelation(rTemp);
					}
					if(index == 2){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role2",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table1.get(c),2);
						metaA1.addRelation(rTemp);
					}
					if(index == 3){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role3",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table1.get(c),2);
						metaA1.addRelation(rTemp);
					}
				}
			}
		}
		for(Iterator j = a1.getPureConclusionConcepts().iterator();j.hasNext();){
			Concept c = (Concept) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Consequent_C",l));
			table1.put(c,cTemp);
			metaA1.addConcept(cTemp);
			id1.put(cTemp.getId(),c.getId());
		}
		for(Iterator j = a1.getConclusionRelations().iterator();j.hasNext();){
			Relation r = (Relation) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Consequent_BR",l));
			if(r.getArity() == 3) cTemp.setType(metaOCGL.getConceptType("Consequent_TR",l));
			table1.put(r,cTemp);
			metaA1.addConcept(cTemp);
			id1.put(cTemp.getId(),r.getId());
			for(int index = 1;index <= r.getArity();index ++){
				Concept c = (Concept) r.getLinkedConcept(index);
				if(c != null){
					if(index == 1){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role1",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table1.get(c),2);
						metaA1.addRelation(rTemp);
					}
					if(index == 2){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role2",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table1.get(c),2);
						metaA1.addRelation(rTemp);
					}
					if(index == 3){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role3",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table1.get(c),2);
						metaA1.addRelation(rTemp);
					}
				}
			}
		}
		// Building the second metaGraph
		Graph metaA2 = new Graph(new Terms("meta-" + a2.getTerm(l)));
		Hashtable table2 = new Hashtable();
		// Id table : metaA2 -> A2
		IdTable id2 = new IdTable();
		for(Iterator j = a2.getHypothesisConcepts().iterator();j.hasNext();){
			Concept c = (Concept) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Antecedent_C",l));
			table2.put(c,cTemp);
			metaA2.addConcept(cTemp);
			id2.put(cTemp.getId(),c.getId());
		}
		for(Iterator j = a2.getHypothesisRelations().iterator();j.hasNext();){
			Relation r = (Relation) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Antecedent_BR",l));
			if(r.getArity() == 3) cTemp.setType(metaOCGL.getConceptType("Antecedent_TR",l));
			table2.put(r,cTemp);
			metaA2.addConcept(cTemp);
			id2.put(cTemp.getId(),r.getId());
			for(int index = 1;index <= r.getArity();index ++){
				Concept c = (Concept) r.getLinkedConcept(index);
				if(c != null){
					if(index == 1){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role1",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table2.get(c),2);
						metaA2.addRelation(rTemp);
					}
					if(index == 2){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role2",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table2.get(c),2);
						metaA2.addRelation(rTemp);
					}
					if(index == 3){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role3",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table2.get(c),2);
						metaA2.addRelation(rTemp);
					}
				}
			}
		}
		for(Iterator j = a2.getPureConclusionConcepts().iterator();j.hasNext();){
			Concept c = (Concept) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Consequent_C",l));
			table2.put(c,cTemp);
			metaA2.addConcept(cTemp);
			id2.put(cTemp.getId(),c.getId());
		}
		for(Iterator j = a2.getConclusionRelations().iterator();j.hasNext();){
			Relation r = (Relation) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Consequent_BR",l));
			if(r.getArity() == 3) cTemp.setType(metaOCGL.getConceptType("Consequent_TR",l));
			table2.put(r,cTemp);
			metaA2.addConcept(cTemp);
			id2.put(cTemp.getId(),r.getId());
			for(int index = 1;index <= r.getArity();index ++){
				Concept c = (Concept) r.getLinkedConcept(index);
				if(c != null){
					if(index == 1){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role1",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table2.get(c),2);
						metaA2.addRelation(rTemp);
					}
					if(index == 2){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role2",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table2.get(c),2);
						metaA2.addRelation(rTemp);
					}
					if(index == 3){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role3",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table2.get(c),2);
						metaA2.addRelation(rTemp);
					}
				}
			}
		}
		// Getting projections between the metaGraphs
		LinkedList projs1 = cc.getGraphProjections(metaOCGL,metaA1,metaA2,l);
		LinkedList projs2 = cc.getGraphProjections(metaOCGL,metaA2,metaA1,l);
		for(Iterator i = projs1.iterator();i.hasNext();){
			Projection p1 = (Projection) i.next();
			for(Iterator j = projs2.iterator();j.hasNext();){
				Projection p2 = (Projection) j.next();
				if(Projection.reciprocalProjections(p1,p2)){
					IdTable result = new IdTable();
					for(Enumeration k = p1.getCorrespondances().keys();k.hasMoreElements();){
						int key = ((Integer) k.nextElement()).intValue();
						int value = p1.getCorrespondance(key);
						// Omitting role id
						if(id1.get(key) != -1) result.put(id1.get(key),id2.get(value));
					}
					return result;
				}
			}
		}
		return null;
	}
	
	/** Returns the meta+ (that is meta projection with type identity links) projection 
	 *  from a1 to a2 and from a2 to a1, if it exists, null otherwise. The metasupport
	 *  (metaOCGL) must have been created on the server and the metaOCGL ontology must 
	 *  be given as parameter. */
	public static IdTable getMetaPlusProj(Axiom a1, Axiom a2, Language l,Ontology metaOCGL, CogitantClient cc) throws FileNotFoundException,IOException,WrongSignatureException{
		// Building the first metaGraph
		Graph metaA1 = new Graph(new Terms("meta-" + a1.getTerm(l)));
		Hashtable table1 = new Hashtable();
		// Id table : metaA1 -> A1
		IdTable id1 = new IdTable();
		for(Iterator j = a1.getHypothesisConcepts().iterator();j.hasNext();){
			Concept c = (Concept) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Antecedent_C",l));
			table1.put(c,cTemp);
			metaA1.addConcept(cTemp);
			id1.put(cTemp.getId(),c.getId());
		}
		for(Iterator j = a1.getHypothesisRelations().iterator();j.hasNext();){
			Relation r = (Relation) j.next();
			Concept cTemp = new Concept(metaOCGL.getConceptType("Antecedent_BR",l));
			if(r.getArity() == 3) cTemp.setType(metaOCGL.getConceptType("Antecedent_TR",l));
			table1.put(r,cTemp);
			metaA1.addConcept(cTemp);
			id1.put(cTemp.getId(),r.getId());
			for(int index = 1;index <= r.getArity();index ++){
				Concept c = (Concept) r.getLinkedConcept(index);
				if(c != null){
					if(index == 1){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role1",l));
						rTemp.setLinkedConcept(cTemp,1);
						rTemp.setLinkedConcept((Concept) table1.get(c),2);
						metaA1.addRelation(rTemp);
					}
					if(index == 2){
						Relation rTemp = new Relation(metaOCGL.getRelationType("role2",l));

⌨️ 快捷键说明

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