Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions siteupdate/cplusplus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CommonObjects = \
functions/format_clinched_mi.o \
functions/lower.o \
functions/split.o \
functions/strd.o \
functions/upper.o \
functions/valid_num_str.o

Expand Down
1 change: 1 addition & 0 deletions siteupdate/cplusplus/classes/Route/compute_stats_r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ void Route::compute_stats_r()
} else if (city.empty())
Datacheck::add(this, "", "", "", "ABBREV_NO_CITY", CSV_LINE);
#undef CSV_LINE
for (Waypoint* w : point_list) w->label_selfref();
}
1 change: 0 additions & 1 deletion siteupdate/cplusplus/classes/Route/read_wpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ void Route::read_wpt(WaypointQuadtree *all_waypoints, ErrorList *el, bool usa_fl
w->label_invalid_ends();
w->label_looks_hidden();
w->label_parens();
w->label_selfref(slash);
w->label_slashes(slash);
w->lacks_generic();
w->underscore_datachecks(slash);
Expand Down
122 changes: 89 additions & 33 deletions siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../DBFieldLength/DBFieldLength.h"
#include "../HighwaySystem/HighwaySystem.h"
#include "../Route/Route.h"
#include "../../functions/strd.h"
#include "../../functions/valid_num_str.h"
#include <cmath>
#include <cstring>
Expand Down Expand Up @@ -311,6 +312,55 @@ bool Waypoint::label_references_route(Route *r)
return 0;
}

Route* Waypoint::coloc_same_number(const char* digits)
{ if (colocated)
for (Waypoint* w : *colocated)
{ if (w == this) continue;
const char* d = w->route->route.data();
while (!isdigit(*d) && *d) ++d;
std::string other(d);
if (w->route->banner[0] == '-') other += w->route->banner;
if (digits == other) return w->route;
}
return 0;
}

Route* Waypoint::coloc_same_designation(const std::string& rte)
{ if (colocated)
for (Waypoint* w : *colocated)
if ( w != this && rte == (w->route->banner[0] == '-' ? w->route->route : w->route->name_no_abbrev()) )
return w->route;
return 0;
}

Route* Waypoint::self_intersection()
{ if (colocated)
for (Waypoint* w : *colocated)
if (w != this && w->route == route)
return w->route;
return 0;
}

bool Waypoint::banner_after_slash(const char* slash)
{ // return whether colocated with a bannered route of same designation whose banner
// is contained in this waypoint's label after a slash, before underscore if exists
if (colocated)
for (Waypoint* w : *colocated)
if (w != this && w->route->banner.size() && w->route->route == route->route && strdstr(slash+1, w->route->banner.data(), '_'))
return 1;
return 0;
}

Route* Waypoint::coloc_banner_matches_abbrev()
{ // return whether colocated with a bannered route of same designation whose banner
// matches this route's abbrev
if (colocated)
for (Waypoint* w : *colocated)
if (w != this && w->route->route == route->route && w->route->banner == route->abbrev)
return w->route;
return 0;
}

/* Datacheck */

void Waypoint::distance_update(char *fstr, double &vis_dist, Waypoint *prev_w)
Expand Down Expand Up @@ -426,42 +476,48 @@ void Waypoint::label_parens()
Datacheck::add(route, label, "", "", "LABEL_PARENS", "");
}

