summaryrefslogtreecommitdiff
path: root/freebase/api
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/api
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/api')
-rw-r--r--freebase/api/session.py96
1 files changed, 2 insertions, 94 deletions
diff --git a/freebase/api/session.py b/freebase/api/session.py
index 7c6b98b..5d3b6a0 100644
--- a/freebase/api/session.py
+++ b/freebase/api/session.py
@@ -860,7 +860,8 @@ class HTTPMetawebSession(MetawebSession):
"""DEPRECATED: reconcile name to guid. For a more complete description,
see http://www.freebase.com/view/en/dataserver_reconciliation
- If interested, check out http://data.labs.freebase.com/recon/"""
+ If interested in a non-deprecated version,
+ check out http://data.labs.freebase.com/recon/"""
service = '/dataserver/reconciliation'
r = self._httpreq_json(service, 'GET', form={'name':name, 'types':','.join(etype)})
@@ -870,99 +871,6 @@ class HTTPMetawebSession(MetawebSession):
#self._mqlresult(r)
return r
- ### SCHEMA MANIPULATION ###
- # Object helpers
- def create_object(self, name="", path=None, key=None, namespace=None,
- included_types=None, create="unless_exists",
- extra=None, use_permission_of=None, attribution=None):
- if type(included_types) is str:
- included_types = [included_types]
-
- if path and (key or namespace):
- raise ValueError("You can't specify both the path and a key and namespace.")
-
- if path:
- key, namespace = get_key_namespace(path)
-
- if (key and not namespace) or (not key and namespace):
- raise ValueError("You must either specify both a key and a namespace, or neither.")
-
- if included_types:
- its = set(included_types)
- q = [{
- "id|=" : included_types,
- "/freebase/type_hints/included_types" : [{"id" : None}]
- }]
- for res in self.mqlread(q):
- its.update([x["id"] for x in res["/freebase/type_hints/included_types"]])
-
- wq = {
- "id" : None,
- "name" : name,
- "create" : create
- }
-
- # conditionally add key creation
- if key:
- wq.update({"key" : {
- "namespace" : namespace,
- "value" : key,
- }})
-
- if included_types:
- wq.update(type = [{ "id" : it, "connect" : "insert" } for it in its])
-
- if extra:
- wq.update(extra)
-
- return self.mqlwrite(wq, use_permission_of=use_permission_of, attribution_id=attribution)
-
-
- def connect_object(self, id, newpath, extra=None, use_permission_of=None, attribution=None):
-
- key, namespace = get_key_namespace(newpath)
-
- wq = {
- "id" : id,
- "key" : {
- "namespace" : namespace,
- "value" : key,
- "connect" : "insert"
- }
- }
-
- if extra: wq.update(extra)
-
- return self.mqlwrite(wq, use_permission_of=use_permission_of, attribution_id=attribution)
-
-
- def disconnect_object(self, id, extra=None, use_permission_of=None, attribution=None):
-
- key, namespace = get_key_namespace(id)
-
- wq = {
- "id" : id,
- "key" : {
- "namespace" : namespace,
- "value" : key,
- "connect" : "delete"
- }
- }
- if extra: wq.update(extra)
- return self.mqlwrite(wq, use_permission_of=use_permission_of, attribution_id=attribution)
-
- def move_object(self, oldpath, newpath, use_permission_of=None, attribution=None):
- a = self.connect_object(oldpath, newpath, use_permission_of=use_permission_of, attribution=attribution)
- b = self.disconnect_object(oldpath, use_permission_of=use_permission_of, attribution=attribution)
- return a, b
-
-
-
-def get_key_namespace(path):
- # be careful with /common
- namespace, key = path.rsplit("/", 1)
- return (key, namespace or "/")
-
if __name__ == '__main__':
console = logging.StreamHandler()