示例#1
0
def evalChangeDiversity(request):
    if len(request.GET.keys()) == 0:
        return HttpResponse(status=404)
    if request.GET['search'] is None:
        return HttpResponse(status=404)

    search = request.GET['search'].encode("UTF-8")

    srch = Search.objects.filter(query__exact = search).order_by('searchID').last()
    results = SearchResult.objects.filter(searchID__exact = srch).order_by('rank')
    matrix = [[0 for x in range(results.__len__())] for y in range(results.__len__())]

    firstRes = results.first().resultID
    lastRes = results.last().resultID
    distQ = Distances.objects.filter(firstDoc__resultID__gte = firstRes, firstDoc__resultID__lte = lastRes).order_by('firstDoc', 'secondDoc')
    if distQ is None or distQ.__len__() == 0:
        return HttpResponse(status=404)

    for dist in distQ:
            matrix[dist.firstDoc.resultID-firstRes][dist.secondDoc.resultID-firstRes] = dist.distance
            matrix[dist.secondDoc.resultID-firstRes][dist.firstDoc.resultID-firstRes] = dist.distance

    if request.GET['lambda'] is None:
        lamb = 0.0
    else:
        lamb = float(request.GET['lambda'])
    ranking = Diversity.diversityRanking(matrix, results, lamb)

    ILDMatrix = [[0 for x in range(sizeILD)] for y in range(sizeILD)]

    for i in range(sizeILD):
        for j in range(sizeILD):
            ILDMatrix[i][j] = matrix[ranking[i]-1][ranking[j]-1]

    ild = Diversity.calculateILD(ILDMatrix)

    lnkList = []
    for i in range(results.__len__()):
        result = results[ranking[i]-1]
        lnk = Link()
        lnk.url = result.url
        lnk.title = result.title
        lnk.descr = result.snippet
        lnk.query = search
        lnk.rank = result.rank
        lnk.save = False

        lnkList.append(lnk)

    context = {'serverName' : request.META['SERVER_NAME'], 'serverPort' : request.META['SERVER_PORT'], 'query2': search, 'query': urllib.quote(request.GET['search'].encode("UTF-8")), 'diversityList': lnkList, 'ildDiversity' : ild }
    return render(request, 'evaluation/evalchangediversity.html', context)
示例#2
0
def evaldoDiversity(request):
    if len(request.GET.keys()) == 0:
        return HttpResponse(status=404)
    if request.GET['search'] is None:
        return HttpResponse(status=404)

    search = request.GET['search'].encode("UTF-8")
    ws = Webservice()
    list_result = ws.call_ws_search(search, False, request.META['REMOTE_ADDR'],
                                    request.META['HTTP_USER_AGENT'])

    #Obtaining the results
    url = 'http://localhost:10000/search?query=' + urllib.quote(
        search) + '&clientIP=' + request.META['REMOTE_ADDR'] + '&filter=False'

    srch = Search()
    srch.query = search
    srch.numResults = list_result['search'].__len__()
    srch.save()
    saveL = True

    linkList = list()
    results = list()
    i = 1
    for result in list_result['search']:
        lnk = Link()
        lnk.url = result['url']
        lnk.title = result['title']
        lnk.descr = result['snippet']
        lnk.query = search
        lnk.rank = result['rank']
        linkList.append(lnk)

        lnkres = SearchResult()
        lnkres.url = lnk.url
        lnkres.snippet = lnk.descr
        lnkres.searchID = srch
        lnkres.rank = lnk.rank
        lnkres.title = lnk.title
        lnkres.value = result['value']
        lnkres.save()
        results.append(lnkres)

    matrix = [[0 for x in range(results.__len__())]
              for y in range(results.__len__())]
    url = 'http://localhost:10000/diversity/?query=' + urllib.quote(
        search) + '&clientIP=' + request.META['REMOTE_ADDR'] + '&filter=False'
    list_matrix = ws.call_ws(url, request.META['HTTP_USER_AGENT'])

    for dist in list_matrix['matrix']:
        d = Distances()
        leng = results.__len__()
        rank1 = dist['rank1']
        rank2 = dist['rank2']
        d.firstDoc = results[dist['rank1'] - 1]
        d.secondDoc = results[dist['rank2'] - 1]
        d.distance = dist['distance']
        d.save()
        matrix[dist['rank1'] - 1][dist['rank2'] - 1] = d.distance
        matrix[dist['rank2'] - 1][dist['rank1'] - 1] = d.distance

    ILDMatrix = [[0 for x in range(sizeILD)] for y in range(sizeILD)]
    for i in range(sizeILD):
        for j in range(sizeILD):
            ILDMatrix[i][j] = matrix[i][j]
    #Obtaining the ILD result for both lists (it will be the same in first instance
    ild = Diversity.calculateILD(ILDMatrix)

    context = {
        'serverName': request.META['SERVER_NAME'],
        'serverPort': request.META['SERVER_PORT'],
        'query2': search,
        'query': urllib.quote(search),
        'linkList': linkList,
        'diversityList': linkList,
        'ildRankSym': ild,
        'ildDiversity': ild
    }
    return render(request, 'evaluation/evaldiversity.html', context)
