21 #include <QTextStream> 34 #include <dataquay/BasicStore.h> 35 #include <dataquay/PropertyObject.h> 39 using Dataquay::Nodes;
40 using Dataquay::Triple;
41 using Dataquay::Triples;
42 using Dataquay::BasicStore;
43 using Dataquay::PropertyObject;
73 return "*.rdf *.n3 *.ttl";
104 std::vector<Transform>
117 m_store(new BasicStore),
122 m_store->addPrefix(
"vamp", Uri(
"http://purl.org/ontology/vamp/"));
125 if (url.startsWith(
"file:")) {
128 qurl = QUrl::fromLocalFile(url);
130 m_store->import(qurl, BasicStore::ImportIgnoreDuplicates);
158 std::vector<Transform>
161 std::vector<Transform> transforms;
163 std::map<QString, Transform> uriTransformMap;
166 (Triple(Node(), Uri(
"a"),
m_store->expand(
"vamp:Transform"))).subjects();
170 foreach (Node tnode, tnodes) {
173 (Triple(tnode,
m_store->expand(
"vamp:plugin"), Node()));
175 if (pnode == Node()) {
176 cerr <<
"RDFTransformFactory: WARNING: No vamp:plugin for " 177 <<
"vamp:Transform node " << tnode
178 <<
", skipping this transform" << endl;
182 QString transformUri = tnode.value;
183 QString pluginUri = pnode.value;
186 if (pluginId ==
"") {
187 cerr <<
"RDFTransformFactory: WARNING: Unknown plugin <" 188 << pluginUri <<
"> for transform <" 189 << transformUri <<
">, skipping this transform" 197 if (!
setOutput(transform, transformUri)) {
205 uriTransformMap[transformUri] = transform;
207 static const char *optionals[] = {
218 for (
int j = 0; j < int(
sizeof(optionals)/
sizeof(optionals[0])); ++j) {
220 QString optional = optionals[j];
223 (Triple(Uri(transformUri),
224 m_store->expand(QString(
"vamp:") + optional), Node()));
226 if (onode.type != Node::Literal)
continue;
228 if (optional ==
"program") {
230 }
else if (optional ==
"summary_type") {
233 }
else if (optional ==
"step_size") {
235 }
else if (optional ==
"block_size") {
237 }
else if (optional ==
"window_type") {
240 (onode.value.toLower().toStdString()));
241 }
else if (optional ==
"sample_rate") {
243 }
else if (optional ==
"start") {
246 }
else if (optional ==
"duration") {
250 cerr <<
"RDFTransformFactory: ERROR: Inconsistent optionals lists (unexpected optional \"" << optional <<
"\"" << endl;
254 cerr <<
"RDFTransformFactory: NOTE: Transform is: " << endl;
257 transforms.push_back(transform);
265 QString transformUri)
267 Node outputNode =
m_store->complete
268 (Triple(Uri(transformUri),
m_store->expand(
"vamp:output"), Node()));
270 if (outputNode == Node())
return true;
272 if (outputNode.type != Node::URI && outputNode.type != Node::Blank) {
273 m_errorString = QString(
"vamp:output for output of transform <%1> is not a URI or blank node").arg(transformUri);
281 Node identNode =
m_store->complete
282 (Triple(outputNode,
m_store->expand(
"vamp:identifier"), Node()));
284 if (identNode == Node()) {
286 const BasicStore *index = indexer->
getIndex();
287 identNode = index->complete
288 (Triple(outputNode, index->expand(
"vamp:identifier"), Node()));
291 if (identNode == Node() || identNode.type != Node::Literal) {
292 m_errorString = QString(
"No vamp:identifier found for output of transform <%1>, or vamp:identifier is not a literal").arg(transformUri);
304 QString transformUri)
306 Nodes bindings =
m_store->match
307 (Triple(Uri(transformUri),
m_store->expand(
"vamp:parameter_binding"), Node())).objects();
309 foreach (Node binding, bindings) {
311 Node paramNode =
m_store->complete
312 (Triple(binding,
m_store->expand(
"vamp:parameter"), Node()));
314 if (paramNode == Node()) {
315 cerr <<
"RDFTransformFactoryImpl::setParameters: No vamp:parameter for binding " << binding << endl;
319 Node valueNode =
m_store->complete
320 (Triple(binding,
m_store->expand(
"vamp:value"), Node()));
322 if (paramNode == Node()) {
323 cerr <<
"RDFTransformFactoryImpl::setParameters: No vamp:value for binding " << binding << endl;
332 Node idNode =
m_store->complete
333 (Triple(paramNode,
m_store->expand(
"vamp:identifier"), Node()));
335 if (idNode == Node()) {
337 const BasicStore *index = indexer->
getIndex();
338 idNode = index->complete
339 (Triple(paramNode, index->expand(
"vamp:identifier"), Node()));
342 if (idNode == Node() || idNode.type != Node::Literal) {
343 cerr <<
"RDFTransformFactoryImpl::setParameters: No vamp:identifier for parameter " << paramNode << endl;
347 transform.
setParameter(idNode.value, valueNode.value.toFloat());
367 if (pluginUri !=
"") {
368 s << uri <<
" a vamp:Transform ;" << endl;
369 s <<
" vamp:plugin <" << QUrl(pluginUri).toEncoded().data() <<
"> ;" << endl;
371 cerr <<
"WARNING: RDFTransformFactory::writeTransformToRDF: No plugin URI available for plugin id \"" << pluginId <<
"\", writing synthetic plugin and library resources" << endl;
372 QString type, soname, label;
374 s << uri <<
"_plugin a vamp:Plugin ;" << endl;
375 s <<
" vamp:identifier \"" << label <<
"\" .\n" << endl;
376 s << uri <<
"_library a vamp:PluginLibrary ;" << endl;
377 s <<
" vamp:identifier \"" << soname <<
"\" ;" << endl;
378 s <<
" vamp:available_plugin " << uri <<
"_plugin .\n" << endl;
379 s << uri <<
" a vamp:Transform ;" << endl;
380 s <<
" vamp:plugin " << uri <<
"_plugin ;" << endl;
384 QString outputId = transform.
getOutput();
387 if (transform.
getOutput() !=
"" && outputUri ==
"") {
388 cerr <<
"WARNING: RDFTransformFactory::writeTransformToRDF: No output URI available for transform output id \"" << transform.
getOutput() <<
"\", writing a synthetic output resource" << endl;
392 s <<
" vamp:step_size \"" << transform.
getStepSize() <<
"\"^^xsd:int ; " << endl;
395 s <<
" vamp:block_size \"" << transform.
getBlockSize() <<
"\"^^xsd:int ; " << endl;
404 s <<
" vamp:sample_rate \"" << transform.
getSampleRate() <<
"\"^^xsd:float ; " << endl;
409 s <<
" vamp:program \"\"\"" << program <<
"\"\"\" ;" << endl;
414 s <<
" vamp:summary_type \"" << summary <<
"\" ;" << endl;
418 for (Transform::ParameterMap::const_iterator i = parameters.begin();
419 i != parameters.end(); ++i) {
420 QString name = i->first;
421 float value = i->second;
422 s <<
" vamp:parameter_binding [" << endl;
423 s <<
" vamp:parameter [ vamp:identifier \"" << name <<
"\" ] ;" << endl;
424 s <<
" vamp:value \"" << value <<
"\"^^xsd:float ;" << endl;
428 if (outputUri !=
"") {
429 s <<
" vamp:output <" << QUrl(outputUri).toEncoded().data() <<
"> ." << endl;
430 }
else if (outputId !=
"") {
431 s <<
" vamp:output [ vamp:identifier \"" << outputId <<
"\" ] ." << endl;
QString getURIForPluginId(QString pluginId)
std::string toXsdDuration() const
Return a string in xsd:duration format.
QString getIdForPluginURI(QString uri)
static void parseIdentifier(QString identifier, QString &type, QString &soName, QString &label)
const Dataquay::BasicStore * getIndex()
virtual QString toXmlString(QString indent="", QString extraAttributes="") const
Convert this exportable object to XML in a string.
QString getOutputUri(QString outputId) const
static PluginRDFIndexer * getInstance()
static const RealTime zeroTime
static RealTime fromXsdDuration(std::string xsdd)