public static void addFigerAnnotationToDocument(Annotation d) throws SQLException {

    List<CoreMap> sentences = d.get(CoreAnnotations.SentencesAnnotation.class);
    Set<String> entityIds = new HashSet<String>();
    for (CoreMap sen : sentences) {
      List<Triple<Pair<Integer, Integer>, String, Float>> nelAnnotation =
          sen.get(NamedEntityLinkingAnnotation.class);
      for (Triple<Pair<Integer, Integer>, String, Float> t : nelAnnotation) {
        String id = t.second;
        if (!id.equals("null")) {
          entityIds.add(id);
        }
      }
    }
    Map<String, Set<String>> idTypeMap = bigQuery(entityIds);
    // add type onto sentences
    for (CoreMap sen : sentences) {
      List<Triple<Pair<Integer, Integer>, String, Float>> nelAnnotation =
          sen.get(NamedEntityLinkingAnnotation.class);
      List<Triple<Set<String>, Integer, Integer>> figerData = new ArrayList<>();
      for (Triple<Pair<Integer, Integer>, String, Float> t : nelAnnotation) {
        Integer start = t.first.first;
        Integer end = t.first.second;
        Set<String> types = null;
        if (!t.second.equals("null")) {
          types = idTypeMap.get(GuidMidConversion.convertBackward(t.second));
        }
        Triple<Set<String>, Integer, Integer> figerTrip = new Triple<>(types, start, end);
        figerData.add(figerTrip);
      }
      sen.set(FigerAnnotation.class, figerData);
    }
  }
 private static void process50ids(Set<String> idSet, Map<String, Set<String>> documentIdTypeMap)
     throws SQLException {
   // process 1000ids
   int j = 1;
   String lastId = null;
   for (String queryId : idSet) {
     lastId = queryId;
     bigTypeQuery.setString(j, GuidMidConversion.convertBackward(queryId));
     j++;
   }
   if (j != 50) {
     while (j <= 50) {
       bigTypeQuery.setString(j, GuidMidConversion.convertBackward(lastId));
       j++;
     }
   }
   ResultSet rs = bigTypeQuery.executeQuery();
   Map<String, Set<String>> guidToFbTypesMap = new HashMap<String, Set<String>>();
   while (rs.next()) {
     String rowId = rs.getString(1);
     String fbType = rs.getString(2);
     if (guidToFbTypesMap.containsKey(rowId)) {
       guidToFbTypesMap.get(rowId).add(fbType);
     } else {
       Set<String> fbTypes = new HashSet<String>();
       fbTypes.add(fbType);
       guidToFbTypesMap.put(rowId, fbTypes);
     }
   }
   for (String guid : guidToFbTypesMap.keySet()) {
     if (!documentIdTypeMap.containsKey(guid)) {
       Set<String> figerTypes = new HashSet<String>();
       Set<String> fbTypes = guidToFbTypesMap.get(guid);
       for (String fbType : fbTypes) {
         String figerType = mapToFigerType(fbType);
         if (figerType != null) {
           //	System.out.println(fbType + " = " + figerType);
           figerTypes.add(figerType);
         }
       }
       documentIdTypeMap.put(guid, figerTypes);
     }
   }
 }
 public static void main(String[] args) {
   init();
   // String fbType = "/government/us_president";
   Set<String> fbTypes = getFreebaseTypesFromID(GuidMidConversion.convertBackward("/m/0269xm9"));
   System.out.println("FB Types:");
   for (String fType : fbTypes) {
     System.out.println(fType);
   }
   close();
 }