1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
package EvalClass;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.*;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
public class Utilitaire {
static HashMap<String, Set<String>> G = new HashMap<String, Set<String>>() ;
static HashMap<String, Set<String>> ConeptsRef= new HashMap<String, Set<String>>() ;
static Set<String> ClassesSys= null;
static HashMap<String, HashMap<String, Set<String>>> H = new HashMap<String, HashMap<String, Set<String>>> () ;
static SemanticClass sc = new SemanticClass("", null);
public static float CalculPrecisionParClasse(int similarCorrect,int sizeCSys){
float p = 0;
p = (float)similarCorrect / sizeCSys;
return p;
}
public static float CalculRappelParClasse(int similarCorrect,int sizeCRef){
float r = 0;
r = (float)similarCorrect / sizeCRef;
return r;
}
public static float CalculFMesureParClasse(float p, float r){
float fmesure = 0;
float a = 2 * p * r;
float b = p + r;
fmesure = a / b;
return fmesure;
}
public static HashMap <String, HashMap<Set<String>,HashMap<Set<String> , Float>>> ConstructionMatrixChaqueSysteme (String sys, HashMap<Set<String>,HashMap<Set<String> , Float>> correspCRCS){
HashMap <String, HashMap<Set<String>,HashMap<Set<String> , Float>>> matrixSys = new HashMap <String, HashMap<Set<String>,HashMap<Set<String> , Float>>>();
matrixSys.put(sys, correspCRCS);
return matrixSys;
}
public static boolean trouve (Set<String> set,String a)
{
return(set.contains(a));
}
/// degré de similarité entre deux classes
public static void similaires(Set<String> C, HashMap<String, Set<String>> D, String sys)
{
int CSimilarToD = 0;
float p ;
float r ;
float fmesure ;
HashMap<Set<String> , Float> coupleCRfmesure = new HashMap<Set<String> , Float>();
HashMap<Set<String>,HashMap<Set<String> , Float>> correspCRCS = new HashMap<Set<String>,HashMap<Set<String> , Float>>();
HashMap <String, HashMap<Set<String>,HashMap<Set<String> , Float>>> matrixSys = new HashMap <String, HashMap<Set<String>,HashMap<Set<String> , Float>>>();
Iterator <Set<String>> i = D.values().iterator();
Set<String> label =null;
boolean LabelDansListe;
String a="";
ArrayList<Object> liste = new ArrayList<Object>();
while (i.hasNext())
{
int SimilarCorrect = 0;
label = i.next();
LabelDansListe = false ;
Iterator<String> j = C.iterator();
while(j.hasNext()){
a = j.next();
if((trouve(label, a))){
LabelDansListe = true;
SimilarCorrect++;
}
}
if(SimilarCorrect!=0){//trouver des correspondant dans cette référence E
p = CalculPrecisionParClasse(SimilarCorrect, C.size());
r = CalculRappelParClasse(SimilarCorrect, label.size());
fmesure = CalculFMesureParClasse(p,r);
coupleCRfmesure.put(label, fmesure);
CSimilarToD++;//incrémente le compteur pour la suite
}
}
System.out.println(C);
System.out.println(" Contenu Hashmap CR - fmesure : ");
System.out.println(coupleCRfmesure.entrySet());
correspCRCS.put(C, coupleCRfmesure);
System.out.println(" Contenu Hashmap CS - CR - fmesure : ");
System.out.println(correspCRCS.entrySet());
matrixSys = ConstructionMatrixChaqueSysteme(sys, correspCRCS);
System.out.println(" Contenu de système : " + sys);
System.out.println(matrixSys.entrySet());
System.out.println("nombre de classes correspondantes : " + CSimilarToD);
}
public static void correspondanceRefSys (HashMap<String, Set<String>> G, Set<String> E, String sys ) throws IOException{
/****************** Phase de comparaison Classe / concept******************/
System.out.println("******** Comparaison Classe / Concept **************");
similaires(E,G, sys);
}
public static void main(String[] args) throws IOException {
try
{//load les fichiers .owl et .txt d'un répertoire
String path = System.getProperty("user.dir") + "\\data";
String filtre = "(\\w*_\\d*)";
String [] s = new File(path).list();
for (int i=0; i<s.length;i++){
// create an empty model
OntModel model = ModelFactory.createOntologyModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(path + "\\" + s[i]);
if (in == null) {throw new IllegalArgumentException("File: " + s[i] + " not found");}
G = sc.extractSemanticClass(s[i],model,in,path);
H.put(s[i],G);
}
for (int i =0; i<s.length;i++){
if (!(s[i].equals("OntoRef.owl"))){
System.out.println("Le système : " + s[i]);
Iterator<Set<String>> j = H.get(s[i]).values().iterator();
while (j.hasNext()){
ConeptsRef = H.get("OntoRef.owl");
correspondanceRefSys(ConeptsRef, ClassesSys, s[i]);
}
}
}
}
catch (PatternSyntaxException pse)
{
pse.printStackTrace();
}
}
} |
Partager