19
Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Embed Size (px)

Citation preview

Page 1: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Sharing address cleaning patterns for Patstat: a metadata structure proposal

By Gianluca Tarasconi

Page 2: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

From chaos to order...

Main milestones of clearing and standardizing patstat persons (inventors and applicants) can be synthesized as follows:

PRE-PARSING CLEANING STANDARDIZATION DEDUPLICATIONDue to the strict sequentiality of the process, last steps (address

standardization and deduplication) results greatly depend from the quality of first two steps.

Page 3: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

... and back to chaos...

Different team specialize on ‘local’ addresses [countrywise data cleaning]

Standards (i.e. sequence in toponym, street name, number) differ from team to team

Enrichments / links to other data may need special data structure

Eventually results of data parsing and cleaning may differ much among different workteams.

Page 4: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Metadata structure proposal (I)

We figure that there will be a certain point in which data coming from patstat are parsed into an intermediate data structure where original strings are splitted into several fields according to the meaning of geographic information contained.

Data origin (206,

206ascii…)

Parsed data

structure

Parsed & clean

data

Pre-parsing Cleaning

Standard data

Standard.Standard

& disambig

data

Dedupl.

Page 5: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Metadata structure proposal (II)

ADDRESS Tipically toponim, name, number LOCALITY City area (optional) ADDR_OTHER Other specifics different than toponims (floor, building, but

also c/o company name) [should be data not relevant for standardization]

CITY Municipality name COUNTY Administrative level above municipality REGION Administrative level above county STATE Administrative level above region for federal nations ZIP_CODE Alphanumeric zip code

Page 6: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Dimensions in data cleaning: operators (I)

typical operators in order to clean/move pieces of information across fields are:

MOVE moves a string from one field to another REPLACE changes a string inside a field INSERT inserts a string without removing other strings DELETE removes a string without removing other strings

For such operators we should consider two dimensions indicating where the operation takes place:

FIELD FROM name of the field where operation start from FIELD TO name of the final target of operator (optional)

Also we need to list what string has to be found and what must be replaced with

FIND string to be found REPLACE string replacing the string found

Page 7: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Dimensions in data cleaning: operators (II)

We may reduce the number of operators only to MOVE considering the other as particular cases of MOVE

REPLACE = MOVE where FIELD FROM = FIELD TO INSERT = MOVE where FIELD FROM = FIELD TO and

REPLACE string = FIND + insert string DELETE = MOVE where FIELD FROM = FIELD TO and

REPLACE string is empty

This structure allows also combinations of operators like move & replace

