Sie sind auf Seite 1von 5

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package meidsclient.

patternmatching; import import import import java.util.ArrayList; java.util.Collections; java.util.List; java.util.Vector;

/** * * @author Student */ public class PatternMatchingAlgorithms { public static Vector<String> Pattern_Partitioning(List<String> T, StringMatc her M) { List<String> t = Sort(T); Vector<String> vec_fsms = new Vector<String>(); while(t.size()>0) { Object[] fsms_t = Pattern_Mapping(t,M); vec_fsms.add((String) fsms_t[0]); t = (List<String>) fsms_t[1]; } return vec_fsms; } public static Object[] Pattern_Mapping(List<String> ST,StringMatcher M) { List<String> t = ST; Tries tries = null; List<String> mapped_t = null; for(int pi=(M.p()-1);pi>=0;pi--) { mapped_t = front(pi,t); tries = M.Build_Tries(mapped_t); if(tries.number_of_states()>=M.s()) { continue; } else { Remove(mapped_t,t); break; } } String dfas = Add_Failing_Pointers(tries,mapped_t); String fsms = Set_PMVs(dfas,mapped_t); return new Object[] { fsms , t}; } private static String Add_Failing_Pointers(Tries tries,List<String> mapped_t ) { String dfas = ""; if(tries.number_of_states()>states(mapped_t)) { State[] states = tries.getStates(); for(int i=states(mapped_t);i>=states.length;i++) { dfas += states[i].toString(); }

} return dfas; } private static String Set_PMVs(String dfas,List<String> mapped_t) { char[] b2 = dfas.toCharArray(); int index=0; String fsms = ""; for(String mapped_t1 : mapped_t) { if(index>=b2.length) break; char[] b = mapped_t1.toCharArray(); for(char b1 : b) { if(b2[index]==b1) { fsms += b1; } } } return fsms; } private static int states(List<String> mapped_t) { int states = 0; for(String mapped_t1 : mapped_t) { states += mapped_t1.length(); } return states; } private static void Remove(List<String> mapped_t,List<String> t) { for(int i=0;i<mapped_t.size();i++) { t.remove(mapped_t.get(i)); } } private static List<String> front(int pi,List<String> t) { List<String> mapped_t = new ArrayList<String>(); for(int i=0;i<pi;i++) { mapped_t.add(t.get(i)); } return mapped_t; } private static List<String> Sort(List<String> T) { Collections.sort(T); return T; } }

/* * To change this template, choose Tools | Templates

* and open the template in the editor. */ package meidsclient.patternmatching; /** * * @author Student */ public class State { private int state; public int getState() { return state; } public void setState(int state) { this.state = state; } }

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package meidsclient.patternmatching; import java.util.List; import java.util.Vector; /** * * @author Student */ public class StringMatcher { private String[] matcher; private String[] pattern; public String[] getMatcher() { return matcher; } public void setMatcher(String[] matcher) { this.matcher = matcher; } public String[] getPattern() { return pattern; } public void setPattern(String[] pattern) { this.pattern = pattern; } public int p() { return pattern.length;

} public int s() { int s = 0; for(int i=0;i<pattern.length;i++) { s += pattern[i].length(); } return s; } public Tries Build_Tries(List<String> mapped_t) { Tries tries = new Tries(); Vector<State> states = new Vector<State>(); for(String mapped_t1 : mapped_t) { char[] pattern = mapped_t1.toCharArray(); boolean contains = false; for(String pattern1 : this.pattern) { char[] b2 = pattern1.toCharArray(); boolean contains1 = true; for(int i=0,j=0;i<pattern.length && j<b2.length;i++,j++) { char b = pattern[i]; if(b2[j]!=b) { contains1 = false; break; } } if(contains1==true) { contains = true; break; } else { contains = false; } } if(contains) for(char p : pattern) { State state = new State(); if(p=='1') { state.setState(1); } else { state.setState(0); } states.add(state); } } State[] states2 = new State[states.size()]; states.toArray(states2); tries.setStates(states2); return tries; } }

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package meidsclient.patternmatching; /** * * @author Student */ public class Tries { private State[] states; public State[] getStates() { return states; } public void setStates(State[] states) { this.states = states; } public int number_of_states() { return states.length; } }

Das könnte Ihnen auch gefallen