comparison rdf/generator/vamp-rdf-template-generator.cpp @ 364:bca93a149bd7

Produce rather richer RDF output
author Chris Cannam
date Fri, 20 Jun 2014 10:17:09 +0100
parents 34754c776530
children aede6e90a6b8
comparison
equal deleted inserted replaced
363:1c93a020c329 364:bca93a149bd7
28 using std::ios; 28 using std::ios;
29 29
30 using Vamp::HostExt::PluginLoader; 30 using Vamp::HostExt::PluginLoader;
31 using Vamp::Plugin; 31 using Vamp::Plugin;
32 32
33 //??? 33 string programURI = "http://vamp-plugins.org/rdf/template-generator";
34 string programURI = "http://www.vamp-plugins.org/doap.rdf#template-generator";
35 34
36 void usage() 35 void usage()
37 { 36 {
38 cerr << endl; 37 cerr << endl;
39 cerr << "vamp-rdf-template-generator: Create a skeleton RDF description file describing" << endl; 38 cerr << "vamp-rdf-template-generator: Create a skeleton RDF description file describing" << endl;
66 @prefix plugbase: <"+pluginBundleBaseURI+libname+"#> .\n\ 65 @prefix plugbase: <"+pluginBundleBaseURI+libname+"#> .\n\
67 @prefix owl: <http://www.w3.org/2002/07/owl#> .\n\ 66 @prefix owl: <http://www.w3.org/2002/07/owl#> .\n\
68 @prefix dc: <http://purl.org/dc/elements/1.1/> .\n\ 67 @prefix dc: <http://purl.org/dc/elements/1.1/> .\n\
69 @prefix af: <http://purl.org/ontology/af/> .\n\ 68 @prefix af: <http://purl.org/ontology/af/> .\n\
70 @prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\ 69 @prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\
70 @prefix doap: <http://usefulinc.com/ns/doap#> .\n\
71 @prefix cc: <http://web.resource.org/cc/> .\n\ 71 @prefix cc: <http://web.resource.org/cc/> .\n\
72 @prefix : <#> .\n\n"; 72 @prefix : <#> .\n\n";
73 73
74 return res; 74 return res;
75 } 75 }
76 76
77 string describe_doc(string describerURI, string pluginBundleBaseURI, 77 string describe_doc(string describerURI, string pluginBundleBaseURI,
78 string libname) 78 string libname)
79 { 79 {
80 string res=\ 80 string res = "\n## Properties of this document\n\n\
81 "<> a vamp:PluginDescription ;\n"; 81 <> a vamp:PluginDescription ;\n";
82
82 if (describerURI != "") { 83 if (describerURI != "") {
83 res += " foaf:maker <"+describerURI+"> ;\n"; 84 res += " foaf:maker <"+describerURI+"> ;\n";
84 } 85 }
86
85 res += "\ 87 res += "\
86 foaf:maker <"+programURI+"> ;\n\ 88 foaf:maker <"+programURI+"> ;\n\
87 foaf:primaryTopic <"+pluginBundleBaseURI+libname+"> .\n\n"; 89 foaf:primaryTopic <"+pluginBundleBaseURI+libname+"> .\n\n";
88 return res; 90 return res;
89 } 91 }
90 92
93 bool have_multiple_makers(vector<Plugin *> plugins)
94 {
95 string firstMaker = "";
96 for (size_t i = 0; i < plugins.size(); ++i) {
97 if (i == 0) {
98 firstMaker = plugins[i]->getMaker();
99 } else if (plugins[i]->getMaker() != firstMaker) {
100 return true;
101 }
102 }
103 return false;
104 }
105
106 string describe_maker(vector<Plugin *> plugins, bool multipleMakers)
107 {
108 string res = "\n## Maker of the whole plugin library\n\n\
109 :library_maker\n";
110
111 if (!multipleMakers) {
112 string name;
113 if (!plugins.empty()) {
114 name = plugins[0]->getMaker();
115 }
116 res += "\
117 foaf:name \"" + name + "\" ;\n\
118 # foaf:page <> ; # Place maker's homepage URL in here and uncomment\n\
119 # foaf:logo <> ; # URL of an image here, if you happen to have a logo\n";
120
121 } else {
122 res += "\
123 foaf:name \"Multiple makers\" ;\n";
124 }
125
126 res += " .\n\n";
127 return res;
128 }
91 129
92 string describe_library(string libname, vector<Plugin *> plugins) 130 string describe_library(string libname, vector<Plugin *> plugins)
93 { 131 {
94 string res=\ 132 string res = "\n## Properties of the plugin library, and references to the plugins it contains\n\n\
95 ":"+libname+" a vamp:PluginLibrary ;\n\ 133 plugbase:library a vamp:PluginLibrary ;\n\
96 vamp:identifier \""+libname+"\" "; 134 vamp:identifier \""+libname+"\" ;\n\
135 foaf:maker :library_maker";
97 136
98 for (size_t i = 0; i < plugins.size(); ++i) { 137 for (size_t i = 0; i < plugins.size(); ++i) {
99 res += " ; \n\ 138 res += " ; \n\
100 vamp:available_plugin plugbase:"+plugins[i]->getIdentifier(); 139 vamp:available_plugin plugbase:"+plugins[i]->getIdentifier();
101 } 140 }
102 141
103 res += " ; \n\ 142 res += " ; \n\
104 # foaf:page <Place more-information HTML page URL here and uncomment> ;\n\ 143 # dc:title \"\" ; # Place library name here and uncomment\n\
144 # dc:description \"\" ; # Place library description here and uncomment\n\
145 # foaf:page <> ; # Place more-info HTML page URL here and uncomment\n\
146 # doap:download-page <> ; # Place download HTML page URL here and uncomment\n\
105 .\n\n"; 147 .\n\n";
106 return res; 148 return res;
107 } 149 }
108 150
109 string describe_plugin(Plugin* plugin) 151 string describe_plugin(Plugin* plugin, bool multipleMakers)
110 { 152 {
111 string res=\ 153 string res = "\n## Properties of the " + plugin->getName() + " plugin\n\n\
112 "plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\ 154 plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\
113 dc:title \""+plugin->getName()+"\" ;\n\ 155 dc:title \""+plugin->getName()+"\" ;\n\
114 vamp:name \""+plugin->getName()+"\" ;\n\ 156 vamp:name \""+plugin->getName()+"\" ;\n\
115 dc:description \"\"\""+plugin->getDescription()+"\"\"\" ;\n\ 157 dc:description \"\"\""+plugin->getDescription()+"\"\"\" ;\n\
116 foaf:maker [ foaf:name \""+plugin->getMaker()+"\" ] ; # FIXME could give plugin author's URI here\n\ 158 foaf:maker ";
159
160 if (multipleMakers) {
161 res += "[ foaf:name \""+plugin->getMaker()+"\" ] ;\n";
162 } else {
163 res += ":library_maker ;\n";
164 }
165
166 res += "\
117 dc:rights \"\"\""+plugin->getCopyright()+"\"\"\" ;\n\ 167 dc:rights \"\"\""+plugin->getCopyright()+"\"\"\" ;\n\
118 # cc:license <Place plugin license URI here and uncomment> ; \n\ 168 # cc:license <Place plugin license URI here and uncomment> ; \n\
119 vamp:identifier \""+plugin->getIdentifier()+"\" ;\n\ 169 vamp:identifier \""+plugin->getIdentifier()+"\" ;\n\
120 vamp:vamp_API_version vamp:api_version_"+to_string(plugin->getVampApiVersion())+" ;\n\ 170 vamp:vamp_API_version vamp:api_version_"+to_string(plugin->getVampApiVersion())+" ;\n\
121 owl:versionInfo \""+to_string(plugin->getPluginVersion())+"\" ;\n"; 171 owl:versionInfo \""+to_string(plugin->getPluginVersion())+"\" ;\n";
122 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) 172 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain)
123 res+=" vamp:input_domain vamp:FrequencyDomain ;\n\n"; 173 res+=" vamp:input_domain vamp:FrequencyDomain ;\n\n";
124 else 174 else
125 res+=" vamp:input_domain vamp:TimeDomain ;\n"; 175 res+=" vamp:input_domain vamp:TimeDomain ;\n";
126 176
127
128 Plugin::ParameterList params = plugin->getParameterDescriptors(); 177 Plugin::ParameterList params = plugin->getParameterDescriptors();
129 if (!params.empty()) res+="\n";
130 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) 178 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++)
131 res+=" vamp:parameter plugbase:"+plugin->getIdentifier()+"_param_"+(*i).identifier+" ;\n"; 179 res+=" vamp:parameter plugbase:"+plugin->getIdentifier()+"_param_"+(*i).identifier+" ;\n";
132 if (!params.empty()) res+="\n"; 180 if (!params.empty()) res+="\n";
133 181
134 Plugin::OutputList outputs = plugin->getOutputDescriptors(); 182 Plugin::OutputList outputs = plugin->getOutputDescriptors();
352 } 400 }
353 401
354 string describe(vector<Plugin *> plugins, string pluginBundleBaseURI, 402 string describe(vector<Plugin *> plugins, string pluginBundleBaseURI,
355 string describerURI, string libname) 403 string describerURI, string libname)
356 { 404 {
405 bool multipleMakers = have_multiple_makers(plugins);
406
357 string res = describe_namespaces(pluginBundleBaseURI, libname); 407 string res = describe_namespaces(pluginBundleBaseURI, libname);
358 408
359 res += describe_doc(describerURI, pluginBundleBaseURI, libname); 409 res += describe_doc(describerURI, pluginBundleBaseURI, libname);
360 410
411 res += describe_maker(plugins, multipleMakers);
412
361 res += describe_library(libname, plugins); 413 res += describe_library(libname, plugins);
362 414
363 for (size_t i = 0; i < plugins.size(); ++i) { 415 for (size_t i = 0; i < plugins.size(); ++i) {
364 416
365 Plugin *plugin = plugins[i]; 417 Plugin *plugin = plugins[i];
366 418
367 res += describe_plugin(plugin); 419 res += describe_plugin(plugin, multipleMakers);
368 420
369 Plugin::ParameterList params = plugin->getParameterDescriptors(); 421 Plugin::ParameterList params = plugin->getParameterDescriptors();
370 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) 422 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++)
371 res += describe_param(plugin, *i); 423 res += describe_param(plugin, *i);
372 424