26 #include <vamp-hostsdk/PluginHostAdapter.h> 28 #include <dataquay/BasicStore.h> 29 #include <dataquay/RDFException.h> 42 using Vamp::PluginHostAdapter;
46 using Dataquay::Nodes;
47 using Dataquay::Triple;
48 using Dataquay::Triples;
49 using Dataquay::BasicStore;
50 using Dataquay::RDFException;
51 using Dataquay::RDFDuplicateImportException;
66 m_index->addPrefix(
"vamp", Uri(
"http://purl.org/ontology/vamp/"));
67 m_index->addPrefix(
"foaf", Uri(
"http://xmlns.com/foaf/0.1/"));
68 m_index->addPrefix(
"dc", Uri(
"http://purl.org/dc/elements/1.1/"));
86 vector<string> paths = PluginHostAdapter::getPluginPath();
103 for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
105 QDir dir(i->c_str());
106 if (!dir.exists())
continue;
108 QStringList entries = dir.entryList
109 (filters, QDir::Files | QDir::Readable);
111 for (QStringList::const_iterator j = entries.begin();
112 j != entries.end(); ++j) {
114 QFileInfo fi(dir.filePath(*j));
118 QStringList subdirs = dir.entryList
119 (QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Readable);
121 for (QStringList::const_iterator j = subdirs.begin();
122 j != subdirs.end(); ++j) {
124 QDir subdir(dir.filePath(*j));
125 if (subdir.exists()) {
126 entries = subdir.entryList
127 (filters, QDir::Files | QDir::Readable);
128 for (QStringList::const_iterator k = entries.begin();
129 k != entries.end(); ++k) {
130 QFileInfo fi(subdir.filePath(*k));
143 SVDEBUG <<
"PluginRDFIndexer::indexConfiguredURLs" << endl;
146 settings.beginGroup(
"RDF");
148 QString indexKey(
"rdf-indices");
149 QStringList indices = settings.value(indexKey).toStringList();
151 for (
int i = 0; i < indices.size(); ++i) {
153 QString index = indices[i];
155 SVDEBUG <<
"PluginRDFIndexer::indexConfiguredURLs: index url is " 159 if (!cf.
isOK())
continue;
164 if (!reader.isOK())
continue;
167 for (PlaylistFileReader::Playlist::const_iterator j = list.begin();
168 j != list.end(); ++j) {
169 SVDEBUG <<
"PluginRDFIndexer::indexConfiguredURLs: url is " 175 QString urlListKey(
"rdf-urls");
176 QStringList urls = settings.value(urlListKey).toStringList();
178 for (
int i = 0; i < urls.size(); ++i) {
194 (Triple(Node(),
m_index->expand(
"vamp:available_library"), Node()));
196 for (Triple packt: packs) {
197 Triples libraries =
m_index->match
198 (Triple(packt.object(),
m_index->expand(
"a"),
199 m_index->expand(
"vamp:PluginLibrary")));
200 if (libraries.empty()) {
201 SVCERR <<
"WARNING: Plugin pack " << packt.subject()
202 <<
" claims to contain library " << packt.object()
203 <<
" which is not known to us as a vamp:PluginLibrary" 234 SVDEBUG <<
"PluginRDFIndexer::getIdForPluginURI: NOTE: Failed to find a local RDF document describing plugin <" << uri <<
">: attempting to retrieve one remotely by guesswork" << endl;
236 QString baseUrl = QUrl(uri).toString(QUrl::RemoveFragment);
258 for (StringMap::const_iterator i =
m_idToUriMap.begin();
260 ids.push_back(i->first);
268 QUrl url = QUrl::fromLocalFile(filepath);
269 QString urlString = url.toString();
276 bool pulled =
pullURL(urlString);
277 if (!pulled)
return false;
285 Profiler profiler(
"PluginRDFIndexer::indexURL");
291 QUrl local = urlString;
296 CachedFile cf(urlString,
nullptr,
"application/rdf+xml");
303 }
else if (urlString.startsWith(
"file:")) {
305 local = QUrl(urlString);
309 local = QUrl::fromLocalFile(urlString);
313 m_index->import(local, BasicStore::ImportIgnoreDuplicates);
314 }
catch (RDFException &e) {
316 SVDEBUG <<
"PluginRDFIndexer::pullURL: Failed to import document from " 317 << urlString <<
": " << e.what() << endl;
327 (Triple(Node(), Uri(
"a"),
m_index->expand(
"vamp:Plugin")));
328 Nodes plugins = tt.subjects();
330 bool foundSomething =
false;
331 bool addedSomething =
false;
333 foreach (Node plugin, plugins) {
335 if (plugin.type != Node::URI) {
336 SVDEBUG <<
"PluginRDFIndexer::reindex: Plugin has no URI: node is " 342 (Triple(plugin,
m_index->expand(
"vamp:identifier"), Node()));
344 if (idn.type != Node::Literal) {
345 SVDEBUG <<
"PluginRDFIndexer::reindex: Plugin " << plugin
346 <<
" lacks vamp:identifier literal" << endl;
351 (Triple(Node(),
m_index->expand(
"vamp:available_plugin"), plugin));
353 if (libn.type != Node::URI) {
354 SVDEBUG <<
"PluginRDFIndexer::reindex: Plugin " << plugin
355 <<
" is not vamp:available_plugin in any library" << endl;
360 (Triple(libn,
m_index->expand(
"vamp:identifier"), Node()));
362 if (son.type != Node::Literal) {
363 SVDEBUG <<
"PluginRDFIndexer::reindex: Library " << libn
364 <<
" lacks vamp:identifier for soname" << endl;
368 QString pluginUri = plugin.value;
369 QString identifier = idn.value;
370 QString soname = son.value;
373 (
"vamp", soname, identifier);
375 foundSomething =
true;
383 addedSomething =
true;
385 if (pluginUri !=
"") {
387 SVDEBUG <<
"PluginRDFIndexer::reindex: WARNING: Found multiple plugins with the same URI:" << endl;
389 SVDEBUG <<
" 2. Plugin id \"" << pluginId <<
"\"" << endl;
390 SVDEBUG <<
"both claim URI <" << pluginUri <<
">" << endl;
397 if (!foundSomething) {
398 SVDEBUG <<
"PluginRDFIndexer::reindex: NOTE: Plugins found, but none sufficiently described" << endl;
401 return addedSomething;
QString getURIForPluginId(QString pluginId)
bool isRemote() const
Return true if this FileSource is referring to a remote URL.
std::vector< QString > Playlist
QString getIdForPluginURI(QString uri)
Dataquay::BasicStore * m_index
static QString createIdentifier(QString type, QString soName, QString label)
QString getLocalFilename() const
const Dataquay::BasicStore * getIndex()
void indexInstalledURLs()
QStringList getIndexedPluginIds()
FileSource is a class used to refer to the contents of a file that may be either local or at a remote...
void performConsistencyChecks()
Perform various checks for consistency of RDF definitions, printing warnings to stderr/logfile as app...
bool indexURL(QString url)
static bool canHandleScheme(QUrl url)
Return true if FileSource can handle the retrieval scheme for the given URL (or if the URL is for a l...
bool indexConfiguredURLs()
Index all URLs obtained from index files defined in the current settings.
static PluginRDFIndexer * getInstance()
bool pullFile(QString path)
bool pullURL(QString urlString)
static PluginRDFIndexer * m_instance
Profile point instance class.