📄 matchingalgorithm.java
字号:
// Relations properties
for(Iterator i = o1.getRelationTypes().iterator();i.hasNext();){
RelationType rt = (RelationType) i.next();
for(Iterator j = o2.getRelationTypes().iterator();j.hasNext();){
RelationType rtBis = (RelationType) j.next();
if((rt.getArity() == 2) && (rtBis.getArity()==2)){
// Symmetry
if(rt.hasAxiomSchema("toocom.ocgl.RelationSymmetry")){
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationSymmetry")){
// Sym + Sym = + Wsym
list.updateMatchingWithSymmetry(rt,rtBis,1);
}
// Sym + No Sym = - Wsym
else list.updateMatchingWithSymmetry(rt,rtBis,-1);
}
else{
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationSymmetry")){
// No Sym + Sym = - Wsym
list.updateMatchingWithSymmetry(rt,rtBis,-1);
}
// No Sym + No Sym = 0
//else list.updateMatchingWithSymmetry(rt,rtBis,-1);
}
if(trace) System.out.println("Symmetry : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
// Transitivity
if(rt.hasAxiomSchema("toocom.ocgl.RelationTransitivity")){
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationTransitivity")){
// Trans + Trans = + Wtrans
list.updateMatchingWithTransitivity(rt,rtBis,1);
}
// Trans + No Trans = - Wtrans
else list.updateMatchingWithTransitivity(rt,rtBis,-1);
}
else{
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationTransitivity")){
// No Trans + Trans = - Wtrans
list.updateMatchingWithTransitivity(rt,rtBis,-1);
}
// No Trans + No Trans = 0
//else list.updateMatchingWithTransitivity(rt,rtBis,-1);
}
if(trace) System.out.println("Transitivity : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
// Reflexivity
if(rt.hasAxiomSchema("toocom.ocgl.RelationReflexivity")){
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationReflexivity")){
// Ref + Ref = + Wref
list.updateMatchingWithReflexivity(rt,rtBis,1);
}
// Ref + No Ref = - Wref
else list.updateMatchingWithReflexivity(rt,rtBis,-1);
}
else{
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationReflexivity")){
// No Ref + Ref = - Wref
list.updateMatchingWithReflexivity(rt,rtBis,-1);
}
// No Ref + No Ref = 0
//else list.updateMatchingWithReflexivity(rt,rtBis,-1);
}
if(trace) System.out.println("Reflexivity : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
// Irreflexivity
if(rt.hasAxiomSchema("toocom.ocgl.RelationIrreflexivity")){
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationIrreflexivity")){
// Irr + Irr = + Wirr
list.updateMatchingWithIrreflexivity(rt,rtBis,1);
}
// Irr + No Irr = - Wirr
else list.updateMatchingWithIrreflexivity(rt,rtBis,-1);
}
else{
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationIrreflexivity")){
// No Irr + Irr = - Wirr
list.updateMatchingWithIrreflexivity(rt,rtBis,-1);
}
// No Irr + No Irr = 0
//else list.updateMatchingWithIrreflexivity(rt,rtBis,-1);
}
if(trace) System.out.println("Irreflexivity : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
// Incompatibility
if(rt.hasAxiomSchema("toocom.ocgl.RelationIncompatibility")){
// Incomp + Incomp = + Wincomp
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationIncompatibility")) list.updateMatchingWithIncompatibility(rt,rtBis,1);
// Incomp + No Incomp = - Wincomp
else list.updateMatchingWithIncompatibility(rt,rtBis,-1);
}
else{
// No Incomp + Incomp = - Wincomp
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationIncompatibility")) list.updateMatchingWithIncompatibility(rt,rtBis,-1);
// No Incomp + No Incomp = 0
//else list.updateMatchingWithIncompatibility(ct,ctBis,1);
}
if(trace) System.out.println("Incompatibility : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
// Exclusivity
if(rt.hasAxiomSchema("toocom.ocgl.RelationExclusivity")){
// Exclu + Exclu = + Wexclu
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationExclusivity")) list.updateMatchingWithExclusivity(rt,rtBis,1);
// Exclu + No Exclu = - Wexclu
else list.updateMatchingWithExclusivity(rt,rtBis,-1);
}
else{
// No Exclu + Exclu = - Wexclu
if(rtBis.hasAxiomSchema("toocom.ocgl.RelationExclusivity")) list.updateMatchingWithExclusivity(rt,rtBis,-1);
// No Exclu + No Exclu = 0
//else list.updateMatchingWithExclusivity(rt,rtBis,1);
}
if(trace) System.out.println("Exclusivity : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
}
int arity = rt.getArity();
if(rtBis.getArity() == arity){
// Min Cardinality
for(int index = 1;index <= arity;index ++){
int card = RelationMinCardinality.getMinCardinality(rt,index);
int cardBis = RelationMinCardinality.getMinCardinality(rtBis,index);
if(card != -1){
if(cardBis != -1){
if(card == cardBis){
// CardMin + CardMin = + 2*Wcmin
list.updateMatchingWithCmin(rt,rtBis,2);
}
else{
// CardMin1 + CardMin2 = - Wcmin
list.updateMatchingWithCmin(rt,rtBis,-1);
}
}
// CardMin + No CardMin = - 2*Wcmin
else list.updateMatchingWithCmin(rt,rtBis,-2);
}
else{
// No CardMin + CardMin = - 2*Wcmin
if(cardBis != -1) list.updateMatchingWithCmin(rt,rtBis,-2);
}
if(trace) System.out.println("Min Cardinality : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
}
// Max Cardinality
for(int index = 1;index <= arity;index ++){
int card = RelationMaxCardinality.getMaxCardinality(rt,index);
int cardBis = RelationMaxCardinality.getMaxCardinality(rtBis,index);
if(card != -1){
if(cardBis != -1){
if(card == cardBis){
// CardMax + CardMax = + 2*Wcmax
list.updateMatchingWithCmax(rt,rtBis,2);
}
else{
// CardMax1 + CardMax2 = - 2*Wcmax
list.updateMatchingWithCmax(rt,rtBis,-2);
}
}
// CardMax + No CardMax = - Wcmax
else list.updateMatchingWithCmax(rt,rtBis,-1);
}
else{
// No CardMax + CardMax = - Wcmax
if(cardBis != -1) list.updateMatchingWithCmax(rt,rtBis,-1);
}
if(trace) System.out.println("Max Cardinality : " + rt.getTerm(l) + " compared to " + rtBis.getTerm(l));
}
}
}
}
// Axioms comparison
Ontology metaOCGL = CGXMLParser.loadOntology(Constants.METAOCGL_FILE_NAME,l,true);
cc.createServerSupport(metaOCGL,l);
for(Iterator i = o1.getAxioms().iterator();i.hasNext();){
Axiom a1 = (Axiom) i.next();
for(Iterator j = o2.getAxioms().iterator();j.hasNext();){
Axiom a2 = (Axiom) j.next();
IdTable table = MatchingAlgorithm.getMetaProj(a1,a2,l,metaOCGL,cc);
if(table != null){
for(Enumeration e = table.keys();e.hasMoreElements();){
int id1 = ((Integer) e.nextElement()).intValue();
int id2 = table.get(id1);
ConceptualPrimitive cp1 = a1.getNode(id1).getType();
ConceptualPrimitive cp2 = a2.getNode(id2).getType();
list.updateMatchingWithTopo(cp1,cp2,1);
if(trace) System.out.println("Topo : " + cp1.getTerm(l) + " compared to " + cp2.getTerm(l));
}
}
IdTable tablePlus = MatchingAlgorithm.getMetaPlusProj(a1,a2,l,metaOCGL,cc);
if(tablePlus != null){
for(Enumeration e = tablePlus.keys();e.hasMoreElements();){
int id1 = ((Integer) e.nextElement()).intValue();
int id2 = tablePlus.get(id1);
ConceptualPrimitive cp1 = a1.getNode(id1).getType();
ConceptualPrimitive cp2 = a2.getNode(id2).getType();
list.updateMatchingWithTopoPlus(cp1,cp2,1);
if(trace) System.out.println("Topo+ : " + cp1.getTerm(l) + " compared to " + cp2.getTerm(l));
}
}
}
}
cc.closeServerOntology();
// Signatures
/*double conRatio = list.getConceptMatchingRatio();
double relRatio = list.getRelationMatchingRatio();
if(trace) System.out.println("Concept matchings ratio = " + conRatio);
if(trace) System.out.println("Relation matchings ratio = " + relRatio);
if(conRatio > relRatio){
if(trace) System.out.println("Fixing concept matchings");
list.fixConceptMatchings(0);
if(trace) System.out.println("Updating relation matchings with signatures");
MatchingAlgorithm.updateRelationMatchingsWithSignature(list);
}
else{
if(trace) System.out.println("Fixing relation matchings");
list.fixRelationMatchings(0);
if(trace) System.out.println("Updating concept matchings with signatures");
MatchingAlgorithm.updateConceptMatchingsWithSignature(list);
}*/
list.removeIrrelevantMatchings(0);
return list;
}
/** Update the weigths of relation matching if the concepts of the signatures of
* relations match in the list. */
private static void updateRelationMatchingsWithSignature(MatchingList list){
for(Iterator i = list.getMatchings().iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(!(m.getFirstCP() instanceof ConceptType)){
RelationType rt1 = (RelationType) m.getFirstCP();
RelationType rt2 = (RelationType) m.getSecondCP();
if(rt1.getArity() == rt2.getArity()){
boolean match = true;
for(int index = 1;index <= rt1.getArity();){
if(list.match(rt1.getSignature().getConceptType(index),rt2.getSignature().getConceptType(index)) == null)
match =false;
index ++;
}
// Signature match = + Wsign
if(match) m.updateSignatureWeight(1);
// Signature match = - Wsign
else m.updateSignatureWeight(-1);
}
// Different arities = - 2*Wsign
else m.updateSignatureWeight(-2);
}
}
}
/** Update the weigths of concept matching for the concepts of the signatures of
* relations that match in the list. */
private static void updateConceptMatchingsWithSignature(MatchingList list){
for(Iterator i = list.getMatchings().iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(!(m.getFirstCP() instanceof ConceptType)){
RelationType rt1 = (RelationType) m.getFirstCP();
RelationType rt2 = (RelationType) m.getSecondCP();
if(rt1.getArity() == rt2.getArity()){
for(int index = 1;index <= rt1.getArity();){
Matching mBis = list.match(rt1.getSignature().getConceptType(index),rt2.getSignature().getConceptType(index));
// Signature match = + Wsign
if(mBis != null) mBis.updateSignatureWeight(1);
index ++;
}
}
// Different arities = - 2*Wsign
else m.updateSignatureWeight(-2);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -