comparison rdf/PluginRDFDescription.cpp @ 440:5746c559af15

* Merge revisions 1131 to 1201 from sv-rdf-import branch
author Chris Cannam
date Thu, 18 Sep 2008 12:33:30 +0000
parents beb2948baa77
children ef14acd6d102
comparison
equal deleted inserted replaced
439:beb2948baa77 440:5746c559af15
51 PluginRDFDescription::haveDescription() const 51 PluginRDFDescription::haveDescription() const
52 { 52 {
53 return m_haveDescription; 53 return m_haveDescription;
54 } 54 }
55 55
56 PluginRDFDescription::OutputType
57 PluginRDFDescription::getOutputType(QString outputId) const
58 {
59 if (m_outputTypes.find(outputId) == m_outputTypes.end()) {
60 return OutputTypeUnknown;
61 }
62 return m_outputTypes.find(outputId)->second;
63 }
64
65 PluginRDFDescription::OutputDisposition 56 PluginRDFDescription::OutputDisposition
66 PluginRDFDescription::getOutputDisposition(QString outputId) const 57 PluginRDFDescription::getOutputDisposition(QString outputId) const
67 { 58 {
68 if (m_outputDispositions.find(outputId) == m_outputDispositions.end()) { 59 if (m_outputDispositions.find(outputId) == m_outputDispositions.end()) {
69 return OutputDispositionUnknown; 60 return OutputDispositionUnknown;
70 } 61 }
71 return m_outputDispositions.find(outputId)->second; 62 return m_outputDispositions.find(outputId)->second;
72 } 63 }
73 64
74 QString 65 QString
75 PluginRDFDescription::getOutputFeatureTypeURI(QString outputId) const
76 {
77 if (m_outputFeatureTypeURIMap.find(outputId) ==
78 m_outputFeatureTypeURIMap.end()) {
79 return "";
80 }
81 return m_outputFeatureTypeURIMap.find(outputId)->second;
82 }
83
84 QString
85 PluginRDFDescription::getOutputEventTypeURI(QString outputId) const 66 PluginRDFDescription::getOutputEventTypeURI(QString outputId) const
86 { 67 {
87 if (m_outputEventTypeURIMap.find(outputId) == 68 if (m_outputEventTypeURIMap.find(outputId) ==
88 m_outputEventTypeURIMap.end()) { 69 m_outputEventTypeURIMap.end()) {
89 return ""; 70 return "";
90 } 71 }
91 return m_outputEventTypeURIMap.find(outputId)->second; 72 return m_outputEventTypeURIMap.find(outputId)->second;
73 }
74
75 QString
76 PluginRDFDescription::getOutputFeatureAttributeURI(QString outputId) const
77 {
78 if (m_outputFeatureAttributeURIMap.find(outputId) ==
79 m_outputFeatureAttributeURIMap.end()) {
80 return "";
81 }
82 return m_outputFeatureAttributeURIMap.find(outputId)->second;
83 }
84
85 QString
86 PluginRDFDescription::getOutputSignalTypeURI(QString outputId) const
87 {
88 if (m_outputSignalTypeURIMap.find(outputId) ==
89 m_outputSignalTypeURIMap.end()) {
90 return "";
91 }
92 return m_outputSignalTypeURIMap.find(outputId)->second;
92 } 93 }
93 94
94 QString 95 QString
95 PluginRDFDescription::getOutputUnit(QString outputId) const 96 PluginRDFDescription::getOutputUnit(QString outputId) const
96 { 97 {
109 SimpleSPARQLQuery query 110 SimpleSPARQLQuery query
110 (QString 111 (QString
111 ( 112 (
112 " PREFIX vamp: <http://purl.org/ontology/vamp/> " 113 " PREFIX vamp: <http://purl.org/ontology/vamp/> "
113 114
114 " SELECT ?output_id ?output_type ?feature_type ?event_type ?unit " 115 " SELECT ?output ?output_id ?output_type ?unit "
115 " FROM <%1> " 116 " FROM <%1> "
116 117
117 " WHERE { " 118 " WHERE { "
118 119
119 " ?plugin a vamp:Plugin ; " 120 " ?plugin a vamp:Plugin ; "
120 " vamp:identifier \"%2\" ; " 121 " vamp:identifier \"%2\" ; "
121 " vamp:output_descriptor ?output . " 122 " vamp:output ?output . "
122 123
123 " ?output vamp:identifier ?output_id ; " 124 " ?output vamp:identifier ?output_id ; "
124 " a ?output_type . " 125 " a ?output_type . "
125
126 " OPTIONAL { "
127 " ?output vamp:computes_feature_type ?feature_type "
128 " } . "
129
130 " OPTIONAL { "
131 " ?output vamp:computes_event_type ?event_type "
132 " } . "
133 126
134 " OPTIONAL { " 127 " OPTIONAL { "
135 " ?output vamp:unit ?unit " 128 " ?output vamp:unit ?unit "
136 " } . " 129 " } . "
137 130
150 } 143 }
151 144
152 if (results.empty()) { 145 if (results.empty()) {
153 cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: Document at <" 146 cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: Document at <"
154 << url.toStdString() 147 << url.toStdString()
155 << "> does not appear to describe any plugin outputs" << endl; 148 << "> does not appear to describe any outputs for plugin with id \""
149 << label.toStdString() << "\"" << endl;
156 return false; 150 return false;
157 } 151 }
158 152
159 // Note that an output may appear more than once, if it inherits 153 // Note that an output may appear more than once, if it inherits
160 // more than one type (e.g. DenseOutput and QuantizedOutput). So 154 // more than one type (e.g. DenseOutput and QuantizedOutput). So
161 // these results must accumulate 155 // these results must accumulate
162 156
163 for (int i = 0; i < results.size(); ++i) { 157 for (int i = 0; i < results.size(); ++i) {
164 158
159 QString outputUri = results[i]["output"].value;
165 QString outputId = results[i]["output_id"].value; 160 QString outputId = results[i]["output_id"].value;
166
167 if (m_outputTypes.find(outputId) == m_outputTypes.end()) {
168 m_outputTypes[outputId] = OutputTypeUnknown;
169 }
170
171 QString outputType = results[i]["output_type"].value; 161 QString outputType = results[i]["output_type"].value;
172 162
173 if (outputType.contains("DenseOutput")) { 163 if (outputType.contains("DenseOutput")) {
174 m_outputDispositions[outputId] = OutputDense; 164 m_outputDispositions[outputId] = OutputDense;
175 } else if (outputType.contains("SparseOutput")) { 165 } else if (outputType.contains("SparseOutput")) {
176 m_outputDispositions[outputId] = OutputSparse; 166 m_outputDispositions[outputId] = OutputSparse;
177 } else if (outputType.contains("TrackLevelOutput")) { 167 } else if (outputType.contains("TrackLevelOutput")) {
178 m_outputDispositions[outputId] = OutputTrackLevel; 168 m_outputDispositions[outputId] = OutputTrackLevel;
179 } 169 }
180
181 if (results[i]["feature_type"].type == SimpleSPARQLQuery::URIValue) {
182
183 QString featureType = results[i]["feature_type"].value;
184
185 if (featureType != "") {
186 if (m_outputTypes[outputId] == OutputEvents) {
187 m_outputTypes[outputId] = OutputFeaturesAndEvents;
188 } else {
189 m_outputTypes[outputId] = OutputFeatures;
190 }
191 m_outputFeatureTypeURIMap[outputId] = featureType;
192 }
193 }
194
195 if (results[i]["event_type"].type == SimpleSPARQLQuery::URIValue) {
196
197 QString eventType = results[i]["event_type"].value;
198
199 if (eventType != "") {
200 if (m_outputTypes[outputId] == OutputFeatures) {
201 m_outputTypes[outputId] = OutputFeaturesAndEvents;
202 } else {
203 m_outputTypes[outputId] = OutputEvents;
204 }
205 m_outputEventTypeURIMap[outputId] = eventType;
206 }
207 }
208 170
209 if (results[i]["unit"].type == SimpleSPARQLQuery::LiteralValue) { 171 if (results[i]["unit"].type == SimpleSPARQLQuery::LiteralValue) {
210 172
211 QString unit = results[i]["unit"].value; 173 QString unit = results[i]["unit"].value;
212 174
213 if (unit != "") { 175 if (unit != "") {
214 m_outputUnitMap[outputId] = unit; 176 m_outputUnitMap[outputId] = unit;
215 } 177 }
216 } 178 }
179
180 QString queryTemplate =
181 QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> "
182 " SELECT ?%3 FROM <%1> "
183 " WHERE { <%2> vamp:computes_%3 ?%3 } ")
184 .arg(url).arg(outputUri);
185
186 SimpleSPARQLQuery::Value v;
187
188 v = SimpleSPARQLQuery::singleResultQuery
189 (queryTemplate.arg("event_type"), "event_type");
190
191 if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") {
192 m_outputEventTypeURIMap[outputId] = v.value;
193 }
194
195 v = SimpleSPARQLQuery::singleResultQuery
196 (queryTemplate.arg("feature_attribute"), "feature_attribute");
197
198 if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") {
199 m_outputFeatureAttributeURIMap[outputId] = v.value;
200 }
201
202 v = SimpleSPARQLQuery::singleResultQuery
203 (queryTemplate.arg("signal_type"), "signal_type");
204
205 if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") {
206 m_outputSignalTypeURIMap[outputId] = v.value;
207 }
217 } 208 }
218 209
219 return true; 210 return true;
220 } 211 }
221 212