|
3 | 3 | import ace.datatypes.DataBoard; |
4 | 4 | import ace.datatypes.DataSet; |
5 | 5 | import ace.datatypes.FeatureDefinition; |
| 6 | +import java.util.HashSet; |
| 7 | +import java.util.Set; |
6 | 8 | import java.util.concurrent.ExecutionException; |
7 | 9 | import java.util.concurrent.ForkJoinTask; |
8 | 10 | import jsymbolic2.featureutils.Feature; |
9 | 11 | import jsymbolic2.featureutils.FeatureExtractorAccess; |
10 | | -import jsymbolic2.featureutils.MEIFeatureExtractor; |
11 | | -import jsymbolic2.featureutils.Feature; |
12 | 12 | import mckay.utilities.sound.midi.MIDIMethods; |
13 | 13 | import org.apache.commons.lang3.ArrayUtils; |
14 | 14 | import org.ddmal.jmei2midi.meielements.meispecific.MeiSpecificStorage; |
@@ -65,7 +65,13 @@ public class MIDIFeatureProcessor { |
65 | 65 | * The features that are to be extracted (including dependencies of features to be saved, not just the |
66 | 66 | * features to be saved themselves). |
67 | 67 | */ |
68 | | - private Feature[] features; |
| 68 | + private List<Feature> features; |
| 69 | + |
| 70 | + /** |
| 71 | + * The features that are to be extracted (including dependencies of features to be saved, not just the |
| 72 | + * features to be saved themselves). |
| 73 | + */ |
| 74 | + private Set<String> features; |
69 | 75 |
|
70 | 76 | /** |
71 | 77 | * The dependencies of the features in the feature_extractors field. |
@@ -416,59 +422,6 @@ public double[][][] getFeatures(Sequence[] windows, MeiSpecificStorage meiSpecif |
416 | 422 | return results; |
417 | 423 | } |
418 | 424 |
|
419 | | - private void processFeature(Sequence[] windows, MeiSpecificStorage meiSpecificStorage, double[][][] results, int win, MIDIIntermediateRepresentations intermediate, int feat) throws Exception { |
420 | | - // Only extract this feature if enough previous information |
421 | | - // is available to extract this feature |
422 | | - if (win >= maxFeatureOffsets[feat]) { |
423 | | - // Find the correct feature |
424 | | - Feature feature = features[feat]; |
425 | | - |
426 | | - double[][] otherFeatureValues = findPreviousExtractedFeatures(results, win, feat, feature); |
427 | | - |
428 | | - //Check here if the file is an MEI file and if the feature is an MEI feature |
429 | | - //Otherwise just extract the midi feature data |
430 | | - if (null == meiSpecificStorage && feature instanceof MEIFeatureExtractor) { |
431 | | - //Skip if this is a non-mei file as mei features are not valid |
432 | | - return; |
433 | | - } |
434 | | - if (null != meiSpecificStorage && feature instanceof MEIFeatureExtractor) { |
435 | | - results[win][feat] = ((MEIFeatureExtractor) feature).extractMEIFeature(meiSpecificStorage, windows[win], intermediate, otherFeatureValues); |
436 | | - return; |
437 | | - } |
438 | | - // Store the extracted feature values |
439 | | - results[win][feat] = feature.extractFeature(windows[win], intermediate, otherFeatureValues); |
440 | | - return; |
441 | | - } |
442 | | - results[win][feat] = null; |
443 | | - } |
444 | | - |
445 | | - /** |
446 | | - * Find previously extracted feature values that this feature needs |
447 | | - * |
448 | | - * @param results |
449 | | - * @param win |
450 | | - * @param feat |
451 | | - * @param feature |
452 | | - * @return |
453 | | - */ |
454 | | - private double[][] findPreviousExtractedFeatures(double[][][] results, int win, int feat, Feature feature) { |
455 | | - double[][] otherFeatureValues = null; |
456 | | - if (featureExtractorDependencies[feat] != null) { |
457 | | - otherFeatureValues = new double[featureExtractorDependencies[feat].length][]; |
458 | | - for (int i = 0; i < featureExtractorDependencies[feat].length; i++) { |
459 | | - int featureIndice = featureExtractorDependencies[feat][i]; |
460 | | - /* TODO Check if this is a correct bug fix */ |
461 | | - if (feature.getDependencyOffsets() == null) { |
462 | | - otherFeatureValues[i] = results[win][featureIndice]; |
463 | | - } else { |
464 | | - int offset = feature.getDependencyOffsets()[i]; |
465 | | - otherFeatureValues[i] = results[win + offset][featureIndice]; |
466 | | - } |
467 | | - } |
468 | | - } |
469 | | - return otherFeatureValues; |
470 | | - } |
471 | | - |
472 | 425 | /** |
473 | 426 | * Generates DataBoard based in list of DataSets that were constructed during features extractions |
474 | 427 | * |
@@ -639,63 +592,6 @@ private void updateExtraDependencies(Feature[] allFeatureExtractors, String[] al |
639 | 592 | } |
640 | 593 | } |
641 | 594 |
|
642 | | - /** |
643 | | - * Find the indices of the feature extractor dependencies for each feature extractor |
644 | | - */ |
645 | | - private void prepareIndicies() { |
646 | | - featureExtractorDependencies = new int[features.length][]; |
647 | | - String[] feature_names = new String[features.length]; |
648 | | - for (int feat = 0; feat < feature_names.length; feat++) |
649 | | - feature_names[feat] = features[feat].getFeatureDefinition().name; |
650 | | - String[][] featureDependenciesStr = new String[features.length][]; |
651 | | - for (int feat = 0; feat < featureDependenciesStr.length; feat++) |
652 | | - featureDependenciesStr[feat] = features[feat].getDependencies(); |
653 | | - for (int i = 0; i < featureDependenciesStr.length; i++) |
654 | | - if (null != featureDependenciesStr[i]) { |
655 | | - featureExtractorDependencies[i] = new int[featureDependenciesStr[i].length]; |
656 | | - for (int j = 0; j < featureDependenciesStr[i].length; j++) |
657 | | - for (int k = 0; k < feature_names.length; k++) |
658 | | - if (featureDependenciesStr[i][j].equals(feature_names[k])) |
659 | | - featureExtractorDependencies[i][j] = k; |
660 | | - } |
661 | | - } |
662 | | - |
663 | | - /** |
664 | | - * Find the maximum offset for each feature |
665 | | - */ |
666 | | - private void setMaxOffset() { |
667 | | - maxFeatureOffsets = new int[features.length]; |
668 | | - for (int feat = 0; feat < maxFeatureOffsets.length; feat++) { |
669 | | - if (null == features[feat].getDependencyOffsets()) { |
670 | | - maxFeatureOffsets[feat] = 0; |
671 | | - continue; |
672 | | - } |
673 | | - int[] offsetsOfCurrentFeature = features[feat].getDependencyOffsets(); |
674 | | - maxFeatureOffsets[feat] = Math.abs(offsetsOfCurrentFeature[0]); |
675 | | - for (int offsetOfCurrentFeature : offsetsOfCurrentFeature) { |
676 | | - maxFeatureOffsets[feat] = Math.max(Math.abs(offsetOfCurrentFeature), offsetOfCurrentFeature); |
677 | | - } |
678 | | - } |
679 | | - } |
680 | | - |
681 | | - /** |
682 | | - * Find the dependencies of each feature marked to be extracted. |
683 | | - * Mark an entry as null if that entry's matching feature is not set to be extracted. |
684 | | - * Note that an entry will also be null if the corresponding feature has no dependencies. |
685 | | - * |
686 | | - * @param allFeatureExtractors |
687 | | - * @param featuresToSaveAmongAll |
688 | | - * @return |
689 | | - */ |
690 | | - private String[][] getDependencies(Feature[] allFeatureExtractors, boolean[] featuresToSaveAmongAll) { |
691 | | - String[][] dependencies = new String[allFeatureExtractors.length][]; |
692 | | - for (int feat = 0; feat < allFeatureExtractors.length; feat++) { |
693 | | - dependencies[feat] = null; |
694 | | - if (featuresToSaveAmongAll[feat]) dependencies[feat] = allFeatureExtractors[feat].getDependencies(); |
695 | | - } |
696 | | - return dependencies; |
697 | | - } |
698 | | - |
699 | 595 | /** |
700 | 596 | * Find the names of all features |
701 | 597 | * |
|
0 commit comments