Results 1 to 5 of 5
  1. #1
    panny's Avatar
    panny is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default cosine similarity in search engine

    i want to know how to program a cosine similarity in develop search engine using a java/jsp program :cool:

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,652
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by panny View Post
    i want to know how to program a cosine similarity in develop search engine using a java/jsp program :cool:
    I don't understand your question at all; what does a java program or a jsp page have to do with a cosine? And if they do, wouldn't that be purely coincidental?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    panny's Avatar
    panny is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    how to calculate similarity between a query and documents using java program

    I have a set of documents and i have calculate both

    1)Term -Frequency
    2)Inverse-Frequency
    3)TF/IDF

    Now i need to calculate the similarity between a specific query and a document which will produce a score that will rank the document from the highest similarity to the lowest similarity towards the query.

    Can anyone guide me ? I just need to know how to proceed from my current progress.

    thanks

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,652
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by panny View Post
    Can anyone guide me ? I just need to know how to proceed from my current progress.
    So that cosine is gone now? Show us your progress and maybe we'll be able to help you further.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    panny's Avatar
    panny is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    public class tf_idf {

    public static int numDocs = 0;
    public static int numTerms = 0;
    public static int[][] termFreq;
    public static int[] maxTermFreq;
    public static int[] docFreq;
    public static float[][] termWeight;



    public static void TermWeight()//tf*idf
    {
    for (int i = 0; i < numTerms; i++) {
    for (int j = 0; j < numDocs; j++) {
    termWeight[i][j] = ComputeTermWeight(i, j);
    }
    }

    }

    public static float GetTermFrequency(int term, int doc) {
    int freq = termFreq[term][doc]; //bil kata(term) dalam document(doc).E.g: term=2
    int maxfreq = maxTermFreq[doc]; //jum kata dalam document(doc).e.g:doc=3
    System.out.println("Term Frequency: " + ((float) freq / (float) maxfreq));
    return ((float) freq / (float) maxfreq); // (freq/maxfreq) : (2/3)
    }

    public static float GetInverseDocumentFrequency(int term) {
    int df = docFreq[term];
    System.out.println("Inverse Document Frequency: " + Log((float) (numDocs) / (float) df));
    return Log((float) (numDocs) / (float) df);

    /** numDocs=3 df=1 idf=log(3/1)**/
    }

    public static float Log(float num) {
    return (float) Math.log(num); //ln(num)=loge(num)

    }

    public static float ComputeTermWeight(int term, int doc) {
    System.out.println("term: " + term + "doc: " + doc);
    float tf = GetTermFrequency(term, doc);
    float idf = GetInverseDocumentFrequency(term);
    System.out.println("total weight: " + tf * idf);
    return tf * idf;
    }
    }


    >>really don't have any idea to proceed and solve it. hope anyone can help me :-p

Similar Threads

  1. is Cosine Similarity the Default Similarity in Lucene?
    By sethu.iit@gmail.com in forum Lucene
    Replies: 0
    Last Post: 06-30-2010, 09:49 AM
  2. Search Engine on JSP Page
    By samanthamaryhorgan in forum Advanced Java
    Replies: 0
    Last Post: 02-13-2010, 12:40 PM
  3. simple search engine
    By semoche in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 12-07-2009, 08:41 AM
  4. Search Engine , Web Crawler
    By sahil.ansari in forum Advanced Java
    Replies: 5
    Last Post: 07-21-2008, 01:53 AM
  5. Search Engine
    By SSam Varghese in forum Java Servlet
    Replies: 5
    Last Post: 01-05-2008, 08:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •