private DataStore<DBIDs> loadNeighbors(Database database,Relation<?> relation){
  final WritableDataStore<DBIDs> store=DataStoreUtil.makeStorage(relation.getDBIDs(),DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC | DataStoreFactory.HINT_TEMP,DBIDs.class);
  if (LOG.isVerbose()) {
    LOG.verbose("Loading external neighborhoods.");
  }
  if (LOG.isDebugging()) {
    LOG.verbose("Building reverse label index...");
  }
  Map<String,DBID> lblmap=new HashMap<>(relation.size() << 1);
{
    Relation<LabelList> olq=database.getRelation(TypeUtil.LABELLIST);
    Relation<ExternalID> eidq=database.getRelation(TypeUtil.EXTERNALID);
    for (DBIDIter iditer=relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
      if (eidq != null) {
        ExternalID eid=eidq.get(iditer);
        if (eid != null) {
          lblmap.put(eid.toString(),DBIDUtil.deref(iditer));
        }
      }
      if (olq != null) {
        LabelList label=olq.get(iditer);
        if (label != null) {
          for (int i=0; i < label.size(); i++) {
            lblmap.put(label.get(i),DBIDUtil.deref(iditer));
          }
        }
      }
    }
  }
  if (LOG.isDebugging()) {
    LOG.verbose("Loading neighborhood file.");
  }
  try (InputStream in=FileUtil.tryGzipInput(new FileInputStream(file));BufferedReader br=new BufferedReader(new InputStreamReader(in))){
    for (String line; (line=br.readLine()) != null; ) {
      ArrayModifiableDBIDs neighbours=DBIDUtil.newArray();
      String[] entries=line.split(" ");
      DBID id=lblmap.get(entries[0]);
      if (id != null) {
        for (int i=0; i < entries.length; i++) {
          final DBID neigh=lblmap.get(entries[i]);
          if (neigh != null) {
            neighbours.add(neigh);
          }
 else {
            if (LOG.isDebugging()) {
              LOG.debug("No object found for label " + entries[i]);
            }
          }
        }
        store.put(id,neighbours);
      }
 else {
        if (LOG.isDebugging()) {
          LOG.warning("No object found for label " + entries[0]);
        }
      }
    }
    return store;
  }
 catch (  IOException e) {
    throw new AbortException("Loading of external neighborhood failed.",e);
  }
}

private DataStore < DBIDs > loadNeighbors ( Database database , Relation < ? > relation ) { final WritableDataStore < DBIDs > store = DataStoreUtil . makeStorage ( relation . getDBIDs ( ) , DataStoreFactory . HINT_HOT | DataStoreFactory . HINT_STATIC | DataStoreFactory . HINT_TEMP , DBIDs . class ) ; if ( LOG . isVerbose ( ) ) { LOG . verbose ( "Loading external neighborhoods." ) ; } if ( LOG . isDebugging ( ) ) { LOG . verbose ( "Building reverse label index..." ) ; } Map < String , DBID > lblmap = new HashMap < > ( relation . size ( ) << 1 ) ; { Relation < LabelList > olq = database . getRelation ( TypeUtil . LABELLIST ) ; Relation < ExternalID > eidq = database . getRelation ( TypeUtil . EXTERNALID ) ; for ( DBIDIter iditer = relation . iterDBIDs ( ) ; iditer . valid ( ) ; iditer . advance ( ) ) { if ( eidq != null ) { ExternalID eid = eidq . get ( iditer ) ; if ( eid != null ) { lblmap . put ( eid . toString ( ) , DBIDUtil . deref ( iditer ) ) ; } } if ( olq != null ) { LabelList label = olq . get ( iditer ) ; if ( label != null ) { for ( int i = 0 ; i < label . size ( ) ; i ++ ) { lblmap . put ( label . get ( i ) , DBIDUtil . deref ( iditer ) ) ; } } } } } if ( LOG . isDebugging ( ) ) { LOG . verbose ( "Loading neighborhood file." ) ; } try ( InputStream in = FileUtil . tryGzipInput ( new FileInputStream ( file ) ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ) { for ( String line ; ( line = br . readLine ( ) ) != null ; ) { ArrayModifiableDBIDs neighbours = DBIDUtil . newArray ( ) ; String [ ] entries = line . split ( " " ) ; DBID id = lblmap . get ( entries [ 0 ] ) ; if ( id != null ) { for ( int i = 0 ; i < entries . length ; i ++ ) { final DBID neigh = lblmap . get ( entries [ i ] ) ; if ( neigh != null ) { neighbours . add ( neigh ) ; } else { if ( LOG . isDebugging ( ) ) { LOG . debug ( "No object found for label " + entries [ i ] ) ; } } } store . put ( id , neighbours ) ; } else { if ( LOG . isDebugging ( ) ) { LOG . warning ( "No object found for label " + entries [ 0 ] ) ; } } } return store ; } catch ( IOException e ) { throw new AbortException ( "Loading of external neighborhood failed." , e ) ; } }
method to load the external neighbors .
