Java Code Examples for gnu.trove.map.hash.TIntObjectHashMap#put()

The following examples show how to use gnu.trove.map.hash.TIntObjectHashMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataAccessKeyValueStore.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override
public TIntObjectHashMap<EntityType> getAllEntityClasses() throws EntityLinkingDataAccessException {
  TIntObjectHashMap<EntityType> entityClasses = new TIntObjectHashMap<EntityType>();
  try {
    DatabaseKeyValueStore db = DatabaseKeyValueStore.DICTIONARY_ENTITIES;
    if(db.getPartitions() != 1) {
      throw new IllegalArgumentException("Multiple partitions not supported for this key-value store");
    }
    Codec codec = DataAccessKeyValueStoreHandler.singleton().getCodec(db);
    KeyValueStore<byte[], byte[]> keyValueStore = DataAccessKeyValueStoreHandler.singleton().getKeyValueStore(db);
    KeyValueStore.EntryIterator it = keyValueStore.entryIterator();
    while (it.hasNext()) {
      KeyValueStore.Entry<byte[], byte[]> entry = it.next();
      Integer key = (Integer) codec.decodeKey(entry.getKey());
      Integer value = (Integer) codec.decodeValue(entry.getValue());
      entityClasses.put(key, EntityType.getNameforDBId(value));
    }
  } catch (Exception e) {
    throw new EntityLinkingDataAccessException(e);
  }
  return entityClasses;
}
 
Example 2
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override public void getEntityKeyphraseTokens(Entities entities, TIntObjectHashMap<int[]> entityKeyphrases,
    TIntObjectHashMap<int[]> keyphraseTokens) throws EntityLinkingDataAccessException {
  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    int[] keyphrases = new int[(eKps.length - 1) / 2];
    if (eKps.length > 1) {
      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          int kp = DataAccess.getIdForWord(eKps[i]);
          keyphrases[(i - 1) / 2] = kp;

          // Add tokens.
          String[] tokens = eKps[i].split(" ");
          int[] tokenIds = new int[tokens.length];
          for (int j = 0; j < tokens.length; ++j) {
            tokenIds[j] = DataAccess.getIdForWord(tokens[j]);
          }
          keyphraseTokens.put(kp, tokenIds);
        }
      }
    }
    entityKeyphrases.put(entity, keyphrases);
  }
}
 
Example 3
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
public TIntObjectHashMap<TIntIntHashMap> getEntityKeyphraseIntersectionCount(Entities entities) throws EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntIntHashMap> isec = new TIntObjectHashMap<TIntIntHashMap>();
  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    TIntIntHashMap counts = new TIntIntHashMap();
    isec.put(entity, counts);

    if (eKps.length > 1) {
      int currentKp = -1;
      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          currentKp = DataAccess.getIdForWord(eKps[i]);
        } else {
          int count = Integer.parseInt(eKps[i]);
          counts.put(currentKp, count);
        }
      }
    }
  }
  return isec;
}
 
Example 4
Source File: ExternalEntitiesContext.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private TIntObjectHashMap<int[]> buildEntityKeyphrases(Map<KBIdentifiedEntity, List<Keyphrase>> entityKeyphrases) {
  TIntObjectHashMap<int[]> entityKeyphrasesIds = new TIntObjectHashMap<>();
  for (Map.Entry<KBIdentifiedEntity, List<Keyphrase>> entry : entityKeyphrases.entrySet()) {
    KBIdentifiedEntity entityKbId = entry.getKey();
    List<Keyphrase> keyphrases = entry.getValue();
    int[] keyphraseIds = new int[keyphrases.size()];
    for (int i = 0; i < keyphrases.size(); i++) {
      Keyphrase keyphrase = keyphrases.get(i);
      int kpId = getWordId(keyphrase.getKeyphrase());
      keyphraseIds[i] = kpId;
    }
    int entityId = dictionary_.getEntityId(entityKbId);
    entityKeyphrasesIds.put(entityId, keyphraseIds);
  }
  return entityKeyphrasesIds;
}
 
Example 5
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override public TIntObjectHashMap<TIntIntHashMap> getEntityKeywordIntersectionCount(Entities entities) throws EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntIntHashMap> isec = new TIntObjectHashMap<TIntIntHashMap>();

  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    TIntIntHashMap counts = new TIntIntHashMap();
    isec.put(entity, counts);

    if (eKps.length > 1) {
      String[] tokens = null;
      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          tokens = eKps[i].split(" ");
        } else {
          int count = Integer.parseInt(eKps[i]);
          for (String token : tokens) {
            counts.adjustOrPutValue(DataAccess.getIdForWord(token), count, count);
          }
        }
      }
    }
  }
  return isec;
}
 
