Foros del Web » Programación para mayores de 30 ;) » Java »

Backward Oracle Matching Java

Estas en el tema de Backward Oracle Matching Java en el foro de Java en Foros del Web. hola amigos, lo que pasa que necesito ayuda con este codigo, ya tengo buena parte del codigo y si busca el patron solicitado en un ...
  #1 (permalink)  
Antiguo 29/11/2011, 18:17
 
Fecha de Ingreso: noviembre-2011
Ubicación: Zacatecas
Mensajes: 2
Antigüedad: 12 años, 5 meses
Puntos: 0
Exclamación Backward Oracle Matching Java

hola amigos, lo que pasa que necesito ayuda con este codigo, ya tengo buena parte del codigo y si busca el patron solicitado en un texto predeterminado, el problema es que cuando ingresas espacios en el texto predeterminado, aunque en el patron no lo solicites, el codigo tira error ya probe de distintas formas y no puedo solucionar el problema aqui les dejo el codigo para ver si me pueden ayudar

import javax.swing.JOptionPane;

public class BOM{

static int teta = 1000;//teta
static int k = teta;
static int s = teta;
static int pos = 0;
static int current = 0;

public static void main(String[] args){

String texto = JOptionPane.showInputDialog(null, "Ingrese el Texto de Entrada", "BOM", 1);//"AGATACGATATATAC";//input text
String patron = JOptionPane.showInputDialog(null, "Ingrese el Patron a Buscar", "BOM", 1);//"ATATA";//Backward pattern

//mensaje
int n = texto.length();
int m = patron.length();
int lengthAscii = 255;
int states[] = new int[m + 1];
int transitions[][] = new int[m + 1][lengthAscii];

for (int i = 0; i <= m ; i++){
states[i] = teta;
for (int j = 0; j < lengthAscii; j++){
transitions[i][j] = teta;
}
}

for (int j = 1; j <= m; j++){
oracle_add_letter(states, transitions, j - 1, patron.charAt(j - 1));
}

//searching
pos = 0;
while (pos <= n - m){
current = 0;
int j = m;

while(j > 0 && current != teta){
int textPos = Character.getNumericValue(texto.charAt(pos + j));
current = transitions[current][textPos];
j = j - 1;
}

if(current != teta){
System.out.println("El Patron Aparece en la Posicion: " + (pos + 1));
}

pos = pos + j + 1;
}
}

private static void oracle_add_letter(int[] states, int[][] transitions, int m, char sigma){
int sigmaNum = Character.getNumericValue(sigma);

transitions[m][sigmaNum] = m + 1;
k = states[m];

while (k != teta && transitions[k][sigmaNum] == teta){
transitions[k][sigmaNum] = m + 1;
k = states[k];
}

if (k == teta) s = 0;
else s = transitions[k][sigmaNum];
states[m + 1] = s;
}
}
  #2 (permalink)  
Antiguo 13/02/2012, 17:24
 
Fecha de Ingreso: febrero-2012
Ubicación: Zacatecas
Mensajes: 1
Antigüedad: 12 años, 2 meses
Puntos: 0
Respuesta: Backward Oracle Matching Java

Chuy Benitez, nadie te ayudo!! jaja, weno, esta es una traduccion que hice en su momento de un Codigo hecho en C
public class Bom{
private final char TRUE = (char) 1;
private final int UNDEFINED = -1;
void Bom(String patron, String texto){
int i, j, p, period = 0, q, shift;
int m = patron.length();
int n = texto.length();
char y[] = texto.toCharArray();
char T[] = new char[m + 1];
List L[] = new List[m + 1];
oracle(patron,T,L);

j = 0;
while (j <= n - m) {
i = m - 1;
p = m;
shift = m;
while (i + j >= 0 &&
(q = getTransition(patron, p, L, y[i + j])) != UNDEFINED) {
p = q;
if (T[p] == TRUE) {
period = shift;
shift = i;
}
i--;
}
if (i < 0) {
System.out.println("Encontrado en: " + j);
shift = period;
}
j += shift;
}
}
void oracle(String patron, char T[], List L[]){
int i, p, q = 0, m = patron.length();
int S[]= new int[m+1];
char c;
S[m] = m + 1;
for (i = m; i > 0; --i){
c = patron.charAt(i -1);
p = S[i];
while (p <= m &&
(q = getTransition(patron, p, L, c)) == UNDEFINED){

setTransition(p, i - 1, L);
p = S[p];
}
S[i - 1] = (p == m + 1 ? m: q);
}
p = 0;
while (p <= m) {
T[p] = TRUE;
p = S[p];
}
}
int getTransition(String patron, int p, List L[], char c){
List cell;
char x[] = patron.toCharArray();
if (p > 0 && x[p -1] == c){
return (p - 1);
}
else{
cell = L[p];
while (cell != null) {
if (x[cell.element] == c) {
return (cell.element);
}
else {
cell = cell.next;
}
}
return UNDEFINED;
}
}
void setTransition(int p, int q, List L[]){
List cell = new List();
cell.element = q;
cell.next = L[p];
L[p] = cell;
}
public static void main(String args[]) {
Bom busqueda = new Bom();
busqueda.Bom("Java", "Java apesta, y Java es una isla de Indonesia, ironico que aun traduzca para Java");
}
}
public class List {
int element=0;
List next;
}

Etiquetas: oracle, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:55.