25 #include <vamp-hostsdk/PluginHostAdapter.h> 27 #include <dataquay/BasicStore.h> 28 #include <dataquay/RDFException.h> 41 using Vamp::PluginHostAdapter;
45 using Dataquay::Nodes;
46 using Dataquay::Triple;
47 using Dataquay::Triples;
48 using Dataquay::BasicStore;
49 using Dataquay::RDFException;
50 using Dataquay::RDFDuplicateImportException;
65 m_index->addPrefix(
"vamp", Uri(
"http://purl.org/ontology/vamp/"));
66 m_index->addPrefix(
"foaf", Uri(
"http://xmlns.com/foaf/0.1/"));
67 m_index->addPrefix(
"dc", Uri(
"http://purl.org/dc/elements/1.1/"));
85 vector<string> paths = PluginHostAdapter::getPluginPath();
102 for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
104 QDir dir(i->c_str());
105 if (!dir.exists())
continue;
107 QStringList entries = dir.entryList
108 (filters, QDir::Files | QDir::Readable);
110 for (QStringList::const_iterator j = entries.begin();
111 j != entries.end(); ++j) {
113 QFileInfo fi(dir.filePath(*j));
117 QStringList subdirs = dir.entryList
118 (QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Readable);
120 for (QStringList::const_iterator j = subdirs.begin();
121 j != subdirs.end(); ++j) {
123 QDir subdir(dir.filePath(*j));
124 if (subdir.exists()) {
125 entries = subdir.entryList
126 (filters, QDir::Files | QDir::Readable);
127 for (QStringList::const_iterator k = entries.begin();
128 k != entries.end(); ++k) {
129 QFileInfo fi(subdir.filePath(*k));
142 SVDEBUG <<
"PluginRDFIndexer::indexConfiguredURLs" << endl;
145 settings.beginGroup(
"RDF");
147 QString indexKey(
"rdf-indices");
148 QStringList indices = settings.value(indexKey).toStringList();
150 for (
int i = 0; i < indices.size(); ++i) {
152 QString index = indices[i];
154 SVDEBUG <<
"PluginRDFIndexer::indexConfiguredURLs: index url is " 158 if (!cf.
isOK())
continue;
163 if (!reader.isOK())
continue;
166 for (PlaylistFileReader::Playlist::const_iterator j = list.begin();
167 j != list.end(); ++j) {
168 SVDEBUG <<
"PluginRDFIndexer::indexConfiguredURLs: url is " 174 QString urlListKey(
"rdf-urls");
175 QStringList urls = settings.value(urlListKey).toStringList();
177 for (
int i = 0; i < urls.size(); ++i) {
211 cerr <<
"PluginRDFIndexer::getIdForPluginURI: NOTE: Failed to find a local RDF document describing plugin <" << uri <<
">: attempting to retrieve one remotely by guesswork" << endl;
213 QString baseUrl = QUrl(uri).toString(QUrl::RemoveFragment);
235 for (StringMap::const_iterator i =
m_idToUriMap.begin();
237 ids.push_back(i->first);
245 QUrl url = QUrl::fromLocalFile(filepath);
246 QString urlString = url.toString();
253 bool pulled =
pullURL(urlString);
254 if (!pulled)
return false;
262 Profiler profiler(
"PluginRDFIndexer::indexURL");
268 QUrl local = urlString;
273 CachedFile cf(urlString, 0,
"application/rdf+xml");
280 }
else if (urlString.startsWith(
"file:")) {
282 local = QUrl(urlString);
286 local = QUrl::fromLocalFile(urlString);
290 m_index->import(local, BasicStore::ImportFailOnDuplicates);
291 }
catch (RDFDuplicateImportException &e) {
292 cerr << e.what() << endl;
293 cerr <<
"PluginRDFIndexer::pullURL: Document at " << urlString
294 <<
" duplicates triples found in earlier loaded document -- skipping it" << endl;
296 }
catch (RDFException &e) {
297 cerr << e.what() << endl;
298 cerr <<
"PluginRDFIndexer::pullURL: Failed to import document from " 299 << urlString <<
": " << e.what() << endl;
309 (Triple(Node(), Uri(
"a"),
m_index->expand(
"vamp:Plugin")));
310 Nodes plugins = tt.subjects();
312 bool foundSomething =
false;
313 bool addedSomething =
false;
315 foreach (Node plugin, plugins) {
317 if (plugin.type != Node::URI) {
318 cerr <<
"PluginRDFIndexer::reindex: Plugin has no URI: node is " 324 (Triple(plugin,
m_index->expand(
"vamp:identifier"), Node()));
326 if (idn.type != Node::Literal) {
327 cerr <<
"PluginRDFIndexer::reindex: Plugin " << plugin
328 <<
" lacks vamp:identifier literal" << endl;
333 (Triple(Node(),
m_index->expand(
"vamp:available_plugin"), plugin));
335 if (libn.type != Node::URI) {
336 cerr <<
"PluginRDFIndexer::reindex: Plugin " << plugin
337 <<
" is not vamp:available_plugin in any library" << endl;
342 (Triple(libn,
m_index->expand(
"vamp:identifier"), Node()));
344 if (son.type != Node::Literal) {
345 cerr <<
"PluginRDFIndexer::reindex: Library " << libn
346 <<
" lacks vamp:identifier for soname" << endl;
350 QString pluginUri = plugin.value;
351 QString identifier = idn.value;
352 QString soname = son.value;
355 (
"vamp", soname, identifier);
357 foundSomething =
true;
365 addedSomething =
true;
367 if (pluginUri !=
"") {
369 cerr <<
"PluginRDFIndexer::reindex: WARNING: Found multiple plugins with the same URI:" << endl;
370 cerr <<
" 1. Plugin id \"" <<
m_uriToIdMap[pluginUri] <<
"\"" << endl;
371 cerr <<
" 2. Plugin id \"" << pluginId <<
"\"" << endl;
372 cerr <<
"both claim URI <" << pluginUri <<
">" << endl;
379 if (!foundSomething) {
380 cerr <<
"PluginRDFIndexer::reindex: NOTE: Plugins found, but none sufficiently described" << endl;
383 return addedSomething;
QString getURIForPluginId(QString pluginId)
std::vector< QString > Playlist
QString getIdForPluginURI(QString uri)
Dataquay::BasicStore * m_index
static QString createIdentifier(QString type, QString soName, QString label)
const Dataquay::BasicStore * getIndex()
QString getLocalFilename() const
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...
bool isRemote() const
Return true if this FileSource is referring to a remote URL.
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.