Ejemplo n.º 1
0
def massage_mei(in_file, out_file):
    try:
        analysis = make_analysis(in_file)
        MEI_instructions = TransformData(
            arranger_to_editor=True,
            remove_incipit=True,
            replace_longa=True,
            editorial_resp=analysis.has_arranger_element,
            alternates_list=analysis.alternates_list,
            copyright_text=COPYRIGHT,
            color_for_ficta=ANYCOLOR,
            color_for_variants=ANYCOLOR,
            color_for_emendations=ANYCOLOR,
            double_cut_time=True,
            eliminate_bad_beams=True,
            make_invisible_space=True,
            cleanup=True,
        )
        old_res = documentFromFile(in_file)
        old_MEI_doc = old_res.getMeiDocument()
        new_MEI_doc = transform_mei(old_MEI_doc, MEI_instructions)
        status = documentToFile(new_MEI_doc, out_file)

    except Exception as ex:
        logging.critical(ex)
        logging.critical("Error during massaging " + in_file)
Ejemplo n.º 2
0
 def test_readfile(self):
     res = documentFromFile(os.path.join("test", "testdocs", "beethoven.mei"))
     doc = res.getMeiDocument()
     self.assertNotEqual(None, doc)
     el = doc.getElementById("d1e41")
     self.assertEqual("c", el.getAttribute("pname").value)
     self.assertEqual("4", el.getAttribute("oct").value)
Ejemplo n.º 3
0
    def test_segfaultdebug(self):
        variants_list = [
                         ('3', 'VARIANT', '2', 'RISM1560-06'),
                         ('6', 'VARIANT', '5', 'RISM1560-06')
                         ]
        res = documentFromFile(os.path.join("test", "testdocs", "DC1317E.mei"))

        MEI_doc = res.getMeiDocument()

        mei = MeiElement('mei')
        # print(mei)

        head_score = chain_elems(mei, ['meiHead', 'workDesc', 'work', 'incip', 'score'])
        stg = chain_elems(mei, ['music', 'body', 'mdiv', 'score', 'scoreDef', 'staffGrp'])
        sd1 = MeiElement('staffDef')
        sd2 = MeiElement('staffDef')
        sd3 = MeiElement('staffDef')
        sd4 = MeiElement('staffDef')
        sd5 = MeiElement('staffDef')
        sd6 = MeiElement('staffDef')

        sd1.addAttribute('n', '1')
        sd2.addAttribute('n', '2')
        sd3.addAttribute('n', '3')
        sd4.addAttribute('n', '4')
        sd5.addAttribute('n', '5')
        sd6.addAttribute('n', '6')

        stg.addChild(sd1)
        stg.addChild(sd2)
        stg.addChild(sd3)
        stg.addChild(sd4)
        stg.addChild(sd5)
        stg.addChild(sd6)

        MEI_tree = MEI_doc.getRootElement()
        # MEI_tree2 = mei

        # print(MEI_tree)
        # print MEI_tree2

        scoreDefs = MEI_tree.getDescendantsByName('scoreDef')
        # print(scoreDefs)

        mainScoreDef = MeiElement(scoreDefs[0])
        mainScoreDef.id = "blahblahblah"
        meiHead = MEI_tree.getDescendantsByName('meiHead')[0]
        head_score = chain_elems(meiHead, ['workDesc', 'work', 'incip', 'score'])
        head_score.addChild(mainScoreDef)

        for variants_list_item in variants_list:
            stDefs = mainScoreDef.getDescendantsByName('staffDef')
            for staffDef in stDefs:
                if staffDef.hasAttribute('n') and staffDef.getAttribute('n').value == variants_list_item[0]:
                    print("Removing staffDef n=" + staffDef.getAttribute('n').getValue())
                    staffDef.parent.removeChild(staffDef)

        # head_score.addChild(mainScoreDef)
        self.assertEqual(8, len(head_score.getDescendantsByName('staffDef')))
