From bc7d69f0956d1a66ffc9d3f4b645f6419e847331 Mon Sep 17 00:00:00 2001 From: "nitromaster101@gmail.com" Date: Wed, 22 Jul 2009 18:45:54 +0000 Subject: cleanup, incorporate changes from code review, and move merge and split stuff into freebase.experimental git-svn-id: http://freebase-python.googlecode.com/svn/trunk@201 5914aa95-5b3a-0410-a3b5-7b719e7fe9b2 --- freebase/fcl/schema.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 freebase/fcl/schema.py (limited to 'freebase/fcl/schema.py') diff --git a/freebase/fcl/schema.py b/freebase/fcl/schema.py new file mode 100644 index 0000000..47eb1fa --- /dev/null +++ b/freebase/fcl/schema.py @@ -0,0 +1,41 @@ +from freebase.schema import dump_base, dump_type, restore + +try: + import jsonlib2 as json +except ImportError: + try: + import simplejson as json + except ImportError: + import json + +import sys + +def cmd_dump_base(fb, baseid): + """dump a base to stdout + %prog dump_base baseid + + Dump a base by outputting a json representation + of the types and properties involved. + """ + print >> sys.stdout, json.dumps(dump_base(fb.mss, baseid), indent=2) + +def cmd_dump_type(fb, baseid, follow_types=True): + """dump a type to stdout + %prog dump_type typeid [follow_types=True] + + Dump a type by outputting a json representation + of the type and properties involved. + """ + print >> sys.stdout, json.dumps(dump_type(fb.mss, typeid, follow_types), indent=2) + +def cmd_restore(fb, newlocation, graphfile): + """restore a graph object to the graph + %prog restore newlocation graphfile + + Restore a graph object to the newlocation + """ + fh = open(graphfile, "r") + graph = json.loads(fh.read()) + fh.close() + return restore(fb.mss, graph, newlocation, ignore_types=None) + -- cgit v1.3.1