Example 6
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override public TIntObjectHashMap<String> getWordsForIds(int[] ids) {
  TIntObjectHashMap<String> words = new TIntObjectHashMap<String>();
  for (int i = 0; i < ids.length; ++i) {
    if (!id2word.containsKey(ids[i])) {
      throw new IllegalArgumentException(ids[i] + " not in testing");
    } else {
      words.put(ids[i], id2word.get(ids[i]));
    }
  }
  return words;
}
 
Example 7
Source File: DataAccessKeyValueStore.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public TIntObjectHashMap<Type> getTypesForIds(int[] ids) throws EntityLinkingDataAccessException {
  if (ids.length == 0) return new TIntObjectHashMap<>();

  TIntObjectHashMap<Type> typeNames = new TIntObjectHashMap<>(getCapacity(ids.length), troveLoadFactor);
  try {
    DatabaseKeyValueStore db = DatabaseKeyValueStore.TYPE_IDS_ID;
    if(db.getPartitions() != 1) {
      throw new IllegalArgumentException("Multiple partitions not supported for this key-value store");
    }
    Codec entityIdsCodec = DataAccessKeyValueStoreHandler.singleton().getCodec(db);
    KeyValueStore<byte[], byte[]> keyValueStore = DataAccessKeyValueStoreHandler.singleton().getKeyValueStore(db);

    List<byte[]> encodedKeys = new ArrayList<>();
    for (int id : ids) {
      encodedKeys.add(entityIdsCodec.encodeKey(id));
    }
    Map<byte[], byte[]> keyValueMap = keyValueStore.getAll(encodedKeys);

    for (Map.Entry<byte[], byte[]> entry : keyValueMap.entrySet()) {
      if (entry.getKey() == null || entry.getValue() == null) continue;
      int type = (int) entityIdsCodec.decodeKey(entry.getKey());
      //Multiple values retrieve get the first one
      KeyValueStoreRow[] rows = (KeyValueStoreRow[]) entityIdsCodec.decodeValue(entry.getValue());
      typeNames.put(type, new Type(rows[0].getString(1), rows[0].getString(0)));
    }
  } catch (Exception e) {
    throw new EntityLinkingDataAccessException(e);
  }
  return typeNames;
}
 
Example 8
Source File: KeytermEntityEntityMeasureTracer.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public static TIntObjectHashMap<String> getAllWordIds() throws EntityLinkingDataAccessException {
  TObjectIntHashMap<String> wordIds = DataAccess.getAllWordIds();
  TIntObjectHashMap<String> idWords = new TIntObjectHashMap<String>(wordIds.size());
  for (TObjectIntIterator<String> itr = wordIds.iterator(); itr.hasNext(); ) {
    itr.advance();
    idWords.put(itr.value(), itr.key());
  }
  return idWords;
}
 
Example 9
Source File: TaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
private TIntObjectHashMap<int[]> myChanges(TIntIntHashMap[] change) {
    TIntObjectHashMap<int[]> map = new TIntObjectHashMap<>();
    for (int d = 0; d < nbDims; d++) {
        for (int t : change[d].keys()) {
            int[] upd = map.get(t);
            if (upd == null) {
                upd = new int[nbDims];
                map.put(t, upd);
            }
            upd[d] += change[d].get(t);
        }
    }
    return map;
}
 
Example 10
Source File: MixinItemModelMesherForge.java    From VanillaFix with MIT License 5 votes vote down vote up
/**
 * @reason Don't get all models during init (with dynamic loading, that would
 * generate them all). Just store location instead.
 **/
@Overwrite
@Override
public void register(Item item, int meta, ModelResourceLocation location) {
    IRegistryDelegate<Item> key = item.delegate;
    TIntObjectHashMap<ModelResourceLocation> locs = locations.get(key);
    if (locs == null) {
        locs = new TIntObjectHashMap<>();
        locations.put(key, locs);
    }
    locs.put(meta, location);
}
 
Example 11
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override public TIntObjectHashMap<EntityMetaData> getEntitiesMetaData(int[] entitiesIds) throws EntityLinkingDataAccessException {
  TIntObjectHashMap<EntityMetaData> md = new TIntObjectHashMap<>();

  Entities entities = getAllEntities();
  for (Entity e : entities) {
    EntityMetaData emd = new EntityMetaData(e.getId(), e.getIdentifierInKb(), "http://" + e.getIdentifierInKb(), e.getKnowledgebase(), "", "", "",
        e.getKnowledgebase() + ":" + e.getIdentifierInKb());
    md.put(e.getId(), emd);
  }

  return md;
}
 
