View Javadoc

1   package net.sourceforge.jgeocoder.test;
2   import java.io.BufferedReader;
3   import java.io.InputStreamReader;
4   import java.util.concurrent.TimeUnit;
5   
6   import net.sourceforge.jgeocoder.CommonUtils;
7   import net.sourceforge.jgeocoder.JGeocodeAddress;
8   import net.sourceforge.jgeocoder.tiger.JGeocoder;
9   import net.sourceforge.jgeocoder.us.AddressStandardizer;
10  
11  
12  public class JGeocoderParserTestClient {
13    public static void main(String[] args) throws Exception{
14      String in;
15      JGeocoder jg = new JGeocoder();
16      if(args.length != 0){
17        in = args[0];
18        JGeocodeAddress ret  = jg.geocodeAddress(in);
19        long start = System.currentTimeMillis();
20        System.out.println();
21        System.out.println("Parsed: "+ CommonUtils.nvl(AddressStandardizer.toSingleLine(ret.getParsedAddr()), "null"));
22        System.out.println("Normalized: "+ CommonUtils.nvl(AddressStandardizer.toSingleLine(ret.getNormalizedAddr()), "null"));
23        System.out.println("Geocoded: "+ CommonUtils.nvl(AddressStandardizer.toSingleLine(ret.getGeocodedAddr()), "null"));
24        System.out.println(ret.toStringMultiLine());
25        CommonUtils.printElapsed(start, TimeUnit.SECONDS);
26        jg.cleanup();
27        return;
28      }
29      
30      System.out.println("Input raw address as a single line");
31      System.out.println("Enter blank line to end session");
32      System.out.println();
33      
34      BufferedReader inbuf = new BufferedReader(new InputStreamReader(System.in));
35      
36      while ((in = inbuf.readLine()) != null && in.length() != 0){
37        long start = System.currentTimeMillis();
38        System.out.println();
39        JGeocodeAddress ret  = jg.geocodeAddress(in);
40        System.out.println("Parsed: "+ CommonUtils.nvl(AddressStandardizer.toSingleLine(ret.getParsedAddr()), "null"));
41        System.out.println("Normalized: "+ CommonUtils.nvl(AddressStandardizer.toSingleLine(ret.getNormalizedAddr()), "null"));
42        System.out.println("Geocoded: "+ CommonUtils.nvl(AddressStandardizer.toSingleLine(ret.getGeocodedAddr()), "null"));
43        System.out.println(ret.toStringMultiLine());
44        CommonUtils.printElapsed(start, TimeUnit.SECONDS);
45        System.out.println();
46      }
47      jg.cleanup();
48    }
49  
50  }