Mercurial > hg > classical
changeset 42:add3570c6035
* Add new "write" option to composer utility
* Default year transcodes to empty string instead of zero
author | Chris Cannam |
---|---|
date | Tue, 20 Apr 2010 15:21:32 +0100 |
parents | a42493a3baf8 |
children | a3f731205168 |
files | common/Objects.h utilities/composer/composer.cpp utilities/widgettest/widgettest.cpp |
diffstat | 3 files changed, 33 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/common/Objects.h Fri Apr 09 16:19:50 2010 +0100 +++ b/common/Objects.h Tue Apr 20 15:21:32 2010 +0100 @@ -35,10 +35,13 @@ struct Encoder : public Dataquay::Node::VariantEncoder { QString fromVariant(const QVariant &v) { - QString s = QString("%1").arg(v.value<Year>().toInt()); + int y = v.value<Year>().toInt(); + if (y == 0) return ""; + QString s = QString("%1").arg(y); return s; } QVariant toVariant(const QString &s) { + if (s == "") return QVariant::fromValue<Year>(Year()); QVariant v = QVariant::fromValue<Year>(s.toInt()); return v; }
--- a/utilities/composer/composer.cpp Fri Apr 09 16:19:50 2010 +0100 +++ b/utilities/composer/composer.cpp Tue Apr 20 15:21:32 2010 +0100 @@ -68,6 +68,7 @@ cerr << " " << name << " <input-rdf-file> search <text>" << endl; cerr << " " << name << " <input-rdf-file> match <text>" << endl; cerr << " " << name << " <input-rdf-file> merge <target-uri> <dup> [<dup> ...]" << endl; + cerr << " " << name << " <input-rdf-file> write" << endl; exit(-1); } @@ -331,9 +332,11 @@ delete loader; - bool write = false; + bool write = false, writeFull = false; if (command == "merge") { write = true; + } else if (command == "write") { + writeFull = true; } TransactionalStore *ts = 0; @@ -367,7 +370,9 @@ } } - if (command == "list") { + if (command == "write") { + if (!args.empty()) usage(argv[0]); + } else if (command == "list") { if (!args.empty()) usage(argv[0]); listBrief(allComposers); } else if (command == "list-uris") { @@ -402,24 +407,6 @@ } if (write) { -/* - ObjectStorer *storer = new ObjectStorer(store); - - storer->setTypeMapping(tm); - - storer->setPropertyStorePolicy(ObjectStorer::StoreIfChanged); -// storer->setObjectStorePolicy(ObjectStorer::StoreAllObjects); - storer->setBlankNodePolicy(ObjectStorer::NoBlankNodes); - - cerr << "Mapping results back to store..."; -// storer->storeAllObjects(root->children()); -// storer->setFollowPolicy(ObjectStorer::FollowAll); - storer->setFollowPolicy(ObjectStorer::FollowObjectProperties); - storer->store(objects); - cerr << " done" << endl; - - delete storer; -*/ cerr << "Committing changes..."; mapper->commit(); @@ -428,6 +415,26 @@ cerr << "Saving to file out.ttl..."; store->save("out.ttl"); cerr << " done" << endl; + + } else if (writeFull) { + + ObjectStorer *storer = new ObjectStorer(store); + + storer->setTypeMapping(tm); + + storer->setPropertyStorePolicy(ObjectStorer::StoreIfChanged); + storer->setBlankNodePolicy(ObjectStorer::NoBlankNodes); + + cerr << "Mapping results back to store..."; + storer->setFollowPolicy(ObjectStorer::FollowObjectProperties); + storer->store(objects); + cerr << " done" << endl; + + cerr << "Saving to file out.ttl..."; + store->save("out.ttl"); + cerr << " done" << endl; + + delete storer; } delete mapper;
--- a/utilities/widgettest/widgettest.cpp Fri Apr 09 16:19:50 2010 +0100 +++ b/utilities/widgettest/widgettest.cpp Tue Apr 20 15:21:32 2010 +0100 @@ -1,5 +1,7 @@ /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ +#include <dataquay/Uri.h> + #include "TypingSelectWidget.h" #include "TypeRegistrar.h" #include "Objects.h" @@ -7,7 +9,6 @@ #include <dataquay/BasicStore.h> #include <dataquay/Debug.h> -#include <dataquay/Uri.h> #include <dataquay/RDFException.h> #include <dataquay/objectmapper/ObjectLoader.h> #include <dataquay/objectmapper/TypeMapping.h>