File size: 2,085 Bytes
db11cc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 26 14:57:18 2022

@author: syed
"""

from quantities import units as u
from quantities import Quantity

one_plus = "+"
zero_plus = "*"


def get_quantities_regex():
  # myList = [unit for unit in dir(u.length)
  #           if type(getattr(u.length, unit)) is u.length ]
  myList = [unit for unit in dir(u.length) if isinstance(getattr(u.length, unit), Quantity)]

  units = [ x for x in myList if "_" not in x ]
  units_regex = '|'.join(units)
  return "["+units_regex+"]"
def get_number_regex():
  regex = "[0-9]"
  return regex
def get_space_regex():
  regex = "\s"
  return regex

def get_directional_regex():
  cardinals_kwds = "north|south|east|west"
  ordinals_kwds = "north-east|north-west|south-east|south-west|north east|north west|south east|south west|northeast|northwest|southeast|southwest"
  symbols_kwds = "N'|S'|E'|W'|NE'|NW'|SE'|SW'"
  return ordinals_kwds+"|"+symbols_kwds+"|"+cardinals_kwds

def get_center_regex():
  center_kwds = "center|central|downtown|midtown"
  return center_kwds

def get_near_regex():
  near_kwds = "nearby|near|vicinity|close|beside|next|adjacent|immediate|border"
  return near_kwds

def get_surrounding_regex():
  surrounding_kwds = "surrounding|neigbourhood|proximity|territory|locality"
  return surrounding_kwds
def get_level1_regex():
  level_1_regex = "(?i)("+get_directional_regex()+"|"+get_center_regex()+")"
  return level_1_regex

def get_level2_regex():
  level_2_regex = "(?i)("+get_near_regex()+"|"+get_surrounding_regex()+")"
  return level_2_regex

def get_level3_regex():
  level_3_regex = "(?i)("+get_number_regex()+one_plus+get_space_regex()+zero_plus+get_quantities_regex()+one_plus+")"
  return level_3_regex



def get_keywords():
   keywords = []
   keywords = get_directional_regex().split("|")
   keywords.extend(get_near_regex().split("|"))
   keywords.extend(get_surrounding_regex().split("|"))
   keywords.extend(get_center_regex().split("|"))
   keywords.append(",")
   keywords.append("and")
   keywords.append(".")
   
   return keywords