How are you?
I'm doing a small project, but I'm stuck in this part.
Use a stringtokenizer to separate a text file and use a class enum
to assign the tokens the value with regular expressions. That's fine, but I need to evaluate when a value is already assigned and give a message on the screen.
public enum Tipo1
{
funcion(1), String(2),
sepgenero(3), entero(4),
funciongenero(5), funcionartista(6),
funcionfavorito(7), maximogenero(8),
maximoartista(9), maximofavorito(10),
validacion(11),gauss(12),
salida(13),separtista(14),sepnombre(15),separador(16),salto(17),genero(18),artista(19),nombre(20),album(21), ;
private int valor1;
private Tipo1 (int valor1){
this.valor1 = valor1;
}
public int getvalor1() {
return valor1;
}
}
archivos a=new archivos();
String s1= a.leertxt("->.rock:.;.Stones;.;.paintitblack|.|.black,.,.");
StringTokenizer st = new StringTokenizer(s1,"[.]");{
System.out.println("SEMANTICO");
while(st.hasMoreTokens()) {
String jugador= st.nextToken();
ArrayList<String> tokens = new ArrayList<String>();
Scanner tokenize = new Scanner(jugador);
while (tokenize.hasNext()) {
tokens.add(tokenize.next());
System.out.println(tokens);
Map<Sintactico.Tipo1, String> treeMap = new TreeMap<Sintactico.Tipo1, String>();
treeMap.put(Tipo1.funcion, "[->]+");
treeMap.put(Tipo1.genero, "[a-zA-Z\s]+[:]+");
treeMap.put(Tipo1.artista, "[a-zA-Z\s]+[;]");
treeMap.put(Tipo1.nombre, "[a-zA-Z\s]+[|]");
treeMap.put(Tipo1.album, "[a-zA-Z\s]+[,]");
treeMap.put(Tipo1.sepgenero, "[:]+");
treeMap.put(Tipo1.separtista, "[;]+");
treeMap.put(Tipo1.sepnombre, "[|]+");
treeMap.put(Tipo1.separador, "[,]+");
treeMap.put(Tipo1.entero, "[0-9]+");
treeMap.put(Tipo1.funciongenero, "[!Genero]+");
treeMap.put(Tipo1.funcionartista, "[!Artista]+");
treeMap.put(Tipo1.funcionfavorito, "[!Favorito]+");
treeMap.put(Tipo1.maximogenero, "[~Genero]+");
treeMap.put(Tipo1.maximoartista, "[~Artista]+");
treeMap.put(Tipo1.maximofavorito, "[~Favorito]+");
treeMap.put(Tipo1.validacion, "[>>+[¶]+]+");
treeMap.put(Tipo1.gauss, "[+]+");
treeMap.put(Tipo1.salida, "[<-]+");
treeMap.put(Tipo1.salto, "[\s]+");
Iterator<Tipo1> it = treeMap.keySet().iterator();
for(Tipo1 t:treeMap.keySet()){
String cr=treeMap.get(t);
String cr1=treeMap.get(Tipo1.artista);
Tipo1 key = it.next();
if(jugador.matches(cr)){
System.out.println(key);
}
}
And this is the result:
SEMANTICO
[->]
funcion
[rock:]
genero
[;]
separtista
lleva
[Stones;]
artista
[;]
separtista
lleva
[paintitblack|]
nombre
[|]
sepnombre
[black,]
album
[,]
separador
How do I evaluate when more than one separator appears, for example?
I appreciate any advice.