Example 12
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private TIntObjectHashMap<TIntIntHashMap> getEntityUnitIntersectionCountInternal(Entities entities, UnitType unitType)
    throws EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntIntHashMap> isec = new TIntObjectHashMap<>();

  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    TIntIntHashMap counts = new TIntIntHashMap();
    isec.put(entity, counts);

    if (eKps.length > 1) {
      String[] keyphrase = null;

      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          keyphrase = eKps[i].split(" ");
        } else {
          int count = Integer.parseInt(eKps[i]);

          Set<String[]> ngrams = StringUtils.getNgrams(keyphrase, unitType.getUnitSize());
          for (String[] ngram : ngrams) {
            String ngramString = String.join(" ", ngram);
            counts.adjustOrPutValue(DataAccess.getIdForWord(ngramString), count, count);
          }
        }
      }
    }
  }
  return isec;
}
 
Example 13
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override public TIntObjectHashMap<KBIdentifiedEntity> getKnowlegebaseEntitiesForInternalIds(int[] ids) {
  TIntObjectHashMap<KBIdentifiedEntity> entities = new TIntObjectHashMap<KBIdentifiedEntity>();
  for (int i = 0; i < ids.length; ++i) {
    if (!id2entity.containsKey(ids[i])) {
      throw new IllegalArgumentException(ids[i] + " not in testing");
    } else {
      entities.put(ids[i], getTestKBEntity(id2entity.get(ids[i])));
    }
    ++i;
  }
  return entities;
}
 
Example 14
Source File: YagoEntityKeyphraseCooccurrenceDataProviderIteratorTest.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private TIntObjectHashMap<TIntIntHashMap> createHashMap() {
  TIntObjectHashMap<TIntIntHashMap> overallMap = new TIntObjectHashMap<TIntIntHashMap>();
  TIntIntHashMap map1 = new TIntIntHashMap();
  overallMap.put(1, map1);

  TIntIntHashMap map2 = new TIntIntHashMap();
  map2.put(21, 100);
  map2.put(22, 101);
  map2.put(23, 102);
  overallMap.put(2, map2);

  TIntIntHashMap map3 = new TIntIntHashMap();
  map3.put(31, 103);
  map3.put(32, 104);
  map3.put(33, 105);
  overallMap.put(3, map3);

  TIntIntHashMap map4 = new TIntIntHashMap();
  overallMap.put(4, map4);

  TIntIntHashMap map5 = new TIntIntHashMap();
  map5.put(51, 106);
  map5.put(52, 107);
  map5.put(53, 108);
  overallMap.put(5, map5);

  TIntIntHashMap map6 = new TIntIntHashMap();
  overallMap.put(6, map6);

  TIntIntHashMap map7 = new TIntIntHashMap();
  overallMap.put(7, map7);

  return overallMap;
}
 
Example 15
Source File: WordCluster.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String toString(){
	StringBuilder sb = new StringBuilder();

	TIntObjectHashMap<TLinkedHashSet<String>> sets = new TIntObjectHashMap<TLinkedHashSet<String>>();

	for(int i=0;i<alpahbet.size();i++){
		int head = getHead(i);
		TLinkedHashSet<String> s = sets.get(head);
		if(s==null){
			s = new TLinkedHashSet();
			sets.put(head, s);
		}
		s.add(alpahbet.lookupString(i));
	}

	TIntObjectIterator<TLinkedHashSet<String>> it = sets.iterator();
	while(it.hasNext()){
		it.advance();
		if(it.value().size()<2)
			continue;
		sb.append(wordProb.get(it.key()));
		sb.append(" ");
		TObjectHashIterator<String> itt = it.value().iterator();
		while(itt.hasNext()){
			String ss = itt.next();
			sb.append(ss);
			sb.append(" ");
		}
		sb.append("\n");
	}

	return sb.toString();

}
 
Example 16
Source File: DataAccessCache.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public TIntObjectHashMap<EntityType> getEntityClasses(int[] entityIds) {
  TIntObjectHashMap<EntityType> results = new TIntObjectHashMap<>();
  for (int entityId : entityIds) {
    if (entities.getAllData().containsKey(entityId)) {
      results.put(entityId, entities.getAllData().get(entityId));
    }
  }
  return results;
}
 
