Java Code Examples for gnu.trove.iterator.TIntObjectIterator#hasNext()
The following examples show how to use
gnu.trove.iterator.TIntObjectIterator#hasNext() .
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: ComponentGridWidget.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private void clearWidgetFromMap(Widget widget) { this.originByWidget.remove(widget); TIntObjectIterator<Widget> it = this.widgetBySlotIndex.iterator(); while (it.hasNext()) { it.advance(); if (it.value() == widget) { it.remove(); } } }
Example 2
Source File: DataAccess.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
/** * Computes all entity occurrence probabilities based on their incoming links. * * @return Map of Entity->Probability. * @throws EntityLinkingDataAccessException */ public static TIntDoubleHashMap getAllEntityProbabilities() throws EntityLinkingDataAccessException { TIntObjectHashMap<int[]> entityInlinks = getAllInlinks(); TIntDoubleHashMap entityProbabilities = new TIntDoubleHashMap(entityInlinks.size(), 0.5f); // Get the total number of links. long totalLinkCount = 0; TIntObjectIterator<int[]> itr = entityInlinks.iterator(); while (itr.hasNext()) { itr.advance(); totalLinkCount += itr.value().length; } // Derive probabilities from counts. itr = entityInlinks.iterator(); while (itr.hasNext()) { itr.advance(); double probability = (double) itr.value().length / (double) totalLinkCount; entityProbabilities.put(itr.key(), probability); } return entityProbabilities; }
Example 3
Source File: DataAccessKeyValueStore.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
@Override //TODO: language not used public Map<String, int[]> getCategoryIdsForMentions(Set<String> mentions, Language language, boolean isNamedEntity) throws EntityLinkingDataAccessException { Map<String, Entities> entities = getEntitiesForMentions(mentions, 1.0, 0, isNamedEntity); Map<String, Set<Integer>> mentionCategories = new HashMap<>(entities.size()); for (Entry<String, Entities> entry:entities.entrySet()) { Set<Integer> types = mentionCategories.get(entry.getKey()); if (types == null) { types = new HashSet<>(); } List<Integer> entityIds = new ArrayList<>(); for (Entity entity:entry.getValue()) { entityIds.add(entity.getId()); } TIntObjectHashMap<int[]> categories = getCategoryIdsForEntitiesIds(ArrayUtils.toPrimitive(entityIds.toArray(new Integer[0]))); TIntObjectIterator<int[]> it = categories.iterator(); while (it.hasNext()) { types.addAll(Arrays.asList(ArrayUtils.toObject(it.value()))); } } Map<String, int[]> ret = new HashMap<>(); for (String key:mentionCategories.keySet()) { Integer[] temp = mentionCategories.get(key).toArray(new Integer[0]); ret.put(key, ArrayUtils.toPrimitive(temp)); } return ret; }
Example 4
Source File: WikiCorpusTask.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
private static Map<Integer, Set<Integer>> computeEntityOutlinks() throws EntityLinkingDataAccessException, IOException, SQLException { Map<Integer, Set<Integer>> inLinkOutLinkMap = new HashMap<>(); String file_name = EntityLinkingManager.getAidaDbIdentifierLight() + "_" + ENTITY_OUTLINK_CACHE_JSON; if (Files.exists(Paths.get(file_name))) { logger.info("Loading " + file_name + " from cache"); Map<Integer, Set<Integer>> cache = new GsonBuilder().enableComplexMapKeySerialization().create() .fromJson(new JsonReader(new FileReader(file_name)), new TypeToken<Map<Integer, Set<Integer>>>() { }.getType()); if (cache != null) { inLinkOutLinkMap.putAll(cache); return inLinkOutLinkMap; } } logger.info("Computing " + ENTITY_OUTLINK_CACHE_JSON); TIntObjectHashMap<int[]> inlinkNeighbors = DataAccess.getInlinkNeighbors(DataAccess.getAllEntities()); TIntObjectIterator<int[]> iterator = inlinkNeighbors.iterator(); while (iterator.hasNext()) { iterator.advance(); int outEntity = iterator.key(); int[] inEntities = iterator.value(); for (int inEntity : inEntities) { if (!inLinkOutLinkMap.containsKey(inEntity)) { inLinkOutLinkMap.put(inEntity, new HashSet<>()); } Set<Integer> outLinks = inLinkOutLinkMap.get(inEntity); outLinks.add(outEntity); } } if (!inLinkOutLinkMap.isEmpty()) { Gson gson = new Gson(); Files.write(Paths.get(file_name), gson.toJson(inLinkOutLinkMap).getBytes()); } return inLinkOutLinkMap; }
Example 5
Source File: WordCluster.java From fnlp with GNU Lesser General Public License v3.0 | 5 votes |
/** * 一次性统计概率,节约时间 */ private void statisticProb() { System.out.println("统计概率"); TIntFloatIterator it = wordProb.iterator(); while(it.hasNext()){ it.advance(); float v = it.value()/totalword; it.setValue(v); int key = it.key(); if(key<0) continue; Cluster cluster = new Cluster(key,v,alpahbet.lookupString(key)); clusters.put(key, cluster); } TIntObjectIterator<TIntFloatHashMap> it1 = pcc.iterator(); while(it1.hasNext()){ it1.advance(); TIntFloatHashMap map = it1.value(); TIntFloatIterator it2 = map.iterator(); while(it2.hasNext()){ it2.advance(); it2.setValue(it2.value()/totalword); } } }
Example 6
Source File: WordCluster.java From fnlp with GNU Lesser General Public License v3.0 | 5 votes |
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 7
Source File: WikiCorpusTask.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
private void computeNonprocessedEntityMentionLabels(Set<Entity> processingEntities, HashMap<Integer, Map<String, MentionObject>> entityMentionLabelsMap) throws EntityLinkingDataAccessException, InterruptedException { TIntObjectHashMap<int[]> typesIdsForEntitiesIds = DataAccess.getTypesIdsForEntitiesIds(processingEntities .stream() .mapToInt(Entity::getId) .toArray()); TIntObjectHashMap<List<MentionObject>> mentionsForEntities = DataAccess.getMentionsForEntities(new Entities(processingEntities)); TIntObjectIterator<List<MentionObject>> entityMentionsIterator = mentionsForEntities.iterator(); while (entityMentionsIterator.hasNext()) { Map<String, MentionObject> entityResult = new HashMap<>(); entityMentionsIterator.advance(); int eid = entityMentionsIterator.key(); int[] typeIDs = typesIdsForEntitiesIds.get(eid); NerType.Label nerTypeForTypeIds = NerType.getNerTypeForTypeIds(typeIDs); for (MentionObject mentionObject : entityMentionsIterator.value()) { if (Thread.interrupted()) { throw new InterruptedException(); } String entityMention = mentionObject.getMention(); NerType.Label nerTypeForTypeIds_ = nerTypeForTypeIds; // getting rid of the junk from the aida database if (stopwords.contains(entityMention.toLowerCase()) || entityMention.contains("<SPAN") || entityMention.contains("=") || entityMention.contains("<!--") || entityMention.contains("(") && entityMention.contains(")") || isDate(entityMention.trim()) || entityMention.matches("[.,\\/#!$%\\^&\\*;:{}=\\-_`~()]") || entityMention.endsWith("'S") ) { continue; } // i.e. United States is a location, not an organization if (knownCountries.contains(entityMention.toLowerCase())) { nerTypeForTypeIds_ = NerType.Label.LOCATION; } if (languagesList.contains(entityMention.toLowerCase())) { nerTypeForTypeIds_ = NerType.Label.MISC; } MentionObject copy = mentionObject.copy(); copy.setLabel(nerTypeForTypeIds_); entityResult.put(entityMention, copy); } entityMentionLabelsMapCache.put(eid, entityResult); entityMentionLabelsMap.put(eid, entityResult); } }
Example 8
Source File: DataWatcherSerializer.java From Carbon-2 with GNU Lesser General Public License v3.0 | 4 votes |
public static byte[] encodeData(TIntObjectMap<DataWatcherObject> objects) { PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer()); TIntObjectIterator<DataWatcherObject> iterator = objects.iterator(); while (iterator.hasNext()) { iterator.advance(); DataWatcherObject object = iterator.value(); final int tk = ((object.type.getId() << 5) | (iterator.key() & 0x1F)) & 0xFF; serializer.writeByte(tk); switch (object.type) { case BYTE: { serializer.writeByte((byte) object.value); break; } case SHORT: { serializer.writeShort((short) object.value); break; } case INT: { serializer.writeInt((int) object.value); break; } case FLOAT: { serializer.writeFloat((float) object.value); break; } case STRING: { PacketDataSerializerHelper.writeString(serializer, (String) object.value); break; } case ITEMSTACK: { PacketDataSerializerHelper.writeItemStack(serializer, (ItemStack) object.value); break; } case VECTOR3I: { BlockPosition blockPos = (BlockPosition) object.value; serializer.writeInt(blockPos.getX()); serializer.writeInt(blockPos.getY()); serializer.writeInt(blockPos.getZ()); break; } case VECTOR3F: { Vector3f vector = (Vector3f) object.value; serializer.writeFloat(vector.getX()); serializer.writeFloat(vector.getY()); serializer.writeFloat(vector.getZ()); break; } } } serializer.writeByte(127); return Utils.toArray(serializer); }
Example 9
Source File: DataWatcherSerializer.java From Carbon-2 with GNU Lesser General Public License v3.0 | 4 votes |
public static byte[] encodeData(TIntObjectMap<DataWatcherObject> objects) { PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer()); TIntObjectIterator<DataWatcherObject> iterator = objects.iterator(); while (iterator.hasNext()) { iterator.advance(); DataWatcherObject object = iterator.value(); final int tk = ((object.type.getId() << 5) | (iterator.key() & 0x1F)) & 0xFF; serializer.writeByte(tk); switch (object.type) { case BYTE: { serializer.writeByte((byte) object.value); break; } case SHORT: { serializer.writeShort((short) object.value); break; } case INT: { serializer.writeInt((int) object.value); break; } case FLOAT: { serializer.writeFloat((float) object.value); break; } case STRING: { PacketDataSerializerHelper.writeString(serializer, (String) object.value); break; } case ITEMSTACK: { PacketDataSerializerHelper.writeItemStack(serializer, (ItemStack) object.value); break; } case VECTOR3I: { BlockPosition blockPos = (BlockPosition) object.value; serializer.writeInt(blockPos.getX()); serializer.writeInt(blockPos.getY()); serializer.writeInt(blockPos.getZ()); break; } case VECTOR3F: { Vector3f vector = (Vector3f) object.value; serializer.writeFloat(vector.getX()); serializer.writeFloat(vector.getY()); serializer.writeFloat(vector.getZ()); break; } } } serializer.writeByte(127); return Utils.toArray(serializer); }