def make_from_json(jsonData, filename, removeOld=False): if removeOld: try: os.remove(filename) except (OSError): pass # create the document document = Document(filename) # set up a mock example trn = document.database.transaction() with trn: document.database.root['documentType'] = jsonData['documentType'] document.database.root['variety'] = jsonData['variety'] for i, spanData in enumerate(jsonData['spans']): span = Document.persistenceSchema.classes.Span( externalID=i, info=spanData['spanInfo']) for i, token in enumerate(spanData['tokens']): token = Document.persistenceSchema.classes.Token(token) try: token.gloss = spanData['lemmas'][i] except: pass span.addToken(token) document.addSpan(span) trn.commit() document.close()