Skip to content

Commit c9f85f1

Browse files
committed
update imports
1 parent ca8edea commit c9f85f1

3 files changed

Lines changed: 55 additions & 46 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
extra_synonyms = {"VN": {"Vietnam"}, "US": {"USA", "the US", r"U.S", r"U.S.", "U.S.A."}, "CZ": {"Czech Rep", "Czech Republic"},
2+
"AE": {"UAE", r"U.A.E."},
3+
"KR": {"Korea", "Republic of Korea"}, "KP": {"North Korea", "Democratic People's Republic of Korea", "Democratic Peoples Republic of Korea", "DPRK", r"D.P.R.K."},
4+
"CI": {"Ivory Coast", "Cote d'Ivoire", "Cote dIvoire", "Cote Divoire"}, "CD": {"Congo, The Democratic Republic", "Congo, Democratic Republic",
5+
"Democratic Republic of the Congo",
6+
"Democratic Republic of Congo", "DR Congo", "DRC"},
7+
"CV": {"Cape Verde"}, "SH": {"St. Helena", "St Helena"},
8+
"GB": {"Britain", "United Kingdom", "UK", r"U.K", r"U.K."},
9+
"RU": {"Russia"}, "VA": {"Holy See"}, "BN": {"Brunei"}, "LA": {"Laos", "LPDR"},
10+
"VG": {"British Virgin Islands", "Virgin Islands (British)", "Virgin Islands, British",
11+
'Virgin Islands (Great Britain)',
12+
'Virgin Islands (GB)',
13+
'Virgin Islands (Britain)',
14+
'Virgin Islands (UK)'
15+
},
16+
"VI": {"Virgin Islands (US)", "Virgin Islands (U.S.)", "Virgin Islands, US", "Virgin Islands, U.S.",
17+
'Virgin Islands (USA)',
18+
'Virgin Islands (U.S.A.)',
19+
'USA Virgin Islands',
20+
'U.S. Virgin Islands',
21+
'US Virgin Islands',
22+
'American Virgin Islands',
23+
'U.S.A. Virgin Islands',
24+
},
25+
"SY": {"Syria"}, "GE": {"Republic of Georgia"},
26+
'GM': {'gambia, republic of', 'gambia republic', 'republic of gambia', 'republic of the gambia'},
27+
"NL": {"Nerlands"}, "IR": {"Iran"}, "AE": {"UAE", "U.A.E."},
28+
"MK": {"Macedonia, The Former Yugoslav Republic of", "Macedonia, Former", "FYROM"},
29+
"RS": {"Kosovo", "Former Yugoslavia", "Former Serbia and Montenegro"},
30+
# Kosovo currently mapped to Serbia for technical reasons because Kosovo is not currently its own 2 letter code in Debian or Pycountry (the dependencies of this library)
31+
"SZ": {"Swaziland", "eswatini", "eSwatini"},
32+
"LY": {"Libyan Arab Jamahiriya"},
33+
"PS": {"Palestinian Territories, Occupied", "Palestinian Territory, occupied", "Palestine, Occupied",
34+
"Occupied Palestine"},
35+
"CN": {"Macau"},
36+
"LC": {"St Lucia", "St. Lucia"},
37+
"KN": {"St Kitts and Nevis", "St. Kitts and Nevis"},
38+
"VC": {"St Vincent and the Grenadines", "St. Vincent and the Grenadines"},
39+
# For compatibility with various versions of pycountry
40+
"TR": {"Turkey", "Turkiye", "Türkiye"},
41+
"GQ": {"equatorial Guinea", "ecuatorial Guinea", "Equatorial Guinea", "Ecuatorial Guinea",
42+
"Guinea equatorial", "Guinea ecuatorial", "Guinea Equatorial", "Guinea Ecuatorial"}
43+
}

src/country_named_entity_recognition/country_finder.py

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,14 @@
2929

3030
import operator
3131
import re
32-
32+
import sys
33+
import pathlib
34+
this_folder = pathlib.Path(__file__).parent.resolve()
35+
sys.path.append(f"{this_folder}")
36+
sys.path.append(f"{this_folder}/..")
37+
from common import extra_synonyms
3338
import pycountry
3439

