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;
}
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;
}
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();
}
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);
}
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()));
});
}
Aggregations