示例#1
0
 def GET(self, id=None, format="json"):
     options = web.input()
     id = id or options.get("entity")
     if id:
         if id.startswith("/"):
             id = id[1:]
         if id.find("%3A") != -1:
             id = ":".join(id.split("%3A"))
         format = options.get("format", format)
         if id.count(":") == 1 and id.split(":")[0] in [
                 'n', 'i', 's', 'f', 'k', 'type', 'col', 'tt'
         ]:
             tagtype = rev_prefixes.get(id.split(":")[0])
             eb = entity_breakdown(id, r)
             eb['eid'] = id
             if format == "html":
                 return render.entity_view(entities={tagtype: eb})
             return simplejson.dumps({tagtype: eb})
         else:
             results = {}
             for tagtype in prefixes:
                 tag = entity_existence(id, tagtype, r)
                 if tag:
                     results[tagtype] = entity_breakdown(tag, r)
                     results[tagtype]['eid'] = tag
             if format == "html":
                 return render.entity_view(entities=results)
             return simplejson.dumps(results)
     else:
         return render.entity_form()
示例#2
0
 def GET(self, id = None, format = "json"):
     options = web.input()
     id = id or options.get("entity")
     if id:
         if id.startswith("/"):
             id = id[1:]
         if id.find("%3A") != -1:
             id = ":".join(id.split("%3A"))
         format = options.get("format", format)
         if id.count(":") == 1 and id.split(":")[0] in ['n','i','s','f','k','type','col','tt']:
             tagtype = rev_prefixes.get(id.split(":")[0])
             eb = entity_breakdown(id, r)
             eb['eid'] = id
             if format == "html":
                 return render.entity_view(entities={tagtype:eb})
             return simplejson.dumps({tagtype:eb})
         else:
             results = {}
             for tagtype in prefixes:
                 tag = entity_existence(id, tagtype, r)
                 if tag:
                     results[tagtype] = entity_breakdown(tag, r)
                     results[tagtype]['eid'] = tag
             if format == "html":
                 return render.entity_view(entities=results)
             return simplejson.dumps(results)
     else:
         return render.entity_form()
示例#3
0
def get_entities_in_pid(pid, r):
  entities = {}
  for entity in (r.smembers("e:%s" % pid) or []):
    label = r.get(entity).decode('utf-8')
    try:
      itemtype = rev_prefixes.get(entity.split(":")[0])
    except:
      itemtype = "Unknown"
    if not entities.has_key(itemtype):
      entities[itemtype] = []
    entities[itemtype].append((label, entity))
  return entities