Skip to content

Commit

Permalink
Frankfurt Am Main Airport can't be localized, don't use parentheses i…
Browse files Browse the repository at this point in the history
…n station name
  • Loading branch information
Bertware committed Aug 8, 2020
1 parent c42472d commit f63b80c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"ml/json-ld": "^1.0",
"cache/apcu-adapter": "^1.0",
"cache/array-adapter": "^1.0",
"cache/apc-adapter": "^1.0"
"cache/apc-adapter": "^1.0",
"ext-json": "*"
},
"autoload": {
"psr-0": {
Expand Down
15 changes: 6 additions & 9 deletions src/irail/stations/Stations.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Cache\Adapter\Apc\ApcCachePool;
use Cache\Adapter\Common\AbstractCachePool;
use Cache\Adapter\PHPArray\ArrayCachePool;
use stdClass;

class Stations
{
Expand Down Expand Up @@ -132,7 +133,7 @@ public static function getStations($query = '', $country = '', $sorted = false)

// Filter the stations on name match
$stations = self::$stations;
$newstations = new \stdClass();
$newstations = new stdClass();
$newstations->{'@id'} = $stations->{'@id'} . '?q=' . $query;
$newstations->{'@context'} = $stations->{'@context'};
$newstations->{'@graph'} = [];
Expand Down Expand Up @@ -174,7 +175,7 @@ public static function getStations($query = '', $country = '', $sorted = false)

// Dashes are the same as spaces
$query = self::normalizeAccents($query);
$query = preg_replace("/(-| )+/", " ", $query);
$query = preg_replace("/([- ])+/", " ", $query);

$count = 0;

Expand All @@ -196,15 +197,13 @@ public static function getStations($query = '', $country = '', $sorted = false)
// If this is a direct match for case insensitive search (with or without the apostrophe ' characters
$exactMatch = true;
} else {

if (self::isQueryPartOfName($query, $testStationName)) {
// If this is a direct match for case insensitive search (with or without the apostrophe ' characters
$partialMatch = true;
}

// Even when we have a partial match, we should keep searching for an exact math
if (isset($station->alternative)) {

// If this station in the list has an alternative form, try to match alternatives
foreach ($station->alternative as $alternative) {
$testStationName = str_replace(' am ', ' ', self::normalizeAccents($alternative->{'@value'}));
Expand All @@ -221,9 +220,7 @@ public static function getStations($query = '', $country = '', $sorted = false)
$partialMatch = true;
}
}

}

}

if ($exactMatch) {
Expand Down Expand Up @@ -286,14 +283,14 @@ private static function isEqualCaseInsensitive($query, $testStationName)
/**
* Compare 2 stations based on vehicle frequency.
*
* @param $a \stdClass the first station
* @param $b \stdClass the second station
* @param $a stdClass the first station
* @param $b stdClass the second station
*
* @return int The result of the compare. 0 if equal, -1 if a is after b, 1 if b is before a
*/
public static function cmp_stations_vehicle_frequency($a, $b)
{
if ($a == $b) {
if ($a->avgStopTimes == $b->avgStopTimes) {
return 0;
}
//sort sorts from low to high, so lower avgStopTimes will result in a higher ranking.
Expand Down
4 changes: 2 additions & 2 deletions stations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ http://irail.be/stations/NMBS/008844255,Fraipont,,,,,be,5.723665,50.565059,86.14
http://irail.be/stations/NMBS/008881570,Frameries,,,,,be,3.906586,50.405932,27.716418,300
http://irail.be/stations/NMBS/008844347,Franchimont,,,,,be,5.822223,50.525723,31.656716,300
http://irail.be/stations/NMBS/008861143,Franière,,,,,be,4.733548,50.439543,107.41791,300
http://irail.be/stations/NMBS/008061676,Frankfurt am Main Flughafen Fernbf,Francfort-sur-le-Main Aéroport (longue tenue),Frankfurt am Main Luchthaven (Lange-afstand),,Frankfurt am Main Airport (Long distance trains),de,8.66361100,50.1308300,0.11194,300
http://irail.be/stations/NMBS/008011090,Frankfurt am Main Flughafen Reginalbf,Francfort-sur-le-Main Aéroport regional (régional),Frankfurt am Main Luchthaven (Regionale treinen),,Frankfurt am Main Airport (Regional trains),de,8.569853,50.051696,0,
http://irail.be/stations/NMBS/008061676,Frankfurt am Main Flughafen Fernbf,,,,,de,8.66361100,50.1308300,0.11194,300
http://irail.be/stations/NMBS/008011090,Frankfurt am Main Flughafen Reginalbf,,,,,de,8.569853,50.051696,0,
http://irail.be/stations/NMBS/008011068,Frankfurt am Main Hbf,Francfort-sur-le-Main Hbf,,,,de,8.6653708,50.1071318,0.11194,300
http://irail.be/stations/NMBS/008885068,Froyennes,,,,,be,3.354837,50.62989,79.537313,300
http://irail.be/stations/NMBS/008895620,Galmaarden,Gammerages,,,,be,3.965726,50.743918,42.014925,300
Expand Down
3 changes: 1 addition & 2 deletions tests/StationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function testExactNameQueries()

// If this passes, we're off for a good start. Verify all stations.
$stations = Stations::getStations();
echo("Testing exact name queries...");
foreach ($stations->{'@graph'} as $station) {
echo("Testing exact match for $station->name...");
$jsonld = Stations::getStations($station->name);
$this->assertGreaterThanOrEqual(1, count($jsonld->{'@graph'}));
$this->assertEquals($station->name, $jsonld->{'@graph'}[0]->name);
Expand All @@ -87,7 +87,6 @@ public function testExactNameQueries()
}

foreach ($alternatives as $alternative) {
echo("Testing exact match for {$alternative->{"@value"}}...");
$jsonld = Stations::getStations($alternative->{"@value"});
$this->assertGreaterThanOrEqual(1, count($jsonld->{'@graph'}));
$this->assertEquals($station->name, $jsonld->{'@graph'}[0]->name);
Expand Down

0 comments on commit f63b80c

Please sign in to comment.