35-
extra_synonyms = {"VN": {"Vietnam"}, "US": {"USA", "the US", r"U.S", r"U.S.", "U.S.A."}, "CZ": {"Czech Rep", "Czech Republic"},
36-
"AE": {"UAE", r"U.A.E."},
37-
"KR": {"Korea", "Republic of Korea"}, "KP": {"North Korea", "Democratic People's Republic of Korea", "Democratic Peoples Republic of Korea", "DPRK", r"D.P.R.K."},
38-
"CI": {"Ivory Coast", "Cote d'Ivoire", "Cote dIvoire", "Cote Divoire"}, "CD": {"Congo, The Democratic Republic", "Congo, Democratic Republic",
39-
"Democratic Republic of the Congo",
40-
"Democratic Republic of Congo", "DR Congo", "DRC"},
41-
"CV": {"Cape Verde"}, "SH": {"St. Helena", "St Helena"},
42-
"GB": {"Britain", "United Kingdom", "UK", r"U.K", r"U.K."},
43-
"RU": {"Russia"}, "VA": {"Holy See"}, "BN": {"Brunei"}, "LA": {"Laos", "LPDR"},
44-
"VG": {"British Virgin Islands", "Virgin Islands (British)", "Virgin Islands, British",
45-
'Virgin Islands (Great Britain)',
46-
'Virgin Islands (GB)',
47-
'Virgin Islands (Britain)',
48-
'Virgin Islands (UK)'
49-
},
50-
"VI": {"Virgin Islands (US)", "Virgin Islands (U.S.)", "Virgin Islands, US", "Virgin Islands, U.S.",
51-
'Virgin Islands (USA)',
52-
'Virgin Islands (U.S.A.)',
53-
'USA Virgin Islands',
54-
'U.S. Virgin Islands',
55-
'US Virgin Islands',
56-
'American Virgin Islands',
57-
'U.S.A. Virgin Islands',
58-
},
59-
"SY": {"Syria"}, "GE": {"Republic of Georgia"},
60-
'GM': {'gambia, republic of', 'gambia republic', 'republic of gambia', 'republic of the gambia'},
61-
"NL": {"Nerlands"}, "IR": {"Iran"}, "AE": {"UAE", "U.A.E."},
62-
"MK": {"Macedonia, The Former Yugoslav Republic of", "Macedonia, Former", "FYROM"},
63-
"RS": {"Kosovo", "Former Yugoslavia", "Former Serbia and Montenegro"},
64-
# Kosovo currently mapped to Serbia for technical reasons because Kosovo is not currently its own 2 letter code in Debian or Pycountry (the dependencies of this library)
65-
"SZ": {"Swaziland", "eswatini", "eSwatini"},
66-
"LY": {"Libyan Arab Jamahiriya"},
67-
"PS": {"Palestinian Territories, Occupied", "Palestinian Territory, occupied", "Palestine, Occupied",
68-
"Occupied Palestine"},
69-
"CN": {"Macau"},
70-
"LC": {"St Lucia", "St. Lucia"},
71-
"KN": {"St Kitts and Nevis", "St. Kitts and Nevis"},
72-
"VC": {"St Vincent and the Grenadines", "St. Vincent and the Grenadines"},
73-
# For compatibility with various versions of pycountry
74-
"TR": {"Turkey", "Turkiye", "Türkiye"},
75-
"GQ": {"equatorial Guinea", "ecuatorial Guinea", "Equatorial Guinea", "Ecuatorial Guinea",
76-
"Guinea equatorial", "Guinea ecuatorial", "Guinea Equatorial", "Guinea Ecuatorial"}
77-
}
7840
countries_maps = {}
7941

8042
def _add_variant(name: str, country):

src/country_named_entity_recognition/country_finder_spacy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import pycountry
22
import re
3-
from country_finder import extra_synonyms
43
import spacy
54
from spacy.matcher import PhraseMatcher
6-
5+
import sys
6+
import pathlib
7+
this_folder = pathlib.Path(__file__).parent.resolve()
8+
sys.path.append(f"{this_folder}")
9+
sys.path.append(f"{this_folder}/..")
10+
from common import extra_synonyms
711

812
# A set of key words which indicate Georgia the country if they occur within 3 tokens of a mention of Georgia
913
georgia_country_terms = {"country", "caucasus", "sakartvelo", "kartvelian", "ossetia", "black sea", "caspian", "idze",

0 commit comments

Comments
 (0)