示例#3
0
def evaldoDiversity(request):
    if len(request.GET.keys()) == 0:
        return HttpResponse(status=404)
    if request.GET['search'] is None:
        return HttpResponse(status=404)

    search = request.GET['search'].encode("UTF-8")
    ws = Webservice()
    list_result = ws.call_ws_search(search, False, request.META['REMOTE_ADDR'], request.META['HTTP_USER_AGENT'])

    #Obtaining the results
    url = 'http://localhost:10000/search?query='+urllib.quote(search)+'&clientIP='+request.META['REMOTE_ADDR']+'&filter=False'

    srch = Search()
    srch.query = search
    srch.numResults = list_result['search'].__len__()
    srch.save()
    saveL = True

    linkList = list()
    results = list()
    i = 1
    for result in list_result['search']:
        lnk = Link()
        lnk.url = result['url']
        lnk.title = result['title']
        lnk.descr = result['snippet']
        lnk.query = search
        lnk.rank = result['rank']
        linkList.append(lnk)

        lnkres = SearchResult()
        lnkres.url = lnk.url
        lnkres.snippet = lnk.descr
        lnkres.searchID = srch
        lnkres.rank = lnk.rank
        lnkres.title = lnk.title
        lnkres.value = result['value']
        lnkres.save()
        results.append(lnkres)

    matrix = [[0 for x in range(results.__len__())] for y in range(results.__len__())]
    url = 'http://localhost:10000/diversity/?query='+urllib.quote(search)+'&clientIP='+request.META['REMOTE_ADDR']+'&filter=False'
    list_matrix = ws.call_ws(url, request.META['HTTP_USER_AGENT'])


    for dist in list_matrix['matrix']:
        d = Distances()
        leng = results.__len__()
        rank1 = dist['rank1']
        rank2 = dist['rank2']
        d.firstDoc = results[dist['rank1'] - 1]
        d.secondDoc = results[dist['rank2'] - 1]
        d.distance = dist['distance']
        d.save()
        matrix[dist['rank1'] - 1][dist['rank2'] - 1] = d.distance
        matrix[dist['rank2'] - 1][dist['rank1'] - 1] = d.distance

    ILDMatrix = [[0 for x in range(sizeILD)] for y in range(sizeILD)]
    for i in range(sizeILD):
        for j in range(sizeILD):
            ILDMatrix[i][j] = matrix[i][j]
    #Obtaining the ILD result for both lists (it will be the same in first instance
    ild = Diversity.calculateILD(ILDMatrix)

    context = {'serverName' : request.META['SERVER_NAME'], 'serverPort' : request.META['SERVER_PORT'],'query2': search,  'query': urllib.quote(search), 'linkList': linkList, 'diversityList': linkList, 'ildRankSym' : ild, 'ildDiversity' : ild }
    return render(request, 'evaluation/evaldiversity.html', context)
示例#4
0
def evalChangeDiversity(request):
    if len(request.GET.keys()) == 0:
        return HttpResponse(status=404)
    if request.GET['search'] is None:
        return HttpResponse(status=404)

    search = request.GET['search'].encode("UTF-8")

    srch = Search.objects.filter(
        query__exact=search).order_by('searchID').last()
    results = SearchResult.objects.filter(
        searchID__exact=srch).order_by('rank')
    matrix = [[0 for x in range(results.__len__())]
              for y in range(results.__len__())]

    firstRes = results.first().resultID
    lastRes = results.last().resultID
    distQ = Distances.objects.filter(firstDoc__resultID__gte=firstRes,
                                     firstDoc__resultID__lte=lastRes).order_by(
                                         'firstDoc', 'secondDoc')
    if distQ is None or distQ.__len__() == 0:
        return HttpResponse(status=404)

    for dist in distQ:
        matrix[dist.firstDoc.resultID - firstRes][dist.secondDoc.resultID -
                                                  firstRes] = dist.distance
        matrix[dist.secondDoc.resultID - firstRes][dist.firstDoc.resultID -
                                                   firstRes] = dist.distance

    if request.GET['lambda'] is None:
        lamb = 0.0
    else:
        lamb = float(request.GET['lambda'])
    ranking = Diversity.diversityRanking(matrix, results, lamb)

    ILDMatrix = [[0 for x in range(sizeILD)] for y in range(sizeILD)]

    for i in range(sizeILD):
        for j in range(sizeILD):
            ILDMatrix[i][j] = matrix[ranking[i] - 1][ranking[j] - 1]

    ild = Diversity.calculateILD(ILDMatrix)

    lnkList = []
    for i in range(results.__len__()):
        result = results[ranking[i] - 1]
        lnk = Link()
        lnk.url = result.url
        lnk.title = result.title
        lnk.descr = result.snippet
        lnk.query = search
        lnk.rank = result.rank
        lnk.save = False

        lnkList.append(lnk)

    context = {
        'serverName': request.META['SERVER_NAME'],
        'serverPort': request.META['SERVER_PORT'],
        'query2': search,
        'query': urllib.quote(request.GET['search'].encode("UTF-8")),
        'diversityList': lnkList,
        'ildDiversity': ild
    }
    return render(request, 'evaluation/evalchangediversity.html', context)