To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / common / Matcher.h

History | View | Annotate | Download (2.52 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

    
3
#ifndef _CLASSICAL_DATA_MATCHER_H_
4
#define _CLASSICAL_DATA_MATCHER_H_
5

    
6
#include "Objects.h"
7

    
8
#include <dataquay/Uri.h>
9

    
10
#include <QHash>
11
#include <set>
12

    
13
namespace ClassicalData {
14

    
15
class Guess
16
{
17
public:
18
    Guess(float c, NamedEntity *e) : m_confidence(c), m_entity(e) { }
19

    
20
    float confidence() const { return m_confidence; }
21
    void setConfidence(float c) { m_confidence = c; }
22
    
23
    NamedEntity *entity() const { return m_entity; }
24
    void setEntity(NamedEntity *e) { m_entity = e; }
25

    
26
    bool operator<(const Guess &g) const {
27
        if (confidence() == g.confidence()) {
28
            return entity()->uri() < g.entity()->uri();
29
        }
30
        return (confidence() > g.confidence()); // n.b. most confident first
31
    }
32
    
33
private:
34
    float m_confidence;
35
    NamedEntity *m_entity;
36
};
37

    
38
typedef QList<Guess> GuessList;
39
typedef std::set<Guess> GuessSet;
40

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

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

    
57
private:
58
    QList<Composer *> m_composers;
59
};
60

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

    
68
private:
69
    QList<Composer *> m_composers;
70
};
71

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

    
79
private:
80
    QList<Composer *> m_composers;
81
};
82

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

    
90
private:
91
    QList<Work *> m_works;
92
};
93

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

    
101
private:
102
    QList<Work *> m_works;
103
};
104

    
105
}
106

    
107
Q_DECLARE_METATYPE(ClassicalData::Guess*);
108

    
109
#endif
110