class TarqlTest(unittest.TestCase, TestBase): executor = Tarql(QueryUtils()) def test_execute_query_pos(self): query_raw = resource_filename("common.test.resources.tarql", "query.tarql") csv = resource_filename("common.test.resources.tarql", "test.csv") expected_file = resource_filename("common.test.resources.tarql", "out.ttl") result = tarqls_compare(query_raw, csv, expected_file, "--encoding utf8 -d ;") self.assertEqual(result[0], result[1]) def test_execute_query_neg(self): temp = tempfile.NamedTemporaryFile() query_raw = resource_filename("common.test.resources.tarql", "query.tarql") csv = resource_filename("common.test.resources.tarql", "test.csv") self.assertRaises(Exception, self.executor.execute_query, query_raw, csv, temp.name, "--encoding utf8 -dd ;") def test_execute_query_neg_no_qfile(self): temp = tempfile.NamedTemporaryFile() csv = resource_filename("common.test.resources.tarql", "test.csv") self.assertRaises(IOError, self.executor.execute_query, "dummy.file.query", csv, temp.name, "--encoding utf8 -d ;") def test_execute_query_neg_no_csvfile(self): temp = tempfile.NamedTemporaryFile() query_raw = resource_filename("common.test.resources.tarql", "query.tarql") self.assertRaises(Exception, self.executor.execute_query, query_raw, "dummy.file.query", temp.name, "--encoding utf8 -d ;")
# coding: utf-8 from common.sparql.QueryUtils import QueryUtils from common.tarql import Tarql tarql = Tarql(QueryUtils()) queryArgs = { "EL": "mi2019", } basePath = "/home/nikola/projects/semanticElections/data/" ## risky sections basePath = "/home/nikola/projects/semanticElections/data/" infile = "/home/nikola/projects/semanticElections/analysis/akf/risky_2021/11-2021/risky-low.csv" tarql.execute_query(basePath + "tarql/risky_sections.tarql", infile, basePath + "rdf/mappings/risky_2021-11_low.ttl", '-d ,', queryArgs)
# coding: utf-8 from common.sparql.QueryUtils import QueryUtils from common.tarql import Tarql tarql = Tarql(QueryUtils()) basePath = "/home/nikola/projects/semanticElections/data/" ## SECTIONS queryArgs = { "YEAR": "2021" , "EL": "pi2021_11" , "TYP_LABEL": "Парламент на РБ МИР ", "EL_LABEL" : "Избори 14 Ноември 2021", } infile = '/home/nikola/projects/semanticElections/gdrive/data/cikOpenData/pi2021_11/sections_14.11.2021.txt' tarql.execute_query(basePath+"tarql/sections_pi.tarql", infile, basePath+"rdf/pi2021_11/sections.ttl", '-d ; -H', queryArgs) ## VOTE queryArgs = { "EL": "pi2021_11" , "TYP" : "" , "RND" : "" , "MV" : "true", }
# coding: utf-8 from common.sparql.QueryUtils import QueryUtils from common.tarql import Tarql tarql = Tarql(QueryUtils()) queryArgs = { "EL": "mi2019", } basePath = "/home/nikola/projects/semanticElections/data/" ## MAIN PARTIES basePath = "/home/nikola/projects/semanticElections/data/" infile = "/home/nikola/projects/semanticElections/data/static/sheets/main_election_data.csv" tarql.execute_query(basePath + "tarql/main_election_data.tarql", infile, basePath + "rdf/mappings/main_election_data.ttl", '-d ,', queryArgs) ## Coalitions Mapping 2015 infile = "/home/nikola/projects/semanticElections/data/static/sheets/coalitions_mi2015.csv" tarql.execute_query(basePath + "tarql/coalitions_mi2015.tarql", infile, basePath + "rdf/mi2015/coalitions_mapping.ttl", '-d ,', queryArgs) ## Coalitions Mapping 2019 infile = "/home/nikola/projects/semanticElections/data/static/sheets/coalitions_mi2019.csv"
# coding: utf-8 from common.sparql.QueryUtils import QueryUtils from common.tarql import Tarql tarql = Tarql(QueryUtils()) basePath = "/home/nikola/projects/semanticElections/data/" ## SECTIONS queryArgs = { "EL": "ep2019" , "TYP" : "ep", "TYP_LABEL": "Европейски Парламент 2019", "EL_LABEL" : "Избори за Европейски Парламент 2019", } infile = '/home/nikola/projects/semanticElections/gdrive/data/cikOpenData/ep2019/sections.txt' tarql.execute_query(basePath+"tarql/sections_ep.tarql", infile, basePath+"rdf/ep2019/sections.ttl", '-d ; -H', queryArgs) ## PROTOCOLS queryArgs = { "EL": "ep2019" , "TYP" : "" , "RND" : "" , "LINK_HTML" : "https://results.cik.bg/ep2019/protokoli/",
# coding: utf-8 from common.sparql.QueryUtils import QueryUtils from common.tarql import Tarql tarql = Tarql(QueryUtils()) basePath = "/home/nikola/projects/semanticElections/data/" ## SECTIONS queryArgs = { "YEAR": "2014", "EL": "pi2014", "TYP_LABEL": "Парламент на РБ МИР ", "EL_LABEL": "Избори", } infile = '/home/nikola/projects/semanticElections/gdrive/data/cikOpenData/pi2014/sections_pe2014.txt' tarql.execute_query(basePath + "tarql/sections_pi_14.tarql", infile, basePath + "rdf/pi2014/sections.ttl", '-d ; -H', queryArgs) ## VOTE queryArgs = { "EL": "pi2014", "TYP": "", "RND": "", "MV": "", } infile = '/home/nikola/projects/semanticElections/gdrive/data/cikOpenData/pi2014/votes_pe2014.flat.txt' tarql.execute_query(basePath + "tarql/votes.tarql", infile, basePath + "rdf/pi2014/votes.ttl", '-d ; -H', queryArgs)
# coding: utf-8 from common.sparql.QueryUtils import QueryUtils from common.tarql import Tarql tarql = Tarql(QueryUtils()) basePath = "/home/nikola/projects/semanticElections/data/" ## SECTIONS KO TUR1 queryArgs = { "EL": "mi2019", "EL_LABEL": "Местни Избори 2019", "TYP": "ko", "TYP_LABEL": "кмет на община", "RND": "tur1", "RND_LABEL": "Тур 1", "RND_INT": "1" } infile = '/home/nikola/projects/semanticElections/gdrive/data/cikOpenData/mi2019/tur1/ko/sections_27.10.2019.txt' outfilePath = basePath + "rdf/" + queryArgs["EL"] + "/" + queryArgs[ "TYP"] + "_" + queryArgs["RND"].replace("/", "") tarql.execute_query(basePath + "tarql/sections_tur.tarql", infile, outfilePath + "_sections.ttl", '-d ; -H', queryArgs) ## SECTIONS KO TUR2 queryArgs = { "EL": "mi2019", "EL_LABEL": "Местни Избори 2019", "TYP": "ko",
def tarqls_compare(query_path, csv_path, expected_path, tarql_arguments): temp = tempfile.NamedTemporaryFile() Tarql(QueryUtils()).execute_query(query_path, csv_path, temp.name, tarql_arguments) return (sorted(list(Graph().parse(temp.name, format="ttl"))), sorted(list(Graph().parse(expected_path, format="ttl"))))
# coding: utf-8 from common.sparql.QueryUtils import QueryUtils from common.tarql import Tarql tarql = Tarql(QueryUtils()) basePath = "/home/nikola/projects/semanticElections/data/" ## SECTIONS KO TUR2 queryArgs = { "EL": "pvnr2016" , "TYP" : "pvnr", "EL_LABEL" : "Избори за Президент и Вицепрезидент 2016", "RND": "tur1", "RND_LABEL": "Тур 1", "RND_INT": "1" } infile = '/home/nikola/projects/semanticElections/gdrive/data/cikOpenData/pvnr2016/tur1/sections_06.11.2016.txt' tarql.execute_query(basePath+"tarql/sections_pvnr.tarql", infile, basePath+"rdf/pvnr2016/sections_tur1.ttl", '-d ; -H', queryArgs) ## SECTIONS TUR2 queryArgs = { "EL": "pvnr2016" ,