Mercurial > hg > classical
comparison testapp/Loader.cpp @ 9:9e2b203254ab classical-rdf
* test matching of composer names
author | Chris Cannam |
---|---|
date | Fri, 12 Feb 2010 16:56:29 +0000 |
parents | 71cf328c2a9d |
children | d35e5d769c87 |
comparison
equal
deleted
inserted
replaced
8:71cf328c2a9d | 9:9e2b203254ab |
---|---|
31 BasicStore::ImportPermitDuplicates, // fastest mode | 31 BasicStore::ImportPermitDuplicates, // fastest mode |
32 "ntriples"); | 32 "ntriples"); |
33 return true; | 33 return true; |
34 } | 34 } |
35 | 35 |
36 //!!! both nasty and duplicated from Import.cpp | |
37 | |
38 QString makeNameKey(QString name) | |
39 { | |
40 QString key = name.toLower() | |
41 .replace("'", "") | |
42 .replace("x", "ks") | |
43 .replace("y", "i") | |
44 .replace("k", "c") | |
45 .replace("ch", "c") | |
46 .replace("cc", "c") | |
47 .replace("v", "f") | |
48 .replace("ff", "f") | |
49 .replace("th", "t") | |
50 .replace("tch", "ch") | |
51 .replace("er", "r"); | |
52 // DEBUG << "makeNameKey(" << name << "): " << key << endl; | |
53 return key; | |
54 } | |
55 | |
56 bool namesFuzzyMatch(QString an, Composer *b) | |
57 { | |
58 // ew! | |
59 | |
60 QString bn = b->name(); | |
61 if (bn == an) return true; | |
62 if (b->aliases().contains(an)) return true; | |
63 int aSurnameIndex = 0, bSurnameIndex = 0; | |
64 if (an.contains(",")) { | |
65 an.replace(",", ""); | |
66 } else { | |
67 aSurnameIndex = -1; | |
68 } | |
69 if (bn.contains(",")) { | |
70 bn.replace(",", ""); | |
71 } else { | |
72 bSurnameIndex = -1; | |
73 } | |
74 QStringList nl = an.split(QRegExp("[ -]")); | |
75 QStringList bnl = makeNameKey(bn).split(QRegExp("[ -]")); | |
76 int matchCount = 0; | |
77 QString surnameMatch = ""; | |
78 if (aSurnameIndex == -1) aSurnameIndex = nl.size()-1; | |
79 if (bSurnameIndex == -1) bSurnameIndex = bnl.size()-1; | |
80 if (nl[aSurnameIndex][0].isUpper() && | |
81 nl[aSurnameIndex] != "Della" && | |
82 makeNameKey(nl[aSurnameIndex]) == bnl[bSurnameIndex]) { | |
83 surnameMatch = nl[aSurnameIndex]; | |
84 } | |
85 int tested = 0; | |
86 foreach (QString elt, nl) { | |
87 if (!elt[0].isUpper() || elt == "Della") continue; | |
88 QString k = makeNameKey(elt); | |
89 if (bnl.contains(k)) { | |
90 ++matchCount; | |
91 } | |
92 if (++tested == 2 && matchCount == 0) { | |
93 return false; | |
94 } | |
95 } | |
96 if (surnameMatch != "") { | |
97 // DEBUG << "namesFuzzyMatch: note: surnameMatch = " << surnameMatch << endl; | |
98 if (matchCount > 1) { | |
99 return true; | |
100 } else { | |
101 // DEBUG << "(but not enough else matched)" << endl; | |
102 return false; | |
103 } | |
104 } | |
105 return false; | |
106 } | |
107 | |
36 int main(int argc, char **argv) | 108 int main(int argc, char **argv) |
37 { | 109 { |
38 BasicStore *store = new BasicStore(); | 110 BasicStore *store = new BasicStore(); |
39 store->setBaseUri("http://dbtune.org/classical/resource/"); | 111 store->setBaseUri("http://dbtune.org/classical/resource/"); |
40 ObjectMapper *mapper = new ObjectMapper(store); | 112 ObjectMapper *mapper = new ObjectMapper(store); |
50 | 122 |
51 QObject *root = mapper->loadAllObjects(0); | 123 QObject *root = mapper->loadAllObjects(0); |
52 | 124 |
53 delete mapper; | 125 delete mapper; |
54 delete store; | 126 delete store; |
127 | |
128 QObjectList composers; | |
129 foreach (QObject *o, root->children()) { | |
130 if (qobject_cast<Composer *>(o)) composers.push_back(o); | |
131 } | |
132 | |
133 if (argc > 1) { | |
134 QString name = argv[1]; | |
135 std::cerr << "Name: " << name.toStdString() << std::endl; | |
136 foreach (QObject *o, composers) { | |
137 Composer *c = qobject_cast<Composer *>(o); | |
138 if (!c) continue; | |
139 if (namesFuzzyMatch(name, c)) { | |
140 std::cerr << "Matches: " << c->name().toStdString() << std::endl; | |
141 } | |
142 } | |
143 } | |
55 | 144 |
145 /* | |
56 std::cerr << "mapped, storing again..." << std::endl; | 146 std::cerr << "mapped, storing again..." << std::endl; |
147 | |
148 // let's try just writing out the composers | |
57 | 149 |
58 BasicStore *outstore = new BasicStore(); | 150 BasicStore *outstore = new BasicStore(); |
59 outstore->setBaseUri("http://dbtune.org/classical/resource/"); | 151 outstore->setBaseUri("http://dbtune.org/classical/resource/"); |
60 ObjectMapper *outmapper = new ObjectMapper(outstore); | 152 ObjectMapper *outmapper = new ObjectMapper(outstore); |
61 | 153 |
62 TypeRegistrar::addMappings(outstore, outmapper); | 154 TypeRegistrar::addMappings(outstore, outmapper); |
63 | 155 |
64 outmapper->storeObjects(root); | 156 // outmapper->storeObjectTree(root); |
157 outmapper->storeAllObjects(composers); | |
65 delete outmapper; | 158 delete outmapper; |
66 | 159 |
67 std::cerr << "stored, saving..." << std::endl; | 160 std::cerr << "stored, saving..." << std::endl; |
68 | 161 |
69 outstore->save("test-output.ttl"); | 162 outstore->save("test-output.ttl"); |
70 | 163 |
71 delete outstore; | 164 delete outstore; |
165 */ | |
72 } | 166 } |
73 | 167 |