Coverage for presidio_analyzer / predefined_recognizers / country_specific / germany / de_tax_number_recognizer.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-29 09:03 +0000

1from typing import List, Optional 

2 

3from presidio_analyzer import Pattern, PatternRecognizer 

4 

5 

6class DeTaxNumberRecognizer(PatternRecognizer): 

7 """ 

8 Recognizes German Steuernummer using regex. 

9 

10 The Steuernummer is a tax number assigned by the local Finanzamt (tax office) 

11 to individuals and businesses. Unlike the Steueridentifikationsnummer, it can 

12 change (e.g., upon moving to a different Finanzamt district). 

13 

14 Legal basis: § 139a Abgabenordnung (AO). 

15 Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG. 

16 

17 Formats: 

18 - ELSTER unified (bundeseinheitlich, 13 digits): 

19 BB FFF UUUUU P → 2-digit Bundesland code (01–16) + 11 digits 

20 Example: 2181508150X → normalised as 02181508150X 

21 - State-specific human-readable (with slashes/spaces): 

22 NW: 123/4567/8901 (3/4/4 digits) 

23 BY: 123/456/78901 (3/3/5 digits) 

24 BE: 12/345/67890 (2/3/5 digits) 

25 HH: 12/345/67890 (2/3/5 digits) 

26 

27 Bundesland codes (ELSTER): 

28 01=SH, 02=HH, 03=NI, 04=HB, 05=NW, 06=HE, 07=RP, 

29 08=BW, 09=BY, 10=SL, 11=BE, 12=BB, 13=MV, 14=SN, 15=ST, 16=TH 

30 

31 :param patterns: List of patterns to be used by this recognizer 

32 :param context: List of context words to increase confidence in detection 

33 :param supported_language: Language this recognizer supports 

34 :param supported_entity: The entity this recognizer can detect 

35 """ 

36 

37 PATTERNS = [ 

38 Pattern( 

39 "Steuernummer ELSTER (bundeseinheitlich, 13-stellig)", 

40 r"\b(0[1-9]|1[0-6])\d{11}\b", 

41 0.5, 

42 ), 

43 Pattern( 

44 "Steuernummer mit Schrägstrich (Bayern/BW: 3/3/5)", 

45 r"(?<!\w)\d{3}/\d{3}/\d{5}(?!\w)", 

46 0.4, 

47 ), 

48 Pattern( 

49 "Steuernummer mit Schrägstrich (NW: 3/4/4 oder allgemein 2-3/3-4/4-5)", 

50 r"(?<!\w)\d{2,3}/\d{3,4}/\d{4,5}(?!\w)", 

51 0.2, 

52 ), 

53 ] 

54 

55 CONTEXT = [ 

56 "steuernummer", 

57 "steuer-nr", 

58 "steuer nr", 

59 "st.-nr", 

60 "st-nr", 

61 "finanzamt", 

62 "umsatzsteuer", 

63 "einkommensteuer", 

64 "körperschaftsteuer", 

65 "gewerbesteuer", 

66 "steuerveranlagung", 

67 "steuerbescheid", 

68 ] 

69 

70 def __init__( 

71 self, 

72 patterns: Optional[List[Pattern]] = None, 

73 context: Optional[List[str]] = None, 

74 supported_language: str = "de", 

75 supported_entity: str = "DE_TAX_NUMBER", 

76 name: Optional[str] = None, 

77 ): 

78 patterns = patterns if patterns else self.PATTERNS 

79 context = context if context else self.CONTEXT 

80 super().__init__( 

81 supported_entity=supported_entity, 

82 patterns=patterns, 

83 context=context, 

84 supported_language=supported_language, 

85 name=name, 

86 )