An open API service indexing awesome lists of open source software.

https://github.com/jimjonesbr/musicowl

MusicXML parser to RDF based in the MusicOWL Ontology
https://github.com/jimjonesbr/musicowl

linked-data musicxml rdf

Last synced: 5 months ago
JSON representation

MusicXML parser to RDF based in the MusicOWL Ontology

Awesome Lists containing this project

README

          

[![](https://www.uni-muenster.de/imperia/md/images/allgemein/farbunabhaengig/wwu.svg)](https://www.uni-muenster.de/de/)

[![Build Status](https://travis-ci.com/jimjonesbr/musicowl.svg?branch=master)](https://travis-ci.com/jimjonesbr/musicowl)
[![Maven Central](https://img.shields.io/maven-central/v/de.uni-muenster/music2rdf.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22de.uni-muenster%22%20AND%20a:%22music2rdf%22)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Contribute: Gitpod](https://img.shields.io/badge/contribute-gitpod-9cf)](https://gitpod.io/#https://github.com/jimjonesbr/musicowl)

# Music Score to RDF Converter

This converter parses MusicXML 3.0 files and converts them to RDF, based on the [MusicOWL Ontology](http://linkeddata.uni-muenster.de/ontology/musicscore/mso.owl) [ˈmjuːzɪkəl]. It fully supports the following concepts:

* Articulations
* Clefs
* Durations
* Dynamics
* Measures (Bars)
* Note Sets
* Notes
* Staves
* Tonalities
* Voices

## Parameters

`setInputFile`  MusicXML 3.0 file to be converted. Supported are `.xml` and `.mxl` files.

`setOutputFile`  Path and name for RDF output file.

`setThumbnail`  Thumbnail for the converted music score (optional).

`setScoreIdentifier`  URI for the converted score (optional) .

`setScoreTitle`  Music score title.

`issued`  Date issued. Formats accepted: `yyyy`, `yyyyMM`, `yyyyMMdd` (optional).

`setCollection`  Collections can be used for classifying music scores into certaing groups, e.g. "18th Century Composers", "Advanced Music Scores", etc.

`isVerbose`  Setting it to `true` logs in the console the converter progress.

`setOutputFormat`  Sets the RDF notation for the output file. Accepted notations are: `TURLTE`, `NTRIPLES`, `JSON-LD`, `RDF/XML`, `RDF/JSON`.

`addPerson`  This method can be used to add persons related to the music score. It consists of an URI, a name and a role, which can have one of the following attributes:

```java
Role.ARRANGER;
Role.COMPOSER;
Role.EDITOR;
Role.ENCODER;
Role.LIBRETTIST;
Role.LYRICIST;
Role.PERFORMER;
Role.TRANSLATOR;
Role.UNKNOWN;
```

`addResource`  Links existing resources to the converted music score, such as pdf or mp3 files. This method relies on three parameters:

- **Link**: Link to the resource
- **Description**: Text describing the resource
- **Type**: MIME Type

## Music2RDF at Maven Central

To add the Music Score to RDF Converter to your project just add the following dependency in your `pom.xml` file:

```

de.uni-muenster
music2rdf
[VERSION]

```

## Using the Java API

The above mentioned parameters can be used as follows:

```java
package de.wwu.music2rdf.example;

import java.io.File;

import com.google.common.net.MediaType;

import de.wwu.music2rdf.converter.MusicXML2RDF;
import de.wwu.music2rdf.core.Collection;
import de.wwu.music2rdf.core.Person;
import de.wwu.music2rdf.core.Role;
import de.wwu.music2rdf.core.ScoreResource;

public class Example {

public static void main(String[] args) {

MusicXML2RDF music2rdf = new MusicXML2RDF();

music2rdf.setInputFile(new File("musicxml/ulb-muenster/elgar_cello_concerto_op.85.xml"));
music2rdf.setOutputFile("rdf/elgar_cello_concerto_op.85");
music2rdf.setThumbnail("https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/Elgar-cello-concerto-manuscript.jpg/220px-Elgar-cello-concerto-manuscript.jpg");
music2rdf.setScoreIdentifier("http://dbpedia.org/resource/Cello_Concerto_(Elgar)");
music2rdf.addCollection(new Collection("https://wwu.greatcomposers.de","Great Composers"));
music2rdf.addCollection(new Collection("https://sammlungen.ulb.uni-muenster.de","Digitale Sammlung der Universität und Landesbibliothek Münster"));
music2rdf.addPerson(new Person("http://dbpedia.org/resource/Edward_Elgar","Sir Edward William Elgar",Role.COMPOSER));
music2rdf.addPerson(new Person("http://jimjones.de","Jim Jones",Role.ENCODER));
music2rdf.addResource(new ScoreResource("https://musescore.com/score/152011/download/pdf", "Print",MediaType.PDF.toString()));
music2rdf.addResource(new ScoreResource("https://en.wikipedia.org/wiki/Cello_Concerto_(Elgar)", "Wikipedia Article",MediaType.HTML_UTF_8.toString()));
music2rdf.setScoreTitle("Cellokonzert e-Moll op. 85");
music2rdf.isVerbose(false);
music2rdf.setOutputFormat("turtle");
music2rdf.setDateIssued("1919"); //Formats accepted: yyyy, yyyyMM, yyyyMMdd.

music2rdf.parseMusicXML();
}
}

```

## Using the converter in the console

If you don't feel like building the Musci2RDF converter from source, visit the [releases area](https://github.com/jimjonesbr/musicowl/releases) to get a prebuilt jar. You can use this jar with following parameters:

`metadata`  In order to keep the full metadata support via console, you have to pass the metadata in separated file. This metadata file can be encoded in XML ...

```xml

http://dbpedia.org/resource/Cello_Concerto_(Elgar)
Cellokonzert e-Moll op. 85
https://www.rcm.ac.uk/media/Elgar%20Cello%20Concerto%20maunscript%206x4.jpg
1919


Great Composers
https://wwu.greatcomposers.de




http://dbpedia.org/resource/Edward_Elgar
Sir Edward William Elgar
Composer


http://jimjones.de
Jim Jones
Encoder




https://musescore.com/score/152011/download/pdf
Print
application/pdf


https://en.wikipedia.org/wiki/Cello_Concerto_(Elgar)
Wikipedia Article
text/html

```

.. or in case you fancy JSON:

```json
{
"scoreIdentifier": "http://dbpedia.org/resource/Cello_Concerto_(Elgar)",
"scoreTitle": "Cellokonzert e-Moll op. 85",
"thumbnail": "https://www.rcm.ac.uk/media/Elgar%20Cello%20Concerto%20maunscript%206x4.jpg",
"issued": "1919",
"collections": [
{
"collectionLabel": "Great Composers",
"collectionIdentifier": "https://wwu.greatcomposers.de"
}
],
"persons": [
{
"personIdentifier": "http://dbpedia.org/resource/Edward_Elgar",
"personName": "Sir Edward William Elgar",
"personRole": "Composer"
},
{
"personIdentifier": "http://jimjones.de",
"personName": "Jim Jones",
"personRole": "Encoder"
}
],
"resources": [
{
"resourceURL": "https://musescore.com/score/152011/download/pdf",
"resourceLabel": "Print",
"resourceType": "application/pdf"
},
{
"resourceURL": "https://en.wikipedia.org/wiki/Cello_Concerto_(Elgar)",
"resourceLabel": "Wikipedia Article",
"resourceType": "text/html"
}
]
}
```

Further parameters are:

`file`   Music score file.

`output`  Name for the output file.

`outputFormat`  RDF notation for the output file

Example (using the above described metadata file):

```shell
$ java -jar music2rdf-[VERSION].jar file=musicxml/metadata-file/elgar_cello_concerto_op.85.xml
metadata=musicxml/elgar_cello_concerto_op.85-metadata.xml
output=rdf/elgar_cello_concerto_op.85
outputFormat=turtle

File : musicxml/elgar_cello_concerto_op.85.xml
Score URI : http://dbpedia.org/resource/Cello_Concerto_(Elgar)
Title : Cellokonzert e-Moll op. 85
Date Issued : 1919
Thumbnail : https://www.rcm.ac.uk/media/Elgar%20Cello%20Concerto%20maunscript%206x4.jpg
Person URI : http://dbpedia.org/resource/Edward_Elgar
Person Name : Sir Edward William Elgar
Person Role : Composer
Person URI : http://jimjones.de
Person Name : Jim Jones
Person Role : Encoder
Resource URI : https://musescore.com/score/152011/download/pdf
Resource Desc. : Print
Resource Type : application/pdf
Resource URI : https://en.wikipedia.org/wiki/Cello_Concerto_(Elgar)
Resource Desc. : Wikipedia Article
Resource Type : text/html
Collection URI : https://wwu.greatcomposers.de
Collection Name : Great Composers
Output File : rdf/elgar_cello_concerto_op.85
OutputFormat : turtle

[2019-08-11 19:33:14,788] INFO [Converter] - Processing elgar_cello_concerto_op.85.xml ...
[2019-08-11 19:33:15,011] INFO [Converter] - Loading XML file: 222 ms
[2019-08-11 19:33:15,341] WARN [Converter] - The title "Cellokonzert e-Moll op. 85" was provided and will therefore overwrite the title provided in the MusicXML document.
[2019-08-11 19:33:15,341] INFO [Converter] - Creating MusicScore object: 329 ms
[2019-08-11 19:33:16,224] INFO [Converter] - Score serialization: 883 ms
```