def parse_edition(cursor, edition_id): edition = cursor.execute( "SELECT score, name FROM edition WHERE edition.id=?", (edition_id, )).fetchone() composition_id = edition[0] edition_name = edition[1] authors = parse_authors(cursor, edition_id) composition = parse_composition(cursor, composition_id) return scorelib.Edition(composition, authors, edition_name)
def processRecord(record): print_id, title, genre, key, compositionYear, editionName, incipit = None, None, None, None, None, None, None composers, editors, voices = [], [], [] partiture = False for text in record: splitted = text.split(":") element = splitted[0] value = None if (len(splitted) > 1): value = splitted[1].strip() if (len(splitted) > 2): counter = 0 for field in splitted: if (counter > 1): value = value + ":" + splitted[counter] counter = counter + 1 value = value.strip() if (value == None): continue if ("Print" in element): print_id = int(value) if ("Composer" in element): for composerString in value.split(";"): composers.append(createPerson(composerString.strip())) if ("Title" in element): if (value != None and value.strip() != ""): title = value if ("Genre" in element): if (value != None and value.strip() != ""): genre = value if ("Key" in element): if (value != None and value.strip() != ""): key = value if ("Composition" in element): compositionYear = separateYear(value) if ("Edition" in element): if (value != None and value.strip() != ""): editionName = value if ("Editor" in element): #editors = createEditor(value.split(",")) editors.append(createPerson(value.strip())) if ("Voice" in element): voices.append(createVoice(value)) if ("Partiture" in element): partiture = getPartiture(value) if ("Incipit" in element and incipit == None): if (value != None and value.strip() != ""): incipit = value composition = scorelib.Composition(title, incipit, key, genre, compositionYear, voices, composers) edition = scorelib.Edition(editionName, composition, editors) printRecord = scorelib.Print(edition, print_id, partiture) return printRecord
def processPrintLines(printLinesArray): printNumber = None persons = [] title = None genre = None printKey = None compositionYear = None editionTitle = None voices = [] partiture = False incipit = None editors = [] for line in printLinesArray: splitArray = line.split(":") if (len(splitArray) < 2): continue key = splitArray[0].strip() value = splitArray[1].strip() vc = re.compile(r"Voice.*") voiceMatch = vc.match(key) if (voiceMatch): voices.append(processVoiceLine(value)) if (value == ""): continue if (key == "Print Number"): printNumber = int(value) if (key == "Composer"): persons = processComposerLine(value) if (key == "Title"): title = value if (key == "Genre"): genre = value if (key == "Key"): printKey = value if (key == "Composition Year"): compositionYear = processCompositionYear(value) if (key == "Edition"): editionTitle = value if (key == "Editor"): editors.append(value) if (key == "Partiture"): partiture = processPartiture(value) if (key == "Incipit"): incipit = value composition = scorelib.Composition(title, incipit, printKey, genre, compositionYear, voices, persons) edition = scorelib.Edition(composition, editors, editionTitle) printInstance = scorelib.Print(edition, printNumber, partiture) return printInstance
def getPrints(listOfPrintIds): prints = [] for id in listOfPrintIds: composers = [] editors = [] voices = {} cur.execute( '''SELECT print.id, print.partiture, edition.id, edition.name, score.id, score.name, score.incipit, score.key, score.genre, score.year FROM print JOIN edition ON edition.id = print.edition JOIN score ON score.id = edition.score WHERE print.id = ? ''', (id, )) rowMain = cur.fetchone() editionId = rowMain[2] compositionId = rowMain[4] cur.execute( '''SELECT number, range, name FROM voice WHERE score = ? ''', (compositionId, )) for voice in cur: voices[voice[0]] = scorelib.Voice(voice[2], voice[1]) cur.execute( '''SELECT name, born, died FROM score_author JOIN person ON person.id = score_author.composer WHERE score_author.score = ? ''', (compositionId, )) for comp in cur: composers.append(scorelib.Person(comp[0], comp[1], comp[2])) cur.execute( '''SELECT name, born, died FROM edition_author JOIN person ON person.id = edition_author.editor WHERE edition_author.edition = ? ''', (editionId, )) for edi in cur: editors.append(scorelib.Person(edi[0], edi[1], edi[2])) composition = scorelib.Composition(rowMain[5], rowMain[6], rowMain[7], rowMain[8], voices, composers) setattr(composition, "composition year", rowMain[9]) edition = scorelib.Edition(rowMain[3], composition, editors) if (rowMain[1] == "Y" or rowMain[1] == "y"): partiture = True else: partiture = False printInstance = scorelib.Print(edition, partiture) setattr(printInstance, "print number", rowMain[0]) prints.append(printInstance) return prints
def getAllPrints(): dbFilename = "scorelib.dat" conn = sqlite3.connect(dbFilename) cur = conn.cursor() persons = [] compositions = [] editions = [] prints = [] for row in cur.execute('SELECT * FROM score'): compositions.append( scorelib.Composition(row[1], row[4], row[3], row[2], row[5], [], [])) for row in cur.execute('SELECT * FROM person'): persons.append(scorelib.Person(row[3], row[1], row[2])) for row in cur.execute('SELECT * FROM voice'): voice = scorelib.Voice(row[4], row[3]) if (len(compositions[row[2] - 1].Voices) < row[1] - 1): compositions[row[2] - 1].Voices.append(None) if (len(compositions[row[2] - 1].Voices) < row[1] - 1): compositions[row[2] - 1].Voices.append(None) if (len(compositions[row[2] - 1].Voices) < row[1] - 1): compositions[row[2] - 1].Voices.append(None) if (len(compositions[row[2] - 1].Voices) < row[1] - 1): compositions[row[2] - 1].Voices.append(None) compositions[row[2] - 1].Voices.append(voice) for row in cur.execute('SELECT * FROM edition'): edition = scorelib.Edition(compositions[row[1] - 1], [], row[2]) editions.append(edition) for row in cur.execute('SELECT * FROM score_author'): compositions[row[1] - 1].Composer.append(persons[row[2] - 1]) for row in cur.execute('SELECT * FROM edition_author'): editions[row[1] - 1].Editor.append(persons[row[2] - 1]) for row in cur.execute('SELECT * FROM print'): part = True if row[1] == "Y" else False prints.append(scorelib.Print(editions[row[2] - 1], row[0], part)) return prints
def save_edition(cur, edition, score_id): params = [] if edition.name is None: edition_query = 'name is NULL' else: edition_query = 'name=?' params.append(edition.name) params.append(score_id) cur.execute( 'SELECT id FROM edition WHERE ' + edition_query + ' and score=?', (params)) row = cur.fetchone() if row is None: cur.execute('INSERT INTO edition (name, score) VALUES (?, ?)', (edition.name, score_id)) return cur.lastrowid else: tmp_edition = scorelib.Edition() tmp_edition.name = edition.name tmp_edition.composition = edition.composition cur.execute( 'SELECT name from person JOIN edition_author ON person.id=edition_author.editor WHERE edition=?', (row[0], )) result = cur.fetchall() if result is not None: for editor in result: tmp_editor = scorelib.Person() tmp_editor.name = editor[0] tmp_edition.authors.append(tmp_editor) if edition.__eq__(tmp_edition): return row[0] else: cur.execute('INSERT INTO edition (name, score) VALUES (?, ?)', (edition.name, score_id)) return cur.lastrowid
def print_create(list_of_lines): print_object = sc.Print(None, None, False) edition_object = sc.Edition(None, None) composition = sc.Composition(None, None, None, None, None) for line in list_of_lines: print_number = re.match("Print Number: (.*)", line) if print_number: print_object.print_id = int(print_number.group(1)) composers = re.match("Composer: (.*)", line) if composers: pass title = re.match("Title: (.*)", line) if title and title.group(1).strip() != "": composition.name = title.group(1).strip() genre = re.match("Genre: (.*)", line) if genre and genre.group(1).strip() != "": composition.genre = genre.group(1).strip() key = re.match("Key: (.*)", line) if key and key.group(1).strip() != "": composition.key = key.group(1).strip() edition = re.match("Edition: (.*)", line) if edition and edition.group(1).strip() != "": edition_object.name = edition.group(1).strip() incipit = re.match("Incipit: (.*)", line) if incipit and incipit.group(1).strip() != "": composition.incipit = incipit.group(1).strip() partiture = re.match("Partiture: (.*)", line) if partiture and partiture.group(1).strip() != "": part = re.match(".*yes.*", partiture.group(1).strip()) if part: print_object.partiture = True composition_year = re.match("Composition Year: (.*)", line) if composition_year: year = re.match(".*(\d{4}).*", composition_year.group(1).strip()) if year: composition.year = int(year.group(1)) composers = re.match("Composer: (.*)", line) if composers: composers = composers.group(1).split(";") for c in composers: composition.add_author(create_person(c)) editors = re.match("Editor: (.*)", line) if editors: editors = editors.group(1).strip() single_person = re.match("(\w+ \w+|\w+$|\w+-\w+ \w+)", editors) if single_person: editor = create_person(single_person.group(1).strip()) edition_object.add_author(editor) else: single_person = re.match("(\w+, \w+$|\w+, \w+\.$|(\w+\. ){1,2}(\w+[\s]?){1,2}$)", editors) if single_person: editor = create_person(single_person.group(1).strip()) edition_object.add_author(editor) else: persons = editors.split(",") if len(persons) == 2: for person in persons: editor = create_person(person) edition_object.add_author(editor) else: persons = [x+y for x, y in zip(persons[0::2], persons[1::2])] for person in persons: editor = create_person(person) edition_object.add_author(editor) voices = re.match("Voice (\d*): (.*)", line) if voices: voice = create_voice(voices.group(2)) voice.check_range() voice.number = int(voices.group(1)) composition.add_voice(voice) edition_object.composition = composition print_object.edition = edition_object return print_object