Beispiel #1
0
def make_matrix(is_positive=True):
  timestamp =  time.time()

  # addresses ids count from 1
  # to make everyone happy, there'll be a 0 entry who says nothing

  M = make_empty_matrix()
  size = M.get_shape()[0]

  respect_category = Statement.get_category_by_name('RESPECT')
  filters =  { 'active' : True,
              'timestamp__lte' : timestamp,
              'category' : respect_category,
              'author__id__lt' : size,
              'subject__id__lt' : size}

  if is_positive:
    filters['value__gt'] = 0.0
  else:
    filters['value__lt'] = 0.0

  for s in Statement.objects.\
      filter(**filters).\
      order_by('subject'):
      M[s.author.id, s.subject.id] = s.value

  return M
Beispiel #2
0
def _make_statement(request):

    # first get the body to make sure this guy is valid
    body = json.loads(request.body)

    expected = [ 'category' ]

    valid, errors = _validate_json(body, expected)
    if not valid:
        return JsonResponse({'success' : False,
                                'errors' : errors })
                                            
    # extract the fields from the body 
    # create the appropriate networks/addresses if needed

    category = body['category']
    subj_network_name = body['author_network']
    auth_name = body['author_name']
    
    s_network, created = Network.objects.get_or_create(name=subj_network_name)
    if created: s_network.save()

    subject, created = Address.objects.get_or_create(name=subj_name,
                                                     network=s_network)
    if created: subject.save()

    s = Statement.create(author, content, subject)
    s.save()

    return JsonResponse({'success' : True,
                           'id' : s.id})
Beispiel #3
0
def _make_statement(request):

    # first get the body to make sure this guy is valid
    body = json.loads(request.body)

    expected = ['category']

    valid, errors = _validate_json(body, expected)
    if not valid:
        return JsonResponse({'success': False, 'errors': errors})

    # extract the fields from the body
    # create the appropriate networks/addresses if needed

    category = body['category']
    subj_network_name = body['author_network']
    auth_name = body['author_name']

    s_network, created = Network.objects.get_or_create(name=subj_network_name)
    if created: s_network.save()

    subject, created = Address.objects.get_or_create(name=subj_name,
                                                     network=s_network)
    if created: subject.save()

    s = Statement.create(author, content, subject)
    s.save()

    return JsonResponse({'success': True, 'id': s.id})
Beispiel #4
0
def make_matrix(is_positive=True):
    timestamp = time.time()

    # addresses ids count from 1
    # to make everyone happy, there'll be a 0 entry who says nothing

    M = make_empty_matrix()
    size = M.get_shape()[0]

    respect_category = Statement.get_category_by_name('RESPECT')
    filters = {
        'active': True,
        'timestamp__lte': timestamp,
        'category': respect_category,
        'author__id__lt': size,
        'subject__id__lt': size
    }

    if is_positive:
        filters['value__gt'] = 0.0
    else:
        filters['value__lt'] = 0.0

    for s in Statement.objects.\
        filter(**filters).\
        order_by('subject'):
        M[s.author.id, s.subject.id] = s.value

    return M
Beispiel #5
0
  def make_it(self):
    explicit_p = matrix.make_matrix() 
    explicit_n = matrix.make_matrix(False) 

    explicit = explicit_p + explicit_n

    res = {}
    res['explicit' ] = explicit.toarray().tolist()

    implied = matrix.make_implied_matrix(levels=4)

    print 'implied is', implied.toarray().tolist()

    size, _ = implied.get_shape()

    implied_list =  implied.toarray().tolist()

    for source, row in zip(xrange(size), implied_list):
      for dest, value in zip(xrange(size), row):
        if value:
          print 'adding satement by %d about %d' % (source, dest)
          Statement.make_implied_statement(source, dest, value)
Beispiel #6
0
    def make_it(self):
        explicit_p = matrix.make_matrix()
        explicit_n = matrix.make_matrix(False)

        explicit = explicit_p + explicit_n

        res = {}
        res['explicit'] = explicit.toarray().tolist()

        implied = matrix.make_implied_matrix(levels=4)

        print 'implied is', implied.toarray().tolist()

        size, _ = implied.get_shape()

        implied_list = implied.toarray().tolist()

        for source, row in zip(xrange(size), implied_list):
            for dest, value in zip(xrange(size), row):
                if value:
                    print 'adding satement by %d about %d' % (source, dest)
                    Statement.make_implied_statement(source, dest, value)