# !/usr/local/bin/python3.4.2
# ----Copyright (c) 2016 Carnegie Hall | The MIT License (MIT)----
# ----For the full license terms, please visit https://github.com/CarnegieHall/linked-data/blob/master/LICENSE----

## Argument[0] is script to run
## Argument[1] is path to graph

import os
import rdflib
from rdflib import Graph
from rdflib import Graph, Literal, Namespace, OWL, RDF, URIRef, XSD
from rdflib.namespace import DCTERMS, FOAF, OWL, RDF, RDFS, SKOS
from rdflib.plugins.serializers.nt import NTSerializer
from rdflib.plugins.serializers.turtle import TurtleSerializer
import sys

def fetch_name(filepath):
    return os.path.splitext(os.path.basename(filepath))[0]

geonames = Namespace('http://sws.geonames.org/')
wgs84_pos = Namespace('http://www.w3.org/2003/01/geo/wgs84_pos#')

filePath_1 = sys.argv[1]
fileName = fetch_name(filePath_1)

g = Graph()

g.parse(filePath_1, format='nt')

for place in countryDict:
    uri = place
    name = countryDict[place]['label']
    lat = countryDict[place]['lat']
    long = countryDict[place]['long']

    gPlaces.add( (URIRef(uri), RDFS.label, Literal(name)) )
    gPlaces.add( (URIRef(uri), wgs84_pos.lat, Literal(lat)) )
    gPlaces.add( (URIRef(uri), wgs84_pos.long, Literal(long)) )

graph_path = os.path.join(
    os.path.dirname(__file__), os.pardir, 'Graphs', (fileName + '.nt'))

g.bind("geonames", geonames)
gPlaces.bind("wgs84_pos", wgs84_pos)
g.bind("rdfs", RDFS)

g.serialize(destination=graph_path,format='nt')

print('Finished adding country labels to graph')

@@ -268,14 +268,70 @@
  to 
-graph%0A
+countryDict%0A## Argument%5B2%5D is path to placesGraph%0A%0Aimport json
 %0Aimp
@@ -866,16 +866,41 @@
 argv%5B1%5D%0A
+filePath_2 = sys.argv%5B2%5D%0A
 fileName
@@ -922,17 +922,17 @@
 ilePath_
-1
+2
 )%0A%0Ag = G
@@ -956,17 +956,17 @@
 ilePath_
-1
+2
 , format
@@ -977,168 +977,191 @@
 ')%0A%0A
-for place in countryDict:%0A    uri = place%0A    name = countryDict%5Bplace%5D%5B'label'%5D%0A    lat = countryDict%5Bplace%5D%5B'lat'%5D%0A    long = countryDict%5Bplace%5D%5B'long
+with open(filePath_1, 'rU') as f1:%0A    countries = json.load(f1)%0A    for country in countries:%0A        uri = countries%5Bcountry%5D%5B'uri'%5D%0A        name = countries%5Bcountry%5D%5B'label
 '%5D%0A%0A    
 gPla
@@ -1152,31 +1152,29 @@
 abel'%5D%0A%0A    
+  
-gPlaces
+  g
 .add( (URIRe
@@ -1213,134 +1213,8 @@
 )) )
-%0A    gPlaces.add( (URIRef(uri), wgs84_pos.lat, Literal(lat)) )%0A    gPlaces.add( (URIRef(uri), wgs84_pos.long, Literal(long)) )
 %0A%0Agr
@@ -1345,14 +1345,8 @@
 s)%0Ag
-Places
 .bin
@@ -1477,19 +1477,23 @@
 try 
-labels to g
+info to placesG
 raph

Remove lat/long from script