Spaces:
Sleeping
Sleeping
Create src/regx/concepts.py
Browse files- src/regx/concepts.py +19 -0
src/regx/concepts.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
import re
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
+
PATTERNS = {
|
| 6 |
+
"REMOTE_ID_BCAST": [r"\b(remote|electronic)\s+id(entification)?\b", r"\b(broadcast|bluetooth|wi-?fi)\b"],
|
| 7 |
+
"GEOAWARENESS": [r"\bgeo[-\s]?awareness\b|\bno[-\s]?fly\b|\brestricted\s+area\b"],
|
| 8 |
+
"U_SPACE_NETWORK_RID": [r"\bnetwork\s+remote\s+id(entification)?\b", r"\bservice\b"],
|
| 9 |
+
"OPERATION_CATEGORIES": [r"\b(open|specific|certified)\b\s+(category|operation)"],
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
def auto_concepts(text: str) -> List[str]:
|
| 13 |
+
low = text.lower()
|
| 14 |
+
hits = []
|
| 15 |
+
for cid, regexes in PATTERNS.items():
|
| 16 |
+
score = sum(1 for rx in regexes if re.search(rx, low))
|
| 17 |
+
if score >= max(1, len(regexes) - 1):
|
| 18 |
+
hits.append(cid)
|
| 19 |
+
return hits
|