Mercurial > hg > svcore
comparison rdf/RDFImporter.cpp @ 488:1c66e199e7d9
* remove some unused code
author | Chris Cannam |
---|---|
date | Fri, 21 Nov 2008 14:25:33 +0000 |
parents | 3ffce691c9bf |
children | 82ab61fa9223 |
comparison
equal
deleted
inserted
replaced
487:c45e6c6722e0 | 488:1c66e199e7d9 |
---|---|
58 int &sampleRate, int &windowLength, | 58 int &sampleRate, int &windowLength, |
59 int &hopSize, int &width, int &height); | 59 int &hopSize, int &width, int &height); |
60 | 60 |
61 | 61 |
62 void fillModel(Model *, long, long, bool, std::vector<float> &, QString); | 62 void fillModel(Model *, long, long, bool, std::vector<float> &, QString); |
63 | |
64 /* | |
65 | |
66 typedef std::vector<std::pair<RealTime, float> > DurationValueList; | |
67 typedef std::map<RealTime, DurationValueList> TimeDurationValueMap; | |
68 typedef std::map<QString, TimeDurationValueMap> TypeTimeDurationValueMap; | |
69 typedef std::map<QString, TypeTimeDurationValueMap> SourceTypeTimeDurationValueMap; | |
70 | |
71 void extractStructure(const TimeDurationValueMap &map, bool &sparse, | |
72 int &minValueCount, int &maxValueCount); | |
73 | |
74 void fillModel(SparseOneDimensionalModel *, const TimeDurationValueMap &); | |
75 void fillModel(SparseTimeValueModel *, const TimeDurationValueMap &); | |
76 void fillModel(EditableDenseThreeDimensionalModel *, const TimeDurationValueMap &); | |
77 */ | |
78 }; | 63 }; |
79 | 64 |
80 | 65 |
81 QString | 66 QString |
82 RDFImporter::getKnownExtensions() | 67 RDFImporter::getKnownExtensions() |
395 // structured container that maps from source signal (URI as | 380 // structured container that maps from source signal (URI as |
396 // string) -> feature type (likewise) -> time -> list of values. | 381 // string) -> feature type (likewise) -> time -> list of values. |
397 // If the source signal or feature type is unavailable, the empty | 382 // If the source signal or feature type is unavailable, the empty |
398 // string will do. | 383 // string will do. |
399 | 384 |
400 // SourceTypeTimeDurationValueMap m; | |
401 | |
402 QString prefixes = QString( | 385 QString prefixes = QString( |
403 " PREFIX event: <http://purl.org/NET/c4dm/event.owl#>" | 386 " PREFIX event: <http://purl.org/NET/c4dm/event.owl#>" |
404 " PREFIX tl: <http://purl.org/NET/c4dm/timeline.owl#>" | 387 " PREFIX tl: <http://purl.org/NET/c4dm/timeline.owl#>" |
405 " PREFIX mo: <http://purl.org/ontology/mo/>" | 388 " PREFIX mo: <http://purl.org/ontology/mo/>" |
406 " PREFIX af: <http://purl.org/ontology/af/>" | 389 " PREFIX af: <http://purl.org/ontology/af/>" |
632 long ftime = RealTime::realTime2Frame(time, m_sampleRate); | 615 long ftime = RealTime::realTime2Frame(time, m_sampleRate); |
633 long fduration = RealTime::realTime2Frame(duration, m_sampleRate); | 616 long fduration = RealTime::realTime2Frame(duration, m_sampleRate); |
634 fillModel(model, ftime, fduration, haveDuration, values, label); | 617 fillModel(model, ftime, fduration, haveDuration, values, label); |
635 } | 618 } |
636 } | 619 } |
637 | 620 } |
638 | |
639 /* | |
640 for (SourceTypeTimeDurationValueMap::const_iterator mi = m.begin(); | |
641 mi != m.end(); ++mi) { | |
642 | |
643 QString source = mi->first; | |
644 | |
645 for (TypeTimeDurationValueMap::const_iterator ttvi = mi->second.begin(); | |
646 ttvi != mi->second.end(); ++ttvi) { | |
647 | |
648 QString type = ttvi->first; | |
649 | |
650 // Now we need to work out what sort of model to use for | |
651 // this source/type combination. Ultimately we'll | |
652 // hopefully be able to map directly from the type to the | |
653 // model on the basis of known structures for the types, | |
654 // but we also want to be able to handle untyped data | |
655 // according to its apparent structure so let's do that | |
656 // first. | |
657 | |
658 bool sparse = false; | |
659 int minValueCount = 0, maxValueCount = 0; | |
660 | |
661 extractStructure(ttvi->second, sparse, minValueCount, maxValueCount); | |
662 | |
663 cerr << "For source \"" << source.toStdString() << "\", type \"" | |
664 << type.toStdString() << "\" we have sparse = " << sparse | |
665 << ", min value count = " << minValueCount << ", max = " | |
666 << maxValueCount << endl; | |
667 | |
668 // Model allocations: | |
669 // | |
670 // Sparse, no values: SparseOneDimensionalModel | |
671 // | |
672 // Sparse, always 1 value: SparseTimeValueModel | |
673 // | |
674 // Sparse, > 1 value: No standard model for this. If | |
675 // there are always 2 values, perhaps hack it into | |
676 // NoteModel for now? Or always use SparseTimeValueModel | |
677 // and discard all but the first value. | |
678 // | |
679 // Dense, no values: Meaningless; no suitable model | |
680 // | |
681 // Dense, > 0 values: EditableDenseThreeDimensionalModel | |
682 // | |
683 // These should just be our fallback positions; we want to | |
684 // be reading semantic data from the RDF in order to pick | |
685 // the right model directly | |
686 | |
687 enum { SODM, STVM, EDTDM } modelType = SODM; | |
688 | |
689 if (sparse) { | |
690 if (maxValueCount == 0) { | |
691 modelType = SODM; | |
692 } else if (minValueCount == 1 && maxValueCount == 1) { | |
693 modelType = STVM; | |
694 } else { | |
695 cerr << "WARNING: No suitable model available for sparse data with between " << minValueCount << " and " << maxValueCount << " values" << endl; | |
696 modelType = STVM; | |
697 } | |
698 } else { | |
699 if (maxValueCount == 0) { | |
700 cerr << "WARNING: Dense data set with no values is not meaningful, skipping" << endl; | |
701 continue; | |
702 } else { | |
703 modelType = EDTDM; | |
704 } | |
705 } | |
706 | |
707 //!!! set model name &c | |
708 | |
709 if (modelType == SODM) { | |
710 | |
711 SparseOneDimensionalModel *model = | |
712 new SparseOneDimensionalModel(m_sampleRate, 1, false); | |
713 | |
714 fillModel(model, ttvi->second); | |
715 models.push_back(model); | |
716 | |
717 } else if (modelType == STVM) { | |
718 | |
719 SparseTimeValueModel *model = | |
720 new SparseTimeValueModel(m_sampleRate, 1, false); | |
721 | |
722 fillModel(model, ttvi->second); | |
723 models.push_back(model); | |
724 | |
725 } else { | |
726 | |
727 EditableDenseThreeDimensionalModel *model = | |
728 new EditableDenseThreeDimensionalModel(m_sampleRate, 1, 0, | |
729 false); | |
730 | |
731 fillModel(model, ttvi->second); | |
732 models.push_back(model); | |
733 } | |
734 } | |
735 } | |
736 */ | |
737 } | |
738 | |
739 /* | |
740 void | |
741 RDFImporterImpl::extractStructure(const TimeDurationValueMap &tvm, | |
742 bool &sparse, | |
743 int &minValueCount, | |
744 int &maxValueCount) | |
745 { | |
746 // These are floats intentionally rather than RealTime -- | |
747 // see logic for handling rounding error below | |
748 float firstTime = 0.f; | |
749 float timeStep = 0.f; | |
750 bool haveTimeStep = false; | |
751 | |
752 for (TimeDurationValueMap::const_iterator tvi = tvm.begin(); tvi != tvm.end(); ++tvi) { | |
753 | |
754 RealTime time = tvi->first; | |
755 int valueCount = tvi->second.size(); | |
756 | |
757 if (tvi == tvm.begin()) { | |
758 | |
759 minValueCount = valueCount; | |
760 maxValueCount = valueCount; | |
761 | |
762 firstTime = time.toDouble(); | |
763 | |
764 } else { | |
765 | |
766 if (valueCount < minValueCount) minValueCount = valueCount; | |
767 if (valueCount > maxValueCount) maxValueCount = valueCount; | |
768 | |
769 if (!haveTimeStep) { | |
770 timeStep = time.toDouble() - firstTime; | |
771 if (timeStep == 0.f) sparse = true; | |
772 haveTimeStep = true; | |
773 } else if (!sparse) { | |
774 // test whether this time is within | |
775 // rounding-error range of being an integer | |
776 // multiple of some constant away from the | |
777 // first time | |
778 float timeAsFloat = time.toDouble(); | |
779 int count = int((timeAsFloat - firstTime) / timeStep + 0.5); | |
780 float expected = firstTime + (timeStep * count); | |
781 if (fabsf(expected - timeAsFloat) > 1e-6) { | |
782 cerr << "Event at " << timeAsFloat << " is not evenly spaced -- would expect it to be " << expected << " for a spacing of " << count << " * " << timeStep << endl; | |
783 sparse = true; | |
784 } | |
785 } | |
786 } | |
787 } | |
788 } | |
789 */ | |
790 | 621 |
791 void | 622 void |
792 RDFImporterImpl::fillModel(Model *model, | 623 RDFImporterImpl::fillModel(Model *model, |
793 long ftime, | 624 long ftime, |
794 long fduration, | 625 long fduration, |
869 std::cerr << "WARNING: RDFImporterImpl::fillModel: Unknown or unexpected model type" << std::endl; | 700 std::cerr << "WARNING: RDFImporterImpl::fillModel: Unknown or unexpected model type" << std::endl; |
870 return; | 701 return; |
871 } | 702 } |
872 | 703 |
873 | 704 |
874 /* | |
875 void | |
876 RDFImporterImpl::fillModel(SparseOneDimensionalModel *model, | |
877 const TimeDurationValueMap &tvm) | |
878 { | |
879 //!!! labels &c not yet handled | |
880 | |
881 for (TimeDurationValueMap::const_iterator tvi = tvm.begin(); | |
882 tvi != tvm.end(); ++tvi) { | |
883 | |
884 RealTime time = tvi->first; | |
885 long frame = RealTime::realTime2Frame(time, m_sampleRate); | |
886 | |
887 SparseOneDimensionalModel::Point point(frame); | |
888 | |
889 model->addPoint(point); | |
890 } | |
891 } | |
892 | |
893 void | |
894 RDFImporterImpl::fillModel(SparseTimeValueModel *model, | |
895 const TimeDurationValueMap &tvm) | |
896 { | |
897 //!!! labels &c not yet handled | |
898 | |
899 for (TimeDurationValueMap::const_iterator tvi = tvm.begin(); | |
900 tvi != tvm.end(); ++tvi) { | |
901 | |
902 RealTime time = tvi->first; | |
903 long frame = RealTime::realTime2Frame(time, m_sampleRate); | |
904 | |
905 float value = 0.f; | |
906 if (!tvi->second.empty()) value = *tvi->second.begin()->second; | |
907 | |
908 SparseTimeValueModel::Point point(frame, value, ""); | |
909 | |
910 model->addPoint(point); | |
911 } | |
912 } | |
913 | |
914 void | |
915 RDFImporterImpl::fillModel(EditableDenseThreeDimensionalModel *model, | |
916 const TimeDurationValueMap &tvm) | |
917 { | |
918 //!!! labels &c not yet handled | |
919 | |
920 //!!! start time offset not yet handled | |
921 | |
922 size_t col = 0; | |
923 | |
924 for (TimeDurationValueMap::const_iterator tvi = tvm.begin(); | |
925 tvi != tvm.end(); ++tvi) { | |
926 | |
927 model->setColumn(col++, tvi->second.second); | |
928 } | |
929 } | |
930 | |
931 */ |