self.conn.commit()
+ def add_country(self, country_code, word_token):
+ with self.conn.cursor() as cur:
+ cur.execute("INSERT INTO word (word_token, country_code) VALUES(%s, %s)",
+ (word_token, country_code))
+ self.conn.commit()
+
+
def add_postcode(self, word_token, postcode):
with self.conn.cursor() as cur:
cur.execute("""INSERT INTO word (word_token, word, class, type)
with self.conn.cursor() as cur:
cur.execute("""SELECT word_token, word, class, type, operator
FROM word WHERE class != 'place'""")
- return set((tuple(row) for row in cur))
+ result = set((tuple(row) for row in cur))
+ assert len(result) == cur.rowcount, "Word table has duplicates."
+ return result
+
+
+ def get_country(self):
+ with self.conn.cursor() as cur:
+ cur.execute("""SELECT country_code, word_token
+ FROM word WHERE country_code is not null""")
+ result = set((tuple(row) for row in cur))
+ assert len(result) == cur.rowcount, "Word table has duplicates."
+ return result
def get_postcodes(self):
@pytest.fixture
def make_standard_name(temp_db_cursor):
temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION make_standard_name(name TEXT)
- RETURNS TEXT AS $$ SELECT ' ' || name; $$ LANGUAGE SQL""")
+ RETURNS TEXT AS $$ SELECT '#' || lower(name) || '#'; $$ LANGUAGE SQL""")
@pytest.fixture
analyzer.update_special_phrases([
("König bei", "amenity", "royal", "near"),
("Könige", "amenity", "royal", "-"),
+ ("könige", "amenity", "royal", "-"),
("strasse", "highway", "primary", "in")
], True)
assert word_table.get_special() \
- == set(((' könig bei', 'könig bei', 'amenity', 'royal', 'near'),
- (' könige', 'könige', 'amenity', 'royal', None),
- (' strasse', 'strasse', 'highway', 'primary', 'in')))
+ == set(((' #könig bei#', 'könig bei', 'amenity', 'royal', 'near'),
+ (' #könige#', 'könige', 'amenity', 'royal', None),
+ (' #strasse#', 'strasse', 'highway', 'primary', 'in')))
def test_update_special_phrase_delete_all(analyzer, word_table, make_standard_name):
- word_table.add_special(' foo', 'foo', 'amenity', 'prison', 'in')
- word_table.add_special(' bar', 'bar', 'highway', 'road', None)
+ word_table.add_special(' #foo#', 'foo', 'amenity', 'prison', 'in')
+ word_table.add_special(' #bar#', 'bar', 'highway', 'road', None)
assert word_table.count_special() == 2
def test_update_special_phrases_no_replace(analyzer, word_table, make_standard_name):
- word_table.add_special(' foo', 'foo', 'amenity', 'prison', 'in')
- word_table.add_special(' bar', 'bar', 'highway', 'road', None)
+ word_table.add_special(' #foo#', 'foo', 'amenity', 'prison', 'in')
+ word_table.add_special(' #bar#', 'bar', 'highway', 'road', None)
assert word_table.count_special() == 2
def test_update_special_phrase_modify(analyzer, word_table, make_standard_name):
- word_table.add_special(' foo', 'foo', 'amenity', 'prison', 'in')
- word_table.add_special(' bar', 'bar', 'highway', 'road', None)
+ word_table.add_special(' #foo#', 'foo', 'amenity', 'prison', 'in')
+ word_table.add_special(' #bar#', 'bar', 'highway', 'road', None)
assert word_table.count_special() == 2
], True)
assert word_table.get_special() \
- == set(((' prison', 'prison', 'amenity', 'prison', 'in'),
- (' bar', 'bar', 'highway', 'road', None),
- (' garden', 'garden', 'leisure', 'garden', 'near')))
+ == set(((' #prison#', 'prison', 'amenity', 'prison', 'in'),
+ (' #bar#', 'bar', 'highway', 'road', None),
+ (' #garden#', 'garden', 'leisure', 'garden', 'near')))
+
+
+def test_add_country_names(analyzer, word_table, make_standard_name):
+ analyzer.add_country_names('de', ['Germany', 'Deutschland', 'germany'])
+
+ assert word_table.get_country() \
+ == {('de', ' #germany#'),
+ ('de', ' #deutschland#')}
+
+
+def test_add_more_country_names(analyzer, word_table, make_standard_name):
+ word_table.add_country('fr', ' #france#')
+ word_table.add_country('it', ' #italy#')
+ word_table.add_country('it', ' #itala#')
+
+ analyzer.add_country_names('it', ['Italy', 'IT'])
+
+ assert word_table.get_country() \
+ == {('fr', ' #france#'),
+ ('it', ' #italy#'),
+ ('it', ' #itala#'),
+ ('it', ' #it#')}
def test_process_place_names(analyzer, make_keywords):