Ejemplo n.º 4
0
 def test_readfile(self):
     res = documentFromFile(
         os.path.join("test", "testdocs", "beethoven.mei"))
     doc = res.getMeiDocument()
     self.assertNotEqual(None, doc)
     el = doc.getElementById("d1e41")
     self.assertEqual("c", el.getAttribute("pname").value)
     self.assertEqual("4", el.getAttribute("oct").value)
Ejemplo n.º 5
0
    def __init__(self, file_name, siglum_slug, manuscript_id, min_gram=DEFAULT_MIN_GRAM, max_gram=DEFAULT_MAX_GRAM):
        self.file_name = file_name
        self.siglum_slug = siglum_slug
        self.manuscript_id = manuscript_id

        self.min_gram = min_gram
        self.max_gram = max_gram

        self.doc = pymei.documentFromFile(str(file_name), False).getMeiDocument()
        self.page_number = getPageNumber(file_name)

        solrconn = solr.SolrConnection(settings.SOLR_SERVER)
        self.image_uri = getImageURI(file_name, manuscript_id, solrconn)
Ejemplo n.º 6
0
def analyze(MEI_filename):
    res = documentFromFile(MEI_filename)
    MEI_doc = res.getMeiDocument()
    MEI_tree = MEI_doc.getRootElement()
    has_editor_element_ = editorial.has_editor_element(MEI_tree)
    has_arranger_element_ = editorial.has_arranger_element(MEI_tree)
    editor_name_ = editorial.editor_name(MEI_tree)
    staff_list_ = staves.staff_list(MEI_tree)
    alternates_list_ = staves.alternates_list(staff_list_)
    return AnalyzeData(has_editor_element_,
                       has_arranger_element_,
                       editor_name_,
                       staff_list_,
                       alternates_list_,
                       )
Ejemplo n.º 7
0
    def load_document(self, file_path):
        folio_number = get_folio(file_path)

        if folio_number is None:
            raise DocumentManipulationException('could not identify folio for file {}'.format(file_path))

        try:
            folio = Folio.objects.get(number=folio_number, manuscript=self.manuscript)
        except Folio.DoesNotExist:
            raise DocumentManipulationException('no folio with number {} in manuscript'.format(folio_number))
        except Folio.MultipleObjectsReturned:
            raise DocumentManipulationException('multiple folios with number {} in manuscript...'.format(folio_number))

        doc = pymei.documentFromFile(file_path, False).getMeiDocument()

        return folio_number, folio, doc
Ejemplo n.º 8
0
    def load_document(self, file_path):
        folio_number = get_folio(file_path)

        if folio_number is None:
            raise DocumentManipulationException(
                'could not identify folio for file {}'.format(file_path))

        try:
            folio = Folio.objects.get(number=folio_number,
                                      manuscript=self.manuscript)
        except Folio.DoesNotExist:
            raise DocumentManipulationException(
                'no folio with number {} in manuscript'.format(folio_number))
        except Folio.MultipleObjectsReturned:
            raise DocumentManipulationException(
                'multiple folios with number {} in manuscript...'.format(
                    folio_number))

        doc = pymei.documentFromFile(file_path, False).getMeiDocument()

        return folio_number, folio, doc
