changeset 21:ea477e4cc75c classical-rdf

* update for newer dataquay
author Chris Cannam
date Thu, 25 Feb 2010 18:21:53 +0000
parents c4cb65c436ef
children 9abc896958cf
files common/Objects.h common/TypeRegistrar.cpp utilities/composer/composer.cpp
diffstat 3 files changed, 54 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/common/Objects.h	Tue Feb 23 16:37:49 2010 +0000
+++ b/common/Objects.h	Thu Feb 25 18:21:53 2010 +0000
@@ -4,6 +4,7 @@
 #define _CLASSICAL_DATA_OBJECTS_H_
 
 #include <dataquay/Uri.h>
+#include <dataquay/Node.h>
 
 #include <QObject>
 #include <QMetaType>
@@ -17,28 +18,50 @@
 
 namespace ClassicalData {
 
+class Year
+{
+public:
+    Year() : m_year(0) { }
+    Year(int y) : m_year(y) { }
+
+    int year() const { return m_year; }
+    operator int() { return m_year; }
+
+    struct Encoder : public Dataquay::Node::VariantEncoder {
+        QString fromVariant(const QVariant &v) {
+            return QString("%1").arg(v.value<Year>().year());
+        }
+        QVariant toVariant(const QString &s) {
+            return QVariant::fromValue<Year>(s.toInt());
+        }
+    };
+
+private:
+    int m_year;
+};
+
 class HistoricalEvent : public QObject
 {
     Q_OBJECT
 
-    Q_PROPERTY(int year READ year WRITE setYear STORED true)
+    Q_PROPERTY(ClassicalData::Year year READ year WRITE setYear STORED true)
     Q_PROPERTY(QString place READ place WRITE setPlace STORED true)
     Q_PROPERTY(bool approximate READ approximate WRITE setApproximate STORED true)
 
 public:
     HistoricalEvent() : m_year(0), m_place(), m_approximate(false) { }
-    HistoricalEvent(int y) : m_year(y), m_approximate(false) { }
-    HistoricalEvent(int y, QString p) : m_year(y), m_place(p), m_approximate(false) { }
+    HistoricalEvent(Year y) : m_year(y), m_approximate(false) { }
+    HistoricalEvent(Year y, QString p) : m_year(y), m_place(p), m_approximate(false) { }
 
-    int year() const { return m_year; }
-    void setYear(int y) { m_year = y; }
+    Year year() const { return m_year; }
+    void setYear(Year y) { m_year = y; }
     QString place() const { return m_place; }
     void setPlace(QString p) { m_place = p; }
     bool approximate() const { return m_approximate; }
     void setApproximate(bool a) { m_approximate = a; }
     
 private:
-    int m_year;
+    Year m_year;
     QString m_place;
     bool m_approximate;
 };
@@ -49,8 +72,8 @@
 
 public:
     Birth() : HistoricalEvent() { }
-    Birth(int y) : HistoricalEvent(y) { }
-    Birth(int y, QString p) : HistoricalEvent(y, p) { }
+    Birth(Year y) : HistoricalEvent(y) { }
+    Birth(Year y, QString p) : HistoricalEvent(y, p) { }
 };
 
 class Death : public HistoricalEvent
@@ -59,8 +82,8 @@
 
 public:
     Death() : HistoricalEvent() { }
-    Death(int y) : HistoricalEvent(y) { }
-    Death(int y, QString p) : HistoricalEvent(y, p) { }
+    Death(Year y) : HistoricalEvent(y) { }
+    Death(Year y, QString p) : HistoricalEvent(y, p) { }
 };
 
 class Composer;
@@ -76,8 +99,8 @@
 
 public:
     Composition() : HistoricalEvent(), m_composer(0) { }
-    Composition(int y) : HistoricalEvent(y), m_composer(0) { }
-    Composition(int y, QString p) : HistoricalEvent(y, p), m_composer(0) { }
+    Composition(Year y) : HistoricalEvent(y), m_composer(0) { }
+    Composition(Year y, QString p) : HistoricalEvent(y, p), m_composer(0) { }
 
     Composer *composer() { return m_composer; }
     void setComposer(Composer *c) { m_composer = c; }
@@ -436,6 +459,7 @@
 
 }
 
+Q_DECLARE_METATYPE(ClassicalData::Year);
 Q_DECLARE_METATYPE(ClassicalData::HistoricalEvent*);
 Q_DECLARE_METATYPE(ClassicalData::Birth*);
 Q_DECLARE_METATYPE(ClassicalData::Death*);
