List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:hu.ppke.itk.nlpg.purepos.MorphTagger.java
private IToken findBestLemma(IToken t, int position) { Collection<IToken> stems; if (Util.analysisQueue.hasAnal(position)) { stems = Util.analysisQueue.getAnalysises(position); stems = this.simplifyLemmata(stems); this.isLastGuessed = false; } else {//from w w w . ja v a 2 s . c o m stems = analyzer.analyze(t); this.isLastGuessed = false; } Map<ILemmaTransformation<String, Integer>, Double> tagLogProbabilities = model.getLemmaGuesser() .getTagLogProbabilities(t.getToken()); Map<IToken, Pair<ILemmaTransformation<String, Integer>, Double>> lemmaSuffixProbs = LemmaUtil .batchConvert(tagLogProbabilities, t.getToken(), model.getTagVocabulary()); boolean useMorph = true; if (Util.isEmpty(stems)) { this.isLastGuessed = true; // the guesser is used useMorph = false; stems = lemmaSuffixProbs.keySet(); } // matching tags Collection<IToken> possibleStems = new HashSet<IToken>(); for (IToken ct : stems) { if (t.getTag().equals(ct.getTag())) { // possibleStems.add(new Token(ct.getToken(), ct.getStem(), ct // .getTag())); possibleStems.add(ct); // possibleStems.add(new Token(ct.getToken(), Util.toLower(ct // .getStem()), ct.getTag())); } } if (Util.isEmpty(possibleStems)) { // error handling return new Token(t.getToken(), t.getToken(), t.getTag()); } // most frequrent stem IToken best; if (possibleStems.size() == 1 && !Util.isUpper(t.getToken())) { best = possibleStems.iterator().next(); } else { if (stemFilter != null) { possibleStems = stemFilter.filterStem(possibleStems); } List<Pair<IToken, ILemmaTransformation<String, Integer>>> comp = new LinkedList<Pair<IToken, ILemmaTransformation<String, Integer>>>(); for (IToken possTok : possibleStems) { Pair<ILemmaTransformation<String, Integer>, Double> pair = lemmaSuffixProbs.get(possTok); ILemmaTransformation<String, Integer> traf; if (pair != null) { traf = pair.getKey(); } else { traf = LemmaUtil.defaultLemmaRepresentation(possTok, model.getData()); } comp.add(Pair.of(possTok, traf)); if (!useMorph) { IToken lowerTok = new Token(possTok.getToken(), Util.toLower(possTok.getStem()), possTok.getTag()); comp.add(Pair.of(lowerTok, traf)); } } //try { best = Collections.max(comp, lemmaComparator).getKey(); //} catch (Exception e) { // System.err.println(t); // return null; //} } IToken ret = decodeLemma(best); return ret; }
From source file:alfio.manager.WaitingQueueProcessorIntegrationTest.java
@Test public void testPreRegistration() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);/*from www .j av a 2s. co m*/ Event event = pair.getKey(); waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event), "peppino@garibaldi.com", null, Locale.ENGLISH); waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event), "bixio@mille.org", null, Locale.ITALIAN); assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2); waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size()); TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null); eventManager.insertCategory(event.getId(), tcm, pair.getValue()); waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId()); assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count()); assertTrue(subscriptions.stream() .allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING))); assertTrue(subscriptions.stream() .allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES))); }
From source file:de.johni0702.minecraft.gui.container.AbstractGuiContainer.java
@Override public void convertFor(GuiElement element, Point point, int relativeLayer) { checkState(layedOutElements != null, "Cannot convert position unless rendered at least once."); Pair<ReadablePoint, ReadableDimension> pair = layedOutElements.get(element); checkState(pair != null, "Element " + element + " not part of " + this); ReadablePoint pos = pair.getKey(); if (getContainer() != null) { getContainer().convertFor(this, point, relativeLayer + getLayer()); }/* w w w . jav a2s. c o m*/ point.translate(-pos.getX(), -pos.getY()); }
From source file:com.act.lcms.db.model.PregrowthWell.java
public List<PregrowthWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<String, String> plateAttributes = parser.getPlateProperties(); Map<Pair<String, String>, String> msids = parser.getCompositionTables().get("msid"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(msids.keySet()); Collections.sort(sortedCoordinates, new Comparator<Pair<String, String>>() { // TODO: parse the values of these pairs as we read them so we don't need this silly comparator. @Override/* w w w . j av a 2 s. co m*/ public int compare(Pair<String, String> o1, Pair<String, String> o2) { if (o1.getKey().equals(o2.getKey())) { return Integer.valueOf(Integer.parseInt(o1.getValue())) .compareTo(Integer.parseInt(o2.getValue())); } return o1.getKey().compareTo(o2.getKey()); } }); List<PregrowthWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String msid = msids.get(coords); if (msid == null || msid.isEmpty()) { continue; } String sourcePlate = parser.getCompositionTables().get("source_plate").get(coords); String sourceWell = parser.getCompositionTables().get("source_well").get(coords); String composition = parser.getCompositionTables().get("composition").get(coords); String note = null; if (parser.getCompositionTables().get("note") != null) { note = parser.getCompositionTables().get("note").get(coords); } // TODO: ditch this when we start using floating point numbers for growth values. Integer growth = null; Map<Pair<String, String>, String> growthTable = parser.getCompositionTables().get("growth"); if (growthTable == null || growthTable.get(coords) == null) { String plateGrowth = plateAttributes.get("growth"); if (plateGrowth != null) { growth = Integer.parseInt(trimAndComplain(plateGrowth)); } } else { String growthStr = growthTable.get(coords); if (PLUS_MINUS_GROWTH_TO_INT.containsKey(growthStr)) { growth = PLUS_MINUS_GROWTH_TO_INT.get(growthStr); } else { growth = Integer.parseInt(growthStr); // If it's not using +/- format, it should be an integer from 1-5. } } Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); PregrowthWell s = INSTANCE.insert(db, p.getId(), index.getLeft(), index.getRight(), sourcePlate, sourceWell, msid, composition, note, growth); results.add(s); } return results; }
From source file:com.streamsets.pipeline.stage.processor.hbase.HBaseLookupProcessor.java
private Set<Pair<String, HBaseColumn>> getKeyColumnListMap(Batch batch) throws StageException { Iterator<Record> records; records = batch.getRecords();/*from w ww. j a v a 2 s.co m*/ Record record; Set<Pair<String, HBaseColumn>> keyList = new HashSet<>(); while (records.hasNext()) { record = records.next(); for (HBaseLookupParameterConfig parameters : conf.lookups) { Pair<String, HBaseColumn> key = getKey(record, parameters); if (key != null && !key.getKey().trim().isEmpty()) { keyList.add(key); } else { LOG.debug("No key on Record '{}' with key:'{}', column:'{}', timestamp:'{}'", record, key.getKey(), Bytes.toString(key.getValue().getCf()) + ":" + Bytes.toString(key.getValue().getQualifier()), key.getValue().getTimestamp()); } } } return keyList; }
From source file:com.uber.hoodie.common.util.TestCompactionUtils.java
@Test public void testBuildFromFileSlices() { Pair<List<Pair<String, FileSlice>>, HoodieCompactionPlan> inputAndPlan = buildCompactionPlan(); testFileSlicesCompactionPlanEquality(inputAndPlan.getKey(), inputAndPlan.getValue()); }
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testFixCategoriesSize() { List<TicketCategoryModification> categories = Arrays.asList( new TicketCategoryModification(null, "default", AVAILABLE_SEATS - 1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null), new TicketCategoryModification(null, "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventUsername = initEvent(categories); Event event = eventUsername.getKey(); TicketCategory firstCategory = ticketCategoryRepository.findByEventId(event.getId()).stream() .filter(TicketCategory::isBounded).findFirst().orElseThrow(IllegalStateException::new); int firstCategoryID = firstCategory.getId(); ticketCategoryRepository.updateSeatsAvailability(firstCategoryID, AVAILABLE_SEATS + 1); dataMigrator.fixCategoriesSize(event); assertEquals(AVAILABLE_SEATS - 1, ticketRepository.countAllocatedTicketsForEvent(event.getId()).intValue()); assertEquals(1, ticketRepository.countFreeTicketsForUnbounded(event.getId()).intValue()); assertEquals(AVAILABLE_SEATS - 1,//from ww w . j av a 2 s . co m ticketRepository.countFreeTickets(event.getId(), firstCategoryID).intValue()); assertEquals(AVAILABLE_SEATS - 1, firstCategory.getMaxTickets()); }
From source file:com.act.lcms.db.model.FeedingLCMSWell.java
public List<FeedingLCMSWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<String, String> plateProperties = parser.getPlateProperties(); String msid = null, composition = null; if (!plateProperties.containsKey("msid") && plateProperties.containsKey("composition")) { throw new RuntimeException("ERROR: assumed plate properties 'msid' and 'composition' do not exist"); }/*from www. j a v a2s. co m*/ msid = trimAndComplain(plateProperties.get("msid")); composition = trimAndComplain(plateProperties.get("composition")); // If a few well dones't have a concentration, it's not work keeping. Map<Pair<String, String>, String> concentrations = parser.getCompositionTables().get("concentration"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(concentrations.keySet()); Collections.sort(sortedCoordinates, new Comparator<Pair<String, String>>() { // TODO: parse the values of these pairs as we read them so we don't need this silly comparator. @Override public int compare(Pair<String, String> o1, Pair<String, String> o2) { if (o1.getKey().equals(o2.getKey())) { return Integer.valueOf(Integer.parseInt(o1.getValue())) .compareTo(Integer.parseInt(o2.getValue())); } return o1.getKey().compareTo(o2.getKey()); } }); List<FeedingLCMSWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String concentraitonStr = parser.getCompositionTables().get("concentration").get(coords); if (concentraitonStr == null || concentraitonStr.isEmpty()) { continue; } String extract = parser.getCompositionTables().get("extract").get(coords); String chemical = parser.getCompositionTables().get("chemical").get(coords); Double concentration = Double.parseDouble(concentraitonStr); String note = null; if (parser.getCompositionTables().get("note") != null) { note = parser.getCompositionTables().get("note").get(coords); } Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); FeedingLCMSWell s = INSTANCE.insert(db, new FeedingLCMSWell(null, p.getId(), index.getLeft(), index.getRight(), msid, composition, extract, chemical, concentration, note)); results.add(s); } return results; }
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testUpdateTicketReservation() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventUsername = initEvent(categories); Event event = eventUsername.getKey(); try {/*ww w .j av a 2 s . co m*/ TicketReservationModification trm = new TicketReservationModification(); trm.setAmount(1); trm.setTicketCategoryId(eventManager.loadTicketCategories(event).get(0).getId()); TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm, Optional.empty()); Date expiration = DateUtils.addDays(new Date(), 1); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(r), Collections.emptyList(), expiration, Optional.empty(), Optional.empty(), Locale.ENGLISH, false); dataMigrator.fillReservationsLanguage(); TicketReservation ticketReservation = ticketReservationManager.findById(reservationId).get(); assertEquals("en", ticketReservation.getUserLanguage()); } finally { eventManager.deleteEvent(event.getId(), eventUsername.getValue()); } }
From source file:com.astamuse.asta4d.render.test.RendererTester.java
private Object getAttrAsObject(String selector, String attr, boolean allowList, boolean allowEmpty) { List<Renderer> rendererList = renderer.asUnmodifiableList(); List<Object> valueList = new LinkedList<>(); for (Renderer r : rendererList) { if (r.getSelector().equals(selector)) { List<Transformer<?>> list = r.getTransformerList(); if (list.isEmpty()) { continue; } else { Transformer<?> t = list.get(0); if (t.getContent() instanceof AttributeSetter) { AttributeSetter setter = (AttributeSetter) t.getContent(); @SuppressWarnings("unchecked") Pair<String, Object> data = (Pair<String, Object>) setter.retrieveTestableData(); if (data.getKey().equals(attr)) { Object obj = data.getValue(); valueList.add(obj); }/*from w w w .j av a2 s. c om*/ } else { continue; } } } } if (!allowEmpty && valueList.isEmpty()) { throw new RendererTestException( "There is no value to be rendered for attr:[" + attr + "] of selector:[" + selector + "]"); } else if (valueList.size() > 1) { if (allowList) { return valueList; } else { throw new RendererTestException("There are more than one values(" + valueList.toString() + ") to be rendered for attr:[" + attr + "] of selector:[" + selector + "]"); } } else { if (allowList) { return valueList; } else { return valueList.get(0); } } }