(f.i. remove from a field a misspelled string to the correct field with correct spelling see example #5 below)

Page 8: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Dimensions in data cleaning: example

Eventually we will have to take count, using move operator, in which position of target field we want to move the string. This issue will be faced later on.

Description Field from Field to Find replaceMOVE zip in “LONDON W1 AL2” from city to zip_code

CITY ZIP_CODE W1 AL2 W1 AL2

REPLACE β with SS in ADDRESS ADDRESS ADDRESS β SS

INSERT “ AM “ in “FRANKFURT MAIN”

CITY CITY FRANKFURT MAIN

FRANKFURT AM MAIN

DELETE “/” in cities like “FRANKFURT /MAIN”

CITY CITY /

REMOVE straβe from CITY and put it into ADDRESS as STRASSE

CITY ADDRESS straβe STRASSE

Page 9: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Dimensions in data cleaning: endogenous data

Methods used to clean addresses may differ depending from pieces of information contained in the data themselves. Typical case are:

APPLICATION AUTHORITY gives some ‘address filling hints’ and charset

COUNTRY CODE gives toponyms, administrative data etc. etc.

YEAR FROM / TO (OPT.) some info may change with time (fi: change in ctry code)

PATSTATEDICTION FROM/TO (OPT.) some info can change with changes in patstat.

Page 10: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Dimensions in data cleaning: match patterns

Eventually, at string level, this is the core of our interchange format.

Our proposal is to use SQL REGEXP operator patterns as default, including the following parameters

  LIKE pattern to be found (inclusion criteria) LIKE NOT [OPTIONAL] pattern not to be in (exclusion criteria) POSITION (begin / end) start / end position where pattern can be SQLSTANDARD gives the standard used for filling the

patterns (sql ‘dialect’, like vs regexp…) in order to make easier translation

Page 11: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Interchange data structure proposal: operator

It’s proposed to use a field called OPERATIONKIND where we may store origin and destination of the move operation.

It would be a multilayer indicator having a digit for each of the field of the pattern group, indicating the address field to be addressed.

COUNTRY ADDRESS LOCALITY ADDR_OTHER CITY COUNTY REGION STATE ZIP NOWHERE

A B C D E F G H I 0

FI: BCEFLIKE, LIKE NOT, FIND, REPLACE = BCEF would mean if LIKE pattern is in address, NOT LIKE is not in locality, find FIND pattern in city and insert REPLACE pattern in county.It will be added an optional last digit indicating in case of move operation (where 1st and 4th digit are different) containing L or T respectively where REPLACE pattern must be inserted leading or trailing in target field.FI: BBBDT would mean LIKE, LIKE NOT, FIND are in address, and replace string must be inserted at the end of addr_other field.

Page 12: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Interchange data structure proposal: endogenous data

This is the list of the fields needed; where not indicated meaning of the field is explained in previous slidesAPPLICATION AUTHORITY 2 char string % may indicate valid for

allCOUNTRY CODE 2 char string % may indicate any

countryDATE FROM date [optional] empty means

no exclusionDATE TO date [optional] empty means

no exclusionPATSTATFROM MMYYYY [optional] empty means

no exclusionPATSTATTO MMYYYY [optional] empty means

no exclusion

Page 13: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Interchange data structure proposal: match patterns (I)

Where not indicated meaning of the field is explained in previous slides

ALIKE string (is not called LIKE cause it may cause errors in some SQL )

LIKE NOT [OPTIONAL] string FIND string FIND2 string when literal find do not work

and we need a fix len REPLACE string POSFROM integer start point of string position POSTO integer end of position where string can be SQLSTANDARD string

Page 14: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Interchange data structure proposal: match patterns (II)

Note: some combinations of POSFROM POSTO may have particular meanings like :

(1 , 1) mean start position ; (9999; 9999) means trailing position;

(2 ; 9999) means everywhere but at beginning.

Eventually a field containing a description of the operation is needed;

DESCRIPTION text

Page 15: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Some examples

ID 1 2 99 100 106OPERATIONKIND EEED EEEE BBBB BBBB BBBBAPPLICATION AUTHORITY EP % % % %COUNTRY CODE US % % % %

LIKE PO BOX [0-9][0-9][0-9][0-9] %,,% '[0-9] - [0-9]' '[0-9] BIS [0-9]' '[0-9] A [0-9]'

LIKE NOT ' - .+ - ' ' BIS .+ BIS ' ' A .+ A 'FIND PO BOX ,, ' - ' ' BIS ' ' A 'FIND2 PO BOX #### REPLACE , '-' '-' '-'POSFROM 1 1 2 2 2POSTO 1 9999 9999 9999 9999SQLSTANDARD MYSQL50 MYSQL50 MYSQL50 MYSQL50 MYSQL50DATE FROM DATE TO PATSTATFROM PATSTATTO

DESCRIPTIONmoves PO BOX from city to addr_other

Removes double comma in city

these are different formats aiming to set multiple street number in address to format #-#

Page 16: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Deep into one pattern (I)

Let’s see how query would work in one examples (# 100 the one highlightened)

We suppose we have an intermediate table called address where our fields are structured according to metadata structure proposal (see above).

Our patterns table is called here corrections.

We run it on a record with ADDRESS = “WAGNER STRASSE 3 BIS 12”

 

Page 17: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Deep into one pattern (II): “WAGNER STRASSE 3 BIS 12” VS “ BIS “

update applicant a, corrections b

set a.address=trim(concat(

LEFT(a.address, INSTR(a.address,b.find)-1),

b.replace,

right(a.address, LENGTH(a.address) - length(b.find)-INSTR(a.address, b.find)+1) ))

where

b.OPERATIONKIND = “BBBB”

INSTR(a.address, b.find) >= b.posfrom

and INSTR(a.address, b.find) <= b.POSTO

and a.address regexp b.like

and a. address not regexp b.likenot

and b.datefrom is null and b.dateto is null and

b.pastatfrom is null and b.pastatto is null;

new address field is trimmed aggregation of what was before the change (“WAGNER STRASSE 3“)“-“

“12”  

this means “ – “ is from position 2 onwardthis means “ – “ is before position 9999

address contains reg. expr. '[0-9] BIS [0-9]'addr. don’t contain ' BIS .+ BIS ‘that means twice‘ BIS ‘

no criteria on date or patstat ediction

Page 18: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Open issues (I):

Eventually we have to consider some issues still pending

Define a standard address

Since cleaning pattern rely on backward logic, people sharing these data should have a common target in data standardization. It’s propose to use local post office standards, but such standards may be unavailable / not fitting.

  Company Names standardization

It may be possible to think about adding company names, benefitting from national experience in standardizing legal kind (ie CO. LTD GMBH…) of company names.

Automatic query generation

User would greatly benefit from exchanging patterns if it could be possible to create a query generating tool that would, from pattern table, create SQL files.

Page 19: Sharing address cleaning patterns for Patstat: a metadata structure proposal By Gianluca Tarasconi

Open issues (II):

High correlation & chronology

Quality and results of data cleaning may depend from the order steps have been run (FI: if I do not remove PO BOXES numbers from addresses before cleaning street numbers I may have wrong results).

Most of all some patterns must be run recursively and in some cases groups of patterns should run recursively (fi: MOVE from address PO BOX, CITY, ZIP, REMOVE COMMA; since I do not know the order the elements have in ADDRESS I should run the group of queries 4 times to be sure)

A partial solution may be to add fields indicating the ID of previous query, of following query and number of repetitions.

Remain open the issue of how do we manage group of repetitions and cleaning patterns needing a ‘loop until no match is found.