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

📄 metagraph.java

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

import java.io.*;
import java.util.*;
import toocom.iotools.*;
import toocom.ocgl.*;

/**
 * This class is used to build ontology metagraph.
 *
 * @author Fr閐閞ic F黵st
 */ 
public class MetaGraph{
	
	/** Build the metagraph corresponding to the ontology stored in the source file and save
	 *  the graph in the target file. */
	public static void buildMetaGraph(File source, File target, File metaFile, Language l) throws FileNotFoundException,IOException{
		Ontology metaOCGL = CGXMLParser.loadOntology(metaFile.getPath(),l,true);
		Ontology onto = CGXMLParser.loadOntology(source.getAbsolutePath(),l,true);
		Graph metaGraph = new Graph(new Terms(onto.getTerm(l)));
		// Concepts
		ConceptType metaConcept = metaOCGL.getConceptType("Concept",l);
		for(Iterator i = onto.getConceptTypes().iterator();i.hasNext();){
			ConceptType ct = (ConceptType) i.next();
			Concept c = new Concept(metaConcept);
			c.setTerm(ct.getTerm(l),l);
			metaGraph.addConcept(c);
			// Abstraction
			if(ct.hasAxiomSchema("toocom.ocgl.ConceptAbstraction")){
				Concept cTemp = new Concept(metaOCGL.getConceptType("Abstraction",l));
				metaGraph.addConcept(cTemp);
				Relation rTemp = new Relation(metaOCGL.getRelationType("has_c",l));
				rTemp.setLinkedConcept(c,1);
				rTemp.setLinkedConcept(cTemp,2);
				metaGraph.addRelation(rTemp);
			}
		}
		// ISA link between concept types and disjunctions between concept types
		for(Iterator i = onto.getConceptTypes().iterator();i.hasNext();){
			ConceptType ct = (ConceptType) i.next();
			for(Iterator j = ct.getParents().iterator();j.hasNext();){
				ConceptType parent = (ConceptType) j.next();
				Relation r = new Relation(metaOCGL.getRelationType("isa_c",l));
				r.setLinkedConcept(metaGraph.getConcept(ct.getTerm(l),l),1);
				r.setLinkedConcept(metaGraph.getConcept(parent.getTerm(l),l),2);
				metaGraph.addRelation(r);
			}
			for(Iterator j = ct.getAxiomSchemata("toocom.ocgl.ConceptDisjunction").iterator();j.hasNext();){
				ConceptDisjunction disj = (ConceptDisjunction) j.next();
				ConceptType disjoint = (ConceptType) disj.getTheOtherPrimitive(ct);
				Concept c1 = metaGraph.getConcept(ct.getTerm(l),l);
				Concept c2 = metaGraph.getConcept(disjoint.getTerm(l),l);
				if(!metaGraph.existsRelation("disjunction",l,c1,c2)){
					Relation r = new Relation(metaOCGL.getRelationType("disjunction",l));
					r.setLinkedConcept(c1,1);
					r.setLinkedConcept(c2,2);
					metaGraph.addRelation(r);
				}
			}

		}	
		// Relations
		ConceptType metaRelationBin = metaOCGL.getConceptType("Binary_R",l);
		ConceptType metaRelationTer = metaOCGL.getConceptType("Ternary_R",l);
		for(Iterator i = onto.getRelationTypes().iterator();i.hasNext();){
			RelationType rt = (RelationType) i.next();
			if(rt.getArity() == 2){
				Concept c = new Concept(metaRelationBin);
				c.setTerm(rt.getTerm(l),l);
				c.translate(0,CGConstants.Y_MAX);
				metaGraph.addConcept(c);
				// Signature
				ConceptType ct1 = rt.getSignature().getConceptType(1);
				if(ct1 != null){
					Relation r1 = new Relation(metaOCGL.getRelationType("role1",l));
					r1.setLinkedConcept(c,1);
					r1.setLinkedConcept(metaGraph.getConcept(ct1.getTerm(l),l),2);
					r1.translate(0,CGConstants.Y_MAX);
					metaGraph.addRelation(r1);
				}
				ConceptType ct2 = rt.getSignature().getConceptType(2);
				if(ct2 != null){
					Relation r2 = new Relation(metaOCGL.getRelationType("role2",l));
					r2.setLinkedConcept(c,1);
					r2.setLinkedConcept(metaGraph.getConcept(ct2.getTerm(l),l),2);
					r2.translate(0,CGConstants.Y_MAX);
					metaGraph.addRelation(r2);
				}
			}
			if(rt.getArity() == 3){
				Concept c = new Concept(metaRelationTer);
				c.setTerm(rt.getTerm(l),l);
				c.translate(0,CGConstants.Y_MAX);
				metaGraph.addConcept(c);
				// Signature
				ConceptType ct1 = rt.getSignature().getConceptType(1);
				if(ct1 != null){
					Relation r1 = new Relation(metaOCGL.getRelationType("role1",l));
					r1.setLinkedConcept(c,1);
					r1.setLinkedConcept(metaGraph.getConcept(ct1.getTerm(l),l),2);
					r1.translate(0,CGConstants.Y_MAX);
					metaGraph.addRelation(r1);
				}
				ConceptType ct2 = rt.getSignature().getConceptType(2);
				if(ct2 != null){
					Relation r2 = new Relation(metaOCGL.getRelationType("role2",l));
					r2.setLinkedConcept(c,1);
					r2.setLinkedConcept(metaGraph.getConcept(ct2.getTerm(l),l),2);
					r2.translate(0,CGConstants.Y_MAX);
					metaGraph.addRelation(r2);
				}
				ConceptType ct3 = rt.getSignature().getConceptType(3);
				if(ct3 != null){
					Relation r3 = new Relation(metaOCGL.getRelationType("role3",l));
					r3.setLinkedConcept(c,1);
					r3.setLinkedConcept(metaGraph.getConcept(ct3.getTerm(l),l),2);
					r3.translate(0,CGConstants.Y_MAX);
					metaGraph.addRelation(r3);
				}
			}
			
		}
		for(Iterator i = onto.getRelationTypes().iterator();i.hasNext();){
			RelationType rt = (RelationType) i.next();
			// ISA link between relation types
			for(Iterator j = rt.getParents().iterator();j.hasNext();){
				RelationType parent = (RelationType) j.next();
				Relation r = new Relation(metaOCGL.getRelationType("isa_r",l));
				r.setLinkedConcept(metaGraph.getConcept(rt.getTerm(l),l),1);
				r.setLinkedConcept(metaGraph.getConcept(parent.getTerm(l),l),2);
				r.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(r);
			}
			// Exclusivity and incompatibility between relation types
			for(Iterator j = rt.getAxiomSchemata("toocom.ocgl.RelationIncompatibility").iterator();j.hasNext();){
				RelationType incomp = (RelationType) ((RelationIncompatibility) j.next()).getTheOtherPrimitive(rt);
				Relation r = new Relation(metaOCGL.getRelationType("incompatibility",l));
				r.setLinkedConcept(metaGraph.getConcept(rt.getTerm(l),l),1);
				r.setLinkedConcept(metaGraph.getConcept(incomp.getTerm(l),l),2);
				r.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(r);
			}
			for(Iterator j = rt.getAxiomSchemata("toocom.ocgl.RelationExclusivity").iterator();j.hasNext();){
				RelationType exclu = (RelationType) ((RelationExclusivity) j.next()).getTheOtherPrimitive(rt);
				Relation r = new Relation(metaOCGL.getRelationType("exclusivity",l));
				r.setLinkedConcept(metaGraph.getConcept(rt.getTerm(l),l),1);
				r.setLinkedConcept(metaGraph.getConcept(exclu.getTerm(l),l),2);
				r.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(r);
			}
			// Algebraic properties
			Concept c = metaGraph.getConcept(rt.getTerm(l),l);
			// Symmetry
			if(rt.hasAxiomSchema("toocom.ocgl.RelationSymmetry")){
				Concept cTemp = new Concept(metaOCGL.getConceptType("Symmetry",l));
				cTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addConcept(cTemp);
				Relation rTemp = new Relation(metaOCGL.getRelationType("has_r",l));
				rTemp.setLinkedConcept(c,1);
				rTemp.setLinkedConcept(cTemp,2);
				rTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(rTemp);
			}
			// Reflexivity
			if(rt.hasAxiomSchema("toocom.ocgl.RelationReflexivity")){
				Concept cTemp = new Concept(metaOCGL.getConceptType("Reflexivity",l));
				cTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addConcept(cTemp);
				Relation rTemp = new Relation(metaOCGL.getRelationType("has_r",l));
				rTemp.setLinkedConcept(c,1);
				rTemp.setLinkedConcept(cTemp,2);
				rTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(rTemp);
			}
			// Transitivity
			if(rt.hasAxiomSchema("toocom.ocgl.RelationTransitivity")){
				Concept cTemp = new Concept(metaOCGL.getConceptType("Transitivity",l));
				cTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addConcept(cTemp);
				Relation rTemp = new Relation(metaOCGL.getRelationType("has_r",l));
				rTemp.setLinkedConcept(c,1);
				rTemp.setLinkedConcept(cTemp,2);
				rTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(rTemp);
			}
			// Irreflexivity
			if(rt.hasAxiomSchema("toocom.ocgl.RelationIrreflexivity")){
				Concept cTemp = new Concept(metaOCGL.getConceptType("Irreflexivity",l));
				cTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addConcept(cTemp);
				Relation rTemp = new Relation(metaOCGL.getRelationType("has_r",l));
				rTemp.setLinkedConcept(c,1);
				rTemp.setLinkedConcept(cTemp,2);
				rTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(rTemp);
			}
			// Antisymmetry
			if(rt.hasAxiomSchema("toocom.ocgl.RelationAntisymmetry")){
				Concept cTemp = new Concept(metaOCGL.getConceptType("Antisymmetry",l));
				cTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addConcept(cTemp);
				Relation rTemp = new Relation(metaOCGL.getRelationType("has_r",l));
				rTemp.setLinkedConcept(c,1);
				rTemp.setLinkedConcept(cTemp,2);
				rTemp.translate(0,CGConstants.Y_MAX);
				metaGraph.addRelation(rTemp);
			}
			// CARDINALITIES
		}
		// AXIOMS
		int cpt = 1;
		for(Iterator i = onto.getAxioms().iterator();i.hasNext();){
			Axiom axiom = (Axiom) i.next();
			Hashtable table = new Hashtable();
			cpt ++;
			for(Iterator j = axiom.getHypothesisConcepts().iterator();j.hasNext();){
				Concept c = (Concept) j.next();
				Concept cTemp = new Concept(metaOCGL.getConceptType("Antecedent_C",l));
				cTemp.translate(0,cpt*CGConstants.Y_MAX);

⌨️ 快捷键说明

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