-
Notifications
You must be signed in to change notification settings - Fork 0
/
line.py
45 lines (40 loc) · 1.78 KB
/
line.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Class module for managing bus lines."""
from rdf_utils import write_rdf_prop, print_stops
class Line(object):
"""Class describing a bus line according to the attributes
provided by the Grand Lyon Open Data platform."""
BUS_GRAPHNAME = "tcl:busLines"
SUB_GRAPHNAME = "tcl:subwayLines"
TRAM_GRAPHNAME = "tcl:tramLines"
def __init__(self, num, line, index, color, label, garage, titan, orientation, stops):
"""Line object constructor."""
self.number = num
self.index = index
self.line_number = line
self.color = color
self.label = label
self.garage = garage
self.titan = titan
self.orientation = orientation
self.stops = stops
def print_rdf(self, out, graph_name):
"""Outputs the matching rdf properties (in Turtle syntax)
for a Line object on a given file."""
if graph_name == self.BUS_GRAPHNAME:
prop = "gtfs:Bus"
letter = 'b'
elif graph_name == self.SUB_GRAPHNAME:
prop = "gtfs:Subway"
letter = 's'
elif graph_name == self.TRAM_GRAPHNAME:
prop = "gtfs:LightRail"
letter = 't'
out.write("\ttcl:" + letter + str(self.number) + "\n")
write_rdf_prop(out, 2, "a", prop, False)
write_rdf_prop(out, 2, "tcl:lineNumber", '"'+self.line_number+'"', False)
write_rdf_prop(out, 2, "tcl:indexNumber", '"'+self.index+'"', False)
write_rdf_prop(out, 2, "rdfs:label", '"'+self.label+'"', False)
write_rdf_prop(out, 2, "tcl:orientation", '"'+self.orientation+'"', False)
print_stops(out, self.stops)
write_rdf_prop(out, 2, "tcl:titanCode", '"'+self.titan+'"', False)
write_rdf_prop(out, 2, "tcl:garageCode", '"'+self.garage+'"', True)