Skip to content
Snippets Groups Projects
Select Git revision
  • cd864a63a4a6803e992dc1a1578730931f238e4a
  • master default protected
  • deanonimzer
  • v2 protected
  • v1 protected
  • develop protected
6 results

number.py

Blame
  • number.py 612 B
    import regex as re
    from typing import List, Dict, Any, Tuple
    from src.detections import NumberDetection
    from src.detectors.interface import Detector
    
    NUMBER_REGEX = re.compile(
        r"\d+",
        re.I,
    )
    
    
    class NumberDetector(Detector):
        def __init__(self) -> None:
            super().__init__()
    
        def detect(
            self, text: str, annotations: Dict[str, List[Tuple[int, int, Any]]]
        ) -> List[Tuple[int, int, NumberDetection]]:
    
            numbers = []
    
            for number in NUMBER_REGEX.finditer(text):
                numbers.append((number.start(), number.end(), NumberDetection()))
    
            return numbers