Skip to content
Snippets Groups Projects
Commit 28505770 authored by Enzo Simonnet's avatar Enzo Simonnet
Browse files

Replace wikstraktor.py

parent 017cf28e
No related branches found
No related tags found
No related merge requests found
......@@ -98,7 +98,7 @@ class Example:
if self.source != None:
res["source"] = self.source
if self.url != None:
res["url"] = url
res["url"] = self.url
return res
class Sense:
......@@ -255,6 +255,7 @@ class ParserContext:
self.create_entry()
def create_entry(self):
#Dans le dictionnaire de keys, il n'y a jamais de senses ou de POS
res = Entry(self.lemma)
for l in self.context:
if "pro" in l.keys():
......@@ -343,14 +344,19 @@ class Wikstraktor:
while self.parserContext.get_level() > s.level:
self.parserContext.pop()
self.parserContext.set_top_wiki(s)
if s.title == self.constants['pro']:
if self.wtp.parse(s.title).templates == []:
stitle = s.title
else:
stitle = self.wtp.parse(s.title).templates[0].arguments[0].value
if stitle == self.constants['pro']:
self.parserContext.set_top_entry_info('pro', self.process_pronunciation(self.wtp.parse(s.contents)))
elif self.constants['ety'] in s.title:
elif self.constants['ety'] in stitle:
self.parserContext.set_top_entry_info('ety', self.process_etymology(self.wtp.parse(s.contents)))
elif s.title in self.constants['POS'].keys():
pos = self.constants['POS'][s.title]
self.parserContext.set_top_entry_info('POS', pos, False)
self.parserContext.set_top_entry_info('senses', self.process_senses(entry, pos+str(len(self.parserContext.entries)), self.wtp.parse(s.contents)))
elif stitle in self.constants['POS'].keys():
if s.title in self.constants['POS'].keys():
pos = self.constants['POS'][stitle]
self.parserContext.set_top_entry_info('POS', pos, False)
self.parserContext.set_top_entry_info('senses', self.process_senses(entry, pos+str(len(self.parserContext.entries)), self.wtp.parse(s.contents)))
res = len(self.parserContext.entries)
if res > 0:
for e in self.parserContext.entries:
......@@ -374,12 +380,19 @@ class Wikstraktor:
if __name__ == "__main__":
e = Wikstraktor.get_instance('en', "en")
#e = Wikstraktor.get_instance('en', "en")
f = Wikstraktor.get_instance('fr', 'en')
# print(e.get_file_url("File:LL-Q1860 (eng)-Nattes à chat----parent.wav"))
# print(e.get_file_url("File:LL-Q1860 (eng)-Nattes à chat-parent.wav"))
e.fetch("test")
#e.fetch("water")
f.fetch("water")
# print(e.fetch("test"), "entries added")
print(e)
#print(e)
file_path = 'test.json'
fichier = open(file_path, "w")
#fichier.write(str(f))
fichier.write(str(f))
fichier.close()
# site = pywikibot.Site(f'wiktionary:en')
# p = pywikibot.FilePage(site, "File:LL-Q1860 (eng)-Nattes à chat----parent.wav")
# print(p)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment