Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 886E7B5DBDB for ; Mon, 23 May 2011 21:59:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 22369-08 for ; Tue, 24 May 2011 00:59:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id 5BEEAB5DBDA for ; Mon, 23 May 2011 21:59:32 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id 3C83F2D; Mon, 23 May 2011 20:59:32 -0400 (EDT) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id gHs-RWx5gzKf; Mon, 23 May 2011 20:59:31 -0400 (EDT) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id 468A227; Mon, 23 May 2011 20:59:31 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 3A16DAE466; Tue, 24 May 2011 08:59:30 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id CfmqjrtQJJfv; Tue, 24 May 2011 08:59:24 +0800 (WST) Received: from [10.1.1.3] (124-169-254-58.dyn.iinet.net.au [124.169.254.58]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 6768BAE349; Tue, 24 May 2011 08:59:24 +0800 (WST) Message-ID: <4DDB02E9.9040509@postnewspapers.com.au> Date: Tue, 24 May 2011 08:59:21 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: Tarlika Elisabeth Schmitz CC: sql pgsql Subject: Re: extracting location info from string References: <20110522210526.0f8b66fa@dick.coachhouse> <20110522230041.28d1bc35@dick.coachhouse> <20110523233949.07fb0005@dick.coachhouse> In-Reply-To: <20110523233949.07fb0005@dick.coachhouse> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/140 X-Sequence-Number: 35424 On 24/05/2011 6:39 AM, Tarlika Elisabeth Schmitz wrote: > Indeed. However, the situation is not quite as bleak as it appears: > - I am only dealing with 50 countries (Luxemburg and Vatican are not > amongst them) > - Only for two countries will city/region be displayed instead of > country. > - Ultimately, where the only important bit of imformation is the > country. > - The only really important persons are those from the two countries. Ah, see that's critical. You've just been able to restrict the problem domain to a much simpler task with a smaller and well-defined range of possibilities. Most of the complexity is in the nasty corner cases and weirdness, and you've (probably) just cut most of that away. > Of 17000 historical records, 4400 don't match this simple pattern. > Of the 4400, 1300 are "USA" or "Usa" instead of "United States", 900 > "North America" whatever that is! There are plenty of common + > valid region abbreviations. > > I get about 1000 new records of this type per year. I'd do this kind of analysis in a PL/Perl or PL/python function myself. It's easier to write "If then else " logic in a readable form, and such chained tests are usually better for this sort of work. That also makes it easier to do a cleanup pass first, where you substitute common spelling errors and canonicalize country names. > However, the import process has to be as automatic as possible in such > a way that inconsistencies are flagged up for later manual > intervention. I say later because, for instance, a person's data will > have to be imported with or without location info because other new > data will link to it. That's another good reason to use a PL function for this cleanup work. It's easy to INSERT a record into a side table that flags it for later examination if necessary, and to RAISE NOTICE or to issue a NOTIFY if you need to do closer-to-realtime checking. -- Craig Ringer Tech-related writing at http://soapyfrogs.blogspot.com/