From 33cfdfc91214d7c062db24e34f03f107382a9d77 Mon Sep 17 00:00:00 2001
From: Enzo Simonnet <enzosim@laposte.net>
Date: Wed, 30 Nov 2022 16:50:17 +0000
Subject: [PATCH] Replace wikstraktor.py

---
 wikstraktor.py | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/wikstraktor.py b/wikstraktor.py
index 41d0cbf..5257c6c 100755
--- a/wikstraktor.py
+++ b/wikstraktor.py
@@ -258,6 +258,7 @@ class ParserContext:
 		#Dans le dictionnaire de keys, il n'y a jamais de senses ou de POS
 		res = Entry(self.lemma)
 		for l in self.context:
+			print(l.keys())
 			if "pro" in l.keys():
 				res.set_pronunciations(l['pro'])
 			if "ety" in l.keys():
@@ -344,17 +345,19 @@ class Wikstraktor:
 					while self.parserContext.get_level() > s.level:
 						self.parserContext.pop()
 					self.parserContext.set_top_wiki(s)
-				if self.wtp.parse(s.title).templates == []:
+				stitle = self.wtp.parse(s.title).templates
+				if stitle == []:
 					stitle = s.title
 				else:
-					stitle = self.wtp.parse(s.title).templates[0].arguments[0].value
-				if stitle == self.constants['pro']:
+					stitle = stitle[0].arguments[0].value
+				if self.isPro(stitle):
 					self.parserContext.set_top_entry_info('pro', self.process_pronunciation(self.wtp.parse(s.contents)))
-				elif self.constants['ety'] in stitle:
+				elif self.isEty(stitle):
 					self.parserContext.set_top_entry_info('ety', self.process_etymology(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]
+# 				elif stitle in self.constants['POS'].keys():
+				else:
+					pos = self.process_POS(stitle)
+					if pos != None :
 						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)
@@ -363,6 +366,24 @@ class Wikstraktor:
 				self.entries.append(e)
 		return res
 
+	def isPro(self, title):
+		if type(self.constants['pro']) == str:
+			res = title == self.constants['pro']
+		else:
+			res = title in self.constants['pro']
+		print(title, res)
+		return res
+	
+	def isEty(self, title):
+		if type(self.constants['ety']) == str:
+			res = title == self.constants['ety']
+		else:
+			res = title in self.constants['ety']
+		return res
+	
+	def process_POS(self, parsedwikitext):
+		pass#in subclass
+
 	def process_pronunciation(self, parsedwikitext):
 		pass#in subclass
 
@@ -385,7 +406,7 @@ if __name__ == "__main__":
 	# 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("water")
-	f.fetch("water")
+	f.fetch("blue")
 	# print(e.fetch("test"), "entries added")
 	#print(e)
 	file_path = 'test.json'
-- 
GitLab