📄 matchinglist.java
字号:
package toocom.matching;
import java.util.*;
import java.io.*;
import toocom.ocgl.*;
/**
* This class represent a list of matchings of conceptual primitives.
*
* @author Fr閐閞ic F黵st
*/
public class MatchingList{
private Ontology o1;
private Ontology o2;
private LinkedList list;
public MatchingList(Ontology o1, Ontology o2){
this.o1 = o1;
this.o2 = o2;
this.list = new LinkedList();
}
public void addMatching(Matching m){
this.list.add(m);
}
public Ontology getFirstOnto(){
return this.o1;
}
public Ontology getSecondOnto(){
return this.o2;
}
public LinkedList getMatchings(){
return this.list;
}
public int getConceptMatchingNumber(){
int result = 0;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP() instanceof ConceptType) result++;
}
return result;
}
public int getRelationMatchingNumber(){
int result = 0;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP() instanceof RelationType) result++;
}
return result;
}
/** Returns the ratio between the number of found concept matchings and those of possible
* concept matchings, that is min(number of concepts in O1,number of concepts in O2). */
public double getConceptMatchingRatio(){
int nb = Math.min(this.o1.getConceptTypes().size(),this.o2.getConceptTypes().size());
if(nb != 0) return this.getConceptMatchingNumber()/nb;
else return 0;
}
/** Returns the ratio between the number of found relation matchings and those of possible
* relation matchings, that is min(number of relations in O1,number of relations in O2). */
public double getRelationMatchingRatio(){
int nb = Math.min(this.o1.getRelationTypes().size(),this.o2.getRelationTypes().size());
if(nb != 0) return this.getRelationMatchingNumber()/nb;
else return 0;
}
/** Returns the matching (cp1,cp2) if it exists in the list, null otherwise. */
public Matching match(ConceptualPrimitive cp1,ConceptualPrimitive cp2){
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
return m;
}
}
return null;
}
/** Add nb times the weight of abstraction to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithAbstraction(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateAbstractionWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateAbstractionWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of disjunction to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithDisjunction(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateDisjunctionWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateDisjunctionWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of incompatibility to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithIncompatibility(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateIncompatibilityWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateIncompatibilityWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of exclusivity to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithExclusivity(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateExclusivityWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateExclusivityWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of symmetry to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithSymmetry(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateSymmetryWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateSymmetryWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of transitivity to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithTransitivity(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateTransitivityWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateTransitivityWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of reflesivity to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithReflexivity(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateReflexivityWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateReflexivityWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of irreflesivity to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithIrreflexivity(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateIrreflexivityWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateIrreflexivityWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of antisymmetry to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithAntisymmetry(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateAntisymmetryWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateAntisymmetryWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of cmin to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithCmin(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateCminWeight(nb);
exists = true;
}
}
if(!exists){
Matching newMatching = new Matching(cp1,cp2);
newMatching.updateCminWeight(nb);
this.list.add(newMatching);
}
}
/** Add nb times the weight of cmax to the weight of the matchings (cp1,cp2).
* Creates the matching with this weight if it does not exist. */
public void updateMatchingWithCmax(ConceptualPrimitive cp1,ConceptualPrimitive cp2,int nb){
boolean exists = false;
for(Iterator i = this.list.iterator();i.hasNext();){
Matching m = (Matching) i.next();
if(m.getFirstCP().equals(cp1) && m.getSecondCP().equals(cp2)){
m.updateCmaxWeight(nb);
exists = true;
}
}
if(!exists){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -