java - How can i store the frequency of the tags in any website page in Hashmap? -


i using paired hashmap in storing tags , frequency confused how can store frequency in variable. code follows :

package z; import java.awt.list; import java.io.ioexception; import java.util.arraylist; import java.util.hashmap; import java.util.hashset;  import org.jsoup.jsoup; import org.jsoup.nodes.document; import org.jsoup.select.collector; import org.jsoup.select.elements; import org.jsoup.select.evaluator; import org.jsoup.nodes.element;   public class crawler {      static string url="";          public static void main(string[] args) {             int val=0;             string url = "http://stackoverflow.com/";             hashmap<integer, string> mymap = new hashmap<integer, string>();             mymap.clear();               try {                 document document = jsoup.connect(url).get();                 arraylist<string> tags = new arraylist<string>();                  system.out.println("number of tags select(\"*\") method =" + document.select("*").size());                 for(element e : document.getallelements()){                     tags.add(e.tagname().tolowercase());                     mymap.put(val,tags.tostring());                     val++;                 }                 system.out.println("the tags = " + tags);                 system.out.println("distinct tags = " + new hashset<string>(tags));                 system.out.println("distinct tags = " + mymap);             } catch (ioexception e) {                system.out.println(e);             }        }   } 

how can increment value of val can store frequency of tags? need more 1 variable?

i'd suggest use tag key, not frequency. loop this

string tagn; for(element e : document.getallelements()){     tagn = tagname().tolowercase();     val = 1;     if(tags.contains(tagn){         val+ = tags.get(tagn);     }      tags.put(tagn, val); } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -