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 parse_composition(cursor, composition_id): composition = cursor.execute( "SELECT name, genre, key, incipit, year FROM score WHERE score.id=?", (composition_id, )).fetchone() composition_name = composition[0] composition_genre = composition[1] composition_key = composition[2] composition_incipit = composition[3] composition_year = composition[4] composition_composers = parse_composers(cursor, composition_id) composition_voices = parse_voices(cursor, composition_id) return scorelib.Composition(composition_name, composition_incipit, composition_key, composition_genre, composition_year, composition_voices, composition_composers)
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 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
def save_score(cur, composition): params = [] #params.append(composition.name) if composition.name is None: name_query = 'name is NULL' else: name_query = 'name=?' params.append(composition.name) if composition.genre is None: genre_query = 'genre is NULL' else: genre_query = 'genre=?' params.append(composition.genre) if composition.key is None: key_query = 'key is NULL' else: key_query = 'key=?' params.append(composition.key) if composition.incipit is None: incipit_query = 'incipit is NULL' else: incipit_query = 'incipit=?' params.append(composition.incipit) if composition.year is None: year_query = 'year is NULL' else: year_query = 'year=?' params.append(composition.year) cur.execute( 'SELECT id FROM score WHERE ' + name_query + ' and ' + genre_query + ' and ' + key_query + ' and ' + incipit_query + ' and ' + year_query, (params)) row = cur.fetchone() if row is None: cur.execute( 'INSERT INTO score (name, genre, key, incipit, year) VALUES (?, ?, ?, ?, ?)', (composition.name, composition.genre, composition.key, composition.incipit, composition.year)) return cur.lastrowid else: tmp_composition = scorelib.Composition() tmp_composition.name = composition.name tmp_composition.genre = composition.genre tmp_composition.key = composition.key tmp_composition.incipit = composition.incipit tmp_composition.year = composition.year cur.execute( 'SELECT name from person JOIN score_author ON person.id=score_author.composer WHERE score=?', (row[0], )) result = cur.fetchall() if result is not None: for composer in result: tmp_composer = scorelib.Person() tmp_composer.name = composer[0] tmp_composition.authors.append(tmp_composer) cur.execute('SELECT number, name, range from voice WHERE score=?', (row[0], )) result = cur.fetchall() if result is not None: for i in range(0, len(result)): tmp_voice = scorelib.Voice() tmp_voice.number = int(result[i][0]) tmp_voice.name = result[i][1] tmp_voice.range = result[i][2] tmp_composition.voices.append(tmp_voice) if composition.__eq__(tmp_composition): return row[0] else: cur.execute( 'INSERT INTO score (name, genre, key, incipit, year) VALUES (?, ?, ?, ?, ?)', (composition.name, composition.genre, composition.key, composition.incipit, composition.year)) return cur.lastrowid