Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # -*- coding: utf-8 -*-
"""The full fill_monuments_all generation."""
""" Initialize the fill_monuments_all SQL object.
@param datasets: list of MonumentDatasetSql objects. """ os.path.dirname(os.path.abspath(__file__)), "sql")
"""Construct the opening SQL describing the main table."""
"""Construct the ending SQL replacing the real table by the new one."""
"""Construct the full SQL needed to insert all datasets.""" intro=self.make_intro_sql(), data='\n'.join([dataset.get_sql() for dataset in self.datasets]), outro=self.make_outro_sql())
"""Output the SQL to the correct file.""" filename = "fill_table_{domain}_all.sql".format(domain=self.domain) with open(os.path.join(self.sql_dir, filename), "w", encoding='utf-8') as f: f.write(self.get_sql())
"""A single dataset (country) in the fill_monuments_all generation."""
""" Initialize the dataset SQL object.
@param country: Full text name of country or dataset. E.g. 'Andorra' or 'Sweden (Listed historical ships)'. @param language: Full text name of the language. E.g. 'Swedish'. @param table: Table name (need not be "{domain}_{country}_({lang})") @param replacements: Dictionary with target variable as key and replacement SQL a value. e.g. {"adm0": "'ad'", "lat": "`lat`"} @param where: A WHERE SQL clause, without the "WHERE" (optional). """
('country', None), ('lang', None), ('project', None), ('id', None), ('adm0', None), ('adm1', None), ('adm2', None), ('adm3', None), ('adm4', None), ('name', None), ('address', None), ('municipality', None), ('lat', None), ('lon', None), ('lat_int', 'ROUND(`lat` * @granularity)'), ('lon_int', 'ROUND(`lon` * @granularity)'), ('image', None), ('wd_item', None), ('commonscat', None), ('source', None), ('changed', None), ('monument_article', None), ('registrant_url', None) ])
""" Implement less than to allow for sorting.
Sorting is done on table name.
@param other: a second MonumentDatasetSql object. """
"""Return the list of replaced variables."""
"""Return the formated where clause."""
"""Construct the full SQL needed to insert a dataset.""" " FROM `{table}`{where};\n") intro=self.make_intro_sql(), variable=self.make_varible_sql(), where=self.make_where_sql(), table=self.table)
"""Construct the opening SQL listing fields to be replaced.""" "REPLACE INTO\n" " `{domain}_all_tmp` (\n" " {replaced}\n" ") SELECT\n") dataset=self.country, lang=self.language, domain=self.domain, replaced=", ".join(["`{}`".format(x) for x in replaced]))
"""Construct the SQL for mapping country tables variables.""" val=value, var=variable))
""" Load the dataset specific replacements into self.variables.
Does not accept variables other than those in self.variables. Automatically handles lat_int and lon_int.
@param replacements: Dictionary with target variable as key and replacement SQL a value. e.g. {"adm0": "'ad'", "lat": "`lat`"} """ raise ValueError( "All of the required fields '{}' must be replaced".format( "','".join(required_fields)))
raise ValueError( "All variables must be encoded through VariableType, " "'{}' was not".format(variable))
pywikibot.warning( "Unrecognized variable in {table}: {variable}".format( table=self.table, variable=target))
"""A single dataset (country) in the fill_monuments_all generation."""
""" Initialize the dataset SQL object.
@param country: Full text name of country or dataset. E.g. 'Andorra' or 'Sweden (Listed historical ships)'. @param language: Full text name of the language. E.g. 'Swedish'. @param table: Table name (need not be "{domain}_{country}_({lang})") @param replacements: Dictionary with target variable as key and replacement SQL a value. e.g. {"adm0": "'ad'", "lat": "`lat`"} @param where: A WHERE SQL clause, without the "WHERE" (optional). """ country, language, table, replacements, where)
"""Return the list of replaced variables.""" # the following list is determined by the sql template 'municipality', 'lat', 'lon', 'lat_int', 'lon_int', 'image', 'wd_item', 'commonscat', 'source', 'changed', 'monument_article', 'registrant_url']
""" Load the dataset specific replacements.
Does not accept variables other than those in self.variables. Automatically handles lat_int and lon_int.
@param replacements: Dictionary with target variable as key and replacement SQL a value. e.g. {"adm0": "'ad'", "lat": "`lat`"} """ raise ValueError( "All of the required fields '{}' must be replaced".format( "','".join(required_fields)))
"""Make the main body of the sql file, i.e. the mapping.""" dataset=self.dataset, lang=self.lang, adm0=self.adm0 )
def load_wikidata_template_sql(): """Fetch the SQL template for a wikidata config."""
"""Abstract class to hold the variable type for a replacement variable."""
"""Output the variable in a sql compatible mode.""" raise NotImplementedError
"""A plain string."""
"""A field reference."""
"""Raw sql."""
"""Return directory containing config files.""" os.path.dirname(os.path.abspath(__file__)), 'monuments_config')
"""Return directory containing template files.""" os.path.dirname(os.path.abspath(__file__)), 'template')
"""Load config file as json."""
"""Construct MonumentDatasetSql from json data.""" data['table'], sql_data, data.get('sql_where'))
"""Convert loaded sql data entries to objects.""" 'Text': Text, 'Field': Field, 'Raw': Raw } except TypeError: raise ValueError('Unknown type detected: {}'.format(v['type']))
"""Return all MonumentDatasetSql which can be constructed from configs."""
"""Make and write the fill_monuments_all.sql file.""" datasets = get_all_dataset_sql(domain) MonumentsAllSql(datasets, domain).write_sql()
make_fill_monuments_all() |