greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 16348

Show
Ignore:
Timestamp:
2008-07-11 09:15:15 (4 months ago)
Author:
kjdon
Message:

indented the code with smaller indents in preparation for some modifications

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • indexers/trunk/mgpp/java/org/greenstone/mgpp/Queryer.java

    r4215 r16348  
    2020  public void printHelp() { 
    2121         
    22        System.out.println( "commands available are:\n"+ 
    23                             "\t.q\t\tquit\n"+ 
    24                             "\t.h\t\tprint this help message\n"+ 
    25                             "\t.d\t\tprint the current query parameter settings\n" + 
    26                             "\t.i<level>\tchange the search level to level\n"+ 
    27                             "\t.l<level>\tchange the result level to level\n"+ 
    28                             "\t.r0/.r1\t\tranking off/on\n"+ 
    29                             "\t.t0/.t1\t\tquery type some/all\n"+ 
    30                             "\t.c0/.c1\t\tcasefolding off/on\n"+ 
    31                             "\t.s0/.s1\t\tstemming off/on\n"+ 
    32                             "\t.o0/.o1\t\tshort output off/on\n"+ 
    33                             "\t.m<num>\t\tset max docs to return to num\n\n"+ 
    34                             "\t.p<docnum>\tprint document docnum\n"+ 
    35                             "\t<query string>\t do a query\n"); 
    36    
     22    System.out.println( "commands available are:\n"+ 
     23                        "\t.q\t\tquit\n"+ 
     24                        "\t.h\t\tprint this help message\n"+ 
     25                        "\t.d\t\tprint the current query parameter settings\n" + 
     26                        "\t.i<level>\tchange the search level to level\n"+ 
     27                        "\t.l<level>\tchange the result level to level\n"+ 
     28                        "\t.r0/.r1\t\tranking off/on\n"+ 
     29                        "\t.t0/.t1\t\tquery type some/all\n"+ 
     30                        "\t.c0/.c1\t\tcasefolding off/on\n"+ 
     31                        "\t.s0/.s1\t\tstemming off/on\n"+ 
     32                        "\t.o0/.o1\t\tshort output off/on\n"+ 
     33                        "\t.m<num>\t\tset max docs to return to num\n\n"+ 
     34                        "\t.p<docnum>\tprint document docnum\n"+ 
     35                        "\t<query string>\t do a query\n"); 
     36 
    3737 
    3838    
    39     public static void main(String[] args) { 
    40         if (args.length != 3) { 
    41             System.out.println("Usage: java org.greenstone.mgpp.Queryer <basedir> <indexdir> <textdir>"); 
    42             return; 
     39  public static void main(String[] args) { 
     40    if (args.length != 3) { 
     41      System.out.println("Usage: java org.greenstone.mgpp.Queryer <basedir> <indexdir> <textdir>"); 
     42      return; 
     43    } 
     44         
     45    Queryer self = new Queryer(); 
     46         
     47    String base_dir = args[0]; 
     48    String text_path = args[2]; 
     49    String index_path = args[1]; 
     50 
     51    text_path = base_dir + File.separatorChar+text_path; 
     52    index_path = base_dir  + File.separatorChar+ index_path; 
     53         
     54    // the jni class to access mgpp stuff 
     55    MGPPWrapper wrapper = new MGPPWrapper(); 
     56    wrapper.loadIndexData(index_path); 
     57         
     58    // the return level 
     59    String level = "Section"; 
     60 
     61    System.out.println("Welcome to Java Queryer :-)"); 
     62    self.printHelp(); 
     63 
     64    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
     65    boolean shortOutput=false; 
     66 
     67    String command; // user input 
     68    char x; // the command letter 
     69    String data=null; // any auxiliary input to a command 
     70    while (true) { 
     71      System.out.print(">"); // the prompt 
     72      try { 
     73        command = br.readLine(); 
     74        command=command.trim(); 
     75        if (command.startsWith(".")) { 
     76          // a system command 
     77          x = command.charAt(1); 
     78          if (command.length() > 2) { 
     79            data = command.substring(2); 
     80            data = data.trim(); 
     81                         
     82          } 
     83          switch (x) { 
     84          case 'q': // clean up and exit 
     85            wrapper.unloadIndexData(); 
     86            return;   
     87          case 'h': // print help message 
     88            self.printHelp(); 
     89            break; 
     90          case 'd': // print query param settings 
     91            String info = wrapper.getQueryParams(); 
     92            System.out.println(info); 
     93            break; 
     94          case 'p': // print doc 
     95            int docnum = Integer.parseInt(data); 
     96            String doc = wrapper.getDocument(text_path,  
     97                                             level, docnum); 
     98            System.out.println(doc); 
     99            break; 
     100          case 'm': //match docs 
     101            int match = Integer.parseInt(data); 
     102            wrapper.setMaxDocs(match); 
     103            break; 
     104          case 's': // set stem on/off 
     105            int stem = Integer.parseInt(data); 
     106            if (stem==0 ){ 
     107              wrapper.setStem(false); 
     108            } else if(stem==1) { 
     109              wrapper.setStem(true); 
     110            } else { 
     111              System.err.println("Error: stem should be 0 or 1"); 
     112            } 
     113            break; 
     114          case 'c': // set case on/off 
     115            int casef = Integer.parseInt(data); 
     116            if (casef==0) { 
     117              wrapper.setCase(false); 
     118            } else if (casef==1) { 
     119              wrapper.setCase(true); 
     120            } else { 
     121              System.err.println("Error: case should be 0 or 1"); 
     122            } 
     123            break; 
     124          case 'i': // set search level 
     125            wrapper.setQueryLevel(data); 
     126            break; 
     127          case 'l': // set result level 
     128            wrapper.setReturnLevel(data); 
     129            level = data; 
     130            break;  
     131          case 'r': // set rank on/off 
     132            int rank = Integer.parseInt(data); 
     133            if (rank==0) { 
     134              wrapper.setSortByRank(false); 
     135            } else if (rank==1) { 
     136              wrapper.setSortByRank(true); 
     137            } else { 
     138              System.err.println("Error: rank should be 0 or 1"); 
     139            } 
     140            break; 
     141          case 't': // set query type some/all 
     142            int type = Integer.parseInt(data); 
     143            if (type==0 || type==1) { 
     144              wrapper.setMatchMode(type); 
     145            } else { 
     146              System.err.println("Error: type should be 0 (some) or 1 (all)"); 
     147            } 
     148            break; 
     149          case 'o': // set output short/long 
     150            int output = Integer.parseInt(data); 
     151            if (output==0) { 
     152              shortOutput = false; 
     153            } else if (output==1) { 
     154              shortOutput = true; 
     155            }else { 
     156              System.err.println("Error: output should be 0 or 1"); 
     157            } 
     158            break; 
     159          } 
    43160        } 
    44          
    45         Queryer self = new Queryer(); 
    46          
    47         String base_dir = args[0]; 
    48         String text_path = args[2]; 
    49         String index_path = args[1]; 
     161        else { 
     162          // a query 
     163          wrapper.runQuery(command); 
     164          MGPPQueryResult res = wrapper.getQueryResult(); 
     165          if (res.hasSyntaxError()) { 
     166            System.out.println("invalid syntax error\n"); 
     167          } else { 
     168            if (shortOutput) { 
     169              System.out.println(res.toShortString()); 
     170            } else { 
     171              System.out.println(res.toString()); 
     172            } 
     173          } 
     174        } 
     175                     
     176      } catch (Exception e) { 
     177        System.out.println("Queryer error: "+e.getClass() + " "+e.getMessage()); 
     178      } 
    50179 
    51         text_path = base_dir + File.separatorChar+text_path; 
    52         index_path = base_dir  + File.separatorChar+ index_path; 
    53          
    54         // the jni class to access mgpp stuff 
    55         MGPPWrapper wrapper = new MGPPWrapper(); 
    56         wrapper.loadIndexData(index_path); 
    57          
    58         // the return level 
    59         String level = "Section"; 
    60  
    61         System.out.println("Welcome to Java Queryer :-)"); 
    62         self.printHelp(); 
    63  
    64         BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
    65         boolean shortOutput=false; 
    66  
    67         String command; // user input 
    68         char x; // the command letter 
    69         String data=null; // any auxiliary input to a command 
    70         while (true) { 
    71           System.out.print(">"); // the prompt 
    72             try { 
    73                 command = br.readLine(); 
    74                 command=command.trim(); 
    75                 if (command.startsWith(".")) { 
    76                     // a system command 
    77                     x = command.charAt(1); 
    78                     if (command.length() > 2) { 
    79                         data = command.substring(2); 
    80                         data = data.trim(); 
    81                          
    82                     } 
    83                     switch (x) { 
    84                     case 'q': // clean up and exit 
    85                         wrapper.unloadIndexData(); 
    86                         return;   
    87                     case 'h': // print help message 
    88                         self.printHelp(); 
    89                         break; 
    90                     case 'd': // print query param settings 
    91                         String info = wrapper.getQueryParams(); 
    92                         System.out.println(info); 
    93                         break; 
    94                     case 'p': // print doc 
    95                         int docnum = Integer.parseInt(data); 
    96                         String doc = wrapper.getDocument(text_path,  
    97                                                          level, docnum); 
    98                         System.out.println(doc); 
    99                         break; 
    100                     case 'm': //match docs 
    101                         int match = Integer.parseInt(data); 
    102                         wrapper.setMaxDocs(match); 
    103                         break; 
    104                     case 's': // set stem on/off 
    105                         int stem = Integer.parseInt(data); 
    106                         if (stem==0 ){ 
    107                             wrapper.setStem(false); 
    108                         } else if(stem==1) { 
    109                             wrapper.setStem(true); 
    110                         } else { 
    111                             System.err.println("Error: stem should be 0 or 1"); 
    112                         } 
    113                         break; 
    114                     case 'c': // set case on/off 
    115                         int casef = Integer.parseInt(data); 
    116                         if (casef==0) { 
    117                             wrapper.setCase(false); 
    118                         } else if (casef==1) { 
    119                             wrapper.setCase(true); 
    120                         } else { 
    121                             System.err.println("Error: case should be 0 or 1"); 
    122                         } 
    123                         break; 
    124                     case 'i': // set search level 
    125                         wrapper.setQueryLevel(data); 
    126                         break; 
    127                     case 'l': // set result level 
    128                         wrapper.setReturnLevel(data); 
    129                         level = data; 
    130                         break;  
    131                     case 'r': // set rank on/off 
    132                         int rank = Integer.parseInt(data); 
    133                         if (rank==0) { 
    134                             wrapper.setSortByRank(false); 
    135                         } else if (rank==1) { 
    136                             wrapper.setSortByRank(true); 
    137                         } else { 
    138                             System.err.println("Error: rank should be 0 or 1"); 
    139                         } 
    140                         break; 
    141                     case 't': // set query type some/all 
    142                         int type = Integer.parseInt(data); 
    143                         if (type==0 || type==1) { 
    144                             wrapper.setMatchMode(type); 
    145                         } else { 
    146                             System.err.println("Error: type should be 0 (some) or 1 (all)"); 
    147                         } 
    148                         break; 
    149                     case 'o': // set output short/long 
    150                         int output = Integer.parseInt(data); 
    151                         if (output==0) { 
    152                             shortOutput = false; 
    153                         } else if (output==1) { 
    154                             shortOutput = true; 
    155                         }else { 
    156                             System.err.println("Error: output should be 0 or 1"); 
    157                         } 
    158                         break; 
    159                     } 
    160                 } 
    161                 else { 
    162                     // a query 
    163                     wrapper.runQuery(command); 
    164                     MGPPQueryResult res = wrapper.getQueryResult(); 
    165                     if (res.hasSyntaxError()) { 
    166                       System.out.println("invalid syntax error\n"); 
    167                     } else { 
    168                       if (shortOutput) { 
    169                         System.out.println(res.toShortString()); 
    170                       } else { 
    171                         System.out.println(res.toString()); 
    172                       } 
    173                     } 
    174                 } 
    175                      
    176             } catch (Exception e) { 
    177                 System.out.println("Queryer error: "+e.getClass() + " "+e.getMessage()); 
    178             } 
    179  
    180         } 
    181180    } 
     181  } 
    182182 
    183183