📄 matchingalgorithm.java
字号:
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);
}
}
}
}
// Type identities
for(Iterator j = a1.getAllConcepts().iterator();j.hasNext();){
Concept c = (Concept) j.next();
for(Iterator k = a1.getAllConcepts().iterator();k.hasNext();){
Concept cTemp = (Concept) k.next();
if(!c.equals(cTemp) && (c.getType().equals(cTemp.getType()))){
Relation r = new Relation(metaOCGL.getRelationType("type_identity",l));
r.setLinkedConcept((Concept) table1.get(c),1);
r.setLinkedConcept((Concept) table1.get(cTemp),2);
metaA1.addRelation(r);
}
}
}
for(Iterator j = a1.getAllRelations().iterator();j.hasNext();){
Relation r = (Relation) j.next();
for(Iterator k = a1.getAllRelations().iterator();k.hasNext();){
Relation rTemp = (Relation) k.next();
if(!r.equals(rTemp) && (r.getType().equals(rTemp.getType()))){
Relation rIdent = new Relation(metaOCGL.getRelationType("type_identity",l));
rIdent.setLinkedConcept((Concept) table1.get(r),1);
rIdent.setLinkedConcept((Concept) table1.get(rTemp),2);
metaA1.addRelation(rIdent);
}
}
}
// 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);
}
}
}
}
// Type identities
for(Iterator j = a2.getAllConcepts().iterator();j.hasNext();){
Concept c = (Concept) j.next();
for(Iterator k = a2.getAllConcepts().iterator();k.hasNext();){
Concept cTemp = (Concept) k.next();
if(!c.equals(cTemp) && (c.getType().equals(cTemp.getType()))){
Relation r = new Relation(metaOCGL.getRelationType("type_identity",l));
r.setLinkedConcept((Concept) table2.get(c),1);
r.setLinkedConcept((Concept) table2.get(cTemp),2);
metaA2.addRelation(r);
}
}
}
for(Iterator j = a2.getAllRelations().iterator();j.hasNext();){
Relation r = (Relation) j.next();
for(Iterator k = a2.getAllRelations().iterator();k.hasNext();){
Relation rTemp = (Relation) k.next();
if(!r.equals(rTemp) && (r.getType().equals(rTemp.getType()))){
Relation rIdent = new Relation(metaOCGL.getRelationType("type_identity",l));
rIdent.setLinkedConcept((Concept) table2.get(r),1);
rIdent.setLinkedConcept((Concept) table2.get(rTemp),2);
metaA2.addRelation(rIdent);
}
}
}
// 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;
}
public static MatchingList matchOntos(Ontology o1, Ontology o2,Language l, CogitantClient cc, boolean trace) throws IOException,WrongSignatureException{
MatchingList list = new MatchingList(o1,o2);
// Concepts properties
for(Iterator i = o1.getConceptTypes().iterator();i.hasNext();){
ConceptType ct = (ConceptType) i.next();
for(Iterator j = o2.getConceptTypes().iterator();j.hasNext();){
ConceptType ctBis = (ConceptType) j.next();
// Abstraction & partition
if(ct.hasAxiomSchema("toocom.ocgl.ConceptAbstraction")){
if(ctBis.hasAxiomSchema("toocom.ocgl.ConceptAbstraction")){
if(ct.hasAxiomSchema("toocom.ocgl.ConceptPartition")){
// Part + Part = + 2*Wabs
if(ctBis.hasAxiomSchema("toocom.ocgl.ConceptPartition")) list.updateMatchingWithAbstraction(ct,ctBis,2);
// Part + Abs = + Wabs
else list.updateMatchingWithAbstraction(ct,ctBis,1);
}
else{
// Abs + Part = + Wabs
if(ctBis.hasAxiomSchema("toocom.ocgl.ConceptPartition")) list.updateMatchingWithAbstraction(ct,ctBis,1);
// Abs + Abs = + Wabs
else list.updateMatchingWithAbstraction(ct,ctBis,1);
}
}
else{
// Part + No Abs = - 2*Wabs
if(ct.hasAxiomSchema("toocom.ocgl.ConceptPartition")) list.updateMatchingWithAbstraction(ct,ctBis,-2);
// Abs + No Abs = - Wabs
else list.updateMatchingWithAbstraction(ct,ctBis,-1);
}
}
else{
if(ctBis.hasAxiomSchema("toocom.ocgl.ConceptAbstraction")){
// No Abs + Part = - 2*Wabs
if(ctBis.hasAxiomSchema("toocom.ocgl.ConceptPartition")) list.updateMatchingWithAbstraction(ct,ctBis,-2);
// No Abs + Abs = - Wabs
else list.updateMatchingWithAbstraction(ct,ctBis,-1);
}
// No Abs + No Abs = 0
//else list.updateMatchingWithAbstraction(ct,ctBis,1);
}
if(trace) System.out.println("Abstraction : " + ct.getTerm(l) + " compared to " + ctBis.getTerm(l));
// Disjunction
if(ct.hasAxiomSchema("toocom.ocgl.ConceptDisjunction")){
// Disj + Disj = + Wdisj
if(ctBis.hasAxiomSchema("toocom.ocgl.ConceptDisjunction")) list.updateMatchingWithDisjunction(ct,ctBis,1);
// Disj + No Disj = - Wdisj
else list.updateMatchingWithAbstraction(ct,ctBis,-1);
}
else{
// No Disj + Disj = - Wdisj
if(ctBis.hasAxiomSchema("toocom.ocgl.ConceptDisjunction")) list.updateMatchingWithDisjunction(ct,ctBis,-1);
// No Disj + No Disj = 0
//else list.updateMatchingWithAbstraction(ct,ctBis,1);
}
if(trace) System.out.println("Disjunction : " + ct.getTerm(l) + " compared to " + ctBis.getTerm(l));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -