package dataObjects;

import utilities.TermExtractor;

import java.util.HashMap;

/**
 * Created by Thagus on 03/09/16.
 * Purpose: Store the document data
 */
public class Document implements Comparable<Document>{
    private String url;
    private String title;
    private String text;

    private double similarity;

    public Document(String url){
        this.url = url;
        this.similarity = 0;
    }

    public Document(String url, String title, String text) {
        this.url = url;
        this.title = title;
        this.text = text;
        this.similarity = 0;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    public void setText(String text) {
        this.text = text;
    }
    public void setSimilarity(double similarity) {
        this.similarity = similarity;
    }

    /****************
     *  Getters     *
     ****************/
    public String getUrl() { return url; }
    public String getTitle() {
        return title;
    }
    public String getText() {
        return text;
    }
    public double getSimilarity() {
        return similarity;
    }

    /**
     * Count the terms contained in the document, and add those terms to a global list of terms
     * @return The HashMap containing the terms and their TF
     */
    public HashMap<String, Integer> countWords(){
        return TermExtractor.extractTerms(this.text);
    }

    /**
     * Compare two Documents
     * @param o The document to compare to
     * @return 0 if they are equal, -1 if this document is smaller, 1 if its bigger in similarity
     */
    @Override
    public int compareTo(Document o) {
        if(this.similarity == o.similarity)
            return 0;
        else if (this.similarity<o.similarity)
            return -1;
        else
            return 1;
    }
}

@@ -502,34 +502,31 @@
         
-this.t
+setT
 itle
- = 
+(
 title
+)
 ;%0A      
@@ -527,32 +527,29 @@
         
-this.text = 
+setText(
 text
+)
 ;%0A      
@@ -712,24 +712,48 @@
 .text = text
+.replaceAll(%22%5C%5Cs+%22, %22 %22)
 ;%0A    %7D%0A    

Replace excessively long spaces with only one