| Home >> All >> org >> alicebot >> server >> core >> [ util Javadoc ] |
Source code: org/alicebot/server/core/util/InputNormalizer.java
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov. 2 // Jad home page: http://www.geocities.com/kpdus/jad.html 3 // Decompiler options: packimports(3) 4 5 package org.alicebot.server.core.util; 6 7 import java.text.StringCharacterIterator; 8 import java.util.*; 9 10 // Referenced classes of package org.alicebot.server.core.util: 11 // Toolkit 12 13 public class InputNormalizer 14 { 15 16 public InputNormalizer() 17 { 18 } 19 20 public static ArrayList sentenceSplit(ArrayList arraylist, String s) 21 { 22 ArrayList arraylist1 = new ArrayList(); 23 int i = s.length(); 24 if(i == 0) 25 { 26 arraylist1.add(""); 27 return arraylist1; 28 } 29 ArrayList arraylist2 = new ArrayList(); 30 for(Iterator iterator = arraylist.iterator(); iterator.hasNext();) 31 { 32 String s1 = (String)iterator.next(); 33 for(int j = s.indexOf(s1); j != -1; j = s.indexOf(s1, j + 1)) 34 arraylist2.add(new Integer(j)); 35 36 } 37 38 if(arraylist2.size() == 0) 39 { 40 arraylist1.add(s); 41 return arraylist1; 42 } 43 Collections.sort(arraylist2); 44 ListIterator listiterator = arraylist2.listIterator(); 45 int l; 46 for(int k = ((Integer)listiterator.next()).intValue(); listiterator.hasNext(); k = l) 47 { 48 l = ((Integer)listiterator.next()).intValue(); 49 if(l == k + 1) 50 { 51 listiterator.previous(); 52 listiterator.previous(); 53 listiterator.remove(); 54 } 55 } 56 57 listiterator = arraylist2.listIterator(); 58 int i1 = 0; 59 int j1 = i - 1; 60 while(listiterator.hasNext()) 61 { 62 int k1 = ((Integer)listiterator.next()).intValue(); 63 arraylist1.add(s.substring(i1, k1 + 1).trim()); 64 i1 = k1 + 1; 65 } 66 if(i1 < i - 1) 67 arraylist1.add(s.substring(i1).trim()); 68 return arraylist1; 69 } 70 71 public static String patternFit(String s) 72 { 73 s = Toolkit.removeMarkup(s); 74 StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s); 75 StringBuffer stringbuffer = new StringBuffer(s.length()); 76 for(char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next()) 77 if(!Character.isLetterOrDigit(c) && c != '*' && c != '_') 78 stringbuffer.append(' '); 79 else 80 stringbuffer.append(Character.toUpperCase(c)); 81 82 return Toolkit.filterWhitespace(stringbuffer.toString()); 83 } 84 85 public static String patternFitIgnoreCase(String s) 86 { 87 s = Toolkit.removeMarkup(s); 88 StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s); 89 StringBuffer stringbuffer = new StringBuffer(s.length()); 90 for(char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next()) 91 if(!Character.isLetterOrDigit(c)) 92 stringbuffer.append(' '); 93 else 94 stringbuffer.append(c); 95 96 return Toolkit.filterWhitespace(stringbuffer.toString()); 97 } 98 99 private static final String EMPTY_STRING = ""; 100 }