From 150f059522f5692db19c27cb9584d7f1dcabe01b Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Wed, 25 May 2011 00:17:43 +0200 Subject: [PATCH 1/2] implement JSON and YAML containers --- sloth/annotations/container.py | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/sloth/annotations/container.py b/sloth/annotations/container.py index 84daec5..9235013 100644 --- a/sloth/annotations/container.py +++ b/sloth/annotations/container.py @@ -6,6 +6,14 @@ try: import cPickle as pickle except: import pickle +try: + import json +except: + pass +try: + import yaml +except: + pass class AnnotationContainerFactory: def __init__(self, containers): @@ -119,6 +127,36 @@ class PickleContainer(AnnotationContainer): pickle.dump(self.annotations(), f) self.filename_ = fname +class JSONContainer(AnnotationContainer): + """ + Simple container which writes the annotations to disk in JSON format. + """ + + def load(self, fname): + f = open(fname, "r") + self.annotations_ = json.load(f) + self.filename_ = fname + + def save(self, fname): + f = open(fname, "w") + json.dump(self.annotations(), f, indent=4) + self.filename_ = fname + +class YAMLContainer(AnnotationContainer): + """ + Simple container which writes the annotations to disk in YAML format. + """ + + def load(self, fname): + f = open(fname, "r") + self.annotations_ = yaml.load(f) + self.filename_ = fname + + def save(self, fname): + f = open(fname, "w") + yaml.dump(self.annotations(), f, indent=4) + self.filename_ = fname + class FeretContainer(AnnotationContainer): """ Container for Feret labels. From ae1fbecc661ad5dc1f34e1522932761d219e1beb Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Wed, 25 May 2011 00:20:14 +0200 Subject: [PATCH 2/2] add json and yaml containers to default config --- sloth/conf/default_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sloth/conf/default_config.py b/sloth/conf/default_config.py index c90e284..83ce800 100644 --- a/sloth/conf/default_config.py +++ b/sloth/conf/default_config.py @@ -15,6 +15,8 @@ INSERTERS = { } CONTAINERS = ( + ('*.json': 'sloth.annotations.container.JSONContainer'), + ('*.yaml': 'sloth.annotations.container.YAMLContainer'), ) PLUGINS = (