You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
737 B

  1. from editdistance import eval as editdistance
  2. import re
  3. import json
  4. class StopSearch:
  5. def __init__(self,query):
  6. parts = re.split(r' ?(?:and|&) ?',query)
  7. self.query = ' & '.join(parts)
  8. self.query_reversed = ' & '.join(reversed(parts))
  9. def __call__(self,stop):
  10. stop = stop.lower()
  11. return min(
  12. editdistance(self.query,stop),
  13. editdistance(self.query_reversed,stop)
  14. )
  15. def __str__(self):
  16. return '{}|{}'.format(self.query,self.query_reversed)
  17. def __repr__(self):
  18. return str(self)
  19. if __name__ == "__main__":
  20. with open('stops_out.json') as file:
  21. data = json.load(file)
  22. names = [stop['stpnm'] for stop in data['stops']]