Search in sources :

Example 1 with Int2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap in project geode by apache.

the class AbstractStringIdResourceBundle method readDataFile.

private Int2ObjectOpenHashMap readDataFile(InputStream is) {
    Int2ObjectOpenHashMap map = new Int2ObjectOpenHashMap();
    boolean complete = false;
    BufferedReader input = null;
    try {
        input = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String line = null;
        while ((line = input.readLine()) != null) {
            int equalSign = line.indexOf('=');
            String idAsString = line.substring(0, equalSign - 1).trim();
            // The +2 is because we need to skip the "= ", we dont use trim because some messages want
            // leading whitespace
            String message = line.substring(equalSign + 2).replaceAll("\\\\n", "\n");
            try {
                int id = Integer.parseInt(idAsString);
                map.put(id, message);
            } catch (NumberFormatException nfe) {
                // unit tests should prevent this from happening in a customer situation
                throw new InternalGemFireException(nfe);
            }
            complete = true;
        }
    } catch (IOException ioe) {
    // @TODO log this exception
    } finally {
        if (!complete) {
            // something went wrong, clean up and revert back to English
            try {
                if (input != null) {
                    input.close();
                } else {
                    is.close();
                }
            } catch (IOException ignore) {
            }
            // set map back to null so we default to English
            map = null;
        }
    }
    return map;
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) InputStreamReader(java.io.InputStreamReader) InternalGemFireException(org.apache.geode.InternalGemFireException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 2 with Int2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap in project mkgmap by openstreetmap.

the class HousenumberGenerator method identifyServiceRoads.

/**
 * process option --x-name-service-roads=n
 * The program identifies unnamed roads which are only connected to one
 * road with a name or to multiple roads with the same name. The process is
 * repeated n times. If n > 1 the program will also use unnamed roads which
 * are connected to unnamed roads if those are connected to named roads.
 * Higher values for n mean deeper search, but reasonable values are
 * probably between 1 and 5.
 *
 * These roads are then used for house number processing like the named
 * ones. If house numbers are assigned to these roads, they are named so
 * that address search will find them.
 */
private void identifyServiceRoads() {
    Int2ObjectOpenHashMap<String> roadNamesByNodeIds = new Int2ObjectOpenHashMap<>();
    HashMap<MapRoad, List<Coord>> coordNodesUnnamedRoads = new HashMap<>();
    HashSet<Integer> unclearNodeIds = new HashSet<>();
    long t1 = System.currentTimeMillis();
    List<MapRoad> unnamedRoads = new ArrayList<>();
    for (MapRoad road : allRoads) {
        if (road.isSkipHousenumberProcessing())
            continue;
        if (road.getStreet() == null) {
            // the road probably has a ref. We assume these are not service roads.
            if (road.getName() == null) {
                unnamedRoads.add(road);
                List<Coord> nodes = new ArrayList<>();
                for (Coord co : road.getPoints()) {
                    if (co.getId() != 0)
                        nodes.add(co);
                }
                coordNodesUnnamedRoads.put(road, nodes);
            }
        } else {
            identifyNodes(road.getPoints(), road.getStreet(), roadNamesByNodeIds, unclearNodeIds);
        }
    }
    int numUnnamedRoads = unnamedRoads.size();
    long t2 = System.currentTimeMillis();
    if (log.isDebugEnabled())
        log.debug("identifyServiceRoad step 1 took", (t2 - t1), "ms, found", roadNamesByNodeIds.size(), "nodes to check and", numUnnamedRoads, "unnamed roads");
    long t3 = System.currentTimeMillis();
    int named = 0;
    for (int pass = 1; pass <= nameSearchDepth; pass++) {
        int unnamed = 0;
        List<MapRoad> namedRoads = new ArrayList<>();
        for (int j = 0; j < unnamedRoads.size(); j++) {
            MapRoad road = unnamedRoads.get(j);
            if (road == null)
                continue;
            unnamed++;
            List<Coord> coordNodes = coordNodesUnnamedRoads.get(road);
            String name = null;
            for (Coord co : coordNodes) {
                if (unclearNodeIds.contains(co.getId())) {
                    name = null;
                    // don't process again
                    unnamedRoads.set(j, null);
                    break;
                }
                String possibleName = roadNamesByNodeIds.get(co.getId());
                if (possibleName == null)
                    continue;
                if (name == null)
                    name = possibleName;
                else if (name.equals(possibleName) == false) {
                    name = null;
                    // don't process again
                    unnamedRoads.set(j, null);
                    break;
                }
            }
            if (name != null) {
                named++;
                road.setStreet(name);
                namedRoads.add(road);
                // don't process again
                unnamedRoads.set(j, null);
            }
        }
        for (MapRoad road : namedRoads) {
            road.setNamedByHousenumberProcessing(true);
            String name = road.getStreet();
            if (log.isDebugEnabled())
                log.debug("pass", pass, "using unnamed road for housenumber processing,id=", road.getRoadDef().getId(), ":", name);
            List<Coord> coordNodes = coordNodesUnnamedRoads.get(road);
            identifyNodes(coordNodes, name, roadNamesByNodeIds, unclearNodeIds);
        }
        if (namedRoads.isEmpty())
            break;
        if (log.isDebugEnabled())
            log.debug("pass", pass, unnamed, named);
    }
    long t4 = System.currentTimeMillis();
    if (log.isDebugEnabled()) {
        log.debug("indentifyServiceRoad step 2 took", (t4 - t3), "ms, found a name for", named, "of", numUnnamedRoads, "roads");
    }
    return;
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) MultiHashMap(uk.me.parabola.util.MultiHashMap) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) Coord(uk.me.parabola.imgfmt.app.Coord) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with Int2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap in project webanno by webanno.

the class ConllUReader method convert.

public void convert(JCas aJCas, BufferedReader aReader) throws IOException {
    if (readPos) {
        try {
            posMappingProvider.configure(aJCas.getCas());
        } catch (AnalysisEngineProcessException e) {
            throw new IOException(e);
        }
    }
    JCasBuilder doc = new JCasBuilder(aJCas);
    List<String[]> words;
    while ((words = readSentence(aReader)) != null) {
        if (words.isEmpty()) {
            // markers following each other.
            continue;
        }
        int sentenceBegin = doc.getPosition();
        int sentenceEnd = sentenceBegin;
        int surfaceBegin = -1;
        int surfaceEnd = -1;
        String surfaceString = null;
        // Tokens, Lemma, POS
        Int2ObjectMap<Token> tokens = new Int2ObjectOpenHashMap<>();
        for (String[] word : words) {
            if (word[ID].contains("-")) {
                String[] fragments = word[ID].split("-");
                surfaceBegin = Integer.valueOf(fragments[0]);
                surfaceEnd = Integer.valueOf(fragments[1]);
                surfaceString = word[FORM];
                continue;
            }
            // Read token
            int tokenIdx = Integer.valueOf(word[ID]);
            Token token = doc.add(word[FORM], Token.class);
            tokens.put(tokenIdx, token);
            if (!StringUtils.contains(word[MISC], "SpaceAfter=No")) {
                doc.add(" ");
            }
            // Read lemma
            if (!UNUSED.equals(word[LEMMA]) && readLemma) {
                Lemma lemma = new Lemma(aJCas, token.getBegin(), token.getEnd());
                lemma.setValue(word[LEMMA]);
                lemma.addToIndexes();
                token.setLemma(lemma);
            }
            // Read part-of-speech tag
            if (!UNUSED.equals(word[POSTAG]) && readPos) {
                Type posTag = posMappingProvider.getTagType(word[POSTAG]);
                POS pos = (POS) aJCas.getCas().createAnnotation(posTag, token.getBegin(), token.getEnd());
                pos.setPosValue(word[POSTAG]);
                pos.addToIndexes();
                token.setPos(pos);
            }
            // Read morphological features
            if (!UNUSED.equals(word[FEATS]) && readMorph) {
                MorphologicalFeatures morphtag = new MorphologicalFeatures(aJCas, token.getBegin(), token.getEnd());
                morphtag.setValue(word[FEATS]);
                morphtag.addToIndexes();
                token.setMorph(morphtag);
                // Try parsing out individual feature values. Since the DKPro Core
                // MorphologicalFeatures type is based on the definition from the UD project,
                // we can do this rather straightforwardly.
                Type morphType = morphtag.getType();
                String[] items = word[FEATS].split("\\|");
                for (String item : items) {
                    String[] keyValue = item.split("=");
                    StringBuilder key = new StringBuilder(keyValue[0]);
                    key.setCharAt(0, Character.toLowerCase(key.charAt(0)));
                    String value = keyValue[1];
                    Feature feat = morphType.getFeatureByBaseName(key.toString());
                    if (feat != null) {
                        morphtag.setStringValue(feat, value);
                    }
                }
            }
            // Read surface form
            if (tokenIdx == surfaceEnd) {
                int begin = tokens.get(surfaceBegin).getBegin();
                int end = tokens.get(surfaceEnd).getEnd();
                SurfaceForm surfaceForm = new SurfaceForm(aJCas, begin, end);
                surfaceForm.setValue(surfaceString);
                surfaceForm.addToIndexes();
                surfaceBegin = -1;
                surfaceEnd = -1;
                surfaceString = null;
            }
            sentenceEnd = token.getEnd();
        }
        // Dependencies
        if (readDependency) {
            for (String[] word : words) {
                if (!UNUSED.equals(word[DEPREL])) {
                    int depId = Integer.valueOf(word[ID]);
                    int govId = Integer.valueOf(word[HEAD]);
                    // Model the root as a loop onto itself
                    makeDependency(aJCas, govId, depId, word[DEPREL], DependencyFlavor.BASIC, tokens, word);
                }
                if (!UNUSED.equals(word[DEPS])) {
                    // list items separated by vertical bar
                    String[] items = word[DEPS].split("\\|");
                    for (String item : items) {
                        String[] sItem = item.split(":");
                        int depId = Integer.valueOf(word[ID]);
                        int govId = Integer.valueOf(sItem[0]);
                        makeDependency(aJCas, govId, depId, sItem[1], DependencyFlavor.ENHANCED, tokens, word);
                    }
                }
            }
        }
        // Sentence
        Sentence sentence = new Sentence(aJCas, sentenceBegin, sentenceEnd);
        sentence.addToIndexes();
        // Once sentence per line.
        doc.add("\n");
    }
    doc.close();
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) MorphologicalFeatures(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.morph.MorphologicalFeatures) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) IOException(java.io.IOException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException) Feature(org.apache.uima.cas.Feature) Type(org.apache.uima.cas.Type) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) SurfaceForm(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.SurfaceForm) JCasBuilder(org.apache.uima.fit.factory.JCasBuilder) Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 4 with Int2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap in project LanternServer by LanternPowered.

the class InventorySnapshotSerializer method deserialize.

public static InventorySnapshot deserialize(List<DataView> itemDataViews) {
    final ObjectSerializer<LanternItemStack> itemStackSerializer = ObjectSerializerRegistry.get().get(LanternItemStack.class).get();
    final Int2ObjectMap<ItemStackSnapshot> itemsByIndex = new Int2ObjectOpenHashMap<>();
    for (DataView itemDataView : itemDataViews) {
        final int slot = itemDataView.getByte(SLOT).get() & 0xff;
        final ItemStackSnapshot itemStackSnapshot = itemStackSerializer.deserialize(itemDataView).createSnapshot();
        itemsByIndex.put(slot, itemStackSnapshot);
    }
    return InventorySnapshot.ofRawMap(itemsByIndex);
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) DataView(org.spongepowered.api.data.DataView) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Example 5 with Int2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap in project BloodMagic by WayofTime.

the class RegistrarBloodMagicItems method registerRenders.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void registerRenders(ModelRegistryEvent event) {
    items.stream().filter(i -> i instanceof IVariantProvider).forEach(i -> {
        Int2ObjectMap<String> variants = new Int2ObjectOpenHashMap<>();
        ((IVariantProvider) i).gatherVariants(variants);
        for (Int2ObjectMap.Entry<String> variant : variants.int2ObjectEntrySet()) ModelLoader.setCustomModelResourceLocation(i, variant.getIntKey(), new ModelResourceLocation(i.getRegistryName(), variant.getValue()));
    });
    items.stream().filter(i -> i instanceof IMeshProvider).forEach(i -> {
        IMeshProvider mesh = (IMeshProvider) i;
        ResourceLocation loc = mesh.getCustomLocation();
        if (loc == null)
            loc = i.getRegistryName();
        Set<String> variants = Sets.newHashSet();
        mesh.gatherVariants(variants::add);
        for (String variant : variants) ModelLoader.registerItemVariants(i, new ModelResourceLocation(loc, variant));
        ModelLoader.setCustomMeshDefinition(i, mesh.getMeshDefinition());
    });
    RegistrarBloodMagicBlocks.blocks.stream().filter(b -> b instanceof IVariantProvider).forEach(b -> {
        Int2ObjectMap<String> variants = new Int2ObjectOpenHashMap<>();
        ((IVariantProvider) b).gatherVariants(variants);
        for (Int2ObjectMap.Entry<String> variant : variants.int2ObjectEntrySet()) ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(b), variant.getIntKey(), new ModelResourceLocation(b.getRegistryName(), variant.getValue()));
    });
}
Also used : WayofTime.bloodmagic.item.soul(WayofTime.bloodmagic.item.soul) Item(net.minecraft.item.Item) IVariantProvider(WayofTime.bloodmagic.client.IVariantProvider) WayofTime.bloodmagic.item(WayofTime.bloodmagic.item) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ComponentTypes(WayofTime.bloodmagic.item.types.ComponentTypes) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBMBlock(WayofTime.bloodmagic.block.IBMBlock) Lists(com.google.common.collect.Lists) Side(net.minecraftforge.fml.relauncher.Side) RegistryEvent(net.minecraftforge.event.RegistryEvent) Mod(net.minecraftforge.fml.common.Mod) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) ItemPackSelfSacrifice(WayofTime.bloodmagic.item.gear.ItemPackSelfSacrifice) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) EnumHelper(net.minecraftforge.common.util.EnumHelper) IMeshProvider(WayofTime.bloodmagic.client.IMeshProvider) ItemLivingArmourPointsUpgrade(WayofTime.bloodmagic.item.alchemy.ItemLivingArmourPointsUpgrade) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ItemCuttingFluid(WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid) ItemFluidRouterFilter(WayofTime.bloodmagic.item.routing.ItemFluidRouterFilter) ItemNodeRouter(WayofTime.bloodmagic.item.routing.ItemNodeRouter) Items(net.minecraft.init.Items) ItemPackSacrifice(WayofTime.bloodmagic.item.gear.ItemPackSacrifice) Set(java.util.Set) WayofTime.bloodmagic.item.sigil(WayofTime.bloodmagic.item.sigil) ShardType(WayofTime.bloodmagic.item.types.ShardType) Sets(com.google.common.collect.Sets) ItemSentientArmour(WayofTime.bloodmagic.item.armour.ItemSentientArmour) List(java.util.List) BloodMagic(WayofTime.bloodmagic.BloodMagic) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ItemRouterFilter(WayofTime.bloodmagic.item.routing.ItemRouterFilter) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) IMeshProvider(WayofTime.bloodmagic.client.IMeshProvider) IVariantProvider(WayofTime.bloodmagic.client.IVariantProvider) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)29 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)8 List (java.util.List)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)5 HashMap (java.util.HashMap)5 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 Preconditions (com.google.common.base.Preconditions)2 Stopwatch (com.google.common.base.Stopwatch)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Maps (com.google.common.collect.Maps)2 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)2 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)2 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)2 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)2 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2