Skip to content

Commit

Permalink
Refactoring on XML/JSON metadata format.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjonesbr committed Sep 16, 2019
1 parent 4173355 commit b4c3b90
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 85 deletions.
10 changes: 5 additions & 5 deletions musicowl/musicxml/metadata-file/metadata.json
@@ -1,12 +1,12 @@
{
"scoreIdentifier": "http://dbpedia.org/resource/Cello_Concerto_(Elgar)",
"title": "Cellokonzert e-Moll op. 85",
"scoreTitle": "Cellokonzert e-Moll op. 85",
"thumbnail": "https://www.rcm.ac.uk/media/Elgar%20Cello%20Concerto%20maunscript%206x4.jpg",
"issued": "1919",
"collections": [
{
"collectionName": "Great Composers",
"collectionURL": "https://wwu.greatcomposers.de"
"collectionLabel": "Great Composers",
"collectionIdentifier": "https://wwu.greatcomposers.de"
}
],
"persons": [
Expand All @@ -24,12 +24,12 @@
"resources": [
{
"resourceURL": "https://musescore.com/score/152011/download/pdf",
"resourceDescription": "Print",
"resourceLabel": "Print",
"resourceType": "application/pdf"
},
{
"resourceURL": "https://en.wikipedia.org/wiki/Cello_Concerto_(Elgar)",
"resourceDescription": "Wikipedia Article",
"resourceLabel": "Wikipedia Article",
"resourceType": "text/html"
}
]
Expand Down
10 changes: 5 additions & 5 deletions musicowl/musicxml/metadata-file/metadata.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<score>
<scoreIdentifier>http://dbpedia.org/resource/Cello_Concerto_(Elgar)</scoreIdentifier>
<title>Cellokonzert e-Moll op. 85</title>
<scoreTitle>Cellokonzert e-Moll op. 85</scoreTitle>
<thumbnail>https://www.rcm.ac.uk/media/Elgar%20Cello%20Concerto%20maunscript%206x4.jpg</thumbnail>
<issued>1919</issued>
<collections>
<collection>
<collectionName>Great Composers</collectionName>
<collectionURL>https://wwu.greatcomposers.de</collectionURL>
<collectionLabel>Great Composers</collectionLabel>
<collectionIdentifier>https://wwu.greatcomposers.de</collectionIdentifier>
</collection>
</collections>
<persons>
Expand All @@ -25,12 +25,12 @@
<resources>
<resource>
<resourceURL>https://musescore.com/score/152011/download/pdf</resourceURL>
<resourceDescription>Print</resourceDescription>
<resourceLabel>Print</resourceLabel>
<resourceType>application/pdf</resourceType>
</resource>
<resource>
<resourceURL>https://en.wikipedia.org/wiki/Cello_Concerto_(Elgar)</resourceURL>
<resourceDescription>Wikipedia Article</resourceDescription>
<resourceLabel>Wikipedia Article</resourceLabel>
<resourceType>text/html</resourceType>
</resource>
</resources>
Expand Down
2 changes: 1 addition & 1 deletion musicowl/pom.xml
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.uni-muenster</groupId>
<artifactId>music2rdf</artifactId>
<version>1.3.6</version>
<version>1.3.7</version>
<name>${project.groupId}:${project.artifactId}</name>
<url>https://github.com/jimjonesbr/musicowl</url>
<description>Music Score to RDF Converter</description>
Expand Down
Expand Up @@ -11,8 +11,7 @@ public static void main(String[] args) {
String outputFile = "";
String outputFormat = "";
boolean verbose = false;



System.out.println("\n");
for(int i = 0; i < args.length; i++) {

Expand Down
Expand Up @@ -50,12 +50,12 @@ public static MusicXML2RDF parseMetadataFile(File metadataFile) {
Element scoreElement = (Element) nNode;

System.out.println("Score URI : " + scoreElement.getElementsByTagName("scoreIdentifier").item(0).getTextContent());
System.out.println("Title : " + scoreElement.getElementsByTagName("title").item(0).getTextContent());
System.out.println("Score Title : " + scoreElement.getElementsByTagName("scoreTitle").item(0).getTextContent());
System.out.println("Date Issued : " + scoreElement.getElementsByTagName("issued").item(0).getTextContent());
System.out.println("Thumbnail : " + scoreElement.getElementsByTagName("thumbnail").item(0).getTextContent());

music2rdf.setScoreURI(scoreElement.getElementsByTagName("scoreIdentifier").item(0).getTextContent());
music2rdf.setDocumentTitle(scoreElement.getElementsByTagName("title").item(0).getTextContent());
music2rdf.setScoreIdentifier(scoreElement.getElementsByTagName("scoreIdentifier").item(0).getTextContent());
music2rdf.setScoreTitle(scoreElement.getElementsByTagName("scoreTitle").item(0).getTextContent());
music2rdf.setDateIssued(scoreElement.getElementsByTagName("issued").item(0).getTextContent());
music2rdf.setThumbnail(scoreElement.getElementsByTagName("thumbnail").item(0).getTextContent());

Expand Down Expand Up @@ -98,11 +98,11 @@ public static MusicXML2RDF parseMetadataFile(File metadataFile) {
Element personElement = (Element) resourceNode;

System.out.println("Resource URI : " + personElement.getElementsByTagName("resourceURL").item(0).getTextContent());
System.out.println("Resource Desc. : " + personElement.getElementsByTagName("resourceDescription").item(0).getTextContent());
System.out.println("Resource Label : " + personElement.getElementsByTagName("resourceLabel").item(0).getTextContent());
System.out.println("Resource Type : " + personElement.getElementsByTagName("resourceType").item(0).getTextContent());

String resourceURI = personElement.getElementsByTagName("resourceURL").item(0).getTextContent();
String resourceDescription = personElement.getElementsByTagName("resourceDescription").item(0).getTextContent();
String resourceDescription = personElement.getElementsByTagName("resourceLabel").item(0).getTextContent();
String resourceType = personElement.getElementsByTagName("resourceType").item(0).getTextContent();

music2rdf.addResource(new ScoreResource(resourceURI, resourceDescription,resourceType));
Expand All @@ -122,12 +122,12 @@ public static MusicXML2RDF parseMetadataFile(File metadataFile) {

Element collectionElement = (Element) collectionNode;

System.out.println("Collection URI : " + collectionElement.getElementsByTagName("collectionURL").item(0).getTextContent());
System.out.println("Collection Name : " + collectionElement.getElementsByTagName("collectionName").item(0).getTextContent());
System.out.println("Collection Identifier : " + collectionElement.getElementsByTagName("collectionIdentifier").item(0).getTextContent());
System.out.println("Collection Label : " + collectionElement.getElementsByTagName("collectionLabel").item(0).getTextContent());


String collectionURL = collectionElement.getElementsByTagName("collectionURL").item(0).getTextContent();
String collectionName = collectionElement.getElementsByTagName("collectionName").item(0).getTextContent();
String collectionURL = collectionElement.getElementsByTagName("collectionIdentifier").item(0).getTextContent();
String collectionName = collectionElement.getElementsByTagName("collectionLabel").item(0).getTextContent();

music2rdf.addCollection(new Collection(collectionURL,collectionName));
}
Expand Down Expand Up @@ -158,12 +158,12 @@ public static MusicXML2RDF parseMetadataFile(File metadataFile) {
JSONObject jsonObject = (JSONObject) obj;

System.out.println("\nScore URI : " + jsonObject.get("scoreIdentifier").toString());
System.out.println("Title : " + jsonObject.get("title").toString());
System.out.println("Title : " + jsonObject.get("scoreTitle").toString());
System.out.println("Date Issued : " + jsonObject.get("issued").toString());
System.out.println("Thumbnail : " + jsonObject.get("thumbnail").toString());

music2rdf.setScoreURI(jsonObject.get("scoreIdentifier").toString());
music2rdf.setDocumentTitle(jsonObject.get("title").toString());
music2rdf.setScoreIdentifier(jsonObject.get("scoreIdentifier").toString());
music2rdf.setScoreTitle(jsonObject.get("scoreTitle").toString());
music2rdf.setDateIssued(jsonObject.get("issued").toString());
music2rdf.setThumbnail(jsonObject.get("thumbnail").toString());

Expand All @@ -173,10 +173,10 @@ public static MusicXML2RDF parseMetadataFile(File metadataFile) {

JSONObject collection = (JSONObject) collections.get(j);

music2rdf.addCollection(new Collection(collection.get("collectionURL").toString(),collection.get("collectionName").toString()));
music2rdf.addCollection(new Collection(collection.get("collectionIdentifier").toString(),collection.get("collectionLabel").toString()));

System.out.println("Collection URI : " + collection.get("collectionURL").toString());
System.out.println("Collection Name : " + collection.get("collectionName").toString());
System.out.println("Collection Identifier: " + collection.get("collectionIdentifier").toString());
System.out.println("Collection Label : " + collection.get("collectionLabel").toString());

}

Expand All @@ -203,11 +203,11 @@ public static MusicXML2RDF parseMetadataFile(File metadataFile) {
JSONObject resource = (JSONObject) resources.get(j);

System.out.println("Resource URI : " + resource.get("resourceURL").toString());
System.out.println("Resource Desc. : " + resource.get("resourceDescription").toString());
System.out.println("Resource Label : " + resource.get("resourceLabel").toString());
System.out.println("Resource Type : " + resource.get("resourceType").toString());

music2rdf.addResource(new ScoreResource(resource.get("resourceURL").toString(),
resource.get("resourceDescription").toString(),
resource.get("resourceLabel").toString(),
resource.get("resourceType").toString()));
}

Expand Down
38 changes: 17 additions & 21 deletions musicowl/src/main/java/de/wwu/music2rdf/converter/MusicXML2RDF.java
Expand Up @@ -83,11 +83,10 @@ public class MusicXML2RDF {
private boolean verbose = false;
private String outputFile = "";
private File inputFile = null;
private String scoreURI = "";
private String documentTitle = "";
private String scoreIdentifier = "";
private String scoreTitle = "";
private String thumbnail = "";
private String outputFormat = "TURTLE";
//private Collection collection;
private static Logger logger = Logger.getLogger("Converter");
private String dateIssued = "";
private ArrayList<Note> accidentalsOverwrite = new ArrayList<Note>();
Expand All @@ -100,8 +99,7 @@ public MusicXML2RDF() {
this.currentNotes = new ArrayList<Note>();
this.persons = new ArrayList<Person>();
this.resources = new ArrayList<ScoreResource>();
this.collections = new ArrayList<Collection>();
//this.collection = new Collection();
this.collections = new ArrayList<Collection>();
}

public void addPerson(Person person) {
Expand All @@ -110,8 +108,6 @@ public void addPerson(Person person) {

public void addCollection(Collection collection) {
this.getCollections().add(collection);
//this.collection.setCollectionURI(collection.getCollectionURI());
//this.collection.setCollectionName(collection.getCollectionName());
}

public void isVerbose (boolean verbose) {
Expand Down Expand Up @@ -958,8 +954,8 @@ private void createRDF(MusicScore score){
Resource resBarline = model.createResource(nodeBaseURI+"MOV" + movementCounter + "_" + partID + "_M" +measureID + "_REPEAT");
model.add(model.createLiteralStatement(resMeasure, MusicOWL.hasBarline,resBarline));

if(score.getParts().get(i).getMeasures().get(j).getBarline().equals("backward")) //ttl.append(barlineObject + rdfTypeURI + musicOWL.replace("OBJECT", "EndRepeat") + " . \n" );
if(score.getParts().get(i).getMeasures().get(j).getBarline().equals("forward")) //ttl.append(barlineObject + rdfTypeURI + musicOWL.replace("OBJECT", "BeginRepeat") + " . \n" );
if(score.getParts().get(i).getMeasures().get(j).getBarline().equals("backward"))
if(score.getParts().get(i).getMeasures().get(j).getBarline().equals("forward"))

if(score.getParts().get(i).getMeasures().get(j).getBarline().equals("backward")){
model.add(model.createStatement(resBarline,RDF.type, MusicOWL.EndRepeat));
Expand Down Expand Up @@ -1472,11 +1468,11 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXExc
MusicScore score = createMusicScoreDocument(musicXMLString);
score.setFileContent(musicXMLString);
score.setOutputFileName(file.getName());
score.setURI(this.scoreURI);
score.setURI(this.scoreIdentifier);

if(!documentTitle.equals("")) {
score.setTitle(this.documentTitle);
logger.warn("The title \""+this.documentTitle+"\" was provided and will therefore overwrite the title provided in the MusicXML document.");
if(!scoreTitle.equals("")) {
score.setTitle(this.scoreTitle);
logger.warn("The title \""+this.scoreTitle+"\" was provided and will therefore overwrite the title provided in the MusicXML document.");
}


Expand Down Expand Up @@ -2172,25 +2168,25 @@ public File getInputFile(){

}

public String getScoreURI(){
public String getScoreIdentifier(){

return this.scoreURI;
return this.scoreIdentifier;
}

public void setScoreURI(String uri){
public void setScoreIdentifier(String uri){

this.scoreURI = uri;
this.scoreIdentifier = uri;
}

public void setDocumentTitle(String title){
public void setScoreTitle(String title){

this.documentTitle = title;
this.scoreTitle = title;

}

public String getDocumentTitle(String title){
public String getScoreTitle(String title){

return this.documentTitle;
return this.scoreTitle;

}

Expand Down
4 changes: 2 additions & 2 deletions musicowl/src/main/java/de/wwu/music2rdf/example/Example.java
Expand Up @@ -19,14 +19,14 @@ public static void main(String[] args) {
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.setScoreURI("http://dbpedia.org/resource/Cello_Concerto_(Elgar)");
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.setDocumentTitle("Cellokonzert e-Moll op. 85");
music2rdf.setScoreTitle("Cellokonzert e-Moll op. 85");
music2rdf.isVerbose(false);
music2rdf.setOutputFormat("turtle");
music2rdf.setDateIssued("1919"); //Formats accepted: yyyy, yyyyMM, yyyyMMdd.
Expand Down

0 comments on commit b4c3b90

Please sign in to comment.