List of usage examples for java.util SortedMap get
V get(Object key);
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
@Override public Map<Cell, byte[]> get(String tableName, Set<Cell> cells) { Stopwatch watch = Stopwatch.createStarted(); checkGetPreconditions(tableName);/* w w w .j a v a 2 s . c om*/ if (Iterables.isEmpty(cells)) { return ImmutableMap.of(); } Map<Cell, byte[]> result = Maps.newHashMap(); SortedMap<Cell, byte[]> writes = writesByTable.get(tableName); if (writes != null) { for (Cell cell : cells) { if (writes.containsKey(cell)) { result.put(cell, writes.get(cell)); } } } // We don't need to read any cells that were written locally. result.putAll(getFromKeyValueService(tableName, Sets.difference(cells, result.keySet()))); if (perfLogger.isDebugEnabled()) { perfLogger.debug("get({}, {} cells) found {} cells (some possibly deleted), took {} ms", tableName, cells.size(), result.size(), watch.elapsed(TimeUnit.MILLISECONDS)); } validateExternalAndCommitLocksIfNecessary(tableName); return Maps.filterValues(result, Predicates.not(Value.IS_EMPTY)); }
From source file:org.omnaest.utils.table.TableTest.java
@Test public void testToMap() throws Exception { Table<String> table = this.filledTable(3, 4); {/*from w w w.j a va2 s . c o m*/ final SortedMap<String, String[]> sortedMap = table.to().sortedMap(1); assertNotNull(sortedMap); assertEquals(3, sortedMap.size()); assertEquals(Arrays.asList("0:1", "1:1", "2:1"), ListUtils.valueOf(sortedMap.keySet())); assertArrayEquals(new String[] { "1:0", "1:1", "1:2", "1:3" }, sortedMap.get("1:1")); } { final SortedMap<String, String> sortedMap = table.to().sortedMap(1, 3); assertNotNull(sortedMap); assertEquals(3, sortedMap.size()); assertEquals(Arrays.asList("0:1", "1:1", "2:1"), ListUtils.valueOf(sortedMap.keySet())); assertEquals("1:3", sortedMap.get("1:1")); } }
From source file:com.aurel.track.exchange.track.importer.TrackImportBL.java
/** * Get the key based matches for the dropdowns * /*from w w w.j a v a 2 s.com*/ * @param externalDropDowns * @param internalDropDowns * @return */ private static Map<String, Map<Integer, Integer>> getDropDownMatcherMap( SortedMap<String, List<ISerializableLabelBean>> externalDropDowns, Map<String, List<ISerializableLabelBean>> internalDropDowns, Map<Integer, Integer> fieldsMatcherMap, Set<Integer> presentFieldIDs) throws ImportExceptionList { ImportExceptionList importExceptionList = new ImportExceptionList(); Map<String, Map<Integer, Integer>> matcherMap = new HashMap<String, Map<Integer, Integer>>(); matcherMap.put(ExchangeFieldNames.FIELD, fieldsMatcherMap); /** * the roles assignments will be added only to the new projects */ List<Integer> internalProjectIDsBeforeMatch = GeneralUtils.createIntegerListFromBeanList( internalDropDowns.get(MergeUtil.mergeKey(SystemFields.INTEGER_PROJECT, null))); /** * the custom lists should be in the correct order because of the * hierarchical relations between them */ List<ISerializableLabelBean> listBeans = externalDropDowns.get(ExchangeFieldNames.LIST); if (listBeans != null) { Collections.sort(listBeans, new Comparator<ISerializableLabelBean>() { public int compare(ISerializableLabelBean o1, ISerializableLabelBean o2) { // suppose the objectID order is enough return o1.getObjectID().compareTo(o2.getObjectID()); } }); } externalDropDowns.put(ExchangeFieldNames.LIST, listBeans); /** * prepare the options by list */ Map<Integer, List<ISerializableLabelBean>> externalOptionsMap = new HashMap<Integer, List<ISerializableLabelBean>>(); List<ISerializableLabelBean> optionBeans = externalDropDowns.get(ExchangeFieldNames.OPTION); if (optionBeans != null) { Iterator<ISerializableLabelBean> itrOptionBeans = optionBeans.iterator(); while (itrOptionBeans.hasNext()) { TOptionBean optionBean = (TOptionBean) itrOptionBeans.next(); Integer listID = optionBean.getList(); List<ISerializableLabelBean> optionBeansList = externalOptionsMap.get(listID); if (optionBeansList == null) { optionBeansList = new ArrayList<ISerializableLabelBean>(); externalOptionsMap.put(listID, optionBeansList); } optionBeansList.add(optionBean); } } List<ISerializableLabelBean> externalList; List<ISerializableLabelBean> internalList; List<String> firstKeys = new ArrayList<String>(); // projectType should be matched before project firstKeys.add(ExchangeFieldNames.PROJECTTYPE); // systemStates should be matched before account, release, project firstKeys.add(ExchangeFieldNames.SYSTEMSTATE); // costcenter should be matched before account and department! firstKeys.add(ExchangeFieldNames.COSTCENTER); // account firstKeys.add(ExchangeFieldNames.ACCOUNT); // department should be matched before person but after costcenter firstKeys.add(ExchangeFieldNames.DEPARTMENT); // role should be matched before role assignments firstKeys.add(ExchangeFieldNames.ROLE); // priority and severity should be matched before person (email reminder // level) firstKeys.add(MergeUtil.mergeKey(SystemFields.INTEGER_PRIORITY, null)); firstKeys.add(MergeUtil.mergeKey(SystemFields.INTEGER_SEVERITY, null)); // status should be matched before project (initial status) firstKeys.add(MergeUtil.mergeKey(SystemFields.INTEGER_STATE, null)); // issue types (and project and projectType) should be matched before // fieldConfig firstKeys.add(MergeUtil.mergeKey(SystemFields.INTEGER_ISSUETYPE, null)); // person should be matched before project (default responsible, default // manager) firstKeys.add(MergeUtil.mergeKey(SystemFields.INTEGER_PERSON, null)); // project should be matched before release, but after person, state, // issueType, priority, severity system state and project type firstKeys.add(MergeUtil.mergeKey(SystemFields.INTEGER_PROJECT, null)); firstKeys.add(MergeUtil.mergeKey(SystemFields.INTEGER_RELEASE, null)); // lists should be matched after project (the project specific lists) firstKeys.add(ExchangeFieldNames.LIST); /** * process the entities which should be processed first */ for (String key : firstKeys) { externalList = externalDropDowns.get(key); // remove the processed entities to not to process again in // remaining entities loop // externalDropDowns.remove(key); internalList = internalDropDowns.get(key); try { addEntityMatchMap(externalList, internalList, key, matcherMap); } catch (ImportExceptionList e) { importExceptionList.getErrorDataList().addAll(e.getErrorDataList()); } } /** * all additional (non-fieldType specific) entities should be processed * now because they can't be broken in parts by MergeUtil like the * remaining entities */ /** * process the custom list options (after the lists are matched) */ if (listBeans != null) { // by now the lists are already matched Map<Integer, Integer> listMatches = matcherMap.get(ExchangeFieldNames.LIST); Iterator<ISerializableLabelBean> itrListBean = listBeans.iterator(); while (itrListBean.hasNext()) { TListBean listBean = (TListBean) itrListBean.next(); Integer externalListID = listBean.getObjectID(); Integer internalListID = listMatches.get(externalListID); // options are not loaded in the internal dropdowns but are // loaded now for each list separately try { addEntityMatchMap(externalOptionsMap.get(externalListID), (List) OptionBL.loadDataSourceByList(internalListID), ExchangeFieldNames.OPTION, matcherMap); } catch (ImportExceptionList e) { importExceptionList.getErrorDataList().addAll(e.getErrorDataList()); } } // externalDropDowns.remove(ExchangeFieldNames.OPTION); } /** * process the fieldConfigs */ List<ISerializableLabelBean> externalFieldConfigBeans = externalDropDowns .get(ExchangeFieldNames.FIELDCONFIG); List<TFieldConfigBean> internalFieldConfigBeans = FieldConfigBL.loadAllForFields(presentFieldIDs); try { addEntityMatchMap(externalFieldConfigBeans, (List) internalFieldConfigBeans, ExchangeFieldNames.FIELDCONFIG, matcherMap); } catch (ImportExceptionList e) { importExceptionList.getErrorDataList().addAll(e.getErrorDataList()); } Map<Integer, Integer> fieldConfigMatch = matcherMap.get(ExchangeFieldNames.FIELDCONFIG); // externalDropDowns.remove(ExchangeFieldNames.FIELDCONFIG); // gather the internalFieldConfigIDs for the field settings List<Integer> internalFieldConfigIDs = new ArrayList<Integer>(); if (fieldConfigMatch != null) { Iterator<Integer> itrFieldConfig = fieldConfigMatch.values().iterator(); while (itrFieldConfig.hasNext()) { Integer fieldConfigID = itrFieldConfig.next(); internalFieldConfigIDs.add(fieldConfigID); } } /** * process the fieldSettings */ List<ISerializableLabelBean> externalOptionSettingsBeans = externalDropDowns .get(ExchangeFieldNames.OPTIONSETTINGS); List<TOptionSettingsBean> internalOptionSettingsBeans = OptionSettingsBL .loadByConfigList(internalFieldConfigIDs); try { addEntityMatchMap(externalOptionSettingsBeans, (List) internalOptionSettingsBeans, ExchangeFieldNames.OPTIONSETTINGS, matcherMap); } catch (ImportExceptionList e) { importExceptionList.getErrorDataList().addAll(e.getErrorDataList()); } // externalDropDowns.remove(ExchangeFieldNames.OPTIONSETTINGS); List<ISerializableLabelBean> externalTextBoxSettingsBeans = externalDropDowns .get(ExchangeFieldNames.TEXTBOXSETTINGS); List<TTextBoxSettingsBean> internalTextBoxSettingsBeans = TextBoxSettingsBL .loadByConfigList(internalFieldConfigIDs); try { addEntityMatchMap(externalTextBoxSettingsBeans, (List) internalTextBoxSettingsBeans, ExchangeFieldNames.TEXTBOXSETTINGS, matcherMap); } catch (ImportExceptionList e) { importExceptionList.getErrorDataList().addAll(e.getErrorDataList()); } // externalDropDowns.remove(ExchangeFieldNames.TEXTBOXSETTINGS); // TODO implement special handling for general settings: specific for // each custom picker /* * List<ISerializableLabelBean> externalGeneralSettingsBeans = * externalDropDowns.get(ExchangeFieldNames.GENERALSETTINGS); * List<TGeneralSettingsBean> internalGeneralSettingsBeans = * generalSettingsDAO.loadByConfigList(internalFieldConfigIDs); * addEntityMatchMap(externalGeneralSettingsBeans, * (List)internalGeneralSettingsBeans, * ExchangeFieldNames.GENERALSETTINGS, matcherMap); */ // externalDropDowns.remove(ExchangeFieldNames.GENERALSETTINGS); /** * process role assignments (after role, person and project match) */ List<Integer> internalProjectIDsAfterMatch = GeneralUtils .createIntegerListFromBeanList(ProjectBL.loadAll()); // add the role assignments only for new projects internalProjectIDsAfterMatch.removeAll(internalProjectIDsBeforeMatch); if (internalProjectIDsAfterMatch != null && !internalProjectIDsAfterMatch.isEmpty()) { Map<Integer, Integer> projectMatch = matcherMap.get(MergeUtil.mergeKey(SystemFields.PROJECT, null)); List<ISerializableLabelBean> externalAccessControlLists = externalDropDowns.get(ExchangeFieldNames.ACL); if (externalAccessControlLists != null) { for (ISerializableLabelBean serializableLabelBean : externalAccessControlLists) { TAccessControlListBean externalAccessControlListBean = (TAccessControlListBean) serializableLabelBean; Integer externalProjectID = externalAccessControlListBean.getProjectID(); Integer internalProjectID = projectMatch.get(externalProjectID); if (internalProjectID != null && internalProjectIDsAfterMatch.contains(internalProjectID)) { externalAccessControlListBean.saveBean(externalAccessControlListBean, matcherMap); } } } } // the workItemIDs of the exported issues will be added during the // processing of each workItem Map<Integer, Integer> workItemIDsMatcherMap = new HashMap<Integer, Integer>(); matcherMap.put(MergeUtil.mergeKey(SystemFields.INTEGER_ISSUENO, null), workItemIDsMatcherMap); // but an attempt will be made to match the only linked but not // explicitly exported workItemIDs through the uuids List<ISerializableLabelBean> externalLinkedItems = externalDropDowns.get(ExchangeFieldNames.LINKED_ITEMS); if (externalLinkedItems != null) { // get the uuid list of the only linked external workItems List<String> externalLinkedUuidsList = new ArrayList<String>(); Iterator<ISerializableLabelBean> itrExternalLinkedItems = externalLinkedItems.iterator(); while (itrExternalLinkedItems.hasNext()) { ISerializableLabelBean externalLinkedItem = itrExternalLinkedItems.next(); externalLinkedUuidsList.add(externalLinkedItem.getUuid()); } if (!externalLinkedUuidsList.isEmpty()) { // get the internal workItems by the linked external uuids Map<String, Integer> internalUuidToObjectIDMap = new HashMap<String, Integer>(); List<TWorkItemBean> internalWorkItemBeanList = workItemDAO.loadByUuids(externalLinkedUuidsList); if (internalWorkItemBeanList != null && !internalWorkItemBeanList.isEmpty()) { // found internal workItems by external uuids Iterator<TWorkItemBean> itrWorkItemBean = internalWorkItemBeanList.iterator(); while (itrWorkItemBean.hasNext()) { TWorkItemBean workItemBean = itrWorkItemBean.next(); internalUuidToObjectIDMap.put(workItemBean.getUuid(), workItemBean.getObjectID()); } itrExternalLinkedItems = externalLinkedItems.iterator(); while (itrExternalLinkedItems.hasNext()) { // match the extarnal and internal workItemIDs by uuids ISerializableLabelBean externalLinkedItem = itrExternalLinkedItems.next(); Integer externObjectID = externalLinkedItem.getObjectID(); Integer internObjectID = internalUuidToObjectIDMap.get(externalLinkedItem.getUuid()); if (internObjectID != null) { workItemIDsMatcherMap.put(externObjectID, internObjectID); } } } } } // force reloading all lists LookupContainer.resetAll(); if (importExceptionList.containsException()) { throw importExceptionList; } return matcherMap; }
From source file:org.onebusaway.community_transit_gtfs.CommunityTransitGtfsFactory.java
/** * Borrowed from OBA StopTimeEntriesFactory. * We have a list of StopTimes, along with their distance traveled along their * trip/block. For any StopTime that has either an arrival or a departure * time, we add it to the SortedMaps of arrival and departure times by * distance traveled.// w w w. j a v a2 s .c o m * * @param stopTimes * @param distances * @param arrivalTimesByDistanceTraveled */ private void populateArrivalAndDepartureTimesByDistanceTravelledForStopTimes(List<StopTime> stopTimes, double[] distances, SortedMap<Double, Integer> scheduleTimesByDistanceTraveled) { for (int i = 0; i < stopTimes.size(); i++) { StopTime stopTime = stopTimes.get(i); double d = distances[i]; // We introduce distinct arrival and departure distances so that our // scheduleTimes map might have entries for arrival and departure times // that are not the same at a given stop double arrivalDistance = d; double departureDistance = d + 1e-6; /** * For StopTime's that have the same distance travelled, we keep the min * arrival time and max departure time */ if (stopTime.getArrivalTime() >= 0) { if (!scheduleTimesByDistanceTraveled.containsKey(arrivalDistance) || scheduleTimesByDistanceTraveled.get(arrivalDistance) > stopTime.getArrivalTime()) scheduleTimesByDistanceTraveled.put(arrivalDistance, stopTime.getArrivalTime()); } if (stopTime.getDepartureTime() >= 0) if (!scheduleTimesByDistanceTraveled.containsKey(departureDistance) || scheduleTimesByDistanceTraveled.get(departureDistance) < stopTime.getDepartureTime()) scheduleTimesByDistanceTraveled.put(departureDistance, stopTime.getDepartureTime()); } }
From source file:de.uni_potsdam.hpi.asg.logictool.mapping.SequenceBasedAndGateDecomposer.java
private Map<Integer, List<Partition>> getPartitions(Set<Signal> signals, int startgatesize) { // cost function SortedMap<Integer, List<Partition>> retVal = new TreeMap<>(Collections.reverseOrder()); Set<Set<Set<Signal>>> parts = getTailCombinations(signals); if (parts == null) { return null; }/*w ww . jav a 2 s . co m*/ for (Set<Set<Signal>> partition : parts) { int cost = 0; Set<PartitionPart> parts2 = new HashSet<>(); for (Set<Signal> partpart : partition) { parts2.add(new PartitionPart(partpart)); if (partpart.size() != 1) { cost += partpart.size(); } } if (partition.size() != 1) { cost += partition.size(); } if (!retVal.containsKey(cost)) { retVal.put(cost, new ArrayList<Partition>()); } retVal.get(cost).add(new Partition(parts2, cost)); } // System.out.println("Startgatesize: " + startgatesize); // filter too large List<Partition> rmPart = new ArrayList<>(); List<Integer> rmKey = new ArrayList<>(); for (Entry<Integer, List<Partition>> entry : retVal.entrySet()) { // System.out.println(entry.getKey()); rmPart.clear(); for (Partition p : entry.getValue()) { // System.out.println("\t" + p.toString()); if (p.getPartition().size() >= startgatesize) { // System.out.println("Rm: " + p); rmPart.add(p); continue; } for (PartitionPart p2 : p.getPartition()) { if (p2.getPart().size() >= startgatesize) { // System.out.println("Rm: " + p); rmPart.add(p); continue; } } } entry.getValue().removeAll(rmPart); if (entry.getValue().isEmpty()) { rmKey.add(entry.getKey()); } } for (int i : rmKey) { retVal.remove(i); } return retVal; }
From source file:tajo.master.GlobalPlanner.java
private Map<String, Map<ScanNode, List<Fragment>>> hashFragments(Map<ScanNode, List<Fragment>> fragMap) { SortedMap<String, Map<ScanNode, List<Fragment>>> hashed = new TreeMap<String, Map<ScanNode, List<Fragment>>>(); String key;//w ww.jav a 2s . c o m Map<ScanNode, List<Fragment>> m = null; List<Fragment> fragList = null; for (Entry<ScanNode, List<Fragment>> e : fragMap.entrySet()) { for (Fragment f : e.getValue()) { key = f.getPath().getName(); if (hashed.containsKey(key)) { m = hashed.get(key); } else { m = new HashMap<ScanNode, List<Fragment>>(); } if (m.containsKey(e.getKey())) { fragList = m.get(e.getKey()); } else { fragList = new ArrayList<Fragment>(); } fragList.add(f); m.put(e.getKey(), fragList); hashed.put(key, m); } } return hashed; }
From source file:fr.aliacom.obm.common.calendar.CalendarBindingImpl.java
private void ensureNewAttendeesWithDelegationAreAccepted(Event before, Event event) { ensureNewAttendeesWithDelegationAreAcceptedOnEvent(before, event); Set<Event> eventExceptions = event.getEventsExceptions(); SortedMap<Event, Event> beforeExceptions = buildSortedMap(before.getEventsExceptions()); for (Event eventException : eventExceptions) { ensureNewAttendeesWithDelegationAreAcceptedOnEvent(beforeExceptions.get(eventException), eventException);//from www .j av a2 s .c om } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.feature.coreference.CoreferenceFeatures.java
@Override protected List<Feature> extract(JCas jCas, Sentence sentence, String sentencePrefix) throws TextClassificationException { List<List<CoreferenceLink>> coreferenceChains = extractCoreferenceChains(jCas); FrequencyDistribution<String> featuresAcrossAllChains = new FrequencyDistribution<>(); DescriptiveStatistics chainLength = new DescriptiveStatistics(); DescriptiveStatistics distanceToPreviousSentence = new DescriptiveStatistics(); DescriptiveStatistics distanceToNextSentence = new DescriptiveStatistics(); DescriptiveStatistics interSentencesCorLinks = new DescriptiveStatistics(); for (List<CoreferenceLink> chain : coreferenceChains) { SortedMap<Integer, List<CoreferenceLink>> sentencesAndLinks = extractSentencesAndLinksFromChain(chain, jCas);//www. jav a 2s . c o m int currentSentencePos = getCurrentSentencePos(jCas, sentence); log.debug(sentencesAndLinks.keySet() + ", current " + currentSentencePos); // is the sentence in chain that spans more sentences? boolean partOfChain = sentencesAndLinks.containsKey(currentSentencePos) && sentencesAndLinks.size() > 1; // is part of a chain? if (partOfChain) { log.debug(chainToString(chain)); featuresAcrossAllChains.inc(FN_PART_OF_CHAIN); // starts the chain? if (sentencesAndLinks.firstKey().equals(currentSentencePos)) { featuresAcrossAllChains.inc(FN_STARTS_THE_CHAIN); } else if (sentencesAndLinks.lastKey().equals(currentSentencePos)) { // ends the chain? featuresAcrossAllChains.inc(FN_ENDS_THE_CHAIN); } else { // in the middle of chain? featuresAcrossAllChains.inc(FN_IN_THE_MIDDLE_OF_CHAIN); } // length of the chain chainLength.addValue(sentencesAndLinks.size()); List<CoreferenceLink> currentSentenceLinks = sentencesAndLinks.get(currentSentencePos); CoreferenceLink currentSentenceFirstLink = currentSentenceLinks.get(0); CoreferenceLink currentSentenceLastLink = currentSentenceLinks.get(currentSentenceLinks.size() - 1); // transition to the previous link, i.e. NOMINAL -> PRONOMINAL if (!sentencesAndLinks.firstKey().equals(currentSentencePos)) { // find the previous sentence List<CoreferenceLink> previousSentenceLinks = null; int prevSentNo = currentSentencePos; while (previousSentenceLinks == null && prevSentNo >= 0) { prevSentNo--; if (sentencesAndLinks.containsKey(prevSentNo)) { previousSentenceLinks = sentencesAndLinks.get(prevSentNo); } } if (previousSentenceLinks == null) { throw new IllegalStateException("Oops :))"); } // distance to previous sentence distanceToPreviousSentence.addValue(currentSentencePos - prevSentNo); // get the last link from the previous sentence CoreferenceLink prevSentenceLastLink = previousSentenceLinks .get(previousSentenceLinks.size() - 1); // add type type transition String prevSentenceLastLinkReferenceType = prevSentenceLastLink.getReferenceType(); String currentSentenceFirstLinkReferenceType = currentSentenceFirstLink.getReferenceType(); String transitionType = prevSentenceLastLinkReferenceType + GLUE + currentSentenceFirstLinkReferenceType; featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TYPE_TYPE + transitionType, 1); // add token - type transition String glueCoreferenceCurrentSentence = glueCoreferenceLinkTokens(currentSentenceFirstLink); String typeToken = prevSentenceLastLinkReferenceType + GLUE + glueCoreferenceCurrentSentence; featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TYPE_TOKEN + typeToken, 1); // add type - token transition String glueCoreferencePrevSentence = glueCoreferenceLinkTokens(prevSentenceLastLink); String tokenType = glueCoreferencePrevSentence + GLUE + currentSentenceFirstLinkReferenceType; featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TOKEN_TYPE + tokenType, 1); // add token token transition String tokenToken = glueCoreferencePrevSentence + GLUE + glueCoreferenceCurrentSentence; featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TOKEN_TOKEN + tokenToken, 1); // exact matching token-token reference? if (glueCoreferencePrevSentence.equals(glueCoreferenceCurrentSentence)) { featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TOKEN_TOKEN_MATCH, 1); } } // transition to the previous link, i.e. NOMINAL -> PRONOMINAL if (!sentencesAndLinks.lastKey().equals(currentSentencePos)) { // find the previous sentence List<CoreferenceLink> nextSentenceLinks = null; int nextSentNo = currentSentencePos; while (nextSentenceLinks == null && nextSentNo <= sentencesAndLinks.lastKey()) { nextSentNo++; if (sentencesAndLinks.containsKey(nextSentNo)) { nextSentenceLinks = sentencesAndLinks.get(nextSentNo); } } if (nextSentenceLinks == null) { throw new IllegalStateException("Oops :))"); } // distance to next sentence distanceToNextSentence.addValue(nextSentNo - currentSentencePos); // get the last link from the previous sentence CoreferenceLink nextSentenceFirstLink = nextSentenceLinks.get(0); // add type type transition String currentSentenceLastLinkReferenceType = currentSentenceLastLink.getReferenceType(); String nextSentenceFirstLinkReferenceType = nextSentenceFirstLink.getReferenceType(); String transitionType = currentSentenceLastLinkReferenceType + GLUE + nextSentenceFirstLinkReferenceType; featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TYPE_TYPE + transitionType, 1); // add token - type transition String glueCoreferenceCurrentSent = glueCoreferenceLinkTokens(currentSentenceLastLink); String typeToken = glueCoreferenceCurrentSent + GLUE + nextSentenceFirstLinkReferenceType; featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TOKEN_TYPE + typeToken, 1); // add type - token transition String glueCoreferenceNextSent = glueCoreferenceLinkTokens(nextSentenceFirstLink); String tokenType = currentSentenceLastLinkReferenceType + GLUE + glueCoreferenceNextSent; featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TYPE_TOKEN + tokenType, 1); // add token token transition String tokenToken = glueCoreferenceCurrentSent + GLUE + glueCoreferenceNextSent; featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TOKEN_TOKEN + tokenToken, 1); // exact matching token-token reference? if (glueCoreferenceNextSent.equals(glueCoreferenceCurrentSent)) { featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TOKEN_TOKEN_MATCH, 1); } } } // number of inter-sentence coreference links if (sentencesAndLinks.containsKey(currentSentencePos)) { int coreferenceLinks = sentencesAndLinks.get(currentSentencePos).size(); interSentencesCorLinks.addValue(coreferenceLinks); } /* List<Integer> positions = positionsOfSentenceInCurrentChain(chain, sentence); // ok, we're in a chain if (!positions.isEmpty()) { log.debug(printChain(chain)); log.debug(sentence.getCoveredText()); log.debug(positions); Integer lastPosition = positions.get(positions.size() - 1); Integer firstPosition = positions.get(0); if (lastPosition == positions.size() - 1) { log.debug("Last sentence of chain"); } log.debug("-----"); } */ } List<Feature> result = new ArrayList<>(); log.debug(featuresAcrossAllChains); if (distanceToNextSentence.getN() > 0) { log.debug("Next:" + distanceToNextSentence); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_NEXT_MIN, distanceToNextSentence.getMin())); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_NEXT_MAX, distanceToNextSentence.getMax())); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_NEXT_AVG, distanceToNextSentence.getMean())); } if (distanceToPreviousSentence.getN() > 0) { log.debug("Prev: " + distanceToPreviousSentence); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_PREV_MIN, distanceToPreviousSentence.getMin())); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_PREV_MAX, distanceToPreviousSentence.getMax())); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_PREV_AVG, distanceToPreviousSentence.getMean())); } if (interSentencesCorLinks.getN() > 0) { result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_INTER_SENT_COR_MIN, interSentencesCorLinks.getMin())); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_INTER_SENT_COR_MAX, interSentencesCorLinks.getMax())); result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_INTER_SENT_COR_AVG, interSentencesCorLinks.getMean())); } log.debug("----"); for (String feat : featuresAcrossAllChains.getKeys()) { // binary result.add(new Feature(sentencePrefix + FEATURE_NAME + feat, 1)); } return result; }
From source file:com.aurel.track.exchange.excel.ExcelImportBL.java
/** * Add the error in the map/* www . j a va2s . c o m*/ * * @param errorsMap * @param rowIndex * @param columIndex * @param value */ private static void addGridError(Map<Integer, SortedMap<Integer, SortedMap<String, ErrorData>>> errorsMap, Integer errorType, int rowIndex, String columIndex, Integer fieldID, String value) { SortedMap<Integer, SortedMap<String, ErrorData>> errorsOfType = errorsMap.get(errorType); if (errorsOfType == null) { errorsOfType = new TreeMap<Integer, SortedMap<String, ErrorData>>(); errorsMap.put(errorType, errorsOfType); } Integer newRowIndex = new Integer(rowIndex + 1); SortedMap<String, ErrorData> rowErrors = errorsOfType.get(newRowIndex); if (rowErrors == null) { rowErrors = new TreeMap<String, ErrorData>(); errorsOfType.put(newRowIndex, rowErrors); } ErrorData errorData = rowErrors.get(columIndex); if (errorData == null) { rowErrors.put(columIndex, new ErrorData(fieldID, value)); } else { // for composite parts when more than one part value is invalid String existingValue = errorData.getResourceKey(); if (existingValue != null && value != null && !"".equals(value.trim())) { errorData.setResourceKey(existingValue + CustomCompositeBaseRT.PART_SPLITTER_STRING + value); } } }
From source file:com.aurel.track.exchange.excel.ExcelImportBL.java
/** * Render grid errors//from w w w.ja v a2s . co m * * @param errorsMap * @param locale * @return */ private static List<String> renderGridErrors(SortedMap<Integer, SortedMap<String, ErrorData>> errorsMap, Locale locale) { List<String> gridErrors = new LinkedList<String>(); if (errorsMap != null) { Iterator<Integer> itrRows = errorsMap.keySet().iterator(); while (itrRows.hasNext()) { Integer row = itrRows.next(); Map<String, ErrorData> errorsOnRow = errorsMap.get(row); if (errorsOnRow != null) { Iterator<String> itrColumns = errorsOnRow.keySet().iterator(); while (itrColumns.hasNext()) { String column = itrColumns.next(); ErrorData originalErrorData = errorsOnRow.get(column); List<ErrorParameter> resourceParameters = new ArrayList<ErrorParameter>(); resourceParameters.add(new ErrorParameter(row)); resourceParameters.add(new ErrorParameter(column)); resourceParameters.add(new ErrorParameter(originalErrorData.getResourceKey())); ErrorData modifiedErrorData = new ErrorData("admin.actions.importExcel.err.gridDataError", resourceParameters); gridErrors.add(ErrorHandlerJSONAdapter.createMessage(modifiedErrorData, locale)); } } } } return gridErrors; }