/usr/include/CLAM/DescriptionScheme.hxx is in libclam-dev 1.4.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | /*
* Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
* UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef _DescriptionScheme_hxx_
#define _DescriptionScheme_hxx_
#include "DescriptionScope.hxx"
/*
You can find the doxygen of the SemanticalAnalysis group
at the end of this file.
*/
namespace CLAM
{
/**
* The description scheme defines the set of attributes (Attribute)
* to be used for feature extraction systems.
* @ingroup SemanticalAnalysis
*
* A DescriptionScheme is only an specification.
* The real data is held in a DescriptionDataPool,
* a container that fits its structure to the one defined on
* the DescriptionScheme specification.
*
* Attributes in a DescriptionScheme have a name and a type
* and they are organized in scopes.
* Each scope (see DescriptionScope) defines a kind of target for the attributes:
* (note scope, sample scope, frame scope, phrase scope, sample scope...)
*
* You can add Attributes to the DescriptionScheme by
* using the DescriptionScheme::AddAttribute method.
* The rest of the methods are utility for the pool classes.
*
* @see SemanticalAnalysis module, that describes
* the full usage of those classes.
* @see DescriptionDataPool class, which instanciates a DescriptionScheme
*
*/
class DescriptionScheme : public Component
{
private:
typedef std::map<std::string, unsigned> ScopeMap;
typedef std::vector<DescriptionScope *> Scopes;
private:
Scopes _scopes;
ScopeMap _scopeNameMap;
public:
DescriptionScheme()
{
}
~DescriptionScheme();
/**
* Adds a new attribute to the description scheme.
* If the scope does not exist it will be added.
* @pre The name is alphanumeric
* @pre The scope has no other attribute with the same name
* @param DataType The type of the argument to be added
* @param scope The scope where the attributes applies to
* @param name The name for the attribute
*/
template < typename DataType >
void AddAttribute(const std::string &scope, const std::string & name)
{
DescriptionScope & theScope = SearchScopeOrAdd(scope);
theScope.template Add<DataType>(name);
}
DescriptionScope & SearchScopeOrAdd(const std::string scopeName)
{
const unsigned nScopes = _scopes.size();
std::pair<ScopeMap::iterator,bool> result =
_scopeNameMap.insert(std::make_pair(scopeName,nScopes));
if (!result.second) return *_scopes[result.first->second];
DescriptionScope * theScope = new DescriptionScope(scopeName);
_scopes.push_back(theScope);
return *theScope;
}
unsigned GetScopeIndex(const std::string & name) const
{
ScopeMap::const_iterator it = _scopeNameMap.find(name);
CLAM_ASSERT(it!=_scopeNameMap.end(), ("Attribute scope '" + name + "' not found").c_str());
return it->second;
}
const DescriptionScope & GetScope(unsigned scopeIndex) const
{
CLAM_ASSERT(scopeIndex < _scopes.size(), "Accessing an illegal scope index for the description scheme");
return *_scopes[scopeIndex];
}
const DescriptionScope & GetScope(const std::string & name) const
{
unsigned scopeIndex = GetScopeIndex(name);
return GetScope(scopeIndex);
}
unsigned GetNScopes() const
{
return _scopes.size();
}
const std::string & GetScopeName(unsigned scopeIndex) const
{
const DescriptionScope & scope = GetScope(scopeIndex);
return scope.GetName();
}
void StoreOn(Storage & storage) const;
void LoadFrom(Storage & storage);
const char * GetClassName() const { return "DescriptionScheme"; }
};
}
/**
* @defgroup SemanticalAnalysis Semantical Analysis
*
* This module explains how to use CLAM to handle audio description
* extraction using the DescriptionScheme object and its relatives.
* They will allow you to do the extraction in a modular and incremental way
* taking from other projects the parts you are interested in and
* adding your own descriptors in a incremental way.
*
* This module intends to implement the system described on
* http://www.iua.upf.es/mtg/clam/devel/doc/descriptors/Descriptors.html
* but there is still some way to achieve the full functionality
* described in there.
*
* @section DescriptionSpecification Defining and instanciating descriptors
*
* The central object for description extraction is the DescriptionScheme.
* The description scheme (CLAM::DescriptionScheme) defines
* which are the attributes (CLAM::Attribute) we want to compute.
* You can relate attributes to a name and a type and you
* can organize attributes in different ''scopes''.
* You can understand a scope (CLAM::DescriptionScope) as
* the kind of target for a given set of attributes.
* For example, we normaly talk about
* note scope, sample scope, frame scope, phrase scope...
* that means that a given attribute will have a value for
* every single note, sample, frame, phrase...
*
* @code
* CLAM::DescriptionScheme scheme;
* scheme.AddAttribute <CLAM::TData> ("AudioSample", "SignalLevel");
* scheme.AddAttribute <CLAM::TData> ("AudioSample", "FilteredSignal");
* scheme.AddAttribute <SamplePosition> ("Frame", "Center");
* scheme.AddAttribute <CLAM::TData> ("Frame", "Energy");
* scheme.AddAttribute <CLAM::TData> ("Frame", "RMS");
* scheme.AddAttribute <CLAM::Spectrum> ("Frame", "SpectralDistribution");
* scheme.AddAttribute <FramePosition> ("Note", "Onset");
* scheme.AddAttribute <CLAM::Pitch> ("Note", "Pitch");
* @endcode
*
* The description scheme only specifies the attribute organization.
* The real values are hold into the data pool (CLAM::DescriptionDataPool).
* An instance of a DescriptionDataPool will hold the attributes
* extracted from a single description source (ie, an audio).
* It take the structure defined by the description scheme.
*
* @code
* CLAM::DescriptionDataPool pool(scheme);
* @endcode
*
* So, summarizing:
* - A description scheme defines attributes to be computed
* - Every attribute has its name and type and is related to a given scope
* - A scope specifies the kind of attribute target
* - A description data pool is the real container for the values computed by extraction.
* - A description data pool matches the structure specified by a given description scheme.
*
* @dot
digraph lala
{
edge [fontname=Helvetica, fontsize=10]
node [shape=rectangle, fontname=Helvetica, fontsize=12, style=filled]
node [URL="classCLAM_1_1\N.html"]
{
edge[dir=back, arrowtail=diamond, taillabel=" * "]
node [color=indigo,fillcolor="0.6 0.1 .9"]
DescriptionScheme -> DescriptionScope -> Attribute
node [color=darkgreen,fillcolor="0.2 0.1 1.0"]
DescriptionDataPool -> ScopePool -> AttributePool
}
{
edge[dir=back, constraint=false]
DescriptionScheme -> DescriptionDataPool
DescriptionScope -> ScopePool
Attribute -> AttributePool
}
}
* @enddot
*
* @section PoolByHand Accessing the pool by hand
*
* Accessing the pool by hand is not the ideal way of doing it but,
* currently, extractor binding is not so complete so, by now,
* it is the only way to do certain things.
*
* The scope provides interface to:
* - Populate a given scope with a size.
* That is for the scope Note, telling how many notes there are.
* @code
* pool.SetNumberOfContexts("Note",60);
* @endcode
* - Obtaining the attribute pool for writting,
* so you will get a vector of pitches one for every note.
* @code
* CLAM::Pitch * pitches = pool.GetWritePool<CLAM::Pitch>("Note","Pitch");
* @endcode
* - Obtaining the attribute pool for reading
* @code
* const CLAM::Pitch * pitches = pool.GetReadPool<CLAM::Pitch>("Note","Pitch");
* @endcode
*
* @warning A write access is required before any read access.
* The pool will create the attribute pool memory only when
* somebody requires to write in it.
*
* The access is templatized by the attribute type.
* The pool user need not to handle generic types (void*, casts...)
* and her code keeps typesafe.
* Some checking between the usage and the real type
* for the attribute is done on run-time.
* So if you use a different value type an assertion will fail.
*
* @section XML
*
* Description data pools can be loaded or stored in XML, as any
* other CLAM::Component, by using an CLAM::XmlStorage.
*
* @code
* // Storing a description in XML
* CLAM::XmlStorage::Dump(pool, "DescriptionPool", "mysong.xml");
* @endcode
*
* @code
* // Recovering an XML description
* CLAM::XmlStorage::Restore(pool, "mysong.xml");
* @endcode
*
*
* @section ExtractorBinding Binding extractors
*
* While you can use the pool simply as a container,
* like it has been explained above,
* the aim of this system is to be able to deploy the extraction
* system from an XML file that describes the Description Scheme and the Extraction Scheme.
* This would be done by encapsulating algorithms that compute
* attributes on an abstraction called CLAM::Extractors.
* They should be something very close to what a CLAM::Processing is
* and, in fact, they will likely converge as the iterations go on.
* An extractor has hooks for input and output data that are
* fetched from the data pool.
* The way data is fetched and droped is determined by the binding.
*
* So, this part of the module is work on progress but
* there are some parts already implemented and usable.
* By now, what we have is some kinds of hook binding.
* Current implemented binding operations are bindings on the same context,
* and indirection, that is, using an attribute to point another one even on a different scope.
*
* By now, there is no such abstract CLAM::Extractor but you can take a look
* to some Extractors CLAMTest::CharCopierExtractor and CLAMTest::CharJoinExtractor.
* Also you can see how binding is done by looking at the ExtractorTest.cxx file.
*
* @section DescriptionPoolTodo What is left to implement
*
* - An abstract CLAM::Extractor to derive from
* - An special kind of extractor for scope population (how many items in a scope?)
* - Bindings extension: relative position
* - Solving Range and Relative bindings when outside the scope space
* - The type system
* - Defining units friendly types for using them in attributes
* - Solving the creation of concrete Attribute specification from the type name
* - XML Serialization for schemes
* - Exploring new hook binding functionalities driven by real cases
*
*/
#endif// _DescriptionScheme_hxx_
|