Coverage for src/wiktextract/extractor/fr/models.py: 100%

115 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-13 10:14 +0000

1from pydantic import BaseModel, ConfigDict, Field 

2 

3 

4class FrenchBaseModel(BaseModel): 

5 model_config = ConfigDict( 

6 extra="forbid", 

7 strict=True, 

8 validate_assignment=True, 

9 validate_default=True, 

10 ) 

11 

12 

13class AttestationData(FrenchBaseModel): 

14 date: str 

15 

16 

17class Example(FrenchBaseModel): 

18 text: str = Field(default="", description="Example usage sentence") 

19 bold_text_offsets: list[tuple[int, int]] = [] 

20 translation: str = Field( 

21 default="", description="French translation of the example sentence" 

22 ) 

23 bold_translation_offsets: list[tuple[int, int]] = [] 

24 roman: str = Field( 

25 default="", description="Romanization of the example sentence" 

26 ) 

27 bold_roman_offsets: list[tuple[int, int]] = [] 

28 ref: str = Field( 

29 default="", 

30 description="Source of the sentence, like book title and page number", 

31 ) 

32 attestations: list[AttestationData] = Field( 

33 default=[], 

34 description="For examples in 'Attestations historiques' section", 

35 ) 

36 note: str = "" 

37 raw_tags: list[str] = [] 

38 tags: list[str] = [] 

39 

40 

41class Form(FrenchBaseModel): 

42 form: str = "" 

43 tags: list[str] = [] 

44 raw_tags: list[str] = [] 

45 ipas: list[str] = [] 

46 source: str = Field( 

47 default="", 

48 description="Form line template name or Conjugaison page title", 

49 ) 

50 hiragana: str = "" 

51 roman: str = "" 

52 sense: str = Field(default="", description="Definition of the word") 

53 sense_index: int = Field(default=0, ge=0) 

54 article: str = "" 

55 

56 

57class Sound(FrenchBaseModel): 

58 zh_pron: str = Field(default="", description="Chinese word pronunciation") 

59 ipa: str = Field(default="", description="International Phonetic Alphabet") 

60 audio: str = Field(default="", description="Audio file name") 

61 wav_url: str = "" 

62 oga_url: str = "" 

63 ogg_url: str = "" 

64 mp3_url: str = "" 

65 opus_url: str = "" 

66 flac_url: str = "" 

67 tags: list[str] = [] 

68 raw_tags: list[str] = [] 

69 rhymes: str = "" 

70 categories: list[str] = Field(default=[], exclude=True) 

71 homophone: str = "" 

72 roman: str = "" 

73 

74 

75class Translation(FrenchBaseModel): 

76 lang_code: str = Field( 

77 default="", 

78 description="Wiktionary language code of the translation term", 

79 ) 

80 lang: str = Field(default="", description="Translation language name") 

81 word: str = Field(default="", description="Translation term") 

82 sense: str = Field(default="", description="Translation gloss") 

83 sense_index: int = Field( 

84 default=0, ge=0, description="Number of the definition, start from 1" 

85 ) 

86 tags: list[str] = [] 

87 raw_tags: list[str] = [] 

88 roman: str = "" 

89 traditional_writing: str = Field( 

90 default="", 

91 description="Alternative writting for Chinese, Korean and Mongolian", 

92 ) 

93 ruby: list[tuple[str, ...]] = Field( 

94 default=[], description="Japanese Kanji and furigana" 

95 ) 

96 

97 

98class Linkage(FrenchBaseModel): 

99 word: str 

100 tags: list[str] = [] 

101 raw_tags: list[str] = [] 

102 topics: list[str] = [] 

103 roman: str = "" 

104 alt: str = Field(default="", description="Alternative form") 

105 translation: str = Field(default="", description="French translation") 

106 sense: str = Field(default="", description="Definition of the word") 

107 sense_index: int = Field( 

108 default=0, ge=0, description="Number of the definition, start from 1" 

109 ) 

110 lang: str = Field(default="", description="Localized language name") 

111 lang_code: str = Field(default="", description="Wiktionary language code") 

112 

113 

114class AltForm(FrenchBaseModel): 

115 word: str 

116 

117 

118class Sense(FrenchBaseModel): 

119 glosses: list[str] = [] 

120 tags: list[str] = [] 

121 raw_tags: list[str] = [] 

122 topics: list[str] = [] 

123 categories: list[str] = [] 

124 examples: list[Example] = [] 

125 note: str = "" 

126 alt_of: list[AltForm] = [] 

127 form_of: list[AltForm] = [] 

128 attestations: list[AttestationData] = [] 

129 

130 

131class WordEntry(FrenchBaseModel): 

132 model_config = ConfigDict(title="French Wiktionary") 

133 

134 word: str = Field(description="Word string") 

135 lang_code: str = Field(description="Wiktionary language code") 

136 lang: str = Field(description="Localized language name") 

137 pos: str = Field(default="", description="Part of speech type") 

138 pos_title: str = Field( 

139 default="", 

140 description="Original POS title for matching etymology texts", 

141 ) 

142 pos_id: str = Field( 

143 default="", 

144 description="POS id for matching etymology texts", 

145 exclude=True, 

146 ) 

147 etymology_texts: list[str] = Field(default=[], description="Etymology list") 

148 etymology_examples: list[Example] = Field( 

149 default=[], description="Data in 'Attestations historiques' section" 

150 ) 

151 senses: list[Sense] = Field(default=[], description="Sense list") 

152 forms: list[Form] = Field(default=[], description="Inflection forms list") 

153 sounds: list[Sound] = [] 

154 translations: list[Translation] = [] 

155 antonyms: list[Linkage] = [] 

156 synonyms: list[Linkage] = [] 

157 hyponyms: list[Linkage] = [] 

158 hypernyms: list[Linkage] = [] 

159 holonyms: list[Linkage] = [] 

160 meronyms: list[Linkage] = [] 

161 derived: list[Linkage] = [] 

162 troponyms: list[Linkage] = [] 

163 paronyms: list[Linkage] = [] 

164 related: list[Linkage] = [] 

165 abbreviation: list[Linkage] = [] 

166 proverbs: list[Linkage] = [] 

167 anagrams: list[Linkage] = [] 

168 title: str = Field(default="", description="Redirect page source title") 

169 redirect: str = Field(default="", description="Redirect page target title") 

170 categories: list[str] = [] 

171 notes: list[str] = [] 

172 tags: list[str] = [] 

173 raw_tags: list[str] = [] 

174 attestations: list[AttestationData] = [] 

175 original_title: str = ""