I finished my studies on gun violence. The hypothesis was gun violence is strongly correlated to gun density (gun deaths/100K related to number of guns/100, for all developed nations), as was presented on a graph I was given. I wanted to prove the correlation existed, but the analysis failed to demonstrate a significant correlation. On the other hand, the exercise did provide me with a great opportunity to enjoy some Prolog coding, learn SWI-Prolog, and learn how to do API web interfacing.
Since the hypothesis was not supported, I will not be doing a full writeup for publication, but I did do a quick summary of the goal, procedures, results, supporting data, and the Prolog code. I will email that write-up to anyone interested (just provide me your email address).
Here are the required libraries and the key predicate clause for accessing the web data:
:- use_module(library(http/http_open)) .
:- use_module(library(http/http_client)) .
:- use_module(library(http/json)) .
:- use_module(library(http/json_convert)) .
ask_gunpolicy(Topic, Location, Country, Reply) :-
credentials(User, Key) ,
atomic_list_concat(
[ 'https://www .gunpolicy .org/index.php?option=com_api',
'&app=gpodatapage',
'&clientid=',User,
'&key=', Key,
'&format=raw&resource=getcategorydata',
'&category=', Topic,
'&location_id=', Location
], Query) ,
http_get(Query, Reply, []) ,
atom_json_term(Reply, json([result=json(JT)]), []) ,
{rest omitted}
This predicates takes three inputs, and writes one line of formatted data to output per invocation. Data is returned as a fourth argument mostly to handle exceptions from incorrectly formatted web responses.
Additional code generates the numerous ask_gunpolicy/4 calls for each of 50 countries, and 8 different data categories per country. The final output is comma separated data (“Country, Category1, …, Category 8,”) that is imported directly into Excel for statistical analysis and graphing. Also, each returned Category data has multiple elements that include source reference, and year/value data pairs, and the Prolog separates all the values and returns an average value. Had the study shown a significant correlation, then data would have been further broken down by year, and more of the stat analysis would have been done in Prolog (rather than just a simple averaging).’
Thanks for the much appreciated help and guidance!