diff --git a/parsers/Structure_json.json b/parsers/Structure_json.json deleted file mode 100644 index bb0cd9b8062f6ed235cf06ffe1295b7c73a14031..0000000000000000000000000000000000000000 --- a/parsers/Structure_json.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "Headword":"sleep", - "Items":[ - { - "PartOfSpeech":"verb", - "Pronunciation":[ - { - "api":"\\ˈsliËp\\ ", - "hiragana":"", - "katakana":"", - "bopomofo":"", - "pinyin":"", - "romaji":"", - "accent1":"RP", - "url1":"https://upload.wikimedia.org/wikipedia/commons/1/19/LL-Q1860_%28eng%29-Back_ache-water.wav" - } - ], - "Senses":{ - "v1":{ - "Translations":[ - "translation1", - "...", - "translationn" - ], - "Image":[ - "Stilles Mineralwasser.jpg", - "..." - ], - "Definition":{"lang":"fr", "definition" : "blabla"}, - "Examples":[ - "blabla", - "blabli", - "blablou" - ], - "SubSenses":[ - { - "Definition":{"lang":"en", "definition" : "whatnot"}, - "Examples":[ - "subexa", - "subexb", - "subexz" - ] - } - ] - } - } - } - ] -} - -/*adapter à la généricité des données ? - \"User-defined fields 1\" - \"User-defined fields 2\" - \"User-defined fields 3\" - \"User-defined fields 4\" - \"User-defined fields 5\" - \"Supplementary field for devs 1\" - \"Supplementary field for devs 2\" - \"Supplementary field for devs 3\" - \"Supplementary field for devs 4\" - \"Supplementary field for devs 5\" - ... - \"Supplementary field for devs 10\ */ diff --git a/parsers/Structure_minimale.json b/parsers/Structure_minimale.json deleted file mode 100644 index f990a1905b471b13e55979b1e5fb70aece2c5bba..0000000000000000000000000000000000000000 --- a/parsers/Structure_minimale.json +++ /dev/null @@ -1,8 +0,0 @@ -"lemma" -"partOfSpeech" : -{ - "sense" : - { - "definition" - } -} diff --git a/wikstraktor.py b/wikstraktor.py index ad8513732dfcbfc7d9e942242b26a83379d14f8f..dae797951cc2f4c20b1316b06f56d2546c7fa9b5 100755 --- a/wikstraktor.py +++ b/wikstraktor.py @@ -64,6 +64,7 @@ class Sound: class Pronunciation(SubInfo): prfx = "prn" + next_id = 1 def __init__(self, prefix = None): super().__init__(prefix) @@ -122,6 +123,7 @@ class Pronunciation(SubInfo): class Definition(SubInfo): prfx = "def" key = "definition" + next_id = 1 def __init__(self, lang, text, prefix=None): super().__init__(prefix) @@ -143,9 +145,11 @@ class Definition(SubInfo): class Translation(Definition): prfx = "trad" key = "translation" + next_id = 1 class Example(SubInfo): prfx = "ex" + next_id = 1 def __init__(self, transcript, source=None, url=None, prefix=None): super().__init__(prefix) @@ -171,18 +175,12 @@ class Example(SubInfo): class Sense(SubInfo): prfx = "" + next_id = 1 def __init__(self, lang=None, definition=None, wiki_lang=None, prefix=None): self.lang = lang self.label = None self.set_id(prefix) - #On réinitialise les identifiants des sous-éléments - if not isinstance(self, SubSense): - Definition.reset() - Example.reset() - Translation.reset() - SubSense.reset() - self.definitions = [] #liste des définitions (elles auront une langue et un texte) self.subsenses = [] #liste des sous-définitions (récursif…) self.examples = [] #liste des exemples (un texte obligatoire, source et url sont optionnels) @@ -196,6 +194,15 @@ class Sense(SubInfo): except ValueError as err: raise ValueError(f"Sense.__init__() with empty definition\n{err}") + @classmethod + def reset(cls): + #On réinitialise les identifiants des sous-éléments + if cls.__name__ != "SubSense": + Definition.reset() + Example.reset() + Translation.reset() + SubSense.reset() + def add_metadata(self, key, value): if self.metadata_exists(key): print("Definition.add_metadata", f"for {self.text} replaced {key}:“{self.metadata[key]}†by {key}:“{value}â€") @@ -323,6 +330,7 @@ class Sense(SubInfo): return json.dumps(self.serializable()) class SubSense(Sense): + next_id = 1 def set_id(self, prefix=None): if prefix != None and self.label == None: self.label = f"{prefix}.{self.__class__.next_id}" #l'identifiant du sens diff --git a/wikstraktor.sqlite b/wikstraktor.sqlite index 1f34a516a0c391dab44d1401ff4ad34c2ac2e550..660ec27727267941a1d46949f21b24669ef6d801 100644 Binary files a/wikstraktor.sqlite and b/wikstraktor.sqlite differ