--- a/common/TypeRegistrar.cpp	Tue Feb 23 16:37:49 2010 +0000
+++ b/common/TypeRegistrar.cpp	Thu Feb 25 18:21:53 2010 +0000
@@ -14,6 +14,8 @@
 
 TypeRegistrar::TypeRegistrar()
 {
+    qRegisterMetaType<Year>
+	("ClassicalData::Year");
     qRegisterMetaType<HistoricalEvent *>
 	("ClassicalData::HistoricalEvent*");
     qRegisterMetaType<Birth *>
@@ -45,6 +47,9 @@
     qRegisterMetaType<QSet<Dataquay::Uri> >
 	("QSet<Dataquay::Uri>");
 
+    Node::registerDatatype(Uri("http://www.w3.org/2001/XMLSchema#gYear"),
+			   "ClassicalData::Year", new Year::Encoder());
+
     ObjectBuilder::getInstance()->registerClass
 	<HistoricalEvent>("ClassicalData::HistoricalEvent*");
     ObjectBuilder::getInstance()->registerClass
@@ -107,6 +112,15 @@
     store->addPrefix("cmn", Uri("http://purl.org/ontology/classicalmusicnav#"));
     store->addPrefix("sim", Uri("http://purl.org/ontology/similarity/"));
 
+    mapper->setObjectTypePrefix(Uri("http://dbtune.org/classical/resource/"));
+    mapper->setPropertyPrefix(Uri("http://dbtune.org/classical/resource/vocab/"));
+    mapper->setRelationshipPrefix(Uri("http://dbtune.org/classical/resource/vocab/relationship/"));
+    
+    store->addPrefix("type", mapper->getObjectTypePrefix());
+    store->addPrefix("classical", Uri(mapper->getObjectTypePrefix().toString() + "type/"));
+    store->addPrefix("property", mapper->getPropertyPrefix());
+    store->addPrefix("rel", mapper->getRelationshipPrefix());
+
     store->add(Triple("classical:Composer", "a", store->expand("owl:Class")));
     store->add(Triple("classical:Composer", "rdfs:subClassOf", store->expand("mo:MusicArtist")));
 
@@ -116,15 +130,6 @@
     store->add(Triple("property:death", "a", store->expand("owl:ObjectProperty")));
     store->add(Triple("property:death", "rdfs:subPropertyOf", store->expand("bio:event")));
 
-    mapper->setObjectTypePrefix(Uri("http://dbtune.org/classical/resource/"));
-    mapper->setPropertyPrefix(Uri("http://dbtune.org/classical/resource/vocab/"));
-    mapper->setRelationshipPrefix(Uri("http://dbtune.org/classical/resource/vocab/relationship/"));
-    
-    store->addPrefix("type", mapper->getObjectTypePrefix());
-    store->addPrefix("classical", Uri(mapper->getObjectTypePrefix().toString() + "type/"));
-    store->addPrefix("property", mapper->getPropertyPrefix());
-    store->addPrefix("rel", mapper->getRelationshipPrefix());
-
     mapper->addTypeMapping("ClassicalData::Composer", "classical:Composer");
     mapper->addPropertyMapping("ClassicalData::Composer", "pages", "foaf:page");
     mapper->addPropertyMapping("ClassicalData::Composer", "name", "foaf:name");
@@ -137,9 +142,9 @@
     mapper->addTypeMapping("ClassicalData::Death", "bio:Death");
     mapper->addTypeUriPrefixMapping("ClassicalData::Birth", ":event/");
     mapper->addTypeUriPrefixMapping("ClassicalData::Death", ":event/");
-    mapper->addPropertyMapping("ClassicalData::Birth", "year", "bio:date");
-    mapper->addPropertyMapping("ClassicalData::Death", "year", "bio:date");
-    mapper->addPropertyMapping("ClassicalData::Composition", "year", "bio:date");
+    mapper->addPropertyMapping("ClassicalData::Birth", "year", "dc:date");
+    mapper->addPropertyMapping("ClassicalData::Death", "year", "dc:date");
+    mapper->addPropertyMapping("ClassicalData::Composition", "year", "dc:date");
     mapper->addPropertyMapping("ClassicalData::Birth", "place", "bio:place");
     mapper->addPropertyMapping("ClassicalData::Death", "place", "bio:place");
     mapper->addPropertyMapping("ClassicalData::Composition", "place", "bio:place");
--- a/utilities/composer/composer.cpp	Tue Feb 23 16:37:49 2010 +0000
+++ b/utilities/composer/composer.cpp	Thu Feb 25 18:21:53 2010 +0000
@@ -35,7 +35,7 @@
 
     cerr << "Importing from URL " << url << " ...";
     try {
-	store->import(url, BasicStore::ImportIgnoreDuplicates, "ntriples");
+	store->import(url, BasicStore::ImportPermitDuplicates, "ntriples");
     } catch (RDFException e) {
 	cerr << "failed" << endl;
 	cerr << "Import failed: " << e.what() << endl;