2 # vi: set softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
4 """Matches partial landmark names to full landmark names using a
7 It turns out that you can send a partial name to the travel planner
8 web app and it'll figure out what you mean, but there's no
9 prioritization of partial matches: BAYSHORE maps to
10 BAYSHORE CATHOLIC SCHOOL before it maps to BAYSHORE SHOPPING CENTRE.
12 We do our own prioritization by using landmarkLeech.py to grab
13 an offline copy of the landmark list in landmarks.txt, and
14 listing the categories (transit station, shopping centre, etc.) in
15 priority order in landmarkCategoryPriority.txt."""
17 from PlannerExceptions
import *
19 class LandmarkMatcher
:
20 def __init__(self
, listfile
="landmarks.txt",
21 priofile
="landmarkCategoryPriority.txt"):
25 # List of categories; each one contains a list of landmarks
28 # Map of category to landmark list.
31 self
._loadLandmarks
(listfile
)
32 self
._loadCategoryPrio
(priofile
)
34 def _loadLandmarks(self
, listfile
):
35 listfp
= open(listfile
, "r")
37 parts
= line
.rstrip().split("|")
38 landmark
= parts
[1].upper()
39 self
.all
.add(landmark
)
41 if not parts
[0] in self
.categoryMap
:
42 self
.categoryMap
[parts
[0]] = []
43 self
.categoryMap
[parts
[0]].append(landmark
)
45 def _loadCategoryPrio(self
, priofile
):
46 priofp
= open(priofile
, "r")
48 self
.categories
.append(self
.categoryMap
[line
.rstrip()])
55 for catlist
in self
.categories
:
56 for landmark
in catlist
:
57 if landmark
.startswith(str):
60 raise InvalidLandmarkException("Couldn't find landmark '%s' "
61 "in local database." % str)