lamine25000
Messages postés4Date d'inscriptionsamedi 20 octobre 2007StatutMembreDernière intervention25 mars 2011
-
21 avril 2009 à 10:07
lamine25000
Messages postés4Date d'inscriptionsamedi 20 octobre 2007StatutMembreDernière intervention25 mars 2011
-
21 avril 2009 à 17:11
Bonjour
Voila j'ai un probleme avec le remplissage de ma table de transition ,en fait je veux rempir ma table comme une matrice ,j'ai une chaine de caractere séparées par # des que j'arrive a ce dernier il faut que je passe a la ligne suivante pour la remplir ausssi mais le probleme lors de l'execution j'ai q'une seul dimension et j'ai tous sur une meme ligne ,la partie du code qui ne fonctionne pas est entre les 2 lignesVoici mon code:
public class paris{
private int maxtransit;
private int maxcomponent = 7;
String AutomatonFileTxtName;
public Vector[][] transrule;
private int nbrTransRules;
static String str="a,a,a p p l e,2, ,p,ap,a p p l e,4,#,p,app,a p p l e,5,#,l,appl,a p p l e,7,#,e,apple,a p p l e,8,#,a,a,a p p l e,2,#,p,ap,a p p l e,4,#,p,app,a p p l e,5,#,l,appl,a p p l e,7,#,e,apple,a p p l e,8,#,s,apples,a p p l e s 9,#,p,p,p l y,3,#,l,pl,p l y,6,#,y,ply,p l y,9,#,p,p,p a l y,3,#,a,pa,p a l y,5,#,l,pal,p a l y,7,#,y,paly,p a l y,9";
/**@Constructeur */
/* transrule[i][0]: est un vecteur contenat le label
* transrule[i][1]:contient l'enchainement du mot
* transrule[i][2]: est un vecteur contenat l'expression reg
* transrule[i][3]: est un vecteur contenat les etats
* appartenant a transrule[i][1]
*/
public paris(int maxtrans, String str1){
this.maxtransit=maxtrans;
this.transrule = new Vector[maxtransit][maxcomponent];
this.AutomatonFileTxtName=str1;
this.SetTreeAutomata(str1);
//this.RegExpToFSA();
}
/**@intialize(): crée la table de transition @Transrule*/
public void initialize(){
// System.out.println("initialize" );
for (int i=0; i<=(maxtransit-1); i++)
{
for (int j = 0; j <= (maxcomponent-1); j++)
transrule[i][j] = new Vector();
}
System.out.println("initialize" );
}
/**@SetTreeAutomata:
* A partir d'une chaine de caracteres "str", cette procédure va remplir
* la table de transition @transrule
*/
public void SetTreeAutomata(String str2){
System.out.println("SetTreeAutomata" );
initialize();
int cnt = 0;
if (str2.length() == 0) {
System.err.println(" Missing sequence " );
System.exit(1);
}
System.out.println("if" ); while (str2!null){ StringTokenizer st=new StringTokenizer(str2,"," );
int j=0;
System.out.println("while str2" );
while (st.hasMoreTokens()){
String x1= st.nextToken();
String x=x1.toLowerCase();
//if (x.equals("#" )) transrule[cnt][j].add(new String("" ));
// else
if (!x.equals("#" ))
transrule[cnt][j].add(new String (x));
else cnt++;
// System.out.println("if equals" );
j++;
====================================================
System.out.println(transrule[0][1]);
}
Twinuts
Messages postés5375Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention14 juin 2023111 21 avril 2009 à 13:04
Salut,
pourquoi ne pas faire l'inverse ? soit chercher dans un premier temps les '#' puis les ',' ?
genre :
import java.util.StringTokenizer;
import java.util.Vector;
public class Test {
static String str1 = "a,a,a p p l e,2, ,p,ap,a p p l e,4,#,p,app,a p p l e,5,#,l,appl,a p p l e,7,#,e,apple,a p p l e,8,#,a,a,a p p l e,2,#,p,ap,a p p l e,4,#,p,app,a p p l e,5,#,l,appl,a p p l e,7,#,e,apple,a p p l e,8,#,s,apples,a p p l e s 9,#,p,p,p l y,3,#,l,pl,p l y,6,#,y,ply,p l y,9,#,p,p,p a l y,3,#,a,pa,p a l y,5,#,l,pal,p a l y,7,#,y,paly,p a l y,9";
//j'ai juste ajouté des trous en début et en fin pour montrer la dif
static String str2 = ",a,a,a p p l e,2, ,p,ap,a p p l e,4,#,p,app,a p p l e,5,#,l,appl,a p p l e,7,#,e,apple,a p p l e,8,#,a,a,a p p l e,2,#,p,ap,a p p l e,4,#,p,app,a p p l e,5,#,l,appl,a p p l e,7,#,e,apple,a p p l e,8,#,s,apples,a p p l e s 9,#,p,p,p l y,3,#,l,pl,p l y,6,#,y,ply,p l y,9,#,p,p,p a l y,3,#,a,pa,p a l y,5,#,l,pal,p a l y,7,#,y,paly,p a l y,9,##,";
// changé par un Vector de Vector de String ce qui garde plus l'intérêt d'utiliser une collection plutôt qu'un tableau...
public Vector<Vector<String>> transrule = null;
public void initialize() {
//pour les 2 tests
if(transrule != null) {
transrule.clear();
transrule = null;
}
transrule = new Vector<Vector<String>>();
// blabla
}
public void setTreeAutomataWithStringTokenizer(String str) {
System.out.println("setTreeAutomata" );
initialize();
if (str.length() == 0) {
System.err.println(" Missing sequence " );
System.exit(1);
}
StringTokenizer st1 = new StringTokenizer(str,"#" );
while (st1.hasMoreTokens()) {
StringTokenizer st2 = new StringTokenizer(st1.nextToken(), ",");
Vector<String> vec = new Vector<String>();
while(st2.hasMoreTokens()) vec.add(st2.nextToken());
transrule.add(vec);
}
}
public void setTreeAutomataWithSplit(String str) {
System.out.println("setTreeAutomata" );
initialize();
if (str.length() == 0) {
System.err.println(" Missing sequence " );
System.exit(1);
}
String [] split1 = str.split("#");
for (String s1 : split1) {
String [] split2 = s1.split(",");
Vector<String> vec = new Vector<String>();
for (String s2 : split2) vec.add(s2);
transrule.add(vec);
}
}
public void print() {
System.out.println("transrule.size() : " + transrule.size());
int n = 0;//juste pour l'affichage
for(Vector<String> vec : transrule) {
System.out.println("vec[" + (n++) + "].size() : " + vec.size());
int i = 0;//juste pour l'affichage
for(String s : vec)
System.out.println("item["+ (i++) + "] : " + s);
}
System.out.println();
System.out.println();
}
public static void main(String[] args) {
Test t = new Test();
t.setTreeAutomataWithStringTokenizer(str1);
//affichage
t.print();
t.setTreeAutomataWithSplit(str1);
//affichage
t.print();
}
}
------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."
lamine25000
Messages postés4Date d'inscriptionsamedi 20 octobre 2007StatutMembreDernière intervention25 mars 2011 21 avril 2009 à 17:11
Cool ça marche merci mais le probleme qui se pose maintenant c'est que je ne sais pas manipuler cette structure avant je manipuler un tableau de Vecteur
String q = state.nextToken();
transrule[cnt][5].add(
new String(q))
RunAutomaton RA =