-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatching.py
More file actions
49 lines (33 loc) · 1.07 KB
/
matching.py
File metadata and controls
49 lines (33 loc) · 1.07 KB
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
from config import CORRESP, DOCTYPES, MEMBERS
"""
Catalogue Dict Structure:
{
"Return-String": [
[AND]OR[AND]
]
}
"""
class Catalogue:
def __init__(self, catalogue) -> None:
self.cat = catalogue
def in_context(self, el, context: str = "") -> bool:
el = el.lower()
return el in context
def match(self, context: str) -> str:
context = context.lower()
d = DOCTYPES.catalogue
found = False
for k in self.cat.keys():
for l in self.cat[k]: # OR Elements
ands = all(self.in_context(i, context) for i in l)
if ands:
return k
def match(context: str, catalogue_dict: dict) -> str:
cat = Catalogue(catalogue=catalogue_dict)
return cat.match(context)
def match_correspondent(context):
return match(context=context, catalogue_dict=CORRESP.catalogue)
def match_doctype(context):
return match(context=context, catalogue_dict=DOCTYPES.catalogue)
def match_member(context):
return match(context=context, catalogue_dict=MEMBERS.catalogue)