Ejemplo n.º 9
0
 def test_exportwithcomments(self):
     docf = documentFromFile(os.path.join("test", "testdocs", "campion.mei"))
     status = documentToFile(docf.getMeiDocument(), os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Ejemplo n.º 10
0
 def test_basicexport(self):
     docf = documentFromFile(os.path.join("test", "testdocs", "beethoven.mei"))
     status = documentToFile(docf.getMeiDocument(), os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Ejemplo n.º 11
0
 def test_noversionexception(self):
     with self.assertRaises(NoVersionFoundException) as cm:
         documentFromFile(os.path.join("test", "testdocs", "noversion.mei"))
     self.assertTrue(isinstance(cm.exception, NoVersionFoundException))
Ejemplo n.º 12
0
        def write_transformation(file_path, data=TransformData()):
            old_res = documentFromFile(file_path)
            old_MEI_doc = old_res.getMeiDocument()

            new_MEI_doc = transform_mei(old_MEI_doc, data)
            status = documentToFile(new_MEI_doc, file_path)
Ejemplo n.º 13
0
 def test_readfile_with_frbr(self):
     doc = documentFromFile(
         os.path.join("test", "testdocs", "test-itemlist.mei"))
     self.assertNotEqual(None, doc)
Ejemplo n.º 14
0
 def test_malformedexception(self):
     with self.assertRaises(MeiException) as cm:
         documentFromFile(os.path.join("test", "testdocs", "malformed.mei"))
     self.assertTrue(isinstance(cm.exception, MeiException))
Ejemplo n.º 15
0
    def test_segfaultdebug(self):
        variants_list = [('3', 'VARIANT', '2', 'RISM1560-06'),
                         ('6', 'VARIANT', '5', 'RISM1560-06')]
        res = documentFromFile(os.path.join("test", "testdocs", "DC1317E.mei"))

        MEI_doc = res.getMeiDocument()

        mei = MeiElement('mei')
        # print(mei)

        head_score = chain_elems(
            mei, ['meiHead', 'workDesc', 'work', 'incip', 'score'])
        stg = chain_elems(
            mei, ['music', 'body', 'mdiv', 'score', 'scoreDef', 'staffGrp'])
        sd1 = MeiElement('staffDef')
        sd2 = MeiElement('staffDef')
        sd3 = MeiElement('staffDef')
        sd4 = MeiElement('staffDef')
        sd5 = MeiElement('staffDef')
        sd6 = MeiElement('staffDef')

        sd1.addAttribute('n', '1')
        sd2.addAttribute('n', '2')
        sd3.addAttribute('n', '3')
        sd4.addAttribute('n', '4')
        sd5.addAttribute('n', '5')
        sd6.addAttribute('n', '6')

        stg.addChild(sd1)
        stg.addChild(sd2)
        stg.addChild(sd3)
        stg.addChild(sd4)
        stg.addChild(sd5)
        stg.addChild(sd6)

        MEI_tree = MEI_doc.getRootElement()
        # MEI_tree2 = mei

        # print(MEI_tree)
        # print MEI_tree2

        scoreDefs = MEI_tree.getDescendantsByName('scoreDef')
        # print(scoreDefs)

        mainScoreDef = MeiElement(scoreDefs[0])
        mainScoreDef.id = "blahblahblah"
        meiHead = MEI_tree.getDescendantsByName('meiHead')[0]
        head_score = chain_elems(meiHead,
                                 ['workDesc', 'work', 'incip', 'score'])
        head_score.addChild(mainScoreDef)

        for variants_list_item in variants_list:
            stDefs = mainScoreDef.getDescendantsByName('staffDef')
            for staffDef in stDefs:
                if staffDef.hasAttribute('n') and staffDef.getAttribute(
                        'n').value == variants_list_item[0]:
                    print("Removing staffDef n=" +
                          staffDef.getAttribute('n').getValue())
                    staffDef.parent.removeChild(staffDef)

        # head_score.addChild(mainScoreDef)
        self.assertEqual(8, len(head_score.getDescendantsByName('staffDef')))
Ejemplo n.º 16
0
 def test_readlargefile(self):
     doc = documentFromFile(
         os.path.join("test", "testdocs", "beethoven_no5.mei"))
     self.assertNotEqual(None, doc)
Ejemplo n.º 17
0
 def test_malformedexception(self):
     with self.assertRaises(MeiException) as cm:
         documentFromFile(os.path.join("test", "testdocs", "malformed.mei"))
     self.assertTrue(isinstance(cm.exception, MeiException))
Ejemplo n.º 18
0
 def test_readlargefile(self):
     doc = documentFromFile(os.path.join("test", "testdocs", "beethoven_no5.mei"))
     self.assertNotEqual(None, doc)
Ejemplo n.º 19
0
 def test_exportwithcomments(self):
     docf = documentFromFile(os.path.join("test", "testdocs",
                                          "campion.mei"))
     status = documentToFile(docf.getMeiDocument(),
                             os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Ejemplo n.º 20
0
 def test_basicexport(self):
     docf = documentFromFile(
         os.path.join("test", "testdocs", "beethoven.mei"))
     status = documentToFile(docf.getMeiDocument(),
                             os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Ejemplo n.º 21
0
 def test_readfile_with_frbr(self):
     doc = documentFromFile(os.path.join("test", "testdocs", "test-itemlist.mei"))
     self.assertNotEqual(None, doc)
Ejemplo n.º 22
0
    to occur at the last tone (and would then be notable!).
    If the bass is not present at all at the last tone, then
    the function will return None, which of course bears looking
    into regardless.
    """

    all_measures = MEI_tree.getDescendantsByName('measure')
    last_measure = all_measures[-1]
    # Gets all the staves in the last measure
    last_staves = last_measure.getChildrenByName('staff')
    try:
        bass_staff = last_staves[-1]
        last_bass_note = bass_staff.getChildrenByName('note')[-1]
        last_bass_pname = last_bass_note.getAttribute('pname').getValue()
        if last_bass_note.getAttribute('accid'):
            last_bass_accid = last_bass_note.getAttribute('accid').getValue()
        else:
            last_bass_accid = 'n'  # for natural
        return PITCH_CLASSES[last_bass_pname] + ACCIDENTALS[last_bass_accid]

    except IndexError:
        # Error because no final bass tone?
        return None

if __name__ == "__main__":
    MEI_filename = raw_input('Enter a file name: ')
    res = documentFromFile(MEI_filename)
    MEI_doc = res.getMeiDocument()
    MEI_tree = MEI_doc.getRootElement()
    print last_bass_tone(MEI_tree)
Ejemplo n.º 23
0
 def test_noversionexception(self):
     with self.assertRaises(NoVersionFoundException) as cm:
         documentFromFile(os.path.join("test", "testdocs", "noversion.mei"))
     self.assertTrue(isinstance(cm.exception, NoVersionFoundException))
Ejemplo n.º 24
0
    # Error in the parameters
    if args.apel and len(args.list_of_input_files)>1:
        parser.error("Must use only one 'input_file' with the flag '-apel'")
    if args.merge and args.compare:
        parser.error("The '-compare' flag must not be used together with the '-merge' flag.\nThe '-compare' flag is only to be used together with the '-apel' flag or with no flag at all, as '-compare' is used to compare the output of the 'apel script' (just by itself, or within the context of the 'scoring up' process) against the 'ground truth file'.")
    if args.merge and args.apel:
        parser.error("Don't use both flags '-merge' and '-apel' at the same time. If you want to perform the whole 'scoring_up' script (doing both the 'merging' of the parts and find the 'actual duration of the notes using apel's rules'), you should not use any flag at all.")
    
    # Running the modules according to the parameters specified by the user
    if args.merge:
        quasiscore = merge.merge_music_section(args.list_of_input_files)
        pymei.documentToFile(quasiscore, args.output_file)
    elif args.apel:
        print("\nAPEL RESUTLS - Warnings with respect to rules in conflict\n")
        input_quasiscore_doc = pymei.documentFromFile(args.list_of_input_files[0]).getMeiDocument()
        out_apel = ApelAlg.lining_up(input_quasiscore_doc)
        if args.compare:
            print("\nCOMPARISON RESUTLS - Notes/Rests (with their xml:id and voice number) that don't match with the ground truth\n")
            accuracy_results = ApelAlg.comparison(out_apel, pymei.documentFromFile(args.compare).getMeiDocument())
            print("\nACCURACY:")
            for i in range (0, len(accuracy_results)):
                print("Voice # " + str(i) + ":\t" + str(accuracy_results[i]) + " = " + str(float(accuracy_results[i])*100))
        pymei.documentToFile(out_apel, args.output_file)
    else:
        quasiscore = merge.merge_music_section(args.list_of_input_files)
        print("\nAPEL RESUTLS - Warnings with respect to rules in conflict\n")
        score = ApelAlg.lining_up(quasiscore)
        pymei.documentToFile(score, args.output_file)
        if args.compare:
            print("\nCOMPARISON RESUTLS - Notes/Rests (with their xml:id and voice number) that don't match with the ground truth\n")