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
| public class PrgMain {
public Vector conceptname=new Vector();
public String patidfile;
public String pathcpt;
public PrgMain(String pathconceptfile) {
this.pathcpt=pathconceptfile;
}
//cette mèthode récupère tous les concepts à partir du fichier Z:\\conceot\\conceptname.xml et les mettre dans un vecteur////////
//////////////////******************************************************************************************************/////////
public Vector getConceptName (String pathfile){
org.jdom.Document document;
Element racine;
String in;
pathfile=this.pathcpt;
SAXBuilder sxb = new SAXBuilder();
try
{
//On crée un nouveau document JDOM avec en argument le fichier XML
//Le parsing est terminé ;
System.out.println(pathfile);
document = sxb.build(new File(pathfile));
racine=document.getRootElement();
List listConcept =racine.getChildren("Name");
//On crée un Iterator sur notre liste
Iterator i = listConcept.iterator();
while(i.hasNext())
{
//On recrée l'Element courant à chaque tour de boucle afin de
//pouvoir utiliser les méthodes propres aux Element comme :
//selectionner un noeud fils, modifier du texte, etc...
Element courant = (Element)i.next();
//On affiche le nom de l'element courant
in=courant.getText();
conceptname.addElement(in);
}
}
catch(Exception e){}
return conceptname;
}
///cette mèthode génére les vecteurs pour chque patent qui contiennent les fréquences de chaque concept
public String [] [] FrequencyConcept(Vector vec , String patidfile , int nb){
String [][]matconcept = null;
org.jdom.Document document2;
Element racine2;
Boolean ok =false;
String in;
Element courant = null;
String freq;
int freq1;
SAXBuilder sxb2 = new SAXBuilder();
try
{
System.out.println(patidfile);
document2 = sxb2.build(new File(patidfile));
System.out.println("je parseeeeeeeeeeeeeeeee");
racine2=document2.getRootElement();
List listConcept =racine2.getChildren("Concept");
Iterator i = listConcept.iterator();
for (int l=0; l < vec.size(); l++) {
System.out.println(vec.elementAt(l));
while ((i.hasNext()) && (ok==false))
{
courant = (Element)i.next();
in=( (Element) courant.getChildren("Name")).getText();
if (in.equals(vec.elementAt(l))) { ok=true;}
}
if (ok==false) {matconcept[nb][l]="0"; }
else { freq = ((Element) courant.getChildren("frequency")).getText();
matconcept[nb][l]=freq;}
nb++;
}
}
catch(Exception e){}
return matconcept;
}
public void SimlpeKmeans(String pathpatentnumber, String Result ){
String [][]mat;
String name;
String number;
Vector vect=new Vector();
Vector dataPoints = new Vector();
vect= getConceptName (this.pathcpt);
org.jdom.Document document;
Element racine;
SAXBuilder sxb = new SAXBuilder();
try
{
document = sxb.build(new File(pathpatentnumber));
racine=document.getRootElement();
List listConcept =racine.getChildren("Number");
Iterator i = listConcept.iterator();
int l=0;
while (i.hasNext())
{ Vector petitvect = new Vector();
Element courant = (Element)i.next();
number= courant.getText();
System.out.println("voici le patent:"+number);
this.patidfile=Result+"/"+number+"/"+number.replaceAll(",", "")+".xml";
mat=FrequencyConcept(vect,this.patidfile,l);
for(int p=0; p < mat[0].length ; p++){
petitvect.addElement(mat[l][p]);
}
l++;
dataPoints.add(new PatentData(petitvect,number));
}
}catch(Exception e){}
SimpleKmeans jca = new SimpleKmeans(5,1000,dataPoints);
jca.startAnalysis();
Vector[] v = jca.getClusterOutput();
for (int i=0; i<v.length; i++){
Vector tempV = v[i];
System.out.println("-----------Cluster"+i+"---------");
Iterator iter = tempV.iterator();
while(iter.hasNext()){
PatentData dpTemp = (PatentData)iter.next();
}
}
} |
Partager