Skip to content

Commit

Permalink
Final Summer update for JGeocoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyzheng authored and GraylinKim committed Oct 17, 2012
1 parent af13af1 commit 2029f1c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 62 deletions.
Expand Up @@ -95,14 +95,15 @@ public TigerQueryFailedException(Throwable cause) {
class TigerLineDao{


private static final String TIGER_QUERY = "select t.tlid, t.fraddr, t.fraddl, t.toaddr, t.toaddl,"+
" t.zipL, t.zipR," +
//" t.tolat, t.tolong, t.frlong, t.frlat,"+
private static final String TIGER_QUERY = "SELECT *"+
/*"select t.tlid, t.fraddr, t.fraddl, t.toaddr, t.toaddl,"+
" t.zipL, t.zipR, " +
//" t.tolat, t.tolong, t.frlong, t.frlat,"+
"t.bbox, t.latlongpairs, t.fullname"+
//" t.fedirp, t.fetype, t.fedirs " +
" from TIGER_{0} t where (t.zipL = ? or t.zipR = ?) and t.fullname regexp ? and "+
" t.fedirp, t.fetype, t.fedirs " +*/
" from TIGER_{0} t where t.fename = ? and (t.zipL = ? or t.zipR = ?) and"+
"(" +
" (t.fraddL <= ? and t.toaddL >= ?) or (t.fraddL >= ? and t.toaddL <= ?) "+
"(t.fraddL <= ? and t.toaddL >= ?) or (t.fraddL >= ? and t.toaddL <= ?) "+
" or (t.fraddR <= ? and t.toaddR >= ?) or (t.fraddR >= ? and t.toaddR <= ?))";
private DataSource _tigerDs;
public TigerLineDao(DataSource tigerDs){
Expand Down Expand Up @@ -193,9 +194,9 @@ public List<TigerLineHit> getTigerLineHits(Map<AddressComponent, String> normali

ps = conn.prepareStatement(generateSelectQuery(normalizedAddr.get(AddressComponent.STATE)));
int i=1;
ps.setString(i++, normalizedAddr.get(AddressComponent.STREET));
ps.setString(i++, zip);
ps.setString(i++, zip);
ps.setString(i++, (".*"+normalizedAddr.get(AddressComponent.STREET)+".*"));
ps.setString(i++, streetNum);
ps.setString(i++, streetNum);
ps.setString(i++, streetNum);
Expand Down Expand Up @@ -236,12 +237,9 @@ public List<TigerLineHit> getTigerLineHits(Map<AddressComponent, String> normali
hit.frLat = new Float(firstpairPieces[1]);
hit.toLon = new Float(lastpairPieces[0]);
hit.toLat = new Float(lastpairPieces[1]);
String fullname = ("103 "+rs.getString("fullname")+" "+hit.zipL);
Map<AddressComponent, String> m = AddressParser.parseAddress(fullname);
m = AddressStandardizer.normalizeParsedAddress(m);
hit.fedirp = m.get(PREDIR);
hit.fedirs = m.get(POSTDIR);
hit.fetype = m.get(TYPE);
hit.fedirp = rs.getString("fedirp");
hit.fedirs = rs.getString("fedirs");
hit.fetype = rs.getString("fetype");
ret.add(hit);
}
} catch (Exception e) {
Expand All @@ -260,4 +258,4 @@ private static String generateSelectQuery(String state){
}
return MessageFormat.format(TIGER_QUERY, state);
}
}
}
@@ -1,56 +1,36 @@
/**
*
*/
package net.sourceforge.jgeocoder.tiger
import org.junit.Test
import org.junit.runner.JUnitCore
import net.sourceforge.jgeocoder.AddressComponent
import net.sourceforge.jgeocoder.JGeocodeAddress
package net.sourceforge.jgeocoder.tiger;

import java.util.concurrent.TimeUnit;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import net.sourceforge.jgeocoder.CommonUtils;
import net.sourceforge.jgeocoder.JGeocodeAddress;
import net.sourceforge.jgeocoder.tiger.H2DbDataSourceFactory;
import net.sourceforge.jgeocoder.tiger.JGeocoder;
import net.sourceforge.jgeocoder.tiger.JGeocoderConfig;
/**
* @author jliang
* @author Bobby Zheng
*
*/
public class JGeocoderTest{
def input ="""Google Inc, 1600 Amphitheatre Parkway, Mountain View, 94043
Google Ann Arbor, 112 S. Main St., 2nd Floor, Ann Arbor, MI 48104
Millennium at Midtown, 10 10th Street NE, Suite 600, GA 30309
Plaza 7000, 7000 North MoPac Expressway, 2nd Floor, Austin, TX 78731
Google Boulder, 2590 Pearl Street, Suite 100, 80302
Google Cambridge, 5 Cambridge Center, Floors 3-6, Cambridge, MA 02142
Google Chicago, 20 West Kinzie St., Chicago, IL 60610
Google Coppell, 701 Canyon Drive, Suite 120, Coppell, TX 75019
The Centrum, 3102 Oak Lawn, Suite 200, 75219
Google Denver, 4600 S. Syracuse St., 8th Floor, Denver, CO 80237
Google Detroit, 114 Willits Street, Birmingham, MI 48009
Google Irvine, 19540 Jamboree Road, 2nd Floor, Irvine, CA 92612
Central Way Plaza, 720 4th Avenue, Ste 400, 98033
Google New York, 76 Ninth Avenue, 4th Floor, NY 10011
Google Phoenix, 1551 S. Rural Road, 2nd floor, Tempe, AZ 85281
Collaborative Innovation Center, 4720 Forbes Avenue, Lower Level, Pittsburgh, PA 15213
Google San Francisco, 345 Spear Street, 4th Floor, San Francisco, CA 94105
Google Santa Monica, 604 Arizona Avenue, Santa Monica, CA 90401
Evanston Building, 501 N. 34th Street, Suite 300, Seattle, WA 98103
Google Seattle, 651 N. 34th St., Seattle, WA 98103
Google Washington DC, 1101 New York Avenue N.W., Second Floor, Washington, DC 20005"""
@Test
void testGeocoding(){
try{
def myhome = /C:\Users\jliang\Desktop\jgeocoder\data/;
JGeocoderConfig config = new JGeocoderConfig(_jgeocoderDataHome:myhome)
class JGeocoderTest{
public static void main(String[] args) {
JGeocoderConfig config = new JGeocoderConfig();
config.setJgeocoderDataHome("C:/Users/Bobby/Documents/jgeocoder/jgeocoder/src/data");
config.setTigerDataSource(H2DbDataSourceFactory.getH2DbDataSource("jdbc:h2:C:\\Users\\Bobby\\tiger_ny;LOG=0;UNDO_LOG=0"));
JGeocoder jg = new JGeocoder(config);
new StringReader(input).eachLine{
JGeocodeAddress ja = jg.geocodeAddress(it)
def m = ja.getGeocodedAddr()
assert m.get(AddressComponent.CITY)
assert m.get(AddressComponent.STATE)
assert m.get(AddressComponent.LAT)
assert m.get(AddressComponent.LON)
}
jg.cleanup()
}catch(Exception e){//fix your data.home
e.printStackTrace()
}
long start = System.currentTimeMillis();
// for(int i =0; i<100; i++){
JGeocodeAddress addr = jg.geocodeAddress("30 Tech Valley Dr,East Greenbush, New York 12061 ");
System.out.println(ToStringBuilder.reflectionToString(addr, ToStringStyle.MULTI_LINE_STYLE));
JGeocodeAddress addr2 = jg.geocodeAddress("203 Hoadley Hill Rd, windsor ny 13865");
//JGeocodeAddress addr2 = jg.geocodeAddress("203 Hoadley Hill Rd 13865");

System.out.println(ToStringBuilder.reflectionToString(addr2, ToStringStyle.MULTI_LINE_STYLE));
// }
CommonUtils.printElapsed(start, TimeUnit.SECONDS);

jg.cleanup();
}
}

0 comments on commit 2029f1c

Please sign in to comment.