Beispiel #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()
Beispiel #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()
      print "Generating geo charts"
      gen_charts = True
    else:
      phrase_tokens.append(argv)

  phrase = " ".join(phrase_tokens)

  if phrase in prefixes:
    if csvfile:
      save_set(phrase, r, limit, startswith, csvfile, verbose=True)
    else:
      print_browse_set(phrase, r, limit, startswith)
  elif phrase.count(":") == 1:
    if phrase.startswith("uuid") or phrase.startswith("ora"):
      print_item_stats(phrase, r, gen_charts)
    else:
      print_entity_report(phrase, r, gen_charts)
  else:
    print "Trying to find freetext %s" % phrase
    for tagtype in prefixes:
      tag = entity_existence(phrase, tagtype, r)
      if tag  and (limit == 0 or combined_count(r.get("t:views:%s" % tag), r.get("t:dls:%s" % tag)) > limit):
        print "Found %s (type: %s) for %s" % (tag, tagtype, phrase)
        print "Views: %s, Downloads: %s, Other: %s" % (r.get("t:views:%s" % tag), r.get("t:dls:%s" % tag), r.get("t:other:%s" % tag))
        print "Entity %s(in %s) found in the following items" % (phrase, tagtype)
        for pid in (r.smembers("e:%s" % tag) or []):
          print '"%s" - %s' % (titlelookup(pid), pid)
          if gen_charts:
            print "Geo-breakdown (yellow -> red) %s" % get_gchart_map_for_pid(pid, r)
        print "------------------------------------------------------"