java - add items to complicated data-struc `Map<String, Map<String,String>>` -


i have following complex data-structure:

map<string, map<string,string>> url_and_entities = new hashmap<string, map<string,string>>(); 

on inside of loop want populate can't figure out how.

this code, it's series of nested loops make http request determine if share relationship, revealed presence (or absence) of url. i'm trying save url (if exists), , 2 entities evoked it:

for (string entity_1 : q_value_references_for_sentence_entities)  {    (string entity_2 : q_value_references_for_sentence_entities)    {          string url_czech = "http://milenio.dcc.uchile.cl/sparql?default-graph-uri=&query=prefix+%3a+%3chttp%3a%2f%2fwww.wikidata.org%2fentity%2f%3e%0d%0aselect+*+where+%7b%0d%0a+++%3a"                             + entity_1 + "+%3fsimpleproperty+%3a"                             + entity_2 + "%0d%0a%7d%0d%0a&format=text%2fhtml&timeout=0&debug=on";          url wikidata_page = new url(url_czech);         httpurlconnection wiki_connection = (httpurlconnection)wikidata_page.openconnection();         inputstream wikiinputstream = null;          try          {             // try connect , use input stream             wiki_connection.connect();             wikiinputstream = wiki_connection.getinputstream();         }          catch(ioexception error)          {             // failed, try using error stream             wikiinputstream = wiki_connection.geterrorstream();         }         // parse input stream using jsoup         document docx = jsoup.parse(wikiinputstream, null, wikidata_page.getprotocol()+"://"+wikidata_page.gethost()+"/");           elements link_text = docx.select("table.sparql > tbody > tr:nth-child(2) > td > a");         //link_text.text();         (element l : link_text)          {             string output = l.text();             output = output.substring(0, output.length()-1);             list_of_relation_urls.add( output );              url_and_entities.put( output , (entity_1, entity_2));         }     }            } 

i'm not oppoed using crazy google library of wonky data-strucs, i've used before, in case can't see compelling reason why better map<string, map<string,string>>


update

i'm having trouble getting values out. doesn't work seems

string first__english_lang_q = retrieved_entities.getkey(); string second_english_lang_q = retrieved_entities.getvalue();  system.out.println("`(" + value + ")'" + "`( " + entity_1 + ", " + entity_2 + ")'"); 

you need tuple, can use apache common pair

map<string, pair<string,string>> url_and_entities = new hashmap<string, pair<string,string>>();  url_and_entities.put("something", pair.of("left", "right")) url_and_entities.get("something").getleft(); url_and_entities.get("something").getright(); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -