Mercurial > hg > semantic-sia
comparison src/org/qmul/eecs/c4dm/sia/midi/MidiParser.java @ 83:4ef262740ceb
can be run with a specified maximum number of Datapoints and for a specified midiFileName
author | stevenh |
---|---|
date | Fri, 30 Aug 2013 16:12:28 +0100 |
parents | 39106212a3c6 |
children |
comparison
equal
deleted
inserted
replaced
82:ade1f2d811e8 | 83:4ef262740ceb |
---|---|
77 // The input midi file | 77 // The input midi file |
78 private static final String midiFileName = "/Volumes/USB_DISK/portable/ewerts/Cantata_16_no_5-mids/score.mid"; | 78 private static final String midiFileName = "/Volumes/USB_DISK/portable/ewerts/Cantata_16_no_5-mids/score.mid"; |
79 | 79 |
80 public static void main(String[] args) | 80 public static void main(String[] args) |
81 { | 81 { |
82 MidiParser midiParser = new MidiParser(); | |
83 midiParser.midiToRdf(6, midiFileName); | |
84 } | |
85 | |
86 public void midiToRdf(int maxDatapoints, String midiFileName) | |
87 { | |
88 int numDatapoints = 0; | |
89 | |
82 // First create a Jena ontology model | 90 // First create a Jena ontology model |
83 OntModel model = ModelFactory | 91 OntModel model = ModelFactory |
84 .createOntologyModel(); // OntModelSpec.OWL_MEM | 92 .createOntologyModel(); // OntModelSpec.OWL_MEM |
85 | 93 |
86 // Then read the data from the file into the ontology model | 94 // Then read the data from the file into the ontology model |
230 dimVals.add(timeDimVal); | 238 dimVals.add(timeDimVal); |
231 dimVals.add(pitchDimVal); | 239 dimVals.add(pitchDimVal); |
232 dimVals.add(channelDimVal); | 240 dimVals.add(channelDimVal); |
233 | 241 |
234 datapoint.setDimensionValues(dimVals); | 242 datapoint.setDimensionValues(dimVals); |
235 datapoints.add(datapoint); | |
236 | 243 |
237 // RDF | 244 if (numDatapoints < maxDatapoints) |
245 { | |
246 datapoints.add(datapoint); | |
247 numDatapoints++; | |
238 | 248 |
239 Resource datapointBnode = model.createResource(AnonId.create()); | 249 // RDF |
240 model.add(datapointBnode, RDF.type, datapointResource); | 250 Resource datapointBnode = model.createResource(AnonId.create()); |
241 | 251 model.add(datapointBnode, RDF.type, datapointResource); |
242 // Find or create a DimVal for the TIME dimension | 252 |
243 Resource timeDimValBnode = findOrCreateDimValBNode(model, TIME_DIMENSION, secs); | 253 // Find or create a DimVal for the TIME dimension |
244 | 254 Resource timeDimValBnode = findOrCreateDimValBNode(model, TIME_DIMENSION, secs); |
245 // Find or create a DimVal for the PITCH dimension | 255 |
246 Resource pitchDimValBnode = findOrCreateDimValBNode(model, PITCH_DIMENSION, data1); | 256 // Find or create a DimVal for the PITCH dimension |
247 | 257 Resource pitchDimValBnode = findOrCreateDimValBNode(model, PITCH_DIMENSION, data1); |
248 // Find or create a DimVal for the CHANNEL dimension | 258 |
249 Resource channelDimValBnode = findOrCreateDimValBNode(model, CHANNEL_DIMENSION, trackDimensionMap.get(trackIdx)); | 259 // Find or create a DimVal for the CHANNEL dimension |
250 | 260 Resource channelDimValBnode = findOrCreateDimValBNode(model, CHANNEL_DIMENSION, trackDimensionMap.get(trackIdx)); |
251 // Find or create a Vector for these three DimVals | 261 |
252 Resource vectorBnode = findOrCreateVectorBNode(model, timeDimValBnode, secs, | 262 // Find or create a Vector for these three DimVals |
253 pitchDimValBnode, data1, channelDimValBnode, trackDimensionMap.get(trackIdx)); | 263 Resource vectorBnode = findOrCreateVectorBNode(model, timeDimValBnode, secs, |
254 | 264 pitchDimValBnode, data1, channelDimValBnode, trackDimensionMap.get(trackIdx)); |
255 model.add(datapointBnode, siaVectorProperty, vectorBnode); | 265 |
256 model.add(datapointBnode, siaMemberOfDatasetProperty, datasetBnode); | 266 model.add(datapointBnode, siaVectorProperty, vectorBnode); |
267 model.add(datapointBnode, siaMemberOfDatasetProperty, datasetBnode); | |
268 } | |
257 | 269 |
258 } | 270 } |
259 else if (messageCommand == ShortMessage.PITCH_BEND) | 271 else if (messageCommand == ShortMessage.PITCH_BEND) |
260 { | 272 { |
261 System.out.print("ignoring PITCH_BEND"); | 273 System.out.print("ignoring PITCH_BEND"); |