Example 17
Source File: KeyphrasesMeasureTracer.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public static TIntObjectHashMap<String> getAllWordIds() throws EntityLinkingDataAccessException {
  TObjectIntHashMap<String> wordIds = DataAccess.getAllWordIds();
  TIntObjectHashMap<String> idWords = new TIntObjectHashMap<String>(wordIds.size());
  for (TObjectIntIterator<String> itr = wordIds.iterator(); itr.hasNext(); ) {
    itr.advance();
    idWords.put(itr.value(), itr.key());
  }
  return idWords;
}
 
Example 18
Source File: UnitUtil.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private static TIntObjectHashMap<String> getUsedWords(TIntSet usedTokens, TIntObjectHashMap<String> idsWords) {
  TIntObjectHashMap<String> usedWords = new TIntObjectHashMap<>();
  for (TIntIterator itr = usedTokens.iterator(); itr.hasNext(); ) {
    int usedToken = itr.next();
    usedWords.put(usedToken, idsWords.get(usedToken));
  }
  return usedWords;
}
 
Example 19
Source File: Cluster.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public TIntObjectHashMap<Cluster> refineBy(int column, int[][] values) {
	TIntObjectHashMap<Cluster> map = new TIntObjectHashMap<>();
	for (TIntIterator iter = array.iterator(); iter.hasNext();) {
		int line = iter.next();
		int c = values[line][column];
		if (map.containsKey(c)) {
			map.get(c).add(line);
		} else {
			Cluster p = new Cluster(line);
			map.put(c, p);
		}
	}
	return map;
}
 
Example 20
Source File: DirectionalityRenderer.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
private void build(TIntObjectHashMap<BakedRenderer> bakedRenderers, ImmutableList<NetworkRail<MCPos>> edge){

        for(int edgeIndex = 1; edgeIndex < edge.size() - 1; edgeIndex++) {
            NetworkRail<MCPos> prevRail = edge.get(edgeIndex - 1);
            MCNetworkRail curRail = (MCNetworkRail)edge.get(edgeIndex);
            NetworkRail<MCPos> nextRail = edge.get(edgeIndex + 1);

            EnumHeading prevHeading = curRail.getPos().getRelativeHeading(prevRail.getPos());
            EnumHeading nextHeading = nextRail.getPos().getRelativeHeading(curRail.getPos());
            if(prevHeading == null || nextHeading == null || prevHeading != nextHeading || curRail.getPos().getDimID() != nextRail.getPos().getDimID() || curRail.getPos().getDimID() != prevRail.getPos().getDimID()) continue;

            BakedRenderer bakedRenderer = bakedRenderers.get(curRail.getPos().getDimID());
            if(bakedRenderer == null) {
                bakedRenderer = new BakedRenderer();
                bakedRenderers.put(curRail.getPos().getDimID(), bakedRenderer);
            }

            MCPos pos = curRail.getPos();
            EnumFacing facing = HeadingUtils.toFacing(nextHeading).getOpposite();
            EnumFacing rotatedFacing = facing.rotateY();
            EnumFacing rotatedFacing2 = facing.rotateYCCW();
            int yOffset = AbstractRailRenderer.getRailHeightOffset(curRail, facing);

            Vec3d posVec = new Vec3d(pos.getX() + 0.5, pos.getY() + (yOffset != 0 ? 0.6001 : 0.1001), pos.getZ() + 0.5);

            double arrowSize = 0.1;
            double spacing = 0.1;

            for(int i = -2; i < -1; i++) {
                Vec3d shiftedPosVec = posVec.addVector(facing.getFrontOffsetX() * spacing * i, spacing * i * yOffset + 0.001, facing.getFrontOffsetZ() * spacing * i);
                Vec3d vecBack = shiftedPosVec.addVector(facing.getFrontOffsetX() * arrowSize, arrowSize * yOffset, facing.getFrontOffsetZ() * arrowSize);
                Vec3d c1 = vecBack.addVector(rotatedFacing.getFrontOffsetX() * arrowSize, 0, rotatedFacing.getFrontOffsetZ() * arrowSize);
                Vec3d c2 = vecBack.addVector(rotatedFacing2.getFrontOffsetX() * arrowSize, 0, rotatedFacing2.getFrontOffsetZ() * arrowSize);

                bakedRenderer.add(shiftedPosVec.x, shiftedPosVec.y, shiftedPosVec.z);
                bakedRenderer.add(c1.x, c1.y, c1.z);
                //buffer.pos(shiftedPosVec.x, shiftedPosVec.y, shiftedPosVec.z).color(r, g, b, 1).endVertex();
                bakedRenderer.add(c2.x, c2.y, c2.z);
            }
        }
    }