view common/Matcher.h @ 45:0033259c6772

* More Music Ontology-like structure for audio files & signals
author Chris Cannam
date Fri, 14 May 2010 17:58:04 +0100
parents 271cbaf6e8d9
children
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

#ifndef _CLASSICAL_DATA_MATCHER_H_
#define _CLASSICAL_DATA_MATCHER_H_

#include "Objects.h"

#include <dataquay/Uri.h>

#include <QHash>
#include <set>

namespace ClassicalData {

class Guess
{
public:
    Guess(float c, NamedEntity *e) : m_confidence(c), m_entity(e) { }

    float confidence() const { return m_confidence; }
    void setConfidence(float c) { m_confidence = c; }
    
    NamedEntity *entity() const { return m_entity; }
    void setEntity(NamedEntity *e) { m_entity = e; }

    bool operator<(const Guess &g) const {
        if (confidence() == g.confidence()) {
            return entity()->uri() < g.entity()->uri();
        }
        return (confidence() > g.confidence()); // n.b. most confident first
    }
    
private:
    float m_confidence;
    NamedEntity *m_entity;
};

typedef QList<Guess> GuessList;
typedef std::set<Guess> GuessSet;

class Matcher
{
public:
    // Results are guaranteed to be returned in order from most to
    // least confident
    virtual GuessList match(QString text, int maxResults,
                            float threshold = 0.f) const = 0;
};

class ComposerTypingQuickMatcher : public Matcher
{
public:
    ComposerTypingQuickMatcher(QList<Composer *> cl);
    virtual GuessList match(QString text, int maxResults,
                            float threshold = 0.f) const;

private:
    QList<Composer *> m_composers;
};

class ComposerTypingThoroughMatcher : public Matcher
{
public:
    ComposerTypingThoroughMatcher(QList<Composer *> cl);
    virtual GuessList match(QString text, int maxResults,
                            float threshold = 0.f) const;

private:
    QList<Composer *> m_composers;
};

class ComposerFullTextMatcher : public Matcher
{
public:
    ComposerFullTextMatcher(QList<Composer *> cl);
    virtual GuessList match(QString text, int maxResults,
                            float threshold = 0.f) const;

private:
    QList<Composer *> m_composers;
};

class WorkCatalogueMatcher : public Matcher
{
public:
    WorkCatalogueMatcher(QList<Work *> wl);
    virtual GuessList match(QString text, int maxResults,
                            float threshold = 0.f) const;

private:
    QList<Work *> m_works;
};

class WorkTitleMatcher : public Matcher
{
public:
    WorkTitleMatcher(QList<Work *> wl);
    virtual GuessList match(QString text, int maxResults,
                            float threshold = 0.f) const;

private:
    QList<Work *> m_works;
};

}

Q_DECLARE_METATYPE(ClassicalData::Guess*);

#endif