| | import json
|
| | import re
|
| |
|
| |
|
| | with open("en.json", "r") as f:
|
| | model_data = json.load(f)
|
| |
|
| |
|
| | patterns = {
|
| | "phone": r"\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b",
|
| | "url": r"https?://\S+|www\.\S+",
|
| | "email": r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b"
|
| | }
|
| |
|
| |
|
| | def classify_text(text):
|
| | annotations = []
|
| |
|
| | for entity, pattern in patterns.items():
|
| | matches = re.findall(pattern, text)
|
| | for match in matches:
|
| | annotations.append({"token": match, "type": entity, "confidence_score": 0.9})
|
| |
|
| | return {"annotations": annotations}
|
| |
|
| |
|
| | test_text = "Hello world this is Call 123-456-7890 or visit www.example.com or email test@example.com soe other text."
|
| | result = classify_text(test_text)
|
| | print("Classification Result:", json.dumps(result, indent=2))
|
| |
|