close

  
<p> function get_params() {
  var params = {};
  for (var p in acre.request.params) {
    params[p] = acre.request.params[p];
  }
  for (var p in acre.request.body_params) {
    params[p] = acre.request.body_params[p];
  }
  return params;
}

function get_query(params) {
  var q = acre.require("any_master");
  
  // note that user and group are mutually exclusive
  var ext = {};
  if (params.user) {
    ext["creator.id"] = params.user;
  } else if (params.group) {
    ext["creator.usergroup.id"] = params.group;
  } 
  
  // same with id and url -- mututally exclusive
  if (params.id) {
    ext["source.id"] = params.id;
  } else if (params.url) {
    var fields = params.url.split("/");
    var key = fields[fields.length - 1];
    ext["source.key.value"] = key;
  }
  return q.extend(ext).query;
}

function get_cvt(id, exclude) {
  var doc = acre.freebase.get_topic(id, {});
  var props = doc['properties'];
  var tuple = [];
  for (i in props) {
    var name = props[i]['values'][0]['text'];
    if (name != exclude) {
      tuple.push(name);  
    } 
  }
  return "(" + tuple.join(" : ") + ")";
}

function format_timestamp(timestamp) {
  var fields = timestamp.split('T');
  return fields[0];
}

function get_links(q, cursor) {
  var r = acre.freebase.mqlread(q, {cursor:cursor});
  var links = [];
  console.log(r);
  r.results.forEach(function(res) {
    var link = {};
    link.mid = res['source']['mid'];
    link.name = res['source']['name'];
    link.wpkey = res['source']['key'][0]['value'];

    link.prop = res['master_property']['name'];
    link.timestamp = format_timestamp(res['timestamp']);

    link.target_id = res['target']['mid'];
    link.target_wpkey = null;
    link.mediatorType = null;
    for (i in res['target']['type']) {
      var x = res['target']['type'][i];
      if (x['/freebase/type_hints/mediator']) {
        link.mediatorType = x['id'];
        break; 
      } 
    }

    link.target = res['target_value'];
    if (!link.target &amp;&amp; mediatorType !== null) {
      link.target = get_cvt(link.target_id, link.name);
    } else {
      link.target = res['target']['name'];
    }
    links.push(link);
  });
  return r;
}

 </p>

Comments

Hide