void Waypoint::label_selfref(const char *slash)
{ // looking for the route within the label
// partially complete "references own route" -- too many FP
void Waypoint::label_selfref()
{ // "label references own route"
#define FLAG(SUBTYPE) Datacheck::add(route, label, "", "", "LABEL_SELFREF", SUBTYPE)
const char* l = label.data() + (label[0] == '*');
std::string rte = route->banner[0] == '-' ? route->route : route->name_no_abbrev();
// first check for number match after a slash, if there is one
if (slash)
{ char* digit_starts = isdigit(route->route.back())
? &route->route.back()
: isdigit(route->route[route->route.size()-2]) && isalpha(route->route.back()) ? &route->route.back()-1 : 0;
if (digit_starts)
{ while (digit_starts > route->route.data() && isdigit(digit_starts[-1])) digit_starts--;
if (!strcmp(slash+1, digit_starts) || !strcmp(slash+1, route->route.data()))
{ Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
return;
}
const char *underscore = strchr(slash+1, '_');
if (underscore)
{ std::string postslash(slash+1, underscore-slash-1);
if (postslash == digit_starts || postslash == route->route)
{ Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
return;
}
}
}
const char* slash = strchr(l, '/');
if (slash++ && strncmp(l, "Old", 3))
{ const char* digits = rte.data();
while (!isdigit(*digits) && *digits) ++digits;
if ( digits != rte.data()+rte.size()
&& !strdcmp(slash, digits, '_') && !coloc_same_number(digits)
|| !strdcmp(slash, rte.data(), '_') && !coloc_same_designation(rte)
) return FLAG("NO_COLOC");
}
// now the remaining checks
std::string rte_ban = route->route + route->banner;
if ( strncmp(label.data(), rte_ban.data(), rte_ban.size()) ) return;
const char *c = label.data()+rte_ban.size();
if (*c == 0 || *c == '/')
Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
else if (*c == '_')
if (*++c != 'U')
Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
else { while (isdigit(*++c));
if (*c) Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
}
if ( strncmp(l, rte.data(), rte.size()) ) return;
const char *c = l+rte.size();
switch(*c)
{ case 0: { Route* r = coloc_same_designation(rte);
if (!r) FLAG("NO_COLOC");
else if (r == route) FLAG("NO_SUFFIX");
else if (r->abbrev.size()) FLAG("NO_ABBREV");
} return;
case '_': { if (*++c == 'U')
{ while (isdigit(*++c));
if (!*c) return;
}
Route* r = coloc_same_designation(rte);
if (!r) FLAG("NO_COLOC");
else if (r->abbrev.size()) FLAG("NO_ABBREV");
} return;
case '/': if ((route->banner.size() && route->banner[0] != '-' || !banner_after_slash(slash)) && !coloc_same_designation(rte))
FLAG("NO_COLOC");
return;
default: if ( route->abbrev.size()
&& !strncmp(c, route->abbrev.data(), route->abbrev.size())
&& (!self_intersection() || !c[route->abbrev.size()])
&& !coloc_banner_matches_abbrev()
) FLAG(strchr("_/", c[route->abbrev.size()]) ? "TRUE_ERROR" : "FULL_MATCH");
}
#undef FLAG
}

void Waypoint::label_slashes(const char *slash)
Expand Down
7 changes: 6 additions & 1 deletion siteupdate/cplusplus/classes/Waypoint/Waypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Waypoint
void nmplogs(std::unordered_set<std::string> &, std::ofstream &, std::list<std::string> &);
Waypoint* hashpoint();
bool label_references_route(Route *);
Route* coloc_same_number(const char*);
Route* coloc_same_designation(const std::string&);
Route* self_intersection();
bool banner_after_slash(const char*);
Route* coloc_banner_matches_abbrev();

// Datacheck
void distance_update(char *, double &, Waypoint *);
Expand All @@ -55,7 +60,7 @@ class Waypoint
void label_invalid_ends();
void label_looks_hidden();
void label_parens();
void label_selfref(const char *);
void label_selfref();
void label_slashes(const char *);
void lacks_generic();
void underscore_datachecks(const char *);
Expand Down
16 changes: 16 additions & 0 deletions siteupdate/cplusplus/functions/strd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const char* strdstr(const char* h, const char* n, const char& d)
{ for (; *h && *h != d; h++)
{ const char* a = h;
const char* b = n;
while (*a != d)
if (*a++ != *b++) break;
else if (!*b) return h;
}
return 0;
}

int strdcmp(const char* a, const char* b, const char& d)
{ do if (!*b) return *a == d ? 0 : *a-*b;
while (*a++ == *b++);
return *--a - *--b;
}
2 changes: 2 additions & 0 deletions siteupdate/cplusplus/functions/strd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const char* strdstr(const char*, const char*, const char&);
int strdcmp(const char*, const char*, const char&);
98 changes: 74 additions & 24 deletions siteupdate/python-teresco/siteupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def is_or_colocated_with_active_or_preview(self):
return False

def hashpoint(self):
# return a canonical waypoint for graph vertex hashtable lookup
"""return a canonical waypoint for graph vertex hashtable lookup"""
if self.colocated is None:
return self
return self.colocated[0]
Expand All @@ -808,32 +808,82 @@ def label_references_route(self, r, datacheckerrors):
#datacheckerrors.append(DatacheckEntry(route, [self.label], "UNEXPECTED_DESIGNATION", self.label[len(no_abbrev)+len(r.abbrev)+1:]))
return False

def coloc_same_number(self, digits):
if self.colocated:
for w in self.colocated:
if w == self:
continue;
d = 0
while d < len(w.route.route) and not w.route.route[d].isdigit():
d += 1
other = w.route.route[d:]
if w.route.banner.startswith('-'):
other += w.route.banner
if digits == other:
return True
return False

def coloc_same_designation(self, rte):
if self.colocated:
for w in self.colocated:
if w != self and rte == (w.route.route if w.route.banner.startswith('-') else w.route.name_no_abbrev()):
return w.route;
return None;

def banner_after_slash(self, postslash):
"""return whether colocated with a bannered route of same designation whose banner
is contained in this waypoint's label after a slash, before underscore if exists"""
if self.colocated is not None:
for w in self.colocated:
if w != self and len(w.route.banner) and w.route.route == self.route.route and w.route.banner in postslash:
return True
return False

def label_selfref(self):
# partially complete "references own route" -- too many FP
"""label references own route"""
l = self.label[(self.label[0] == '*'):]
rte = r.route if r.banner.startswith('-') else r.name_no_abbrev()
# first check for number match after a slash, if there is one
if '/' in self.label:
digit_starts = len(r.route)-1 if r.route[-1].isdigit() else \
len(r.route)-2 if r.route[-2].isdigit() and r.route[-1].isalpha() else 0
if digit_starts:
while digit_starts >= 0 and r.route[digit_starts].isdigit():
digit_starts-=1
digits = r.route[digit_starts+1:]
postslash = self.label[self.label.index('/')+1:]
if postslash == digits or postslash == r.route:
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF'))
return
if '_' in postslash:
postslash = postslash[:postslash.index('_')]
if postslash == digits or postslash == r.route:
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF'))
return
if '/' in l and not l.startswith("Old"):
digit_starts = 0
while digit_starts < len(rte) and not rte[digit_starts].isdigit():
digit_starts+=1
digits = rte[digit_starts:]
postslash = l[l.index('/')+1:]
if '_' in postslash:
postslash = postslash[:postslash.index('_')]
if len(digits) \
and postslash == digits and not self.coloc_same_number(digits) \
or postslash == rte and not self.coloc_same_designation(rte):
return datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF','NO_COLOC'))
# now the remaining checks
rte_ban = r.route+r.banner
if self.label.startswith(rte_ban):
c = len(rte_ban)
l = self.label
if len(l) == c or l[c] == '_' and (len(l) == c+1 or l[c+1] != 'U' or len(l) > c+2 and not l[c+2:].isdigit()) or l[c] == '/':
datacheckerrors.append(DatacheckEntry(r,[l],'LABEL_SELFREF'))
if l.startswith(rte):
c = len(rte)
if c == len(l):
route = self.coloc_same_designation(rte)
if route is None:
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF','NO_COLOC'))
elif route == r:
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF','NO_SUFFIX'))
elif len(route.abbrev):
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF','NO_ABBREV'))
elif l[c] == '_':
if len(l) == c+1 or l[c+1] != 'U' or len(l) > c+2 and not l[c+2:].isdigit():
route = self.coloc_same_designation(rte)
if route is None:
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF','NO_COLOC'))
elif len(route.abbrev):
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF','NO_ABBREV'))
elif l[c] == '/':
if (len(r.banner) and r.banner[0] != '-' or not self.banner_after_slash(postslash)) and not self.coloc_same_designation(rte):
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF','NO_COLOC'))
elif len(r.abbrev) \
and l[c:].startswith(r.abbrev) \
and (self.colocated is None \
or (r not in [p.route for p in self.colocated if p != self] or len(l) == c+len(r.abbrev)) \
and r.abbrev not in [p.route.banner for p in self.colocated if p != self]):
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF', \
"TRUE_ERROR" if len(l) == c+len(r.abbrev) or l[c+len(r.abbrev)] in "_/" else "FULL_MATCH"))

class HighwaySegment:
"""This class represents one highway segment: the connection between two
Expand Down