final Node node(int weight, int count, Node tail) { Node result = nodes[nextNode++]; result.weight = weight; result.count = count; result.tail = tail; return result; }
/** * This is exactly as Head Insertion of a Linked List. We choose Head Insertion to get an O(1) * Insertion into an Adjacency List, Tail Insertion can also be used * * @param head * @param value * @return */ private static Node insert(Node head, int value, int weight) { Node p = new DijsktraAlgo().new Node(); p.value = value; p.next = head; p.visited = false; p.weight = weight; return p; }
/** * the array weights should have a weight for each document ID, that is weights[docID] is the * weight for docID * * @param weights */ public void genericWeight(double[] weights) { Node temp = head; while (temp != null) { temp.weight *= weights[temp.docID]; temp = temp.next(); } }
/** Apply log frequency normalization to this postings list */ public void logNormalizeTermFrequencies() { Node temp = head; while (temp != null) { temp.weight = 1 + Math.log(temp.weight); temp = temp.next(); } }
/** multiply all of the weights by log(number_of_docs/number_of_docs_with_this_term) */ public void idfWeight(int numDocs) { double idfWeight = Math.log((double) numDocs / occurrences); Node temp = head; while (temp != null) { temp.weight *= idfWeight; temp = temp.next(); } }
/** Apply boolean term normalization to this postings list */ public void booleanNormalizeTermFrequencies() { Node temp = head; while (temp != null) { if (temp.weight > 0) { temp.weight = 1; } temp = temp.next(); } }
/** * Since this is for boolean queries, the score should be 1.0 for all documents that are in this * posting list */ public double[] getScores() { if (head == null) { return null; } else { double[] scores = new double[occurrences]; Node temp = head; int i = 0; while (temp != null) { scores[i] = temp.weight(); temp = temp.next(); i++; } return scores; } }