{"id":25066794,"url":"https://github.com/stuartemiddleton/geoparsepy","last_synced_at":"2025-06-18T13:39:24.860Z","repository":{"id":50412890,"uuid":"271961251","full_name":"stuartemiddleton/geoparsepy","owner":"stuartemiddleton","description":"geoparsepy is a Python geoparsing library that will extract and disambiguate locations from text. It uses a local OpenStreetMap database which allows very high and unlimited geoparsing throughput, unlike approaches that use a third-party geocoding service (e.g.  Google Geocoding API). this repository holds Python examples to use the PyPI library.","archived":false,"fork":false,"pushed_at":"2021-08-25T16:10:06.000Z","size":148,"stargazers_count":62,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-25T01:45:29.918Z","etag":null,"topics":["artificial-intelligence","geoparse","information-extraction","location-extraction","natural-language-processing","nlp","openstreetmap","postgresql","toponym-resolution"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stuartemiddleton.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-13T07:23:11.000Z","updated_at":"2025-02-13T05:26:47.000Z","dependencies_parsed_at":"2022-09-24T09:50:52.547Z","dependency_job_id":null,"html_url":"https://github.com/stuartemiddleton/geoparsepy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartemiddleton%2Fgeoparsepy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartemiddleton%2Fgeoparsepy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartemiddleton%2Fgeoparsepy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartemiddleton%2Fgeoparsepy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stuartemiddleton","download_url":"https://codeload.github.com/stuartemiddleton/geoparsepy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248945985,"owners_count":21187422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","geoparse","information-extraction","location-extraction","natural-language-processing","nlp","openstreetmap","postgresql","toponym-resolution"],"created_at":"2025-02-06T20:27:56.704Z","updated_at":"2025-04-14T19:33:31.714Z","avatar_url":"https://github.com/stuartemiddleton.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# geoparsepy project\r\n\r\ngeoparsepy is a Python geoparsing library that will extract and disambiguate locations from text. It uses a local OpenStreetMap database which allows very high and unlimited geoparsing throughput, unlike approaches that use a third-party geocoding service (e.g.  Google Geocoding API).\r\n\r\n[geoparsepy PyPI](https://pypi.org/project/geoparsepy/)\r\n\r\nGeoparsing is based on named entity matching against OpenStreetMap (OSM) locations. All locations with names that match tokens will be selected from a target text sentence. This will result in a set of OSM locations, all with a common name or name variant, for each token in the text. Geoparsing included the following features:\r\n  * **token expansion** using location name variants (i.e. OSM multi-lingual names, short names and acronyms)\r\n  * **token expansion** using location type variants (e.g. street, st.)\r\n  * **token filtering** of single token location names against WordNet (non-nouns), language specific stoplists and peoples first names (nltk.corpus.names.words()) to reduce false positive matches\r\n  * **prefix checking** when matching in case a first name prefixes a location token(s) to avoid matching peoples full names as locations (e.g. Victoria Derbyshire != Derbyshire)\r\n\r\nLocation disambiguation is the process of choosing which of a set of possible OSM locations, all with the same name, is the best match. Location disambiguation is based on an evidential approach, with evidential features detailed below in order of importance:\r\n  * **token subsumption**, rejecting smaller phrases over larger ones (e.g. 'New York' will prefer [New York, USA] to [York, UK])\r\n  * **nearby parent region**, preferring locations with a parent region also appearing within a semantic distance (e.g. 'New York in USA' will prefer [New York, USA] to [New York, BO, Sierra Leone])\r\n  * **nearby locations**, preferring locations with closeby or overlapping locations within a semantic distance (e.g. 'London St and Commercial Road' will select from road name choices with the same name based on spatial proximity)\r\n  * **nearby geotag**, preferring locations that are closeby or overlapping a geotag\r\n  * **general before specific**, rejecting locations with a higher admin level (or no admin level at all) compared to locations with a lower admin level (e.g. 'New York' will prefer [New York, USA] to [New York, BO, Sierra Leone]\r\n\r\nCurrently the following languages are supported:\r\n  * English, French, German, Italian, Portuguese, Russian, Ukrainian\r\n  * All other languages will work but there will be no language specific token expansion available\r\n\r\ngeoparsepy works with Python 3.7 and has been tested on Windows 10 and Ubuntu 18.04 LTS.\r\n\r\nThis geoparsing algorithm uses a large memory footprint (e.g. 12 Gbytes RAM for global cities), RAM size proportional to the number of cached locations, to maximize matching speed. It can be naively parallelized, with multiple geoparse processes loaded with different sets of locations and the geoparse results aggregated in a last process where location disambiguation is applied. This approach has been validated across an APACHE Storm cluster.\r\n\r\nThe software is copyright 2020 [University of Southampton](https://www.ecs.soton.ac.uk/people/sem03), UK. It was created over a multi-year period under EU FP7 projects TRIDEC (258723), REVEAL (610928), InnovateUK project LPLP (104875) and ESRC project FloraGuard (ES/R003254/1). This software can only be used for research, education or evaluation purposes. A free commercial license is available on request to {sem03}@soton.ac.uk. The University of Southampton is open to discussions regarding [collaboration](https://www.southampton.ac.uk/~sem03/engagement.html) in future research projects relating to this work.\r\n\r\nFeature suggestions and/or bug reports can be sent to {sem03}@soton.ac.uk. We do not however offer any software support beyond the examples and API documentation already provided.\r\n\r\n\r\n# Scientific publications\r\nMiddleton, S.E. Middleton, L. Modafferi, S. [Real-time Crisis Mapping of Natural Disasters using Social Media](http://eprints.soton.ac.uk/370581/), Intelligent Systems, IEEE , vol.29, no.2, pp.9,17, Mar.-Apr. 2014\r\n\r\nMiddleton, S.E. Krivcovs, V. [Geoparsing and Geosemantics for Social Media: Spatio-Temporal Grounding of Content Propagating Rumours to support Trust and Veracity Analysis during Breaking News](http://eprints.soton.ac.uk/390820/), ACM Transactions on Information Systems (TOIS), 34, 3, Article 16 (April 2016), 26 pages. DOI=10.1145/2842604\r\n\r\nMiddleton, S.E. Kordopatis-Zilos, G. Papadopoulos, S. Kompatsiaris, Y. [Location Extraction from Social Media: Geoparsing, Location Disambiguation, and Geotagging](https://www.southampton.ac.uk/~sem03/middleton_tois_2018.pdf), ACM Transactions on Information Systems (TOIS) 36, 4, Article 40 (June 2018), 27 pages. DOI: https://doi.org/10.1145/3202662. Presented at SIGIR 2019\r\n\r\nA benchmark geoparse dataset is also available for free from the University of Southampton on request via email to {sem03}@soton.ac.uk.\r\n\r\n\r\n# geoparsepy documentation resources\r\n\r\ngeoparsepy [API](https://www.southampton.ac.uk/~sem03/geoparsepy/api/index.html)\r\n\r\ngeoparsepy example code on [github](https://github.com/stuartemiddleton/geoparsepy)\r\n\r\n# Python libs needed (earlier versions may be suitable but are untested)\r\n\r\nPython libs: psycopg2 \u003e= 2.8, nltk \u003e= 3.4, numpy \u003e= 1.18, shapely \u003e= 1.6, setuptools \u003e= 46, soton-corenlppy\u003e=1.0\r\n\r\nDatabase: PostgreSQL \u003e= 11.3, PostGIS \u003e= 2.5\r\n\r\nFor LINUX deployments the following is needed:\r\n\r\n```\r\nsudo apt-get install libgeos-dev libgeos-3.4.2 libpq-dev\r\n```\r\n\r\nYou will need to download NLTK corpra before running geoparsepy:\r\n\r\n```python\r\npython\r\nimport nltk\r\nnltk.download()\r\n==\u003e install all or at least stopwords, names and wordnet\r\n```\r\n\r\n# Installation\r\n\r\npython3 -m pip install geoparsepy\r\n\r\n# Databases needed for geoparsing\r\nDownload pre-processed UTF-8 encoded SQL table dumps from OSM image dated dec 2019. SQL dump is a 1.2 GB tar/zip file created using pg_dump and zipped using 7Zip tool.\r\n\r\n```\r\ndownload zip file from Google drive https://drive.google.com/file/d/1xyCjQox6gCoN8e0upHHyeMLV-uLirthS/view?usp=sharing\r\nunzip geoparsepy_preprocessed_tables.tar.zip\r\ntar -xvf geoparsepy_preprocessed_tables.tar\r\n```\r\n\r\nConnect to PostgreSQL and create the database with the required PostGIS and hstore extensions\r\n\r\n```\r\npsql -U postgres\r\nCREATE DATABASE openstreetmap;\r\nCREATE EXTENSION IF NOT EXISTS postgis;\r\nCREATE EXTENSION IF NOT EXISTS fuzzystrmatch;\r\nCREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;\r\nCREATE EXTENSION IF NOT EXISTS hstore;\r\n```\r\n\r\nImport the precomputed database tables for global cities and places\r\n\r\n```\r\n# Linux\r\npsql -U postgres -d openstreetmap -f global_cities.sql\r\npsql -U postgres -d openstreetmap -f uk_places.sql\r\npsql -U postgres -d openstreetmap -f north_america_places.sql\r\npsql -U postgres -d openstreetmap -f europe_places.sql\r\n\r\n# Windows 10 using powershell\r\n\u0026 'C:\\Program Files\\PostgreSQL\\11\\bin\\psql.exe' -U postgres -d openstreetmap -f global_cities.sql\r\n\u0026 'C:\\Program Files\\PostgreSQL\\11\\bin\\psql.exe' -U postgres -d openstreetmap -f uk_places.sql\r\n\u0026 'C:\\Program Files\\PostgreSQL\\11\\bin\\psql.exe' -U postgres -d openstreetmap -f north_america_places.sql\r\n\u0026 'C:\\Program Files\\PostgreSQL\\11\\bin\\psql.exe' -U postgres -d openstreetmap -f europe_places.sql\r\n\r\n# Linux if username not sem (used for sql dump) not added as a user and some other name is needed (e.g. sem03)\r\nfind * -name \\*.sql -exec sed -i \"s/TO sem;/TO sem03;/g\" {} \\;\r\npsql -d openstreetmap -f uk_places.sql\r\npsql -d openstreetmap -f global_cities.sql\r\npsql -d openstreetmap -f north_america_places.sql\r\npsql -d openstreetmap -f europe_places.sql\r\n\r\n```\r\n\r\n# Example code geoparse (start here)\r\n\r\nGeoparse some text using the default focus areas in the Postgres database. Fully documented example PY file can be found at geoparsepy.example_geoparse.py\r\nnote: loading 300,000+ global locations into memory at startup is slow (10 minutes) but subsequently the geoparsing of text is very fast (real-time speeds)\r\n\r\n```python\r\nimport os, sys, logging, traceback, codecs, datetime, copy, time, ast, math, re, random, shutil, json\r\nimport soton_corenlppy, geoparsepy\r\n\r\nLOG_FORMAT = ('%(message)s')\r\nlogger = logging.getLogger( __name__ )\r\nlogging.basicConfig( level=logging.INFO, format=LOG_FORMAT )\r\nlogger.info('logging started')\r\n\r\ndictGeospatialConfig = geoparsepy.geo_parse_lib.get_geoparse_config( \r\n\tlang_codes = ['en'],\r\n\tlogger = logger,\r\n\twhitespace = u'\"\\u201a\\u201b\\u201c\\u201d()',\r\n\tsent_token_seps = ['\\n','\\r\\n', '\\f', u'\\u2026'],\r\n\tpunctuation = \"\"\",;\\/:+-#~\u0026*=!?\"\"\",\r\n\t)\r\n\r\ndatabaseHandle = soton_corenlppy.PostgresqlHandler.PostgresqlHandler( 'postgres', 'postgres', 'localhost', 5432, 'openstreetmap', 600 )\r\n\r\ndictLocationIDs = {}\r\nlistFocusArea=[ 'global_cities', 'europe_places', 'north_america_places', 'uk_places' ]\r\nfor strFocusArea in listFocusArea :\r\n\tdictLocationIDs[strFocusArea + '_admin'] = [-1,-1]\r\n\tdictLocationIDs[strFocusArea + '_poly'] = [-1,-1]\r\n\tdictLocationIDs[strFocusArea + '_line'] = [-1,-1]\r\n\tdictLocationIDs[strFocusArea + '_point'] = [-1,-1]\r\n\r\ncached_locations = geoparsepy.geo_preprocess_lib.cache_preprocessed_locations( databaseHandle, dictLocationIDs, 'public', dictGeospatialConfig )\r\nlogger.info( 'number of cached locations = ' + str(len(cached_locations)) )\r\n\r\ndatabaseHandle.close()\r\n\r\nindexed_locations = geoparsepy.geo_parse_lib.calc_inverted_index( cached_locations, dictGeospatialConfig )\r\nlogger.info( 'number of indexed phrases = ' + str(len(indexed_locations.keys())) )\r\n\r\nindexed_geoms = geoparsepy.geo_parse_lib.calc_geom_index( cached_locations )\r\nlogger.info( 'number of indexed geoms = ' + str(len(indexed_geoms.keys())) )\r\n\r\nosmid_lookup = geoparsepy.geo_parse_lib.calc_osmid_lookup( cached_locations )\r\n\r\ndictGeomResultsCache = {}\r\n\r\nlistText = [\r\n\tu'hello New York, USA its Bill from Bassett calling',\r\n\tu'live on the BBC Victoria Derbyshire is visiting Derbyshire for an exclusive UK interview',\r\n\t]\r\n\r\nlistTokenSets = []\r\nlistGeotags = []\r\nfor nIndex in range(len(listText)) :\r\n\tstrUTF8Text = listText[ nIndex ]\r\n\tlistToken = soton_corenlppy.common_parse_lib.unigram_tokenize_text( text = strUTF8Text, dict_common_config = dictGeospatialConfig )\r\n\tlistTokenSets.append( listToken )\r\n\tlistGeotags.append( None )\r\n\r\nlistMatchSet = geoparsepy.geo_parse_lib.geoparse_token_set( listTokenSets, indexed_locations, dictGeospatialConfig )\r\n\r\nstrGeom = 'POINT(-1.4052268 50.9369033)'\r\nlistGeotags[0] = strGeom\r\n\r\nlistMatchGeotag = geoparsepy.geo_parse_lib.reverse_geocode_geom( [strGeom], indexed_geoms, dictGeospatialConfig )\r\nif len( listMatchGeotag[0] ) \u003e 0  :\r\n\tfor tupleOSMIDs in listMatchGeotag[0] :\r\n\t\tsetIndexLoc = osmid_lookup[ tupleOSMIDs ]\r\n\t\tfor nIndexLoc in setIndexLoc :\r\n\t\t\tstrName = cached_locations[nIndexLoc][1]\r\n\t\t\tlogger.info( 'Reverse geocoded geotag location [index ' + str(nIndexLoc) + ' osmid ' + repr(tupleOSMIDs) + '] = ' + strName )\r\n\r\nfor nIndex in range(len(listMatchSet)) :\r\n\tlogger.info( 'Text = ' + listText[nIndex] )\r\n\tlistMatch = listMatchSet[ nIndex ]\r\n\tstrGeom = listGeotags[ nIndex ]\r\n\tsetOSMID = set([])\r\n\tfor tupleMatch in listMatch :\r\n\t\tnTokenStart = tupleMatch[0]\r\n\t\tnTokenEnd = tupleMatch[1]\r\n\t\ttuplePhrase = tupleMatch[3]\r\n\t\tfor tupleOSMIDs in tupleMatch[2] :\r\n\t\t\tsetIndexLoc = osmid_lookup[ tupleOSMIDs ]\r\n\t\t\tfor nIndexLoc in setIndexLoc :\r\n\t\t\t\tlogger.info( 'Location [index ' + str(nIndexLoc) + ' osmid ' + repr(tupleOSMIDs) + ' @ ' + str(nTokenStart) + ' : ' + str(nTokenEnd) + '] = ' + ' '.join(tuplePhrase) )\r\n\t\t\t\tbreak\r\n\tlistLocMatches = geoparsepy.geo_parse_lib.create_matched_location_list( listMatch, cached_locations, osmid_lookup )\r\n\tgeoparsepy.geo_parse_lib.filter_matches_by_confidence( listLocMatches, dictGeospatialConfig, geom_context = strGeom, geom_cache = dictGeomResultsCache )\r\n\tgeoparsepy.geo_parse_lib.filter_matches_by_geom_area( listLocMatches, dictGeospatialConfig )\r\n\tgeoparsepy.geo_parse_lib.filter_matches_by_region_of_interest( listLocMatches, [-148838, -62149], dictGeospatialConfig )\r\n\tsetOSMID = set([])\r\n\tfor nMatchIndex in range(len(listLocMatches)) :\r\n\t\tnTokenStart = listLocMatches[nMatchIndex][1]\r\n\t\tnTokenEnd = listLocMatches[nMatchIndex][2]\r\n\t\ttuplePhrase = listLocMatches[nMatchIndex][3]\r\n\t\tstrGeom = listLocMatches[nMatchIndex][4]\r\n\t\ttupleOSMID = listLocMatches[nMatchIndex][5]\r\n\t\tdictOSMTags = listLocMatches[nMatchIndex][6]\r\n\t\tif not tupleOSMID in setOSMID :\r\n\t\t\tsetOSMID.add( tupleOSMID )\r\n\t\t\tlistNameMultilingual = geoparsepy.geo_parse_lib.calc_multilingual_osm_name_set( dictOSMTags, dictGeospatialConfig )\r\n\t\t\tstrNameList = ';'.join( listNameMultilingual )\r\n\t\t\tstrOSMURI = geoparsepy.geo_parse_lib.calc_OSM_uri( tupleOSMID, strGeom )\r\n\t\t\tlogger.info( 'Disambiguated Location [index ' + str(nMatchIndex) + ' osmid ' + repr(tupleOSMID) + ' @ ' + str(nTokenStart) + ' : ' + str(nTokenEnd) + '] = ' + strNameList + ' : ' + strOSMURI )\r\n```\r\n\r\n\r\n# Example geoparse output\r\n```\r\nlogging started\r\nloading stoplist from C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-geo-stoplist-en.txt\r\nloading whitelist from C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-geo-whitelist.txt\r\nloading blacklist from C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-geo-blacklist.txt\r\nloading building types from C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-buildingtype-en.txt\r\nloading location type corpus C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-buildingtype-en.txt\r\n- 3 unique titles\r\n- 76 unique types\r\nloading street types from C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-streettype-en.txt\r\nloading location type corpus C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-streettype-en.txt\r\n- 15 unique titles\r\n- 32 unique types\r\nloading admin types from C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-admintype-en.txt\r\nloading location type corpus C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\corpus-admintype-en.txt\r\n- 14 unique titles\r\n- 0 unique types\r\nloading gazeteer from C:\\Program Files\\Python3\\lib\\site-packages\\geoparsepy\\gazeteer-en.txt\r\ncaching locations : {'global_cities_admin': [-1, -1], 'global_cities_poly': [-1, -1], 'global_cities_line': [-1, -1], 'global_cities_point': [-1, -1], 'europe_places_admin': [-1, -1], 'europe_places_poly': [-1, -1], 'europe_places_line': [-1, -1], 'europe_places_point': [-1, -1], 'north_america_places_admin': [-1, -1], 'north_america_places_poly': [-1, -1], 'north_america_places_line': [-1, -1], 'north_america_places_point': [-1, -1], 'uk_places_admin': [-1, -1], 'uk_places_poly': [-1, -1], 'uk_places_line': [-1, -1], 'uk_places_point': [-1, -1]}\r\nnumber of cached locations = 800820\r\nnumber of indexed phrases = 645697\r\nnumber of indexed geoms = 657264\r\nReverse geocoded geotag location [index 190787 osmid (253067120,)] = Bassett\r\nReverse geocoded geotag location [index 779038 osmid (253067120,)] = Bassett\r\nText = hello New York, USA its Bill from Bassett calling\r\nLocation [index 792265 osmid (29457403,) @ 1 : 2] = new york\r\nLocation [index 737029 osmid (151937435,) @ 1 : 2] = new york\r\nLocation [index 737030 osmid (316976734,) @ 1 : 2] = new york\r\nLocation [index 140096 osmid (-175905,) @ 1 : 2] = new york\r\nLocation [index 737028 osmid (61785451,) @ 1 : 2] = new york\r\nLocation [index 792266 osmid (2218262347,) @ 1 : 2] = new york\r\nLocation [index 146732 osmid (-61320,) @ 1 : 2] = new york\r\nLocation [index 126105 osmid (-134353,) @ 2 : 2] = york\r\nLocation [index 758451 osmid (153595296,) @ 2 : 2] = york\r\nLocation [index 758454 osmid (153968758,) @ 2 : 2] = york\r\nLocation [index 114051 osmid (-1425436,) @ 2 : 2] = york\r\nLocation [index 758455 osmid (158656063,) @ 2 : 2] = york\r\nLocation [index 758452 osmid (153924230,) @ 2 : 2] = york\r\nLocation [index 758450 osmid (153473841,) @ 2 : 2] = york\r\nLocation [index 758449 osmid (151672942,) @ 2 : 2] = york\r\nLocation [index 758458 osmid (316990182,) @ 2 : 2] = york\r\nLocation [index 758448 osmid (151651405,) @ 2 : 2] = york\r\nLocation [index 800785 osmid (20913294,) @ 2 : 2] = york\r\nLocation [index 758447 osmid (151528825,) @ 2 : 2] = york\r\nLocation [index 140948 osmid (-148838,) @ 4 : 4] = usa\r\nLocation [index 190787 osmid (253067120,) @ 8 : 8] = bassett\r\nLocation [index 705552 osmid (151840681,) @ 8 : 8] = bassett\r\nLocation [index 705551 osmid (151463868,) @ 8 : 8] = bassett\r\nDisambiguated Location [index 0 osmid (-61320,) @ 1 : 2] = New York;NY;New York State : http://www.openstreetmap.org/relation/61320\r\nDisambiguated Location [index 3 osmid (-148838,) @ 4 : 4] = United States;US;USA;United States of America : http://www.openstreetmap.org/relation/148838\r\nDisambiguated Location [index 5 osmid (253067120,) @ 8 : 8] =  : http://www.openstreetmap.org/node/253067120\r\nText = live on the BBC Victoria Derbyshire is visiting Derbyshire for an exclusive UK interview\r\nLocation [index 87080 osmid (-2316741,) @ 4 : 4] = victoria\r\nLocation [index 177879 osmid (-10307525,) @ 4 : 4] = victoria\r\nLocation [index 754399 osmid (154301948,) @ 4 : 4] = victoria\r\nLocation [index 45074 osmid (-5606595,) @ 4 : 4] = victoria\r\nLocation [index 595897 osmid (385402175,) @ 4 : 4] = victoria\r\nLocation [index 595901 osmid (462241727,) @ 4 : 4] = victoria\r\nLocation [index 754403 osmid (158651084,) @ 4 : 4] = victoria\r\nLocation [index 754358 osmid (151336948,) @ 4 : 4] = victoria\r\nLocation [index 128827 osmid (-407423,) @ 4 : 4] = victoria\r\nLocation [index 595902 osmid (463188523,) @ 4 : 4] = victoria\r\nLocation [index 595899 osmid (447925715,) @ 4 : 4] = victoria\r\nLocation [index 595898 osmid (435240340,) @ 4 : 4] = victoria\r\nLocation [index 597713 osmid (277608416,) @ 4 : 4] = victoria\r\nLocation [index 45017 osmid (-5606596,) @ 4 : 4] = victoria\r\nLocation [index 775444 osmid (30189922,) @ 4 : 4] = victoria\r\nLocation [index 87296 osmid (-2256643,) @ 4 : 4] = victoria\r\nLocation [index 754364 osmid (151395812,) @ 4 : 4] = victoria\r\nLocation [index 157847 osmid (74701108,) @ 4 : 4] = victoria\r\nLocation [index 754393 osmid (151521359,) @ 4 : 4] = victoria\r\nLocation [index 161280 osmid (75538688,) @ 4 : 4] = victoria\r\nLocation [index 595900 osmid (460070685,) @ 4 : 4] = victoria\r\nLocation [index 754369 osmid (151476805,) @ 4 : 4] = victoria\r\nLocation [index 99056 osmid (-1828436,) @ 4 : 4] = victoria\r\nLocation [index 126056 osmid (-195384,) @ 8 : 8] = derbyshire\r\nLocation [index 146796 osmid (-62149,) @ 12 : 12] = uk\r\nDisambiguated Location [index 0 osmid (-195384,) @ 8 : 8] = Derbyshire : http://www.openstreetmap.org/relation/195384\r\nDisambiguated Location [index 2 osmid (-62149,) @ 12 : 12] = United Kingdom;GB;GBR;UK : http://www.openstreetmap.org/relation/62149\r\n```\r\n\r\n# Databases needed for preprocessing focus areas (optional)\r\nTo preprocess your own focus areas (e.g. a city with all its streets and buildings) you need a local deployment of the planet OpenStreetmapDatabase. Once a focus area is preprocessed a database table will be created for it. This can be used in the geoparse just like the 'global_cities' focus area is in the previous example. Instructions below are dated dec 2020, refer to links for more up-to-date information.\r\n\r\n[Osm2pgsql](http://wiki.openstreetmap.org/wiki/Osm2pgsql#From_the_package_manager)\r\n[Planet.osm](http://wiki.openstreetmap.org/wiki/Planet.osm)\r\n\r\n```\r\n# Download OpenStreetMap map data archive\r\n- http://wiki.openstreetmap.org/wiki/Planet.osm\r\n  + pick a mirror and download planet-latest.osm.bz2 file\r\n  + all maps are WGS84 coord system\r\n  + this will give you a .bz2 compressed .pbf file with the OSM dataset for the country specified\r\n- see https://github.com/openstreetmap/osm2pgsql\r\n\r\n# remove postgres (old versions - might not be needed if clean install)\r\nsudo apt list --installed | grep post\r\nsudo apt-get remove --purge postgresql-10\r\nsudo apt-get remove --purge postgresql-10-postgis-2.4-scripts\r\nsudo apt-get remove --purge postgis\r\n\r\n# install using a version number (otherwise get problems later)\r\nsudo apt-get install python3-apt\r\nsudo apt-get install postgresql-10-postgis-2.4\r\n\r\n# print versions\r\npg_config --version\r\npsql --version\r\n\r\nsudo /etc/init.d/postgresql stop\r\nsudo /etc/init.d/postgresql status\r\n\r\nsudo nano /etc/postgresql/10/main/pg_hba.conf\r\nhost    all             all             127.0.0.1/32            md5\r\nhost    all             all             127.0.0.1/32            trust\r\n\r\nsudo nano /etc/postgresql/10/main/postgresql.conf\r\n+ listen_addresses = '*'\r\n+ shared_buffers = 512MB\r\n+ work_mem = 512MB\r\n+ maintenance_work_mem = 2GB\r\n+ max_worker_processes = 16\r\n+ max_parallel_workers_per_gather = 8\r\n+ max_parallel_workers = 16\r\n+ constraint_exclusion = partition\r\n\r\nsudo /etc/init.d/postgresql start\r\nsudo /etc/init.d/postgresql status\r\n\r\n# check postgresql is running OK\r\nsudo netstat -nlp | grep 5432\r\nsudo cat /var/log/postgresql/postgresql-10-main.log\r\n\r\n# make postgis database (empty initially)\r\nsudo -u postgres createdb openstreetmap\r\nsudo -u postgres psql -d openstreetmap -c 'CREATE EXTENSION postgis; CREATE EXTENSION hstore;'\r\nsudo -u postgres psql -d openstreetmap -c \"SELECT * FROM information_schema.tables WHERE table_schema = 'public'\"\r\n\r\n# install osm\r\nsudo mkdir /var/lib/osm\r\ncd /var/lib/osm\r\nsudo wget http://ftp.snt.utwente.nl/pub/misc/openstreetmap/planet-latest.osm.bz2\r\n\r\n# make flat node file (as planet OSM is too large otherwise for RAM)\r\nsudo mkdir /var/lib/osm/flat-nodes\r\nsudo chown -R postgres /var/lib/osm/flat-nodes\r\n\r\n# run osm2pgsql (will take about 7 days to finish so redirect stderr and stdout to file and run as a deamon process)\r\nsudo apt-get install osm2pgsql\r\nsudo -u postgres osm2pgsql -c -d openstreetmap -P 5432 -E 4326 -S /usr/share/osm2pgsql/default.style -k -s -C 8192 --flat-nodes /var/lib/osm/flat-nodes/flat-node-index-file --number-processes 8 /var/lib/osm/planet-latest.osm.bz2 \u003e /var/lib/osm/osm2pgsql-stdout.log 2\u003e\u00261 \u0026\r\nsudo -u postgres psql -d openstreetmap -c \"SELECT * FROM information_schema.tables WHERE table_schema = 'public'\"\r\n```\r\n\r\n# Example code preprocess focus area (optional)\r\n\r\nPreprocessing new focus area tables in the Postgres database. Fully documented example PY file can be found at geoparsepy.example_preprocess_focus_area.py\r\n\r\n```python\r\nimport os, sys, logging, traceback, codecs, datetime, copy, time, ast, math, re, random, shutil, json\r\nimport soton_corenlppy, geoparsepy\r\n\r\nLOG_FORMAT = ('%(message)s')\r\nlogger = logging.getLogger( __name__ )\r\nlogging.basicConfig( level=logging.INFO, format=LOG_FORMAT )\r\nlogger.info('logging started')\r\n\r\ndictFocusAreaSpec = {\r\n\t'southampton' : {\r\n\t\t'focus_area_id' : 'southampton',\r\n\t\t'admin': ['southampton','south east england', 'united kingdom'],\r\n\t\t'admin_lookup_table' : 'global_cities_admin',\r\n\t}\r\n}\r\n\r\ndictGlobalSpec = None\r\n\r\ndictGeospatialConfig = geoparsepy.geo_parse_lib.get_geoparse_config( \r\n\tlang_codes = ['en'],\r\n\tlogger = logger,\r\n\twhitespace = u'\"\\u201a\\u201b\\u201c\\u201d()',\r\n\tsent_token_seps = ['\\n','\\r\\n', '\\f', u'\\u2026'],\r\n\tpunctuation = \"\"\",;\\/:+-#~\u0026*=!?\"\"\",\r\n\t)\r\n\r\ndbHandlerPool = {}\r\ndbHandlerPool['admin'] = soton_corenlppy.PostgresqlHandler.PostgresqlHandler( 'postgres', 'postgres', 'localhost', 5432, 'openstreetmap' )\r\ndbHandlerPool['point'] = soton_corenlppy.PostgresqlHandler.PostgresqlHandler( 'postgres', 'postgres', 'localhost', 5432, 'openstreetmap' )\r\ndbHandlerPool['poly'] = soton_corenlppy.PostgresqlHandler.PostgresqlHandler( 'postgres', 'postgres', 'localhost', 5432, 'openstreetmap' )\r\ndbHandlerPool['line'] = soton_corenlppy.PostgresqlHandler.PostgresqlHandler( 'postgres', 'postgres', 'localhost', 5432, 'openstreetmap' )\r\n\r\nfor strFocusArea in dictFocusAreaSpec.keys() :\r\n\tlogger.info( 'starting focus area ' + strFocusArea )\r\n\tjsonFocusArea = dictFocusAreaSpec[strFocusArea]\r\n\tgeoparsepy.geo_preprocess_lib.create_preprocessing_tables( jsonFocusArea, dbHandlerPool['admin'], 'public', delete_contents = False, logger = logger )\r\n\tdictNewLocations = geoparsepy.geo_preprocess_lib.execute_preprocessing_focus_area( jsonFocusArea, dbHandlerPool, 'public', logger = logger )\r\n\tlogger.info( 'finished focus area ' + strFocusArea )\r\n\tlogger.info( 'location id range : ' + repr(dictNewLocations) )\r\n\r\ndbHandlerPool['admin'].close()\r\ndbHandlerPool['point'].close()\r\ndbHandlerPool['poly'].close()\r\ndbHandlerPool['line'].close()\r\n```\r\n\r\n# Example code preprocess focus area output (optional)\r\n```\r\nlogging started\r\nloading stoplist from /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-geo-stoplist-en.txt\r\nloading whitelist from /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-geo-whitelist.txt\r\nloading blacklist from /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-geo-blacklist.txt\r\nloading building types from /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-buildingtype-en.txt\r\nloading location type corpus /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-buildingtype-en.txt\r\n- 3 unique titles\r\n- 76 unique types\r\nloading street types from /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-streettype-en.txt\r\nloading location type corpus /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-streettype-en.txt\r\n- 15 unique titles\r\n- 32 unique types\r\nloading admin types from /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-admintype-en.txt\r\nloading location type corpus /home/sem/.local/lib/python3.7/site-packages/geoparsepy/corpus-admintype-en.txt\r\n- 14 unique titles\r\n- 0 unique types\r\nloading gazeteer from /home/sem/.local/lib/python3.7/site-packages/geoparsepy/gazeteer-en.txt\r\nstarting focus area southampton\r\nstarting preprocessing of new focus area : {'focus_area_id': 'southampton', 'admin': ['southampton', 'south east england', 'united kingdom'], 'admin_lookup_table': 'global_cities_admin'}\r\nstarting SQL threads\r\nstart SQL (point x 2)   .\r\nstart SQL (line x 2)   .\r\nstart SQL (poly x 2)   .\r\nstart SQL (admin x 2)   .\r\nwaiting for joins\r\n  . end SQL (admin x 2)   .\r\n  . end SQL (point x 2)   .\r\n  . end SQL (line x 2)   .\r\n  . end SQL (poly x 2)   .\r\njoin successful\r\nfinished focus area southampton\r\nlocation id range : {'southampton_point': (1, 1327), 'southampton_line': (1, 2144), 'southampton_poly': (1, 2748), 'southampton_admin': (1, 7)}\r\n```\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstuartemiddleton%2Fgeoparsepy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstuartemiddleton%2Fgeoparsepy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstuartemiddleton%2Fgeoparsepy/lists"}