From 142e192ff90578499243fe191b910a70e01d9562 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 27 Jan 2021 16:12:48 +0100 Subject: [PATCH] Move examples to the top level --- AspectedRouting/Examples/Format.md | 44 - .../bicycle/aspects/bicycle.comfort.json | 75 -- .../bicycle/aspects/bicycle.legal_access.json | 80 -- .../bicycle.network_is_nodenetwork.json | 13 - .../bicycle/aspects/bicycle.oneway.json | 54 - .../bicycle/aspects/bicycle.safety.json | 84 -- .../bicycle/aspects/bicycle.speed_factor.json | 69 -- AspectedRouting/Examples/bicycle/bicycle.json | 95 -- .../bicycle/tests/bicycle.comfort.test.csv | 18 - .../tests/bicycle.fastest.behaviour_test.csv | 14 - .../tests/bicycle.legal_access.test.csv | 22 - .../tests/bicycle.networks.behaviour_test.csv | 6 - .../bicycle/tests/bicycle.oneway.test.csv | 19 - .../bicycle/tests/bicycle.safety.test.csv | 13 - .../tests/bicycle.shortest.behaviour_test.csv | 5 - .../tests/bicycle.speed_factor.test.csv | 13 - .../general/clean_permission_score.json | 12 - .../general/clean_permission_score.test.csv | 5 - .../Examples/general/ferry_speed.json | 46 - .../Examples/general/ferry_speed.test.csv | 9 - .../Examples/general/legal_maxspeed_be.json | 42 - .../general/legal_maxspeed_be.test.csv | 5 - .../aspects/pedestrian.legal_access.json | 78 -- .../Examples/pedestrian/pedestrian.json | 40 - .../tests/pedestrian.legal_access.test.csv | 4 - .../pedestrian.slow_roads.behaviour_test.csv | 5 - outputhelpText.md | 1058 ----------------- 27 files changed, 1928 deletions(-) delete mode 100644 AspectedRouting/Examples/Format.md delete mode 100644 AspectedRouting/Examples/bicycle/aspects/bicycle.comfort.json delete mode 100644 AspectedRouting/Examples/bicycle/aspects/bicycle.legal_access.json delete mode 100644 AspectedRouting/Examples/bicycle/aspects/bicycle.network_is_nodenetwork.json delete mode 100644 AspectedRouting/Examples/bicycle/aspects/bicycle.oneway.json delete mode 100644 AspectedRouting/Examples/bicycle/aspects/bicycle.safety.json delete mode 100644 AspectedRouting/Examples/bicycle/aspects/bicycle.speed_factor.json delete mode 100644 AspectedRouting/Examples/bicycle/bicycle.json delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.comfort.test.csv delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.fastest.behaviour_test.csv delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.legal_access.test.csv delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.networks.behaviour_test.csv delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.oneway.test.csv delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.safety.test.csv delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.shortest.behaviour_test.csv delete mode 100644 AspectedRouting/Examples/bicycle/tests/bicycle.speed_factor.test.csv delete mode 100644 AspectedRouting/Examples/general/clean_permission_score.json delete mode 100644 AspectedRouting/Examples/general/clean_permission_score.test.csv delete mode 100644 AspectedRouting/Examples/general/ferry_speed.json delete mode 100644 AspectedRouting/Examples/general/ferry_speed.test.csv delete mode 100644 AspectedRouting/Examples/general/legal_maxspeed_be.json delete mode 100644 AspectedRouting/Examples/general/legal_maxspeed_be.test.csv delete mode 100644 AspectedRouting/Examples/pedestrian/aspects/pedestrian.legal_access.json delete mode 100644 AspectedRouting/Examples/pedestrian/pedestrian.json delete mode 100644 AspectedRouting/Examples/pedestrian/tests/pedestrian.legal_access.test.csv delete mode 100644 AspectedRouting/Examples/pedestrian/tests/pedestrian.slow_roads.behaviour_test.csv delete mode 100644 outputhelpText.md diff --git a/AspectedRouting/Examples/Format.md b/AspectedRouting/Examples/Format.md deleted file mode 100644 index 3220ae7..0000000 --- a/AspectedRouting/Examples/Format.md +++ /dev/null @@ -1,44 +0,0 @@ - -# Functions - -- `$funcName` indicates a builtin function -- `#parameter` indicates a configurable parameter - -A profile is a function which maps a set of tags onto a value. It is basically Haskell, except that functions can have _multiple_ types. During typechecking, some types will turn out not to be possible and they will dissappear, potentially fixing the implementation of the function itself. - -# Injected tags - -Aspects can use the following (extra) tags: - -- `_direction` is the value to indicate if the traveller goes forward or backwards. It is not available when calculating the 'oneway' field -- `access` will become the value calculated in the field `access` (not available to calculate access) -- `oneway` will become the value calculated in the field `oneway` (not available to calculate access and speed) - - -# Vehicle.json - -- Metdata: these tags will be copied to the routerdb, but can not be used for routeplanning. A prime example is `name` (the streetname), as it is useful for routeplanning but very useful for navigation afterwards -- vehicletypes: used for turn restrictions, legacy for use with itinero 1.0 -- defaults: a dictionary of `{"#paramName": "value"}`, used in determining the weight of an edge. note: the `#` has to be included -- `access` is a field in the vehicle file. It should be an expression returning a string. If (and only if) this string is `no`, the way will be marked as not accessible and no more values will be calculated. All other values are regarded as being accessible. When calculated, the tag `access` with the calculated value is written into the tag table or the other aspects to use. - - `oneway` is a field in the vehicle file. It should be an expression returning `both`, `with` or `against`. - When calculated, the tag `oneway` is added to the tags for the other aspects to be calculated. - - `speed`: an expression indicating how fast the vehicle can go there. It should take into account legal, practical and social aspects. An example expression could be `{"$min", ["$legal_maxspeed", "#defaultspeed"]}` - -- `priorities`: a table of `{'#paramName', expression}` determining the priority (1/cost) of a way, per meter. The formula used is `paramName * expression + paramName0 * expression0 + ...` (`speed`, `access` and `oneway` can be used here as tags indicate the earlier defined respective aspects). Use a weight == 1 to get the shortest route or `$speed` to get the fastest route - -# Calculating oneway and forward/backward speeds - -There are two possibilities in order to calculate the possible direction of a traveller can go over an edge: - -1) This can be indicated explicitely with the 'oneway'-field. If this expression returns `both`, the edge is traversable in two directions. If it is either `with` or `against`, then it is not -2) This can be indicated with having a speed or factor which is equal to (or smaller then) 0, in conjunction with a `_direction=with` or `_direction=against` tag. Bicycle lanes are an excellent example for this: a `cycleway:right=yes; cycleway:left=no`, the speed and factor for `_direction=with` could be far greater then for `_direction=against` - -Note that `_direction=with` and `_direction=against` are _not_ supported in Itinero1.0 profiles. For maximal compatibility and programming comfort, a mixture of both techniques should be used. For example, one aspect interpreting the legal onewayness in tandem with one aspect determining comfort by direction is optimal. - - -# Pitfalls - -"$all" should not be used together with a mapping: it checks if all _present_ keys return true or yes (or some other value); it does _not_ check that all the specified keys in the mapping are present. - -For this, an additional 'mustHaveKeys' should be added added \ No newline at end of file diff --git a/AspectedRouting/Examples/bicycle/aspects/bicycle.comfort.json b/AspectedRouting/Examples/bicycle/aspects/bicycle.comfort.json deleted file mode 100644 index 8b86ab9..0000000 --- a/AspectedRouting/Examples/bicycle/aspects/bicycle.comfort.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "bicycle.comfort", - "description": "Gives a comfort factor for a road, purely based on physical aspects of the road, which is a bit subjective; this takes a bit of scnery into account with a preference for `railway=abandoned` and `towpath=yes`", - "unit": "[0, 2]", - "$default": 1, - "value": { - "$multiply": { - "highway": { - "cycleway": 1.2, - "primary": 0.3, - "secondary": 0.4, - "tertiary": 0.5, - "unclassified": 0.8, - "track": 0.95, - "residential": 1.0, - "living_street": 1.1, - "footway": 0.95, - "path": 0.5, - "construction": 0.5 - }, - "railway": { - "abandoned": 2 - }, - "towpath": { - "yes": 2 - }, - "cycleway": { - "track": 1.2 - }, - "cyclestreet": { - "yes": 1.1 - }, - "access": { - "designated": 1.2, - "dismount": 0.01 - }, - "bicycle:class":{ - "-3": 0.5, - "-2": 0.7, - "-1": 0.9, - "0": 1, - "1": 1.1, - "2": 1.3, - "3": 1.5 - }, - "surface": { - "#": "The surface mapping heavily resembles the one in speed_factor, but it is not entirely the same", - "paved": 0.99, - "concrete:lanes": 0.8, - "concrete:plates": 1.0, - "sett": 0.9, - "unhewn_cobblestone": 0.75, - "cobblestone": 0.8, - "unpaved": 0.75, - "compacted": 0.95, - "fine_gravel": 0.7, - "gravel": 0.9, - "dirt": 0.6, - "earth": 0.6, - "grass": 0.6, - "grass_paver": 0.9, - "ground": 0.7, - "sand": 0.5, - "woodchips": 0.5, - "snow": 0.5, - "pebblestone": 0.5, - "mud": 0.4 - }, - "route": { - "#": "Discourage ferries", - "ferry": 0.01 - } - } - } -} diff --git a/AspectedRouting/Examples/bicycle/aspects/bicycle.legal_access.json b/AspectedRouting/Examples/bicycle/aspects/bicycle.legal_access.json deleted file mode 100644 index eb27932..0000000 --- a/AspectedRouting/Examples/bicycle/aspects/bicycle.legal_access.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "name": "bicycle.legal_access", - "description": "Gives, for each type of highway, whether or not a normal bicycle can enter legally.\nNote that legal access is a bit 'grey' in the case of roads marked private and permissive, in which case these values are returned ", - "unit": "'designated': Access is allowed and even specifically for bicycles\n'yes': bicycles are allowed here\n'permissive': bicycles are allowed here, but this might be a private road or service where usage is allowed, but could be retracted one day by the owner\n'dismount': cycling here is not allowed, but walking with the bicycle is\n'destination': cycling is allowed here, but only if truly necessary to reach the destination\n'private': this is a private road, only go here if the destination is here\n'no': do not cycle here", - "$default": "no", - "value": { - "$firstMatchOf": [ - "anyways:bicycle", - "anyways:access", - "anyways:construction", - "bicycle", - "access", - "service", - "highway" - ], - "value": { - "access": { - "no": "no", - "customers": "private", - "private": "private", - "#": "Note that we leave out 'yes', as it is meaningless - the default assumption is that everything on OSM is accessible! This forces to fall through to the road type, in order to force `highway=motorway; access=yes` as not to trigger access for bicycles", - "permissive": "permissive", - "destination": "destination", - "delivery": "destination", - "service": "destination", - "permit": "destination" - }, - "highway": { - "cycleway": "designated", - "residential": "yes", - "living_street": "yes", - "service": "yes", - "services": "yes", - "track": "yes", - "crossing": "dismount", - "footway": "dismount", - "pedestrian": "dismount", - "corridor": "dismount", - "construction": "dismount", - "steps": "dismount", - "path": "yes", - "primary": "yes", - "primary_link": "yes", - "secondary": "yes", - "secondary_link": "yes", - "tertiary": "yes", - "tertiary_link": "yes", - "unclassified": "yes", - "road": "yes" - }, - "service": { - "parking_aisle": "permissive", - "driveway": "private", - "alley": "yes", - "bus": "no" - }, - "bicycle": { - "yes": "yes", - "no": "no", - "use_sidepath": "no", - "designated": "designated", - "permissive": "permissive", - "private": "private", - "official": "designated", - "dismount": "dismount", - "permit": "destination" - }, - - "anyways:bicycle": "$id", - "anyways:access": { - "no": "no", - "destination": "destination", - "yes": "yes" - }, - "anyways:construction": { - "yes": "no" - } - } - } -} diff --git a/AspectedRouting/Examples/bicycle/aspects/bicycle.network_is_nodenetwork.json b/AspectedRouting/Examples/bicycle/aspects/bicycle.network_is_nodenetwork.json deleted file mode 100644 index b0e15b3..0000000 --- a/AspectedRouting/Examples/bicycle/aspects/bicycle.network_is_nodenetwork.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "bicycle.network_is_nodenetwork", - "description": "Returns true if the highway is part of a [cycle node network](https://wiki.openstreetmap.org/wiki/Cycle_Node_Network_Tagging)", - "$memberOf": { - "$mustMatch": { - "type": "route", - "route": "bicycle", - "state": {"$not": "proposed"}, - "network:type": "node_network" - } - } -} - diff --git a/AspectedRouting/Examples/bicycle/aspects/bicycle.oneway.json b/AspectedRouting/Examples/bicycle/aspects/bicycle.oneway.json deleted file mode 100644 index eb1348a..0000000 --- a/AspectedRouting/Examples/bicycle/aspects/bicycle.oneway.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "bicycle.oneway", - "description": "Determines wether or not a bicycle can go in both ways in this street, and if it is oneway, in what direction", - "unit": "both: direction is allowed in both direction\nwith: this is a oneway street with direction allowed with the grain of the way\nagainst: oneway street with direction against the way", - "$default": "both", - "value": { - "$firstMatchOf": [ - "oneway:bicycle", - "junction", - "cycleway", - "cycleway:left", - "oneway" - ], - "value": { - "oneway": { - "yes": "with", - "no": "both", - "1": "with", - "-1": "against" - }, - "oneway:bicycle": { - "yes": "with", - "no": "both", - "1": "with", - "-1": "against" - }, - "junction": { - "roundabout": "with" - }, - "cycleway": { - "right": "against", - "#": "We ignore 'no' as it has no meaning and is the default assumption", - "opposite_lane": "both", - "track": "both", - "lane": "both", - "opposite": "both", - "opposite_share_busway": "both", - "opposite_track": "both" - }, - "cycleway:left": { - "no": "with", - "none": "with", - "yes": "both", - "lane": "both", - "track": "both", - "shared_lane": "both", - "share_busway": "both", - "opposite_lane": "both", - "opposite_track": "both", - "opposite": "both" - } - } - } -} \ No newline at end of file diff --git a/AspectedRouting/Examples/bicycle/aspects/bicycle.safety.json b/AspectedRouting/Examples/bicycle/aspects/bicycle.safety.json deleted file mode 100644 index fa78ae6..0000000 --- a/AspectedRouting/Examples/bicycle/aspects/bicycle.safety.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "name": "bicycle.safety", - "description": "Determines how safe a cyclist feels on a certain road, mostly based on car pressure. This is quite a subjective measurem", - "unit": "safety", - "$default": 1, - "value": { - "$multiply": { - "access": { - "#": "access=no and access 'destination' implies this access for cars too and is a bonus!", - "no": 1.5, - "destination": 1.4, - "dismount": 0.2, - "designated": 1.5 - }, - "bicycle:class":{ - "-3": 0.5, - "-2": 0.7, - "-1": 0.9, - "0": 1, - "1": 1.1, - "2": 1.3, - "3": 1.5 - }, - "motor_vehicle": { - "no": 1.5, - "destination": 1.4 - }, - "foot": { - "designated": 0.95 - }, - "bicycle": { - "designated": 1.5 - }, - "cyclestreet": { - "yes": 1.5 - }, - "towpath": { - "yes": 1.1 - }, - "designation": { - "towpath": 1.5 - }, - "highway": { - "cycleway": 1.0, - "primary": 0.1, - "secondary": 0.4, - "tertiary": 0.5, - "unclassified": 0.8, - "track": 0.95, - "residential": 0.9, - "living_street": 0.95, - "footway": 0.95, - "path": 0.9, - "#": "A road under construction often has various objects laying around, rough edges, .... -> chance to fall", - "construction": 0.6 - }, - "cycleway": { - "#": "A distinct cycleway _always_ makes the road safer for cyclists, even if it is but a small lane. The default assumption is 'no', no cycleway, in which case the safety feeling is not improved", - "yes": 1.15, - "lane": 1.15, - "shared": 1.03, - "shared_lane": 1.03, - "share_busway": 1.05, - "track": 1.5 - }, - "cycleway:left": { - "yes": 1.15, - "lane": 1.15, - "shared": 1.03, - "shared_lane": 1.03, - "share_busway": 1.05, - "track": 1.5 - }, - "cycleway:right": { - "yes": 1.15, - "lane": 1.15, - "shared": 1.03, - "shared_lane": 1.03, - "share_busway": 1.05, - "track": 1.5 - } - } - } -} diff --git a/AspectedRouting/Examples/bicycle/aspects/bicycle.speed_factor.json b/AspectedRouting/Examples/bicycle/aspects/bicycle.speed_factor.json deleted file mode 100644 index c61d4f5..0000000 --- a/AspectedRouting/Examples/bicycle/aspects/bicycle.speed_factor.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "bicycle.speed_factor", - "description": "Calculates a speed factor for bicycles based on physical features, e.g. a sand surface will slow a cyclist down; going over pedestrian areas even more, ...", - "$multiply": { - "access": { - "#": "We have to go by foot. Default speed of 20km/h * 0.15 = 3km/h", - "dismount": 0.15 - }, - "highway": { - "#": "A small forest path is typically slow", - "path": 0.5, - "#": "an unmaintained track (in Belgium: tractor path) is slower as well", - "track": 0.7, - "#": "A road under construction slows one down, despite (normally) already being dismount", - "construction": 0.5, - "steps": 0.1 - }, - "ramp:bicycle": { - "#": "These are stairs (highway=steps), but there is a bicycle ramp, so we go a little bit faster", - "yes": 3 - }, - "surface": { - "paved": 0.99, - "asphalt": 1, - "concrete": 1, - "metal": 1, - "wood": 1, - "concrete:lanes": 0.95, - "concrete:plates": 1, - "paving_stones": 1, - "sett": 0.9, - "unhewn_cobblestone": 0.75, - "cobblestone": 0.8, - "unpaved": 0.75, - "compacted": 0.99, - "fine_gravel": 0.99, - "gravel": 0.9, - "dirt": 0.6, - "earth": 0.6, - "grass": 0.6, - "grass_paver": 0.9, - "ground": 0.7, - "sand": 0.5, - "woodchips": 0.5, - "snow": 0.5, - "pebblestone": 0.5, - "mud": 0.4 - }, - "tracktype": { - "grade1": 0.99, - "grade2": 0.8, - "grade3": 0.6, - "grade4": 0.3, - "grade5": 0.1 - }, - "incline": { - "up": 0.75, - "down": 1.25, - "0": 1, - "0%": 1, - "10%": 0.9, - "-10%": 1.1, - "20%": 0.8, - "-20%": 1.2, - "30%": 0.7, - "-30%": 1.3 - } - } -} \ No newline at end of file diff --git a/AspectedRouting/Examples/bicycle/bicycle.json b/AspectedRouting/Examples/bicycle/bicycle.json deleted file mode 100644 index 23c2195..0000000 --- a/AspectedRouting/Examples/bicycle/bicycle.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "name": "bicycle", - "description": "Profile for a normal bicycle", - "vehicletypes": [ - "vehicle", - "bicycle" - ], - "metadata": [ - "name", - "bridge", - "tunnel", - "colour", - "cycle_network_colour", - "cycle_network_ref", - "ref", - "status", - "network" - ], - "access": "$bicycle.legal_access", - "oneway": "$bicycle.oneway", - "speed": { - "$max": [ - "$ferry_speed", - { - "$min": [ - "$legal_maxspeed_be", - "#maxspeed", - { - "$multiply": [ - "#defaultSpeed", - "$bicycle.speed_factor" - ] - } - ] - } - ] - }, - "priority": { - "#comfort": "$bicycle.comfort", - "#safety": "$bicycle.safety", - "#nodeNetworkScore": "$bicycle.network_is_nodenetwork", - "#timeNeeded": "$speed", - "#distance": "$distance", - "#trespassingPenalty": "$clean_permission_score", - "#leastSafetyPenalty": { - "$multiply": [ - "$speed", - { - "$atleast": "#leastSafetyRequired", - "f": "$bicycle.safety", - "then": 0, - "else": -1 - } - ] - } - }, - "defaults": { - "#defaultSpeed": 15, - "#maxspeed": 30, - "#timeNeeded": 0, - "#distance": 0, - "#comfort": 0, - "#safety": 0, - "#operatorNetworkScore": 0, - "#networkOperator": [], - "#cycleHighwayNetworkScore": 0, - "#nodeNetworkScore": 0, - "#bicycleNetworkScore": 0, - "#trespassingPenalty": 15, - "#": "This isn't a weight, but is used as cut-off in 'leastSafetyPenalty'", - "#leastSafetyRequired": 0.11, - "#leastSafetyPenalty": 2 - }, - "behaviours": { - "fastest": { - "description": "The fastest route to your destination", - "#timeNeeded": 1, - "#leastSafetyPenalty": 2 - }, - "shortest": { - "description": "The shortest route, independent of of speed", - "#distance": 1, - "#leastSafetyPenalty": 2 - }, - "comfort": { - "description": "A comfortable route preferring well-paved roads, smaller roads and a bit of scenery at the cost of speed", - "#comfort": 1 - }, - "node_network": { - "description": "A route following the recreational node network. Might make detours", - "#nodeNetworkScore": 10, - "#safety": 1 - } - } -} diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.comfort.test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.comfort.test.csv deleted file mode 100644 index 1c10586..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.comfort.test.csv +++ /dev/null @@ -1,18 +0,0 @@ -expected,highway,foot,bicycle,cyclestreet,cycleway,cycleway:right,surface,railway,towpath -1,,,,,,,,, -1,residential,,,,,,,, -1.1,residential,,,yes,,,,, -1.2,cycleway,,,,,,,, -1.2,cycleway,designated,,,,,,, -0.5,path,designated,designated,,,,,, -0.5,path,,designated,,,,,, -0.95,footway,designated,,,,,,, -0.3,primary,,,,no,,,, -0.3,primary,,,,yes,,,, -0.36,primary,,,,track,,,, -0.4,secondary,,,,lane,,,, -0.4,secondary,,,,,lane,asphalt,, -1.1,residential,,,yes,,,asphalt,, -2,,,,,,,,abandoned, -2,,,,,,,,,yes -4,,,,,,,,abandoned,yes diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.fastest.behaviour_test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.fastest.behaviour_test.csv deleted file mode 100644 index 3bed6e1..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.fastest.behaviour_test.csv +++ /dev/null @@ -1,14 +0,0 @@ -access,oneway,speed,priority,highway,bicycle,surface,cycleway:left,oneway,oneway:bicycle,access,maxspeed,junction -no,both,0,0,,,,,,,,, -designated,both,15,15,cycleway,,,,,,,, -no,both,15,-15,primary,,,,,,,, -no,both,15,-15,primary,yes,,,,,,, -yes,both,15,15,residential,,,,,,,, -yes,both,13.5,13.5,residential,yes,sett,,,,,, -dismount,both,2.25,2.25,pedestrian,,,,,,,, -yes,both,15,15,pedestrian,yes,,,,,,, -yes,both,15,15,unclassified,,,track,yes,no,,, -yes,both,15,15,service,,,,,,,, -yes,both,15,15,tertiary,,,,,,yes,50, -yes,with,15,15,residential,,,,,,,,roundabout -dismount,both,2.25,2.25,footway,dismount \ No newline at end of file diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.legal_access.test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.legal_access.test.csv deleted file mode 100644 index 04807ca..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.legal_access.test.csv +++ /dev/null @@ -1,22 +0,0 @@ -expected,highway,bicycle,access,anyways:access,cycleway:right,cycleway -no,,,,,, -no,,,no,,, -yes,,yes,no,,, -yes,path,,,,, -yes,pedestrian,yes,,,, -dismount,pedestrian,,,,, -designated,cycleway,,,,, -destination,residential,,destination,,, -private,residential,,private,,, -designated,residential,designated,,,, -designated,motorway,designated,,,, -no,residential,use_sidepath,,,, -yes,residential,,no,yes,, -yes,primary,,,,, -yes,primary,,,,yes, -yes,primary,,,,,yes -yes,secondary,,,,track, -destination,service,,destination,,, -no,residential,use_sidepath,,,, -yes,tertiary,,,,,no -dismount,construction,,,,, \ No newline at end of file diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.networks.behaviour_test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.networks.behaviour_test.csv deleted file mode 100644 index 5151d00..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.networks.behaviour_test.csv +++ /dev/null @@ -1,6 +0,0 @@ -access,oneway,speed,priority,highway,_relation:bicycle.network_is_bicycle_network -no,,,,, -designated,both,15,1.5,cycleway, -designated,both,15,4.5,cycleway,yes -yes,both,15,0.9,residential, -yes,both,15,3.9,residential,yes diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.oneway.test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.oneway.test.csv deleted file mode 100644 index d90202c..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.oneway.test.csv +++ /dev/null @@ -1,19 +0,0 @@ -expected,highway,oneway,oneway:bicycle,junction,cycleway,cycleway:right,cycleway:left -both,,,,,,, -both,,no,,,,, -with,,no,yes,,,, -with,,,,roundabout,,, -both,,yes,,,opposite,, -against,,yes,-1,,,, -with,residential,yes,,,,, -both,residential,no,,,,, -both,residential,yes,no,,,, -with,residential,,,roundabout,,, -both,residential,,no,roundabout,,, -against,residential,,-1,,,, -both,residential,invalidKey,no,,,, -with,secondary,yes,,,,track, -both,secondary,yes,,,,,track -both,secondary,yes,,,track,, -with,,yes,,,,,no -both,residential,yes,,,,,lane diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.safety.test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.safety.test.csv deleted file mode 100644 index b404ca2..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.safety.test.csv +++ /dev/null @@ -1,13 +0,0 @@ -expected,highway,cycleway,cyclestreet,foot,bicycle,cycleway:right,access -0.1,primary,no,,,,, -0.115,primary,yes,,,,, -0.15,primary,track,,,,, -0.46,secondary,lane,,,,, -0.9,residential,,,,,, -1.5,cycleway,,,,,,designated -1.35,residential,,yes,,,, -0.95,cycleway,,,designated,,, -0.9025,footway,,,designated,,, -1.2825,path,,,designated,designated,, -1.35,path,,,,designated,, -0.46,secondary,,,,,lane, diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.shortest.behaviour_test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.shortest.behaviour_test.csv deleted file mode 100644 index fa37c20..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.shortest.behaviour_test.csv +++ /dev/null @@ -1,5 +0,0 @@ -access,oneway,speed,priority,highway,surface -no,both,0,0,, -designated,both,15,1,cycleway, -yes,both,5.25,1,path,ground -no,both,15,-29,primary, diff --git a/AspectedRouting/Examples/bicycle/tests/bicycle.speed_factor.test.csv b/AspectedRouting/Examples/bicycle/tests/bicycle.speed_factor.test.csv deleted file mode 100644 index da1eaca..0000000 --- a/AspectedRouting/Examples/bicycle/tests/bicycle.speed_factor.test.csv +++ /dev/null @@ -1,13 +0,0 @@ -expected,incline,surface,highway,access -1,,,, -1,,,residential, -0.75,up,,residential, -1.25,down,,residential, -0.3,up,mud,residential, -1.125,down,sett,residential, -0.675,up,sett,residential, -0.9,,sett,residential, -1,,asphalt,residential, -0.15,,,residential,dismount -0.0315,up,mud,track,dismount -0.9,,sett,primary, diff --git a/AspectedRouting/Examples/general/clean_permission_score.json b/AspectedRouting/Examples/general/clean_permission_score.json deleted file mode 100644 index bb82170..0000000 --- a/AspectedRouting/Examples/general/clean_permission_score.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "clean_permission_score", - "description": "Gives 0 on private roads, 0.1 on destination-only roads, and 0.9 on permissive roads; gives 1 by default. This helps to select roads with no access retrictions on them", - "$default": 0, - "value": { - "access": { - "private": -50, - "destination": -3, - "permissive": -1 - } - } -} \ No newline at end of file diff --git a/AspectedRouting/Examples/general/clean_permission_score.test.csv b/AspectedRouting/Examples/general/clean_permission_score.test.csv deleted file mode 100644 index 64c9b9e..0000000 --- a/AspectedRouting/Examples/general/clean_permission_score.test.csv +++ /dev/null @@ -1,5 +0,0 @@ -expected,access -0,yes --1,permissive --50,private -0,qmsldkfjqsmldkfj diff --git a/AspectedRouting/Examples/general/ferry_speed.json b/AspectedRouting/Examples/general/ferry_speed.json deleted file mode 100644 index a7b45db..0000000 --- a/AspectedRouting/Examples/general/ferry_speed.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "ferry_speed", - "description": "Gives the expected speed for a ferry. This includes the time needed to board and the expected waiting time (if duration is present). This uses the tag '_length', which is expected to be added by the preprocessing-step.", - "unit": "km/h", - "value": { - "$ifDotted": { - "route": { - "ferry": "yes" - } - }, - "then": { - "#": "(length (m) / (duration (minutes) + 5 minutes slack)) * 0.06 minutes/kilometer", - "$multiply": [ - { - "#": "The default value is chosen so that it defaults to 1km/h", - "$default": 83.33333333333333, - "value": { - "_length": "$parse" - } - }, - { - "$inv": { - "$sum": [ - { - "duration": "$parse" - }, - { - "$multiply": [ - { - "#": "Time needed to get on. We assume a continous ferry (pull it your self) which takes a few minutes to be free. If an interval is specified, we take a quarter of the interval as we assume that people will take into account the schedule", - "$default": 20, - "value": { - "interval": "$parse" - } - }, - 0.2 - ] - } - ] - } - }, - 0.06 - ] - } - } -} \ No newline at end of file diff --git a/AspectedRouting/Examples/general/ferry_speed.test.csv b/AspectedRouting/Examples/general/ferry_speed.test.csv deleted file mode 100644 index 9b239a2..0000000 --- a/AspectedRouting/Examples/general/ferry_speed.test.csv +++ /dev/null @@ -1,9 +0,0 @@ -expected,route,duration,interval,_length,comment -1.25,ferry,,, -2,ferry,26,,1000,26 minutes duration + 4 minutes to get on is 30 minutes total for one kilometer -> 2 km/h -4,ferry,11,,1000,10 minutes duration + 4 minutes to get on is 15 minutes total for one kilometer -> 4km/h -null,,,,Ferry is not set -21.465,ferry,00:16,,7155,Waterbus SintAnna-Zwijndrecht - osm.org/way/632117702 -19.513636363636365,ferry,00:16,00:30,7155,Waterbus SintAnna-Zwijndrecht - osm.org/way/632117702 -10.7325,ferry,00:16,2:00,7155,Non-regular waterbus which goes every two hours. Expected time ppl will wait: 24minutes + 16minutes faring duration = 40minutes for 7km = ~9km/h -30,ferry,0:,0:1,100, \ No newline at end of file diff --git a/AspectedRouting/Examples/general/legal_maxspeed_be.json b/AspectedRouting/Examples/general/legal_maxspeed_be.json deleted file mode 100644 index f3216e8..0000000 --- a/AspectedRouting/Examples/general/legal_maxspeed_be.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "legal_maxspeed_be", - "description": "Gives, for each type of highway, which the default legal maxspeed is in Belgium. This file is intended to be reused for in all vehicles, from pedestrian to car. In some cases, a legal maxspeed is not really defined (e.g. on footways). In that case, a socially acceptable speed should be taken (e.g.: a bicycle on a pedestrian path will go say around 12km/h)", - "unit": "km/h", - "$default": 30, - "value": { - "$firstMatchOf": [ - "maxspeed", - "designation", - "highway" - ], - "value": { - "maxspeed": "$parse", - "highway": { - "cycleway": 30, - "footway": 20, - "crossing": 20, - "pedestrian": 15, - "path": 15, - "corridor": 5, - "residential": 30, - "living_street": 20, - "service": 30, - "services": 30, - "track": 50, - "unclassified": 50, - "road": 50, - "motorway": 120, - "motorway_link": 120, - "primary": 90, - "primary_link": 90, - "secondary": 50, - "secondary_link": 50, - "tertiary": 50, - "tertiary_link": 50 - }, - "designation": { - "towpath": 30 - } - } - } -} diff --git a/AspectedRouting/Examples/general/legal_maxspeed_be.test.csv b/AspectedRouting/Examples/general/legal_maxspeed_be.test.csv deleted file mode 100644 index 382b37e..0000000 --- a/AspectedRouting/Examples/general/legal_maxspeed_be.test.csv +++ /dev/null @@ -1,5 +0,0 @@ -expected,highway,maxspeed -30,, -30,residential, -50,secondary, -70,secondary,70 diff --git a/AspectedRouting/Examples/pedestrian/aspects/pedestrian.legal_access.json b/AspectedRouting/Examples/pedestrian/aspects/pedestrian.legal_access.json deleted file mode 100644 index f4cb7d5..0000000 --- a/AspectedRouting/Examples/pedestrian/aspects/pedestrian.legal_access.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "name": "pedestrian.legal_access", - "description": "Gives, for each type of highway, whether or not someone can enter legally.\nNote that legal access is a bit 'grey' in the case of roads marked private and permissive, in which case these values are returned ", - "unit": "'designated': Access is allowed and even specifically for pedestrian\n'yes': pedestrians are allowed here\n'permissive': pedestrians are allowed here, but this might be a private road or service where usage is allowed, but could be retracted one day by the owner\n'destination': walking is allowed here, but only if truly necessary to reach the destination (e.g. a service road)\n'private': this is a private road, only go here if the destination is here\n'no': do not walk here", - "$default": "no", - "value": { - "$firstMatchOf": [ - "anyways:foot", - "anyways:access", - "anyways:construction", - "foot", - "access", - "service", - "highway" - ], - "value": { - "access": { - "no": "no", - "customers": "private", - "private": "private", - "#": "Note that we leave out 'yes', as it is meaningless - the default assumption is that everything on OSM is accessible! This forces to fall through to the road type, in order to force `highway=motorway; access=yes` as not to trigger access for bicycles", - "permissive": "permissive", - "destination": "destination", - "delivery": "destination", - "service": "destination", - "permit": "destination" - }, - "highway": { - "pedestrian": "designated", - "footway": "designated", - "living_street": "designated", - "steps": "yes", - "corridor": "designated", - "residential": "yes", - "service": "yes", - "services": "yes", - "track": "yes", - "crossing": "yes", - "construction": "permissive", - "path": "yes", - "primary": "yes", - "primary_link": "yes", - "secondary": "yes", - "secondary_link": "yes", - "tertiary": "yes", - "tertiary_link": "yes", - "unclassified": "yes", - "road": "yes" - }, - "service": { - "parking_aisle": "permissive", - "driveway": "private", - "alley": "yes", - "bus": "no" - }, - "foot": { - "yes": "yes", - "no": "no", - "use_sidepath": "no", - "designated": "designated", - "permissive": "permissive", - "private": "private", - "official": "designated", - "dismount": "dismount", - "permit": "destination" - }, - "anyways:foot": "$id", - "anyways:access": { - "no": "no", - "destination": "destination", - "yes": "yes" - }, - "anyways:construction": { - "yes": "no" - } - } - } -} diff --git a/AspectedRouting/Examples/pedestrian/pedestrian.json b/AspectedRouting/Examples/pedestrian/pedestrian.json deleted file mode 100644 index e62b450..0000000 --- a/AspectedRouting/Examples/pedestrian/pedestrian.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "pedestrian", - "description": "Profile for someone who is walking", - "vehicletypes": [ - "vehicle", - "foot" - ], - "metadata": [ - "name", - "bridge", - "tunnel", - "colour", - "ref", - "status", - "network" - ], - "access": "$pedestrian.legal_access", - "oneway": "both", - "speed": "#defaultSpeed", - "priority": { - "#timeNeeded": "$speed", - "#distance": "$distance", - "#trespassingPenalty": "$clean_permission_score" - }, - "defaults": { - "#defaultSpeed": 4, - "#maxspeed": 6, - "#timeNeeded": 0, - "#distance": 0, - "#slow_road_preference": 0, - "#trespassingPenalty": 1 - }, - "behaviours": { - "shortest": { - "description": "The shortest route, independent of of speed", - "#distance": 1, - "#leastSafetyPenalty": 2 - } - } -} diff --git a/AspectedRouting/Examples/pedestrian/tests/pedestrian.legal_access.test.csv b/AspectedRouting/Examples/pedestrian/tests/pedestrian.legal_access.test.csv deleted file mode 100644 index 9b99f95..0000000 --- a/AspectedRouting/Examples/pedestrian/tests/pedestrian.legal_access.test.csv +++ /dev/null @@ -1,4 +0,0 @@ -expected,highway,foot,access,anyways:access,cycleway:right,cycleway -no,,,,,, -yes,residential, -designated,pedestrian \ No newline at end of file diff --git a/AspectedRouting/Examples/pedestrian/tests/pedestrian.slow_roads.behaviour_test.csv b/AspectedRouting/Examples/pedestrian/tests/pedestrian.slow_roads.behaviour_test.csv deleted file mode 100644 index 4e47cac..0000000 --- a/AspectedRouting/Examples/pedestrian/tests/pedestrian.slow_roads.behaviour_test.csv +++ /dev/null @@ -1,5 +0,0 @@ -access,oneway,speed,priority,highway -no,,,,, -designated,both,4,2,pedestrian, -designated,both,4,1.8,footway -yes,both,4,1,residential, diff --git a/outputhelpText.md b/outputhelpText.md deleted file mode 100644 index 1988169..0000000 --- a/outputhelpText.md +++ /dev/null @@ -1,1058 +0,0 @@ -## Types - -- double -- pdouble -- nat -- int -- string -- tags -- bool -## Builtin functions - -- eq -- notEq -- not -- inv -- default -- parse -- to_string -- concat -- containedIn -- min -- and -- max -- or -- sum -- plus -- add -- multiply -- atleast -- firstMatchOf -- mustMatch -- memberOf -- if_then_else -- if -- if_then_else_dotted -- ifdotted -- ifDotted -- id -- const -- constRight -- dot -- listDot -- eitherFunc -- stringToTags -- head - - -### Function overview - -#### eq - -a | b | returns | ---- | --- | --- | -$a | $a | bool | -$a | $a | string | - -Returns 'yes' if both values _are_ the same - - - -Lua implementation: - -````lua -function eq(a, b) - if (a == b) then - return "yes" - else - return "no" - end -end - -```` - - -#### notEq - -a | b | returns | ---- | --- | --- | -$a | $a | bool | -$a | $a | string | -bool | bool | - -OVerloaded function, either boolean not or returns 'yes' if the two passed in values are _not_ the same; - - - -Lua implementation: - -````lua -function notEq(a, b) - if (b == nil) then - b = "yes" - end - - if (a ~= b) then - return "yes" - else - return "no" - end -end -```` - - -#### not - -a | b | returns | ---- | --- | --- | -$a | $a | bool | -$a | $a | string | -bool | bool | - -OVerloaded function, either boolean not or returns 'yes' if the two passed in values are _not_ the same; - - - -Lua implementation: - -````lua -function notEq(a, b) - if (b == nil) then - b = "yes" - end - - if (a ~= b) then - return "yes" - else - return "no" - end -end -```` - - -#### inv - -d | returns | ---- | --- | -pdouble | pdouble | -double | double | - -Calculates `1/d` - - - -Lua implementation: - -````lua -function inv(n) - return 1/n -end -```` - - -#### default - -defaultValue | f | returns | ---- | --- | --- | -$a | $b -> $a | $b | $a | - -Calculates function `f` for the given argument. If the result is `null`, the default value is returned instead - - - -Lua implementation: - -````lua -function default(defaultValue, realValue) - if(realValue ~= nil) then - return realValue - end - return defaultValue -end -```` - - -#### parse - -s | returns | ---- | --- | -string | double | -string | pdouble | - -Parses a string into a numerical value. Returns 'null' if parsing fails or no input is given. If a duration is given (e.g. `01:15`), then the number of minutes (75) is returned - - - -Lua implementation: - -````lua -function parse(string) - if (string == nil) then - return 0 - end - if (type(string) == "number") then - return string - end - - if (string == "yes" or string == "true") then - return 1 - end - - if (string == "no" or string == "false") then - return 0 - end - - if (type(string) == "boolean") then - if (string) then - return 1 - else - return 0 - end - end - - if(string:match("%d+:%d+")) then - -- duration in minute - local duration = 0 - for part in string:gmatch "%d+" do - duration = duration * 60 + tonumber(part) - end - return duration - end - - - return tonumber(string) -end -```` - - -#### to_string - -obj | returns | ---- | --- | -$a | string | - -Converts a value into a human readable string - - - -Lua implementation: - -````lua -function to_string(o) - return o; -end -```` - - -#### concat - -a | b | returns | ---- | --- | --- | -string | string | string | - -Concatenates two strings - - - -Lua implementation: - -````lua -function concat(a, b) - return a .. b -end -```` - - -#### containedIn - -list | a | returns | ---- | --- | --- | -list ($a) | $a | bool | - -Given a list of values, checks if the argument is contained in the list. - - - -Lua implementation: - -````lua -function containedIn(list, a) - for _, value in pairs(list) do - if (value == a) then - return true - end - end - - return false; -end -```` - - -#### min - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | bool | - -Out of a list of values, gets the smallest value. In case of a list of bools, this acts as `and`. Note that 'null'-values are ignored. - - - -Lua implementation: - -````lua -function min(list) - local min - for _, value in pairs(list) do - if(value ~= nil) then - if (min == nil) then - min = value - elseif (value < min) then - min = value - end - end - end - - return min; -end -```` - - -#### and - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | bool | - -Out of a list of values, gets the smallest value. In case of a list of bools, this acts as `and`. Note that 'null'-values are ignored. - - - -Lua implementation: - -````lua -function min(list) - local min - for _, value in pairs(list) do - if(value ~= nil) then - if (min == nil) then - min = value - elseif (value < min) then - min = value - end - end - end - - return min; -end -```` - - -#### max - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | bool | - -Returns the biggest value in the list. For a list of booleans, this acts as 'or' - - - -Lua implementation: - -````lua -function max(list) - local max - for _, value in pairs(list) do - if (value ~= nil) then - if (max == nil) then - max = value - elseif (max < value) then - max = value - end - end - end - - return max; -end -```` - - -#### or - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | bool | - -Returns the biggest value in the list. For a list of booleans, this acts as 'or' - - - -Lua implementation: - -````lua -function max(list) - local max - for _, value in pairs(list) do - if (value ~= nil) then - if (max == nil) then - max = value - elseif (max < value) then - max = value - end - end - end - - return max; -end -```` - - -#### sum - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | int | - -Sums all the numbers in the given list. If the list is a list of booleans, `yes` or `true` will be considered to equal `1`. Null values are ignored (and thus handled as being `0`) - - - -Lua implementation: - -````lua -function sum(list) - local sum = 0 - for _, value in pairs(list) do - if(value ~= nil) then - if(value == 'yes' or value == 'true') then - value = 1 - end - sum = sum + value - end - end - return sum; -end -```` - - -#### plus - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | int | - -Sums all the numbers in the given list. If the list is a list of booleans, `yes` or `true` will be considered to equal `1`. Null values are ignored (and thus handled as being `0`) - - - -Lua implementation: - -````lua -function sum(list) - local sum = 0 - for _, value in pairs(list) do - if(value ~= nil) then - if(value == 'yes' or value == 'true') then - value = 1 - end - sum = sum + value - end - end - return sum; -end -```` - - -#### add - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | int | - -Sums all the numbers in the given list. If the list is a list of booleans, `yes` or `true` will be considered to equal `1`. Null values are ignored (and thus handled as being `0`) - - - -Lua implementation: - -````lua -function sum(list) - local sum = 0 - for _, value in pairs(list) do - if(value ~= nil) then - if(value == 'yes' or value == 'true') then - value = 1 - end - sum = sum + value - end - end - return sum; -end -```` - - -#### multiply - -list | returns | ---- | --- | -list (nat) | nat | -list (int) | int | -list (pdouble) | pdouble | -list (double) | double | -list (bool) | bool | - -Multiplies all the values in a given list. On a list of booleans, this acts as 'and' or 'all', as `false` and `no` are interpreted as zero. Null values are ignored and thus considered to be `one` - - - -Lua implementation: - -````lua -function multiply(list) - local factor = 1 - for _, value in pairs(list) do - if (value ~= nil) then - factor = factor * value - end - end - return factor; -end -```` - - -#### atleast - -minimum | f | then | else | returns | ---- | --- | --- | --- | --- | -double | $b -> double | $a | $a | $b | $a | - -Returns 'yes' if the second argument is bigger then the first argument. (Works great in combination with $dot) - - - -Lua implementation: - -````lua -function atleast(minimumExpected, actual, thn, els) - if (minimumExpected <= actual) then - return thn; - end - return els -end -```` - - -#### firstMatchOf - -s | returns | ---- | --- | -list (string) | tags -> list ($a) | tags | $a | - -This higherorder function takes a list of keys, a mapping (function over tags) and a collection of tags. It will try the function for the first key (and it's respective value). If the function fails (it gives null), it'll try the next key. - -E.g. `$firstMatchOf ['maxspeed','highway'] {'maxspeed' --> $parse, 'highway' --> {residential --> 30, tertiary --> 50}}` applied on `{maxspeed=70, highway=tertiary}` will yield `70` as that is the first key in the list; `{highway=residential}` will yield `30`. - - - -Lua implementation: - -````lua -function first_match_of(tags, result, order_of_keys, table) - for _, key in pairs(order_of_keys) do - local v = tags[key] - if (v ~= nil) then - - local mapping = table[key] - if (type(mapping) == "table") then - local resultValue = mapping[v] - if (resultValue ~= nil) then - result.attributes_to_keep[key] = v - return resultValue - end - else - result.attributes_to_keep[key] = v - return mapping - end - end - end - return nil; -end -```` - - -#### mustMatch - -neededKeys (filled in by parser) | f | returns | ---- | --- | --- | -list (string) | tags -> list (string) | tags | bool | - -Checks that every specified key is present and gives a non-false value -. -If, on top, a value is present with a mapping, every key/value will be executed and must return a value that is not 'no' or 'false' -Note that this is a privileged builtin function, as the parser will automatically inject the keys used in the called function. - - - -Lua implementation: - -````lua ---[[ -must_match checks that a collection of tags matches a specification. - -The function is not trivial and contains a few subtilities. - -Consider the following source: - -{"$mustMatch":{ "a":"X", "b":{"not":"Y"}}} - -This is desugared into - -{"$mustMatch":{ "a":{"$eq":"X"}, "b":{"not":"Y"}}} - -When applied on the tags {"a" : "X"}, this yields the table {"a":"yes", "b":"yes} (as `notEq` "Y" "nil") yields "yes".. -MustMatch checks that every key in this last table yields yes - even if it is not in the original tags! - - -]] -function must_match(tags, result, needed_keys, table) - for _, key in ipairs(needed_keys) do - local v = table[key] -- use the table here, as a tag that must _not_ match might be 'nil' in the tags - if (v == nil) then - return false - end - - local mapping = table[key] - if (type(mapping) == "table") then - local resultValue = mapping[v] - if (resultValue == nil or - resultValue == false or - resultValue == "no" or - resultValue == "false") then - return false - end - elseif (type(mapping) == "string") then - local bool = mapping - if (bool == "no" or bool == "0") then - return false - end - - if (bool ~= "yes" and bool ~= "1") then - error("MustMatch got a string value it can't handle: " .. bool) - end - elseif (type(mapping) == "boolean") then - if(not mapping) then - return false - end - else - error("The mapping is not a table. This is not supported. We got " .. tostring(mapping) .. " (" .. type(mapping)..")") - end - end - - -- Now that we know for sure that every key matches, we add them all - for _, key in ipairs(needed_keys) do - local v = tags[key] -- this is the only place where we use the original tags - if (v ~= nil) then - result.attributes_to_keep[key] = v - end - end - - return true -end -```` - - -#### memberOf - -f | tags | returns | ---- | --- | --- | -tags -> bool | tags | bool | - -This function returns true, if the way is member of a relation matching the specified function. - -In order to use this for itinero 1.0, the membership _must_ be the top level expression. - -Conceptually, when the aspect is executed for a way, every relation will be used as argument in the subfunction `f` -If this subfunction returns 'true', the entire aspect will return true. - -In the lua implementation for itinero 1.0, this is implemented slightly different: a flag `_relation:="yes"` will be set if the aspect matches on every way for where this aspect matches. -However, this plays poorly with parameters (e.g.: what if we want to cycle over a highway which is part of a certain cycling network with a certain `#network_name`?) Luckily, parameters can only be simple values. To work around this problem, an extra tag is introduced for _every single profile_:`_relation::=yes'. The subfunction is thus executed `countOr(relations) * countOf(profiles)` time, yielding `countOf(profiles)` tags. The profile function then picks the tags for himself and strips the `:` away from the key. - - - -In the test.csv, one can simply use `_relation:=yes` to mimic relations in your tests - - - -Lua implementation: - -````lua -function member_of(calledIn, parameters, tags, result) - local k = "_relation:" .. calledIn - -- This tag is conventiently setup by all the preprocessors, which take the parameters into account - local doesMatch = tags[k] - if (doesMatch == "yes") then - result.attributes_to_keep[k] = "yes" - return true - end - return false -end -```` - - -#### if_then_else - -condition | then | else | returns | ---- | --- | --- | --- | -bool | $a | $a | $a | -bool | $a | $a | -string | $a | $a | $a | -string | $a | $a | - -Selects either one of the branches, depending on the condition. The 'then' branch is returned if the condition returns the string `yes` or `true`. Otherwise, the `else` branch is taken (including if the condition returns `null`)If the `else` branch is not set, `null` is returned in the condition is false. - - - -Lua implementation: - -````lua -function if_then_else(condition, thn, els) - if (condition ~= nil and (condition == "yes" or condition == true or condition == "true") then - return thn - else - return els -- if no third parameter is given, 'els' will be nil - end -end -```` - - -#### if - -condition | then | else | returns | ---- | --- | --- | --- | -bool | $a | $a | $a | -bool | $a | $a | -string | $a | $a | $a | -string | $a | $a | - -Selects either one of the branches, depending on the condition. The 'then' branch is returned if the condition returns the string `yes` or `true`. Otherwise, the `else` branch is taken (including if the condition returns `null`)If the `else` branch is not set, `null` is returned in the condition is false. - - - -Lua implementation: - -````lua -function if_then_else(condition, thn, els) - if (condition ~= nil and (condition == "yes" or condition == true or condition == "true") then - return thn - else - return els -- if no third parameter is given, 'els' will be nil - end -end -```` - - -#### if_then_else_dotted - -condition | then | else | returns | ---- | --- | --- | --- | -$b -> bool | $b -> $a | $b | $a | -$b -> string | $b -> $a | $b | $a | -$b -> bool | $b -> $a | $b -> $a | $b | $a | -$b -> string | $b -> $a | $b -> $a | $b | $a | - -An if_then_else, but one which takes an extra argument and applies it on the condition, then and else. -Consider `fc`, `fthen` and `felse` are all functions taking an `a`, then: -`(ifDotted fc fthen felse) a` === `(if (fc a) (fthen a) (felse a)Selects either one of the branches, depending on the condition. The 'then' branch is returned if the condition returns the string `yes` or `true` or the boolean `true`If the `else` branch is not set, `null` is returned in the condition is false.In case the condition returns 'null', then the 'else'-branch is taken. - - - -Lua implementation: - -````lua -function applyIfNeeded(f, arg) - if(f == nil) then - return nil - end - if(type(f) == "function") then - return f(arg) - else - return f - end -end - -function if_then_else_dotted(conditionf, thnf, elsef, arg) - local condition = applyIfNeeded(conditionf, arg); - if (condition) then - return applyIfNeeded(thnf, arg) - else - return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil - end -end -```` - - -#### ifdotted - -condition | then | else | returns | ---- | --- | --- | --- | -$b -> bool | $b -> $a | $b | $a | -$b -> string | $b -> $a | $b | $a | -$b -> bool | $b -> $a | $b -> $a | $b | $a | -$b -> string | $b -> $a | $b -> $a | $b | $a | - -An if_then_else, but one which takes an extra argument and applies it on the condition, then and else. -Consider `fc`, `fthen` and `felse` are all functions taking an `a`, then: -`(ifDotted fc fthen felse) a` === `(if (fc a) (fthen a) (felse a)Selects either one of the branches, depending on the condition. The 'then' branch is returned if the condition returns the string `yes` or `true` or the boolean `true`If the `else` branch is not set, `null` is returned in the condition is false.In case the condition returns 'null', then the 'else'-branch is taken. - - - -Lua implementation: - -````lua -function applyIfNeeded(f, arg) - if(f == nil) then - return nil - end - if(type(f) == "function") then - return f(arg) - else - return f - end -end - -function if_then_else_dotted(conditionf, thnf, elsef, arg) - local condition = applyIfNeeded(conditionf, arg); - if (condition) then - return applyIfNeeded(thnf, arg) - else - return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil - end -end -```` - - -#### ifDotted - -condition | then | else | returns | ---- | --- | --- | --- | -$b -> bool | $b -> $a | $b | $a | -$b -> string | $b -> $a | $b | $a | -$b -> bool | $b -> $a | $b -> $a | $b | $a | -$b -> string | $b -> $a | $b -> $a | $b | $a | - -An if_then_else, but one which takes an extra argument and applies it on the condition, then and else. -Consider `fc`, `fthen` and `felse` are all functions taking an `a`, then: -`(ifDotted fc fthen felse) a` === `(if (fc a) (fthen a) (felse a)Selects either one of the branches, depending on the condition. The 'then' branch is returned if the condition returns the string `yes` or `true` or the boolean `true`If the `else` branch is not set, `null` is returned in the condition is false.In case the condition returns 'null', then the 'else'-branch is taken. - - - -Lua implementation: - -````lua -function applyIfNeeded(f, arg) - if(f == nil) then - return nil - end - if(type(f) == "function") then - return f(arg) - else - return f - end -end - -function if_then_else_dotted(conditionf, thnf, elsef, arg) - local condition = applyIfNeeded(conditionf, arg); - if (condition) then - return applyIfNeeded(thnf, arg) - else - return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil - end -end -```` - - -#### id - -a | returns | ---- | --- | -$a | $a | - -Returns the argument unchanged - the identity function. Seems useless at first sight, but useful in parsing - - - -Lua implementation: - -````lua -function id(v) - return v -end -```` - - -#### const - -a | b | returns | ---- | --- | --- | -$a | $b | $a | - -Small utility function, which takes two arguments `a` and `b` and returns `a`. Used extensively to insert freedom - - - -Lua implementation: - -````lua -function const(a, b) - return a -end -```` - - -#### constRight - -a | b | returns | ---- | --- | --- | -$a | $b | $b | - -Small utility function, which takes two arguments `a` and `b` and returns `b`. Used extensively to insert freedom - - - -Lua implementation: - -````lua - -```` - - -#### dot - -f | g | a | returns | ---- | --- | --- | --- | -$b -> $c | $a -> $b | $a | $c | - -Higher order function: converts `f (g a)` into `(dot f g) a`. In other words, this fuses `f` and `g` in a new function, which allows the argument to be lifted out of the expression - - - -Lua implementation: - -````lua - -```` - - -#### listDot - -list | a | returns | ---- | --- | --- | -list ($a -> $b) | $a | list ($b) | - -Listdot takes a list of functions `[f, g, h]` and and an argument `a`. It applies the argument on every single function.It conveniently lifts the argument out of the list. - - - -Lua implementation: - -````lua --- TODO --- listDot -```` - - -#### eitherFunc - -f | g | a | returns | ---- | --- | --- | --- | -$a -> $b | $c -> $d | $a | $b | -$a -> $b | $c -> $d | $c | $d | - -EitherFunc is a small utility function, mostly used in the parser. It allows the compiler to choose a function, based on the types. - -Consider the mapping `{'someKey':'someValue'}`. Under normal circumstances, this acts as a pointwise-function, converting the string `someKey` into `someValue`, just like an ordinary dictionary would do. However, in the context of `mustMatch`, we would prefer this to act as a _check_, that the highway _has_ a key `someKey` which is `someValue`, thus acting as `{'someKey': {'$eq':'someValue'}}. Both behaviours are automatically supported in parsing, by parsing the string as `(eitherFunc id eq) 'someValue'`. The type system is then able to figure out which implementation is needed. - -Disclaimer: _you should never ever need this in your profiles_ - - - -Lua implementation: - -````lua - -```` - - -#### stringToTags - -f | tags | returns | ---- | --- | --- | -string -> string -> $a | tags | list ($a) | - -stringToTags converts a function `string -> string -> a` into a function `tags -> [a]` - - - -Lua implementation: - -````lua -print("ERROR: stringToTag is needed. This should not happen") -```` - - -#### head - -ls | returns | ---- | --- | -list ($a) | $a | - -Select the first non-null value of a list; returns 'null' on empty list or on null - - - -Lua implementation: - -````lua -function head(ls) - if(ls == nil) then - return nil - end - for _, v in pairs(ls) do - if(v ~= nil) then - return v - end - end - return nil -end -```` - -