Mercurial > hg > svcore
comparison rdf/RDFImporter.cpp @ 490:c3fb8258e34d
* Make it possible to import an entire session from an RDF document.
However, at the moment the timings of events appear to be constrained
by how far the audio decoder has got through its audio file at the
time the event is queried -- need to investigate.
author | Chris Cannam |
---|---|
date | Fri, 21 Nov 2008 18:03:14 +0000 |
parents | 82ab61fa9223 |
children | 23945cdd7161 |
comparison
equal
deleted
inserted
replaced
489:82ab61fa9223 | 490:c3fb8258e34d |
---|---|
38 class RDFImporterImpl | 38 class RDFImporterImpl |
39 { | 39 { |
40 public: | 40 public: |
41 RDFImporterImpl(QString url, int sampleRate); | 41 RDFImporterImpl(QString url, int sampleRate); |
42 virtual ~RDFImporterImpl(); | 42 virtual ~RDFImporterImpl(); |
43 | |
44 void setSampleRate(int sampleRate) { m_sampleRate = sampleRate; } | |
43 | 45 |
44 bool isOK(); | 46 bool isOK(); |
45 QString getErrorString() const; | 47 QString getErrorString() const; |
46 | 48 |
49 QString getAudioAvailableUrl() const { return m_audioAvailableAt; } | |
50 | |
47 std::vector<Model *> getDataModels(ProgressReporter *); | 51 std::vector<Model *> getDataModels(ProgressReporter *); |
48 | 52 |
49 protected: | 53 protected: |
50 QString m_uristring; | 54 QString m_uristring; |
51 QString m_errorString; | 55 QString m_errorString; |
56 QString m_audioAvailableAt; | |
52 int m_sampleRate; | 57 int m_sampleRate; |
53 | 58 |
54 void getDataModelsSparse(std::vector<Model *> &, ProgressReporter *); | 59 void getDataModelsSparse(std::vector<Model *> &, ProgressReporter *); |
55 void getDataModelsDense(std::vector<Model *> &, ProgressReporter *); | 60 void getDataModelsDense(std::vector<Model *> &, ProgressReporter *); |
56 | 61 |
77 RDFImporter::~RDFImporter() | 82 RDFImporter::~RDFImporter() |
78 { | 83 { |
79 delete m_d; | 84 delete m_d; |
80 } | 85 } |
81 | 86 |
87 void | |
88 RDFImporter::setSampleRate(int sampleRate) | |
89 { | |
90 m_d->setSampleRate(sampleRate); | |
91 } | |
92 | |
82 bool | 93 bool |
83 RDFImporter::isOK() | 94 RDFImporter::isOK() |
84 { | 95 { |
85 return m_d->isOK(); | 96 return m_d->isOK(); |
86 } | 97 } |
87 | 98 |
88 QString | 99 QString |
89 RDFImporter::getErrorString() const | 100 RDFImporter::getErrorString() const |
90 { | 101 { |
91 return m_d->getErrorString(); | 102 return m_d->getErrorString(); |
103 } | |
104 | |
105 QString | |
106 RDFImporter::getAudioAvailableUrl() const | |
107 { | |
108 return m_d->getAudioAvailableUrl(); | |
92 } | 109 } |
93 | 110 |
94 std::vector<Model *> | 111 std::vector<Model *> |
95 RDFImporter::getDataModels(ProgressReporter *r) | 112 RDFImporter::getDataModels(ProgressReporter *r) |
96 { | 113 { |
99 | 116 |
100 RDFImporterImpl::RDFImporterImpl(QString uri, int sampleRate) : | 117 RDFImporterImpl::RDFImporterImpl(QString uri, int sampleRate) : |
101 m_uristring(uri), | 118 m_uristring(uri), |
102 m_sampleRate(sampleRate) | 119 m_sampleRate(sampleRate) |
103 { | 120 { |
121 SimpleSPARQLQuery::Value value = | |
122 SimpleSPARQLQuery::singleResultQuery | |
123 (SimpleSPARQLQuery::QueryFromSingleSource, | |
124 QString | |
125 (" PREFIX mo: <http://purl.org/ontology/mo/> " | |
126 " SELECT ?url FROM <%1> " | |
127 " WHERE { ?signal a mo:Signal ; mo:available_as ?url } " | |
128 ).arg(uri), | |
129 "url"); | |
130 | |
131 if (value.type == SimpleSPARQLQuery::URIValue) { | |
132 m_audioAvailableAt = value.value; | |
133 } | |
104 } | 134 } |
105 | 135 |
106 RDFImporterImpl::~RDFImporterImpl() | 136 RDFImporterImpl::~RDFImporterImpl() |
107 { | 137 { |
108 } | 138 } |
121 | 151 |
122 std::vector<Model *> | 152 std::vector<Model *> |
123 RDFImporterImpl::getDataModels(ProgressReporter *reporter) | 153 RDFImporterImpl::getDataModels(ProgressReporter *reporter) |
124 { | 154 { |
125 std::vector<Model *> models; | 155 std::vector<Model *> models; |
156 | |
157 if (m_sampleRate == 0) { | |
158 std::cerr << "RDFImporter::getDataModels: invalid sample rate" << std::endl; | |
159 return models; | |
160 } | |
126 | 161 |
127 getDataModelsDense(models, reporter); | 162 getDataModelsDense(models, reporter); |
128 | 163 |
129 QString error; | 164 QString error; |
130 if (!isOK()) error = m_errorString; | 165 if (!isOK()) error = m_errorString; |
701 | 736 |
702 std::cerr << "WARNING: RDFImporterImpl::fillModel: Unknown or unexpected model type" << std::endl; | 737 std::cerr << "WARNING: RDFImporterImpl::fillModel: Unknown or unexpected model type" << std::endl; |
703 return; | 738 return; |
704 } | 739 } |
705 | 740 |
706 | 741 RDFImporter::RDFDocumentType |
742 RDFImporter::identifyDocumentType(QString url) | |
743 { | |
744 bool haveAudio = false; | |
745 bool haveAnnotations = false; | |
746 | |
747 SimpleSPARQLQuery::Value value = | |
748 SimpleSPARQLQuery::singleResultQuery | |
749 (SimpleSPARQLQuery::QueryFromSingleSource, | |
750 QString | |
751 (" PREFIX mo: <http://purl.org/ontology/mo/> " | |
752 " SELECT ?url FROM <%1> " | |
753 " WHERE { ?signal a mo:Signal ; mo:available_as ?url } " | |
754 ).arg(url), | |
755 "url"); | |
756 | |
757 if (value.type == SimpleSPARQLQuery::URIValue) { | |
758 haveAudio = true; | |
759 } | |
760 | |
761 value = | |
762 SimpleSPARQLQuery::singleResultQuery | |
763 (SimpleSPARQLQuery::QueryFromSingleSource, | |
764 QString | |
765 (" PREFIX event: <http://purl.org/NET/c4dm/event.owl#> " | |
766 " SELECT ?thing FROM <%1> " | |
767 " WHERE { ?thing event:time ?time } " | |
768 ).arg(url), | |
769 "thing"); | |
770 | |
771 if (value.type == SimpleSPARQLQuery::URIValue) { | |
772 haveAnnotations = true; | |
773 } | |
774 | |
775 if (!haveAnnotations) { | |
776 | |
777 value = | |
778 SimpleSPARQLQuery::singleResultQuery | |
779 (SimpleSPARQLQuery::QueryFromSingleSource, | |
780 QString | |
781 (" PREFIX af: <http://purl.org/ontology/af/> " | |
782 " SELECT ?thing FROM <%1> " | |
783 " WHERE { ?signal af:signal_feature ?thing } " | |
784 ).arg(url), | |
785 "thing"); | |
786 | |
787 if (value.type == SimpleSPARQLQuery::URIValue) { | |
788 haveAnnotations = true; | |
789 } | |
790 } | |
791 | |
792 if (haveAudio) { | |
793 if (haveAnnotations) { | |
794 return AudioRefAndAnnotations; | |
795 } else { | |
796 return AudioRef; | |
797 } | |
798 } else { | |
799 if (haveAnnotations) { | |
800 return Annotations; | |
801 } else { | |
802 return OtherDocument; | |
803 } | |
804 } | |
805 } | |
806 | |
807 |