Skip to content

Commit

Permalink
Fix #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter Colpaert committed Aug 13, 2015
1 parent 5b0ee38 commit a74307c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/irail/stations/Stations.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ public static function getStations($query = "", $country = "")
$newstations->{"@id"} = $stations->{"@id"} . "?q=" . $query;
$newstations->{"@context"} = $stations->{"@context"};
$newstations->{"@graph"} = array();

//https://github.com/iRail/iRail/issues/66
$query = str_replace(" am "," ", $query);
$query = str_ireplace(" am "," ", $query);
$query = str_ireplace("frankfurt fl","frankfurt main fl", $query);

//https://github.com/iRail/iRail/issues/66
$query = str_replace("Bru.","Brussel", $query);
$query = str_ireplace("Bru.","Brussel", $query);
//make sure something between brackets is ignored
$query = preg_replace("/\s?\(.*?\)/i", "", $query);

// st. is the same as Saint
$query = preg_replace("/st(\s|$)/i", "(saint|st|sint) ", $query);
$query = str_ireplace("st-","st ", $query);
$query = str_ireplace("st.-","st ", $query);
$query = preg_replace("/st(\s|$|\.)/i", "(saint|st|sint) ", $query);
//make sure that we're only taking the first part before a /
$query = explode("/", $query);
$query = trim($query[0]);
Expand Down
12 changes: 11 additions & 1 deletion tests/StationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,23 @@ public function testEdgeCases ()
//test whether sint st. and saint return the same result
$result2a = Stations::getStations("st pancras");
$result2b = Stations::getStations("saint pancras");
$result2c = Stations::getStations("st-pancras");
$result2d = Stations::getStations("st.-pancras");
$this->assertEquals($result2a->{"@graph"}[0]->{"@id"},$result2b->{"@graph"}[0]->{"@id"});
$this->assertEquals($result2b->{"@graph"}[0]->{"@id"},$result2c->{"@graph"}[0]->{"@id"});
$this->assertEquals($result2a->{"@graph"}[0]->{"@id"},$result2d->{"@graph"}[0]->{"@id"});

// Check whether both am mein and mein work
// Check whether both am main and main work
$result3a = Stations::getStations("frankfurt am main");
$result3b = Stations::getStations("frankfurt main");
$this->assertEquals($result3a->{"@graph"}[0]->{"@id"},$result3b->{"@graph"}[0]->{"@id"});

// Check whether flughhaven am main don't get mixed up and all work
$result4a = Stations::getStations("frankfurt am main flughafen");
$result4b = Stations::getStations("frankfurt flughafen");
$result4c = Stations::getStations("frankfurt main flughafen");
$this->assertEquals($result4a->{"@graph"}[0]->{"@id"},$result4b->{"@graph"}[0]->{"@id"});
$this->assertEquals($result4b->{"@graph"}[0]->{"@id"},$result4c->{"@graph"}[0]->{"@id"});
}

public function testId ()
Expand Down

0 comments on commit a74307c

Please sign in to comment.