Guest User

Untitled

a guest
Feb 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. HashMap<String, HashMap<Integer,String>> canlist =
  2. new HashMap<String, HashMap<Integer,String>>();
  3.  
  4. for (String key : entityKey)
  5. {
  6. HashMap<Integer, String> clkey = new HashMap<Integer, String>();
  7. int f=0;
  8. for (String val :mentionKey)
  9. {
  10. //do something
  11. simiscore = (longerLength - costs[m.length()]) / (double) longerLength;
  12.  
  13. if (simiscore > 0.6) {
  14. clkey.put(v1,val);
  15. System.out.print(
  16. " The mention " + val + " added to link entity " + key);
  17. }
  18. f++;
  19. System.out.println("Scan Completed");
  20. }
  21. canlist.put(key,clkey);
  22. JavaPairRDD<String, HashMap<Integer, String>> rad;
  23. rad = context.parallelize(scala.collection.Seq(toScalaMap(canlist)));
  24.  
  25. }
  26. public static <String,Object> Map<String,Object> toScalaMap(HashMap<String,Object> m) {
  27. return (Map<String,Object>) JavaConverters.mapAsScalaMapConverter(m).asScala().toMap(
  28. Predef.<Tuple2<String,Object>>conforms()
  29. );}
  30. }
  31.  
  32. import scala.Tuple2;
  33.  
  34. List<Tuple2<String, HashMap<Integer,String>>> list = new ArrayList<Tuple2<String, HashMap<Integer,String>>>();
  35. for(Map.Entry<String, HashMap<Integer,String>> entry : canlist.entrySet()){
  36. list1.add(new Tuple2<String, HashMap<Integer,String>>(entry.getKey(),entry.getValue()));
  37. }
  38.  
  39. JavaPairRDD<String, HashMap<Integer, String>> javaPairRdd = jsc.parallelizePairs(list);
  40.  
  41. //fromMapToListTuple2() generic method to convert Map<T1, T2> to List<Tuple2<T1, T2>>
  42. public static <T1, T2> List<Tuple2<T1, T2>> fromMapToListTuple2(Map<T1, T2> map)
  43. {
  44. //list of tuples
  45. List<Tuple2<T1, T2>> list = new ArrayList<Tuple2<T1, T2>>();
  46.  
  47. //loop through all key-value pairs add them to the list
  48. for(T1 key : map.keySet())
  49. {
  50. //get the value
  51. T2 value = map.get(key);
  52.  
  53. //Tuple2 is not a collection, but a single tuple => single k-v pair;
  54. Tuple2<T1, T2> tuple2 = new Tuple2<T1, T2>(key, value);
  55.  
  56. //populate the list with created tupple2
  57. list.add(tuple2);
  58. } // for
  59.  
  60. return list;
  61. } // fromMapToListTuple2
Add Comment
Please, Sign In to add comment