Create Unique Places Dataset

# Main Libraries
import pandas as pd
# global variables
PLACES_MAP = '../data/mappings/places_types.json'
# Clean Data

BAUTISMOS_HARMONIZED = pd.read_csv("../data/clean/bautismos_clean.csv")
MATRIMONIOS_HARMONIZED = pd.read_csv("../data/clean/matrimonios_clean.csv")
ENTIERROS_HARMONIZED = pd.read_csv("../data/clean/entierros_clean.csv")

BAUTISMOS_HARMONIZED
file identifier event_type event_date baptized_name baptized_birth_place baptized_birth_date baptized_legitimacy_status father_name father_lastname ... godfather_lastname godfather_social_condition godmother_name godmother_lastname godmother_social_condition event_place event_geographic_descriptor_1 event_geographic_descriptor_2 event_geographic_descriptor_3 event_geographic_descriptor_4
0 APAucará LB L001 B001 Bautizo 1790-10-04 domingo NaN 1790-08-04 Hijo legitimo lucas ayquipa ... guamani NaN NaN NaN NaN Pampamarca NaN Pampamarca NaN NaN
1 APAucará LB L001 B002 Bautizo 1790-10-06 dominga NaN 1790-08-04 Hija legitima juan lulia ... varientos NaN NaN NaN NaN Pampamarca NaN Pampamarca NaN NaN
2 APAucará LB L001 B003 Bautizo 1790-10-07 bartola NaN 1790-08-04 Hija legitima jacinto quispe ... NaN NaN rotonda pocco NaN Pampamarca NaN Pampamarca NaN NaN
3 APAucará LB L001 B004 Bautizo 1790-10-20 francisca NaN 1790-10-15 Hija legitima juan cuebas ... NaN NaN ysabel guillen NaN Aucara NaN NaN NaN NaN
4 APAucará LB L001 B005 Bautizo 1790-10-20 pedro NaN 1790-10-19 Hijo legitimo santos manxo ... NaN NaN josefa santiago NaN Aucara NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
6336 APAucará LB L004 B2042 Bautizo 1888-12-10 leocadio NaN 1888-12-09 Hijo natural, mestizo miguel pacheco ... bendezú NaN NaN NaN NaN Aucará NaN NaN NaN NaN
6337 APAucará LB L004 B2043 Bautizo 1888-12-11 mariano concepcion NaN 1888-12-07 Hijo legítimo, indio facundo vega ... mancco NaN NaN NaN NaN Aucará NaN NaN NaN NaN
6338 APAucará LB L004 B2044 Bautizo 1888-12-12 ambrosio NaN 1888-12-06 Hijo legítimo, indio ysidro ccasane ... tito NaN NaN NaN NaN Aucará NaN Mayobamba NaN NaN
6339 APAucará LB L004 B2045 Bautizo 1888-12-15 francisco NaN 1888-11-30 Hijo legítimo, indio mariano lopez ... dias Indigna de Huaicahuacho NaN NaN NaN Aucará NaN Huaicahuacho NaN NaN
6340 APAucará LB L004 B2046 Bautizo 1888-12-16 laureana NaN 1888-12-01 Hija legítima, india bernarda champa ... NaN NaN manuela de la cruz NaN Aucará NaN NaN NaN NaN

6341 rows × 26 columns

Map Places

Create a list of unique places from the datasets and create a json file with the mapping of places to their respective geographic descriptors.

from actions.extractors import placeRecognition

extractor = placeRecognition.PlaceExtractor()
bautismos_place_columns = [
    'baptized_birth_place', 'event_place', 'event_geographic_descriptor_1',
        'event_geographic_descriptor_2', 'event_geographic_descriptor_3',
        'event_geographic_descriptor_4'
]

for col in bautismos_place_columns:
    if col in BAUTISMOS_HARMONIZED.columns:
        BAUTISMOS_HARMONIZED[col] = extractor.extract_places_per_row(BAUTISMOS_HARMONIZED[col])

BAUTISMOS_HARMONIZED[bautismos_place_columns]
baptized_birth_place event_place event_geographic_descriptor_1 event_geographic_descriptor_2 event_geographic_descriptor_3 event_geographic_descriptor_4
0 NaN Pampamarca NaN Pampamarca NaN NaN
1 NaN Pampamarca NaN Pampamarca NaN NaN
2 NaN Pampamarca NaN Pampamarca NaN NaN
3 NaN NaN NaN NaN NaN NaN
4 NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ...
6336 NaN NaN NaN NaN NaN NaN
6337 NaN NaN NaN NaN NaN NaN
6338 NaN NaN NaN Mayobamba NaN NaN
6339 NaN NaN NaN Huaicahuacho NaN NaN
6340 NaN NaN NaN NaN NaN NaN

6341 rows × 6 columns

matrimonios_place_columns = [
    'groom_birth_place',
       'groom_resident_in', 
       'bride_birth_place', 'bride_resident_in', 
       'event_place', 'event_geographic_descriptor_1', 'event_geographic_descriptor_2',
       'event_geographic_descriptor_3', 'event_geographic_descriptor_4',
       'event_geographic_descriptor_5', 'event_geographic_descriptor_6'
]

for col in matrimonios_place_columns:
    if col in MATRIMONIOS_HARMONIZED.columns:
        MATRIMONIOS_HARMONIZED[col] = extractor.extract_places_per_row(MATRIMONIOS_HARMONIZED[col])

MATRIMONIOS_HARMONIZED[matrimonios_place_columns]
groom_birth_place groom_resident_in bride_birth_place bride_resident_in event_place event_geographic_descriptor_1 event_geographic_descriptor_2 event_geographic_descriptor_3 event_geographic_descriptor_4 event_geographic_descriptor_5 event_geographic_descriptor_6
0 Ciudad de Huamanga NaN NaN NaN NaN NaN Huamanga NaN NaN NaN NaN
1 NaN NaN NaN NaN NaN NaN Colca NaN NaN NaN NaN
2 Pampamarca NaN Pampamarca NaN NaN NaN Pampamarca NaN NaN NaN NaN
3 Pampamarca NaN Pampamarca NaN NaN NaN Pampamarca NaN NaN NaN NaN
4 NaN NaN NaN NaN NaN NaN Pampamarca NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ...
1714 Pampamarca NaN Pampamarca NaN Pampamarca NaN Pampamarca NaN NaN NaN NaN
1715 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1716 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1717 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1718 Pampamarca NaN Pampamarca NaN Pampamarca NaN Pampamarca NaN NaN NaN NaN

1719 rows × 11 columns

entierros_place_columns = [
    'event_place', 'deceased_birth_place', 'burial_place', 'event_geographic_descriptor_1',
    'event_geographic_descriptor_2', 'event_geographic_descriptor_3',
    'event_geographic_descriptor_4'
]

for col in entierros_place_columns:
    if col in ENTIERROS_HARMONIZED.columns:
        ENTIERROS_HARMONIZED[col] = extractor.extract_places_per_row(ENTIERROS_HARMONIZED[col])

ENTIERROS_HARMONIZED[entierros_place_columns]
event_place deceased_birth_place burial_place event_geographic_descriptor_1 event_geographic_descriptor_2 event_geographic_descriptor_3 event_geographic_descriptor_4
0 NaN NaN NaN NaN Lucanas NaN NaN
1 NaN NaN NaN NaN Lucanas NaN NaN
2 NaN NaN NaN NaN Lucanas NaN NaN
3 NaN NaN NaN NaN Lucanas NaN NaN
4 NaN NaN NaN NaN Lucanas NaN NaN
... ... ... ... ... ... ... ...
2193 NaN Santa Ana de Aucara NaN NaN Santa Ana de Aucara NaN NaN
2194 NaN Pampamarca NaN NaN Pampamarca NaN NaN
2195 NaN Santa Ana de Aucara NaN NaN Santa Ana de Aucara NaN NaN
2196 NaN NaN NaN NaN NaN NaN NaN
2197 NaN NaN NaN NaN NaN NaN NaN

2198 rows × 7 columns

%%capture

bautismos_places = BAUTISMOS_HARMONIZED[bautismos_place_columns]
matrimonios_places = MATRIMONIOS_HARMONIZED[matrimonios_place_columns] 
entierros_places = ENTIERROS_HARMONIZED[entierros_place_columns]

