From 4ff8dbd26eadf66d3255dca2238751bb3c7d17a4 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 19 May 2023 22:23:32 +0200 Subject: [PATCH] =?UTF-8?q?Spezifischen=20Content=20f=C3=BCr=20jeden=20Fra?= =?UTF-8?q?getyp=20abgreifen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sosci2word/_SoSci2Word.mm | 35 +++++++++++++++++++++++--- sosci2word/sosci2word.py | 53 ++++++++++++++++++++++++++++++++------- 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/sosci2word/_SoSci2Word.mm b/sosci2word/_SoSci2Word.mm index dfe1b80..8df3955 100644 --- a/sosci2word/_SoSci2Word.mm +++ b/sosci2word/_SoSci2Word.mm @@ -61,7 +61,7 @@ - + @@ -238,7 +238,36 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -468,7 +497,7 @@ - + diff --git a/sosci2word/sosci2word.py b/sosci2word/sosci2word.py index 08b0cad..b710176 100644 --- a/sosci2word/sosci2word.py +++ b/sosci2word/sosci2word.py @@ -29,38 +29,73 @@ def convertSosci2Word(): class QuestionElement: - def __init__(self, questionID): + def __init__(self, questionID, question): self.qid = questionID + self.title = question.find('title').text + self.desc = question.find('description').text + + def dumpBasis(self, type): + return "##--%s--##\ndes=%s\ntitle=%s" % (type, self.desc, self.title) def dump(self): - return "##--Basis--##" + return self.dumpBasis("Basis") class LikertItem(QuestionElement): def __init__(self, questionID, question): - QuestionElement.__init__(self, questionID) - + QuestionElement.__init__(self, questionID, question) + self.labels = [] + for entry in question.find('labels').findall('li'): + code = int(entry.get('i')) + text = entry.text + self.labels.append((code,text)) + self.items = [] + for item in question.findall('item'): + code = int(getSpecificID(item)) + text = item.find('text').text + self.items.append((code,text)) + + def dump(self): - return "##--LikertItem--##" + return ( self.dumpBasis('Likert') + + "\nLabels: " + str(list("(%d,%s)" % (c,t) for c,t in self.labels)) + + "\nItems: " + str(list("(%d,%s)" % (c,t) for c,t in self.items)) + ) + + class SelectItem(QuestionElement): def __init__(self, questionID, question): - QuestionElement.__init__(self, questionID) + QuestionElement.__init__(self, questionID, question) + self.items = [] + for item in question.findall('item'): + code = int(getSpecificID(item)) + text = item.find('text').text + self.items.append((code,text)) def dump(self): - return "##--SelectItem--##" + return ( self.dumpBasis('Select') + + "\nItems: " + str(list("(%d,%s)" % (c,t) for c,t in self.items)) + ) class TextElement(QuestionElement): def __init__(self, questionID, question): - QuestionElement.__init__(self, questionID) + QuestionElement.__init__(self, questionID, question) + lead = question.find('lead') + if lead == None: + self.text = "" + else: + self.text = lead.text def dump(self): - return "##--TextElement--##" + return ( self.dumpBasis('Text') + + "\nText: " + self.text + )