package com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers;

import com.grayben.riskExtractor.htmlScorer.partScorers.TagAndAttribute;
import org.jsoup.nodes.Attribute;
import org.jsoup.parser.Tag;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class TagAndAttributeScorer
		extends MapScorer<TagAndAttribute> {

    public final static String SCORE_LABEL
            = "tag-and-attribute-emphasis";

    public TagAndAttributeScorer(Map<TagAndAttribute, Integer> tagScores) {
        super(SCORE_LABEL, tagScores);
    }

    @Override
	public int score(TagAndAttribute input) {
        validateScoreInput(input);
		return super.score(input);
	}

    private void validateScoreInput(TagAndAttribute input){
        if(input == null){
            throw new NullPointerException(
                    "The input cannot be null"
            );
        }
        if (input.getAttribute() == null){
            throw new NullPointerException(
                    "The input cannot have null Attribute"
            );
        }
        if (input.getTag() == null){
            throw new NullPointerException(
                    "The input cannot have null Tag"
            );
        }
        if(input.getAttribute().getKey().isEmpty()){
            throw new IllegalArgumentException(
                    "The input cannot have an empty Attribute"
            );
        }
        if(input.getTag().getName().isEmpty()){
            throw new IllegalArgumentException(
                    "The input cannot have an empty Tag"
            );
        }
    }

	public static final Map<TagAndAttribute, Integer> defaultMap() {

        String[] tagNames = {"font", "div", "p"};
        Set<Tag> tags = new HashSet<>();
        for (String tagName: tagNames) {
            tags.add(Tag.valueOf(tagName));
        }

        Set<Attribute> attributes = new HashSet<>();
        attributes.add(new Attribute("style", "bold"));
        attributes.add(new Attribute("style", "underline"));

        Set<TagAndAttribute> tagAndAttributes = new HashSet<>();
        for (Tag tag: tags)
            for (Attribute attribute : attributes)
                tagAndAttributes.add(
                        new TagAndAttribute(
                                tag,
                                attribute
                        )
                );

        Map<TagAndAttribute, Integer> scoresMap = new HashMap<>();
        for (TagAndAttribute tagAndAttribute : tagAndAttributes) {
            scoresMap.put(tagAndAttribute, 1);
        }

        return scoresMap;

	}


}

@@ -63,16 +63,80 @@
 orers;%0A%0A
+import com.grayben.riskExtractor.htmlScorer.partScorers.Scorer;%0A
 import c
@@ -361,16 +361,104 @@
 l.Set;%0A%0A
+/**%0A * Scores %7B@link TagAndAttribute%7D objects.%0A * %3Cp%3E%0A * Created by Ben Gray, 2015.%0A */%0A
 public c
@@ -483,19 +483,17 @@
 teScorer
-%0A%09%09
+ 
 extends 
@@ -518,24 +518,173 @@
 tribute%3E %7B%0A%0A
+    /**%0A     * The string (uniquely) labelling this class.%0A     * %3Cp%3E%0A     * Used to identify this class in a collection of %7B@link Scorer%7Ds.%0A     */%0A
     public f
@@ -713,28 +713,16 @@
 RE_LABEL
-%0A           
  = %22tag-
@@ -755,125 +755,407 @@
     
-public TagAndAttributeScorer(Map%3CTagAndAttribute, Integer%3E tagScores) %7B%0A        super(SCORE_LABEL, tagScores);%0A    %7D%0A
+/**%0A     * Construct with the specified map.%0A     * @param tagScores the map with which to construct this instance.%0A     */%0A    public TagAndAttributeScorer(Map%3CTagAndAttribute, Integer%3E tagScores) %7B%0A        super(SCORE_LABEL, tagScores);%0A    %7D%0A%0A    /**%0A     * Use the underlying %7B@link MapScorer%7D to score the specified input.%0A     * @param input the input to score%0A     * @return the score%0A     */
 %0A   
@@ -1276,16 +1276,74 @@
 t);%0A%09%7D%0A%0A
+    /**%0A     * @param input the input to validate%0A     */%0A
     priv
@@ -2241,16 +2241,84 @@
 %0A    %7D%0A%0A
+    /**%0A     * @return the default score map for this class%0A     */%0A
 %09public 
@@ -2324,22 +2324,16 @@
  static 
-final 
 Map%3CTagA
@@ -2453,32 +2453,104 @@
 ew HashSet%3C%3E();%0A
+        /**%0A         * %7B@link tags%7D := (%22font%22, %22div%22, %22p%22)%0A         */%0A
         for (Str
@@ -2674,32 +2674,133 @@
 ew HashSet%3C%3E();%0A
+        /**%0A         * %7B@link attributes%7D := (%22style%22 =%3E %22bold%22, %22style%22 =%3E %22underline%22)%0A         */%0A
         attribut
@@ -2958,32 +2958,146 @@
 ew HashSet%3C%3E();%0A
+        /**%0A         * %7B@link tagAndAttributes%7D := cartesianProduct(%7B@link tags%7D, %7B@link attributes%7D)%0A         */%0A
         for (Tag
@@ -3589,12 +3589,10 @@
 ap;%0A%0A%09%7D%0A
-%0A%0A
 %7D%0A

Document TagAndAttributeScorer