map_places = placeRecognition.MapPlaces([bautismos_places, matrimonios_places, entierros_places], places_map=PLACES_MAP)
all_unique_places = map_places.resolve_places()
print("All unique places extracted:")
print(all_unique_places)
all_unique_places.to_csv("../data/interim/unique_places.csv", index=False)

Manual Data

The file data/interim/unique_places_manual.csv serves as the authoritative normalization reference for all place mentions across sacramental records. The resolution was performed manually to ensure accuracy for ambiguous toponyms such as Ishua and Pampamarca. The AuthoritativePlaceResolver class uses this file to link canonical names with their variants (mentioned_as) and resolves each canonical name using GeoNames, TGN, WHG, and Wikidata. The output (data/clean/unique_places.csv) is now the trusted lookup table for place resolution across the project.

We also added the category “administrative division” to places_types.json to be included in the geoResolver library, via placeRecognition module.

"administrative division": {
    "geonames": "A",
    "wikidata": "Q5",
    "tgn": "administrative divisions",
    "whg": "a"
  }
%%capture

manual_data = '../data/interim/unique_places_manual.csv'

manual_data = pd.read_csv(manual_data)

resolver = placeRecognition.AuthoritativePlaceResolver(data=manual_data, places_map=PLACES_MAP)
result_df = resolver.resolve_places()

print("Resolved places:")
print(result_df)

Add Place IDs

This step is added in preparation for database integration, where each unique place will be assigned a unique identifier (place_id).

result_df['place_id'] = result_df.index + 1
result_df = result_df.set_index('place_id')

