Mercurial > hg > svcore
comparison rdf/RDFImporter.cpp @ 616:3a61a4df6d53
* RDF importer: Features that are on different timeline URIs should go
into separate models (_not_ just on separate signal URIs as there may
not be any meaningful signal URIs)
* FileSource: if a file is not found, try again assuming its name is
encoded (not just in tolerant mode)
author | Chris Cannam |
---|---|
date | Thu, 15 Oct 2009 10:50:43 +0000 |
parents | a03aafaacb5a |
children | 24f06d34ac99 |
comparison
equal
deleted
inserted
replaced
615:521438145bd7 | 616:3a61a4df6d53 |
---|---|
149 std::vector<Model *> models; | 149 std::vector<Model *> models; |
150 | 150 |
151 getDataModelsAudio(models, reporter); | 151 getDataModelsAudio(models, reporter); |
152 | 152 |
153 if (m_sampleRate == 0) { | 153 if (m_sampleRate == 0) { |
154 std::cerr << "RDFImporter::getDataModels: invalid sample rate from audio" << std::endl; | 154 m_errorString = QString("Invalid audio data model (is audio file format supported?)"); |
155 std::cerr << m_errorString.toStdString() << std::endl; | |
155 return models; | 156 return models; |
156 } | 157 } |
157 | 158 |
158 QString error; | 159 QString error; |
159 | 160 |
214 for (int i = 0; i < results.size(); ++i) { | 215 for (int i = 0; i < results.size(); ++i) { |
215 | 216 |
216 QString signal = results[i]["signal"].value; | 217 QString signal = results[i]["signal"].value; |
217 QString source = results[i]["source"].value; | 218 QString source = results[i]["source"].value; |
218 | 219 |
220 std::cerr << "NOTE: Seeking signal source \"" << source.toStdString() | |
221 << "\"..." << std::endl; | |
222 | |
219 FileSource *fs = new FileSource(source, reporter); | 223 FileSource *fs = new FileSource(source, reporter); |
224 if (fs->isAvailable()) { | |
225 std::cerr << "NOTE: Source is available: Local filename is \"" | |
226 << fs->getLocalFilename().toStdString() | |
227 << "\"..." << std::endl; | |
228 } | |
229 | |
220 #ifdef NO_SV_GUI | 230 #ifdef NO_SV_GUI |
221 if (!fs->isAvailable()) { | 231 if (!fs->isAvailable()) { |
222 m_errorString = QString("Signal source \"%1\" is not available").arg(source); | 232 m_errorString = QString("Signal source \"%1\" is not available").arg(source); |
223 delete fs; | 233 delete fs; |
224 continue; | 234 continue; |
225 } | 235 } |
226 #else | 236 #else |
227 if (!fs->isAvailable()) { | 237 if (!fs->isAvailable()) { |
238 std::cerr << "NOTE: Signal source \"" << source.toStdString() | |
239 << "\" is not available, using file finder..." << std::endl; | |
228 FileFinder *ff = FileFinder::getInstance(); | 240 FileFinder *ff = FileFinder::getInstance(); |
229 if (ff) { | 241 if (ff) { |
230 QString path = ff->find(FileFinder::AudioFile, | 242 QString path = ff->find(FileFinder::AudioFile, |
231 fs->getLocation(), | 243 fs->getLocation(), |
232 m_uristring); | 244 m_uristring); |
574 " PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" | 586 " PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" |
575 ); | 587 ); |
576 | 588 |
577 QString queryString = prefixes + QString( | 589 QString queryString = prefixes + QString( |
578 | 590 |
579 " SELECT ?signal ?timed_thing ?event_type ?value" | 591 " SELECT ?signal ?timed_thing ?timeline ?event_type ?value" |
580 " FROM <%1>" | 592 " FROM <%1>" |
581 | 593 |
582 " WHERE {" | 594 " WHERE {" |
583 | 595 |
584 " ?signal a mo:Signal ." | 596 " ?signal a mo:Signal ." |
585 | 597 |
586 " ?signal mo:time ?interval ." | 598 " ?signal mo:time ?interval ." |
587 " ?interval tl:onTimeLine ?tl ." | 599 " ?interval tl:onTimeLine ?timeline ." |
588 " ?time tl:onTimeLine ?tl ." | 600 " ?time tl:onTimeLine ?timeline ." |
589 " ?timed_thing event:time ?time ." | 601 " ?timed_thing event:time ?time ." |
590 " ?timed_thing a ?event_type ." | 602 " ?timed_thing a ?event_type ." |
591 | 603 |
592 " OPTIONAL {" | 604 " OPTIONAL {" |
593 " ?timed_thing af:feature ?value" | 605 " ?timed_thing af:feature ?value" |
594 " }" | 606 " }" |
595 " }" | 607 " }" |
596 | 608 |
597 ).arg(m_uristring); | 609 ).arg(m_uristring); |
610 | |
611 //!!! NB we're using rather old terminology for these things, apparently: | |
612 // beginsAt -> start | |
613 // onTimeLine -> timeline | |
598 | 614 |
599 QString timeQueryString = prefixes + QString( | 615 QString timeQueryString = prefixes + QString( |
600 | 616 |
601 " SELECT ?time FROM <%1> " | 617 " SELECT ?time FROM <%1> " |
602 " WHERE { " | 618 " WHERE { " |
672 start, for each of the source+type keys, and then push each | 688 start, for each of the source+type keys, and then push each |
673 feature into the relevant model depending on what we find out | 689 feature into the relevant model depending on what we find out |
674 about it. Then return only non-empty models. | 690 about it. Then return only non-empty models. |
675 */ | 691 */ |
676 | 692 |
677 // Map from signal source to event type to dimensionality to | 693 // Map from timeline uri to event type to dimensionality to |
678 // presence of duration to model ptr. Whee! | 694 // presence of duration to model ptr. Whee! |
679 std::map<QString, std::map<QString, std::map<int, std::map<bool, Model *> > > > | 695 std::map<QString, std::map<QString, std::map<int, std::map<bool, Model *> > > > |
680 modelMap; | 696 modelMap; |
681 | 697 |
682 for (int i = 0; i < results.size(); ++i) { | 698 for (int i = 0; i < results.size(); ++i) { |
684 if (i % 4 == 0) { | 700 if (i % 4 == 0) { |
685 if (reporter) reporter->setProgress(i/4); | 701 if (reporter) reporter->setProgress(i/4); |
686 } | 702 } |
687 | 703 |
688 QString source = results[i]["signal"].value; | 704 QString source = results[i]["signal"].value; |
705 QString timeline = results[i]["timeline"].value; | |
689 QString type = results[i]["event_type"].value; | 706 QString type = results[i]["event_type"].value; |
690 QString thinguri = results[i]["timed_thing"].value; | 707 QString thinguri = results[i]["timed_thing"].value; |
691 | 708 |
692 RealTime time; | 709 RealTime time; |
693 RealTime duration; | 710 RealTime duration; |
745 if (values.size() == 1) dimensions = 2; | 762 if (values.size() == 1) dimensions = 2; |
746 else if (values.size() > 1) dimensions = 3; | 763 else if (values.size() > 1) dimensions = 3; |
747 | 764 |
748 Model *model = 0; | 765 Model *model = 0; |
749 | 766 |
750 if (modelMap[source][type][dimensions].find(haveDuration) == | 767 if (modelMap[timeline][type][dimensions].find(haveDuration) == |
751 modelMap[source][type][dimensions].end()) { | 768 modelMap[timeline][type][dimensions].end()) { |
752 | 769 |
753 /* | 770 /* |
754 std::cerr << "Creating new model: source = " << source.toStdString() | 771 std::cerr << "Creating new model: source = " << source.toStdString() |
755 << ", type = " << type.toStdString() << ", dimensions = " | 772 << ", type = " << type.toStdString() << ", dimensions = " |
756 << dimensions << ", haveDuration = " << haveDuration | 773 << dimensions << ", haveDuration = " << haveDuration |
834 ).arg(m_uristring).arg(type); | 851 ).arg(m_uristring).arg(type); |
835 QString title = SimpleSPARQLQuery::singleResultQuery | 852 QString title = SimpleSPARQLQuery::singleResultQuery |
836 (s, titleQuery, "title").value; | 853 (s, titleQuery, "title").value; |
837 if (title != "") model->setObjectName(title); | 854 if (title != "") model->setObjectName(title); |
838 | 855 |
839 modelMap[source][type][dimensions][haveDuration] = model; | 856 modelMap[timeline][type][dimensions][haveDuration] = model; |
840 models.push_back(model); | 857 models.push_back(model); |
841 } | 858 } |
842 | 859 |
843 model = modelMap[source][type][dimensions][haveDuration]; | 860 model = modelMap[timeline][type][dimensions][haveDuration]; |
844 | 861 |
845 if (model) { | 862 if (model) { |
846 long ftime = RealTime::realTime2Frame(time, m_sampleRate); | 863 long ftime = RealTime::realTime2Frame(time, m_sampleRate); |
847 long fduration = RealTime::realTime2Frame(duration, m_sampleRate); | 864 long fduration = RealTime::realTime2Frame(duration, m_sampleRate); |
848 fillModel(model, ftime, fduration, haveDuration, values, label); | 865 fillModel(model, ftime, fduration, haveDuration, values, label); |
999 if (value.type == SimpleSPARQLQuery::URIValue) { | 1016 if (value.type == SimpleSPARQLQuery::URIValue) { |
1000 haveAudio = true; | 1017 haveAudio = true; |
1001 } | 1018 } |
1002 } | 1019 } |
1003 | 1020 |
1021 std::cerr << "NOTE: RDFImporter::identifyDocumentType: haveAudio = " | |
1022 << haveAudio << std::endl; | |
1023 | |
1004 value = | 1024 value = |
1005 SimpleSPARQLQuery::singleResultQuery | 1025 SimpleSPARQLQuery::singleResultQuery |
1006 (SimpleSPARQLQuery::QueryFromSingleSource, | 1026 (SimpleSPARQLQuery::QueryFromSingleSource, |
1007 QString | 1027 QString |
1008 (" PREFIX event: <http://purl.org/NET/c4dm/event.owl#> " | 1028 (" PREFIX event: <http://purl.org/NET/c4dm/event.owl#> " |
1029 | 1049 |
1030 if (value.type == SimpleSPARQLQuery::URIValue) { | 1050 if (value.type == SimpleSPARQLQuery::URIValue) { |
1031 haveAnnotations = true; | 1051 haveAnnotations = true; |
1032 } | 1052 } |
1033 } | 1053 } |
1054 | |
1055 std::cerr << "NOTE: RDFImporter::identifyDocumentType: haveAnnotations = " | |
1056 << haveAnnotations << std::endl; | |
1034 | 1057 |
1035 SimpleSPARQLQuery::closeSingleSource(url); | 1058 SimpleSPARQLQuery::closeSingleSource(url); |
1036 | 1059 |
1037 if (haveAudio) { | 1060 if (haveAudio) { |
1038 if (haveAnnotations) { | 1061 if (haveAnnotations) { |