summaryrefslogtreecommitdiff
path: root/freebase/fcl/schema.py
diff options
context:
space:
mode:
authornitromaster101@gmail.com <nitromaster101@gmail.com@5914aa95-5b3a-0410-a3b5-7b719e7fe9b2>2009-07-22 18:45:54 +0000
committernitromaster101@gmail.com <nitromaster101@gmail.com@5914aa95-5b3a-0410-a3b5-7b719e7fe9b2>2009-07-22 18:45:54 +0000
commitbc7d69f0956d1a66ffc9d3f4b645f6419e847331 (patch)
treea3b99784e9c3016b972e13bba07c90128fd6de32 /freebase/fcl/schema.py
parent605b7096f3fbbe7cf000d7464e480d66fee3aa42 (diff)
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
Diffstat (limited to 'freebase/fcl/schema.py')
-rw-r--r--freebase/fcl/schema.py41
1 files changed, 41 insertions, 0 deletions
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)
+