result_df
manually_normalized_place standardize_label language latitude longitude source id uri country_code part_of part_of_uri confidence threshold match_type mentioned_as
place_id
1 Acobamba Acobamba es -12.077570 -74.871270 GeoNames 8663907 http://sws.geonames.org/8663907/ PE 100.0 90.0 exact [Acobamba]
2 Alcamenca Alcamenca es -13.657049 -74.147134 Wikidata Q130369762 https://www.wikidata.org/entity/Q130369762 PE Distrito de Alcamenca https://www.wikidata.org/entity/Q3824932 100.0 90.0 exact [Alcamenca]
4 Andamarca Andamarca es -15.638330 -70.588480 GeoNames 3947725 http://sws.geonames.org/3947725/ PE 100.0 90.0 exact [Andamarca]
5 Antay Antayaje es -14.068861 -71.755222 Wikidata Q97160355 https://www.wikidata.org/entity/Q97160355 PE Distrito de Omacha https://www.wikidata.org/entity/Q2893883 100.0 90.0 exact [Antay]
7 Aucará Aucará es -14.250000 -74.083330 GeoNames 3947087 http://sws.geonames.org/3947087/ PE 100.0 90.0 exact [Aucara, Aucara Barrio de Mayo, Aucará, Barrio...
11 Huaycahuaycho Huaycahuaycho es -14.150000 -74.016670 GeoNames 3939003 http://sws.geonames.org/3939003/ PE 100.0 90.0 exact [Aucara Huaycahuacho, Huaicahuacho]
12 Ayacucho Ayacucho es -13.163800 -74.223450 GeoNames 3947019 http://sws.geonames.org/3947019/ PE 100.0 90.0 exact [Ayacucho, Ayacuchoi, Ciuda de Ayacucho, Ciuda...
13 Cabana Cabana es -8.400000 -78.033330 GeoNames 3699185 http://sws.geonames.org/3699185/ PE 100.0 90.0 exact [Aucara Cabana, Cabana]
14 Canaria Canaria es -13.816670 -73.866670 GeoNames 3945879 http://sws.geonames.org/3945879/ PE 100.0 90.0 exact [Canaria]
15 Cangallo Cangallo es -13.628610 -74.143890 GeoNames 3945793 http://sws.geonames.org/3945793/ PE 100.0 90.0 exact [Cangallo, provincia Cangallo]
16 Caralla Caralla es -15.295350 -71.566920 GeoNames 3955233 http://sws.geonames.org/3955233/ PE 100.0 90.0 exact [Caralla]
17 Carapo Carapo es -13.750000 -74.233330 GeoNames 3945552 http://sws.geonames.org/3945552/ PE 100.0 90.0 exact [Carapo]
18 Carmen Alto Carmen Alto es -14.700310 -70.517300 GeoNames 13318788 http://sws.geonames.org/13318788/ PE 100.0 90.0 exact [Carmen Alto]
20 Castilla Puquio Castilla Puquio es -15.900160 -70.591520 GeoNames 3945238 http://sws.geonames.org/3945238/ PE 100.0 90.0 exact [Castilla]
21 Cayara Cayara es -15.318360 -73.550030 GeoNames 3945148 http://sws.geonames.org/3945148/ PE 100.0 90.0 exact [Cayara]
22 Chacralla Chacralla es -14.207360 -73.992780 GeoNames 3944632 http://sws.geonames.org/3944632/ PE 100.0 90.0 exact [Ccaralla, Cementerio general Chacralla, Chac...
23 Checca Checca es -14.472780 -71.393890 Wikidata Q5089024 https://www.wikidata.org/entity/Q5089024 PE Departamento de Cusco https://www.wikidata.org/entity/Q205057 100.0 90.0 exact [Ccecca, Cecca]
24 Pampamarca Pampamarca es -14.146390 -71.459440 GeoNames 3933218 http://sws.geonames.org/3933218/ PE 100.0 90.0 exact [Cementerio de Pampamarca, Cementerio general ...
26 Chacalla Chacalla es -13.968890 -72.205560 GeoNames 6392254 http://sws.geonames.org/6392254/ PE 100.0 90.0 exact [Chacalla]
27 Chalhuanca Chalhuanca es -14.300560 -73.230830 GeoNames 3944545 http://sws.geonames.org/3944545/ PE 100.0 90.0 exact [Chalhuanca, Challhuanca]
28 Chilcas Chilcas es -12.372840 -74.846870 GeoNames 8664084 http://sws.geonames.org/8664084/ PE 100.0 90.0 exact [Chilcas]
29 Chumpe Chumpe es -12.296110 -75.697780 GeoNames 6304004 http://sws.geonames.org/6304004/ PE 100.0 90.0 exact [Chumpe]
30 San Nicolás Puerto San Nicolás es -15.261240 -75.225360 GeoNames 3929384 http://sws.geonames.org/3929384/ PE 100.0 90.0 exact [Colca]
31 Córdova Puesto Cabo Córdova es -4.191480 -80.457730 GeoNames 3693175 http://sws.geonames.org/3693175/ PE 100.0 90.0 exact [Cordoba]
33 Huacaña Huacaña es -15.518610 -72.018840 GeoNames 3940068 http://sws.geonames.org/3940068/ PE 100.0 90.0 exact [Huacaña]
34 Huallatalloc Huallatalloc es -13.516670 -70.950000 GeoNames 3939794 http://sws.geonames.org/3939794/ PE 100.0 90.0 exact [Hualla]
35 Huanca Santos Huanca Santos es -13.920000 -74.334110 GeoNames 3939474 http://sws.geonames.org/3939474/ PE 100.0 90.0 exact [Huanca, Sancos]
36 Huanta Huanta es -12.933330 -74.250000 GeoNames 3939386 http://sws.geonames.org/3939386/ PE 100.0 90.0 exact [Huanta]
37 Santa Ana de Huaycahuacho Santa Ana de Huaycahuacho es -14.950000 -73.216670 GeoNames 3929281 http://sws.geonames.org/3929281/ PE 100.0 90.0 exact [Huaycahuacho]
38 Huaytará Huaytará es -13.604450 -75.353080 GeoNames 3938825 http://sws.geonames.org/3938825/ PE 100.0 90.0 exact [Huaytara]
39 Ica Ica es -14.075380 -75.734220 GeoNames 3938527 http://sws.geonames.org/3938527/ PE 100.0 70.0 exact [Ica]
40 Ishua Ishua es -14.249860 -73.955560 GeoNames 3938160 http://sws.geonames.org/3938160/ PE 100.0 90.0 exact [Iglesia de Yshua, India de Hishua, Ishua, Yshua]
41 Jauja Jauja es -11.775840 -75.496560 GeoNames 3937733 http://sws.geonames.org/3937733/ PE 100.0 90.0 exact [Jauja]
42 Julcamarca Julcamarca es -9.288680 -77.990510 GeoNames 6380634 http://sws.geonames.org/6380634/ PE 100.0 90.0 exact [Julcamarca]
43 Laramate Laramate es -13.027150 -74.387020 GeoNames 3936871 http://sws.geonames.org/3936871/ PE 100.0 90.0 exact [Laramate]
44 Larcay Larcay es -12.738050 -74.536730 GeoNames 8661432 http://sws.geonames.org/8661432/ PE 100.0 90.0 exact [Larcay]
45 Lima Lima es -12.043180 -77.028240 GeoNames 3936456 http://sws.geonames.org/3936456/ PE 100.0 70.0 exact [Lima]
47 Cajamarca Cajamarca es -7.163780 -78.500270 GeoNames 3699088 http://sws.geonames.org/3699088/ PE 100.0 90.0 exact [Mar]
48 Mayobamba Mayobamba es -14.375830 -73.891940 GeoNames 3935121 http://sws.geonames.org/3935121/ PE 100.0 90.0 exact [Mayobamba]
50 Moyobamba Moyobamba es -6.034410 -76.974230 GeoNames 3694564 http://sws.geonames.org/3694564/ PE 100.0 90.0 exact [Moyobamba]
51 Provincia de Nazca Provincia de Nazca es -14.830980 -74.938950 GeoNames 3934356 http://sws.geonames.org/3934356/ PE 100.0 90.0 exact [Nasca, Nazca]
52 Ocaña Ocaña es -13.045060 -74.378400 GeoNames 3934206 http://sws.geonames.org/3934206/ PE 100.0 90.0 exact [Ocaña]
53 Pampa Grande Pampa Grande es -6.751690 -79.481010 GeoNames 3693998 http://sws.geonames.org/3693998/ PE 100.0 90.0 exact [Pampa]
54 Puno Puno es -15.840030 -70.021980 GeoNames 3931276 http://sws.geonames.org/3931276/ PE 100.0 70.0 exact [Puna]
55 Puquio Puquio es -14.700000 -74.133330 GeoNames 3931223 http://sws.geonames.org/3931223/ PE 100.0 90.0 exact [Puquio]
56 Querobamba Querobamba es -13.866670 -73.833330 GeoNames 3930947 http://sws.geonames.org/3930947/ PE 100.0 90.0 exact [Querobamba]
57 Sacsamarca Sacsamarca es -13.150850 -74.278690 GeoNames 3930088 http://sws.geonames.org/3930088/ PE 100.0 90.0 exact [Sacsamarca]
58 San Jeronimo De Tunan San Jeronimo De Tunan es -11.955910 -75.284110 GeoNames 3929611 http://sws.geonames.org/3929611/ PE 100.0 90.0 exact [San Jeronimo]
59 San Juan San Juan es -3.776110 -73.281390 GeoNames 3692462 http://sws.geonames.org/3692462/ PE 100.0 90.0 exact [San Juan de Lucanas]
60 Santa Ana Santa Ana es -12.866670 -72.716670 GeoNames 3929295 http://sws.geonames.org/3929295/ PE 100.0 90.0 exact [Santa Ana, Santa Ana de Aucara]
61 Sondondo Sondondo es -14.297950 -73.939280 GeoNames 3928450 http://sws.geonames.org/3928450/ PE 100.0 90.0 exact [Sondondo]
62 Soras Pata Soras Pata es -14.237410 -70.650110 GeoNames 13238703 http://sws.geonames.org/13238703/ PE 100.0 90.0 exact [Soras]
63 Umasi Umasi es -14.891420 -70.687010 GeoNames 13238711 http://sws.geonames.org/13238711/ PE 100.0 90.0 exact [Umaci, Umasi]
64 Urubamba Urubamba es -13.304720 -72.115830 GeoNames 3926438 http://sws.geonames.org/3926438/ PE 100.0 90.0 exact [Urabamba]
65 Vilcashuamán Vilcashuamán es -13.653610 -73.953060 GeoNames 3926141 http://sws.geonames.org/3926141/ PE 100.0 90.0 exact [Vilcas]
66 Villa San Juan Villa San Juan es -6.372520 -79.802920 GeoNames 3820188 http://sws.geonames.org/3820188/ PE 100.0 90.0 exact [Villa de San Juan]
result_df.to_csv("../data/clean/unique_places.csv", index=True)