예제 #1
0
def createPerson(composerString):
    if (composerString == None or composerString == ""):
        return scorelib.Person(None, None, None)

    name = None
    born = None
    died = None

    name = re.sub(r'\(.*\d.*\)', '', composerString).strip()

    rBrackets = re.compile(r'\((.*\d.*)\)')
    mBrackets = rBrackets.search(composerString)
    if (mBrackets != None):
        findYears = re.findall(r'\d{4}', mBrackets.group(1))

        if (len(findYears) == 2):
            born = findYears[0]
            died = findYears[1]
        else:
            rBorn = re.compile(r"(\d{4}-)")
            rDied = re.compile(r"(-\d{4})")
            mBorn = rBorn.match(mBrackets.group(1))
            mDied = rDied.match(mBrackets.group(1))
            if (mBorn):
                born = int(findYears[0])
            elif (mDied):
                died = int(findYears[0])
            elif ("*" in mBrackets.group(1)):
                born = int(findYears[0])
            elif ("+" in mBrackets.group(1)):
                died = int(findYears[0])

    return scorelib.Person(name, born, died)
예제 #2
0
def createEditor(listOfStrings):
    if (len(listOfStrings) == 0):
        return scorelib.Person(None, None, None)

    listOfEditors = []
    name = None
    born = None
    died = None
    index = 0

    while index < len(listOfStrings):
        stringToProcess = ""
        if (" " in listOfStrings[index].strip()):
            stringToProcess = listOfStrings[index].strip()
            name = re.sub(r'\(.*\d.*\)', '', stringToProcess).strip()
            index = index + 1
        elif (index + 1 < len(listOfStrings)):
            stringToProcess = listOfStrings[index] + "," + listOfStrings[
                index + 1].strip()
            name = re.sub(r'\(.*\d.*\)', '', stringToProcess).strip()
            index = index + 2
        else:
            stringToProcess = listOfStrings[index].strip()
            name = re.sub(r'\(.*\d.*\)', '', stringToProcess).strip()
            index = index + 1

        rBrackets = re.compile(r'\((.*\d.*)\)')
        mBrackets = rBrackets.search(stringToProcess)
        if (mBrackets != None):
            findYears = re.findall(r'\d{4}', mBrackets.group(1))

            if (len(findYears) == 2):
                born = findYears[0]
                died = findYears[1]
            else:
                rBorn = re.compile(r"(\d{4}-)")
                rDied = re.compile(r"(-\d{4})")
                mBorn = rBorn.match(mBrackets.group(1))
                mDied = rDied.match(mBrackets.group(1))
                if (mBorn):
                    born = int(findYears[0])
                elif (mDied):
                    died = int(findYears[0])
                elif ("*" in mBrackets.group(1)):
                    born = int(findYears[0])
                elif ("+" in mBrackets.group(1)):
                    died = int(findYears[0])

        listOfEditors.append(scorelib.Person(name, born, died))
    return listOfEditors
예제 #3
0
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
예제 #4
0
파일: test.py 프로젝트: koncak/PV248
def create_person(person_string):
    p = sc.Person(None, None, None)
    o = re.match("(.*)\((.*?)\)", person_string)
    if o:
        born = None
        died = None
        alive = re.match("(\d{4}--$|\*\d{4})", o.group(2))
        if alive:
            born = int(re.findall(r"(\d+)", alive.group(1))[0])

        else:
            born_died = re.match("(\d{4})-{1,2}(\d{4})", o.group(2))

            died_plus = re.match('\+(\d{4})', o.group(2))

            if born_died:
                born = int(born_died.group(1))
                died = int(born_died.group(2))

            if died_plus:
                died = int(died_plus.group(1))

        p.name = o.group(1).strip()
        p.born = born
        p.died = died

    else:
        p.name = person_string.strip()

    return p
예제 #5
0
def processComposerLine(composerLine):
    persons = []
    for composer in composerLine.split(';'):
        composerName = re.sub(r'\(.*\d.*\)', '', composer).strip()
        born = None
        died = None
        bc = re.compile(r".+ \((.+)\)")
        bracketsMatch = bc.match(composer)
        if bracketsMatch:
            bracketsContent = bracketsMatch.group(1)
            slashc = re.compile(r"(\d{4})-(\d{4})")
            slashMatch = slashc.match(bracketsContent)
            if (slashMatch):
                born = int(slashMatch.group(1))
                died = int(slashMatch.group(2))

            doubleShlashc = re.compile(r"(\d{4})--(\d{4})")
            doubleSlashMatch = doubleShlashc.match(bracketsContent)
            if (doubleSlashMatch):
                born = int(doubleSlashMatch.group(1))
                died = int(doubleSlashMatch.group(2))

            birthc = re.compile(r"(\d{4})--")
            birthMatch = birthc.match(bracketsContent)
            if (birthMatch):
                born = int(birthMatch.group(1))

            deadc = re.compile(r"\+(\d{4})")
            deadMatch = deadc.match(bracketsContent)
            if (deadMatch):
                died = int(deadMatch.group(1))

        persons.append(scorelib.Person(composerName, born, died))
    return persons
예제 #6
0
def parse_people(list_people):
    result = []
    for people in list_people:
        people_name = people[0]
        people_born = people[1]
        people_died = people[2]
        result.append(scorelib.Person(people_name, people_born, people_died))
    return result
예제 #7
0
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
예제 #8
0
파일: import.py 프로젝트: jksdf/pv248
def loadPeople(prints):
    people = defaultdict(lambda: [])
    for p in prints:
        for person in p.edition.authors:
            people[person.name].append(person)
        for person in p.composition().authors:
            people[person.name].append(person)
    peopleset = set()
    for personname in people.keys():
        born, died = None, None
        for p in people[personname]:
            if p.born:
                born = p.born
            if p.died:
                died = p.died
        peopleset.add(scorelib.Person(personname, born, died))
    return peopleset
예제 #9
0
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
예제 #10
0
파일: getprint.py 프로젝트: Medic840/PV248
import sys
import sqlite3
import json
import scorelib

inputPrintNumber = sys.argv[1]

listOfAuthors = []

conn = sqlite3.connect("scorelib.dat")
cur = conn.cursor()

for row in cur.execute(
        '''SELECT person.name,person.born,person.died FROM person
JOIN score_author ON person.id = score_author.composer
JOIN edition ON edition.score = score_author.score
JOIN print ON print.edition = edition.id
WHERE print.id = ?''', (inputPrintNumber, )):
    listOfAuthors.append(scorelib.Person(row[0], row[1], row[2]))


def serialize(obj):
    return obj.__dict__


print(
    json.dumps(listOfAuthors, default=serialize, indent=2, ensure_ascii=False))
예제 #11
0
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