List of usage examples for org.apache.commons.collections15 Bag add
boolean add(E object);
From source file:com.diversityarrays.kdxplore.boxplot.BoxPlotPanel.java
private BoxAndWhiskerCategoryDataset createSampleDataSet(Bag<String> missingOrBad, Bag<String> suppressed, Double[] minMax) {//w w w. ja v a 2s . c o m final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); seriesCountByTraitName.clear(); minMax[0] = null; minMax[1] = null; int count = 0; for (TraitInstance instance : traitInstances) { TraitInstanceValueRetriever<?> y_tivr = tivrByTi.get(instance); String instanceName = traitNameStyle.makeTraitInstanceName(instance); List<Double> data = new ArrayList<Double>(); for (PlotOrSpecimen pos : plotSpecimens) { Plot plot = plotInfoProvider.getPlotByPlotId(pos.getPlotId()); if (plot == null || !plot.isActivated()) { continue; } TraitValue yTraitValue = y_tivr.getAttributeValue(plotInfoProvider, plot, null); if (yTraitValue == null || !(yTraitValue.comparable instanceof Number)) { missingOrBad.add(instanceName); continue; } else if (yTraitValue.suppressed) { // TODO count suppressed suppressed.add(instanceName); continue; } double y = ((Number) yTraitValue.comparable).doubleValue(); data.add(y); if (minMax[0] == null) { minMax[0] = y; minMax[1] = y; } else { minMax[0] = Math.min(minMax[0], y); minMax[1] = Math.max(minMax[1], y); } } seriesCountByTraitName.put(instanceName, count); String columnKey = ""; // TODO use something better? //$NON-NLS-1$ dataset.add(data, instanceName, columnKey); count++; } return dataset; }
From source file:com.diversityarrays.kdxplore.KDXploreFrame.java
private void initialiseKdxApps() throws IOException { String[] classNames = KdxploreConfig.getInstance().getMainPluginClassNames(); if (classNames != null && classNames.length > 0) { List<String> classNamesToLoad = new ArrayList<>(); Collections.addAll(classNamesToLoad, classNames); if (!classNamesToLoad.contains(OFFLINE_DATA_APP_SERVICE_CLASS_NAME)) { classNamesToLoad.add(0, OFFLINE_DATA_APP_SERVICE_CLASS_NAME); classNames = classNamesToLoad.toArray(new String[classNamesToLoad.size()]); }/* w ww. jav a2s . co m*/ } Map<KdxApp, Component> componentByApp = collectKdxApps(classNames); appByComponent.clear(); for (KdxApp app : componentByApp.keySet()) { Component comp = componentByApp.get(app); if (comp != null) { appByComponent.put(comp, app); } } allKdxApps.clear(); allKdxApps.addAll(componentByApp.keySet()); // Initialise the apps in initialisation order. allKdxApps.sort(Comparator.comparing(KdxApp::getInitialisationOrder)); // And while we're initialising them we collect // those that can perform a databaseBackup (i.e. have a BackupProvider). backupProviders.clear(); List<KdxApp> wantedAppsWithUi = new ArrayList<>(); for (KdxApp app : allKdxApps) { BackupProvider bp = app.getBackupProvider(); if (bp != null) { backupProviders.add(bp); } /** * See {@link com.diversityarrays.kdxplore.prefs.KdxplorePreferences#SHOW_ALL_APPS} */ if (appIsWanted(app)) { try { app.initialiseAppBeforeUpdateCheck(appInitContext); } catch (Exception e) { String msg = Msg.MSG_KDXAPP_INIT_PROBLEM(app.getAppName()); Shared.Log.w(TAG, msg, e); messagesPanel.println(msg); messagesPanel.println(e.getMessage()); } } if (appIsWanted(app) && null != componentByApp.get(app)) { wantedAppsWithUi.add(app); } } // - - - - - - - - - - - - - - - - - - - - - // Display the apps in display order. wantedAppsWithUi.sort(Comparator.comparing(KdxApp::getDisplayOrder)); backupProviders.sort(Comparator.comparing(BackupProvider::getDisplayOrder)); switch (wantedAppsWithUi.size()) { case 0: JLabel label = new JLabel(Msg.MSG_NO_KDXPLORE_APPS_AVAILABLE()); label.setHorizontalAlignment(JLabel.CENTER); cardPanel.add(label, CARD_KDXAPPS); break; case 1: KdxApp kdxApp = wantedAppsWithUi.get(0); Component uiComponent = componentByApp.get(kdxApp); Component appComponent = makeComponentForTab(kdxApp, uiComponent); cardPanel.add(appComponent, CARD_KDXAPPS); getRootPane().setDefaultButton(kdxApp.getDefaultButton()); String msg = Msg.MSG_SHOWING_KDXAPP(kdxApp.getAppName()); messagesPanel.println(msg); System.err.println(msg + " uiClass=" //$NON-NLS-1$ + uiComponent.getClass().getName()); break; default: kdxAppTabs = new JTabbedPane(JTabbedPane.LEFT); cardPanel.add(kdxAppTabs, CARD_KDXAPPS); Bag<String> tabsSeen = new HashBag<>(); for (KdxApp app : wantedAppsWithUi) { Component ui = componentByApp.get(app); String tabName = app.getAppName(); DevelopmentState devState = app.getDevelopmentState(); switch (devState) { case ALPHA: tabName = tabName + " (\u03b1)"; // TODO move to UnicodeChars break; case BETA: tabName = tabName + " (\u03b2)"; // TODO move to UnicodeChars break; case PRODUCTION: break; default: tabName = tabName + " " + devState.name(); break; } tabsSeen.add(tabName); int count = tabsSeen.getCount(tabName); if (count > 1) { tabName = tabName + "_" + count; //$NON-NLS-1$ } Component tabComponent = makeComponentForTab(app, ui); kdxAppTabs.addTab(tabName, tabComponent); if (macapp == null) { int index = kdxAppTabs.indexOfTab(tabName); if (index >= 0) { JLabel tabLabel = new JLabel(tabName); tabLabel.setBorder(new EmptyBorder(2, 2, 2, 2)); tabLabel.setUI(new VerticalLabelUI(VerticalLabelUI.UPWARDS)); kdxAppTabs.setTabComponentAt(index, tabLabel); } } messagesPanel.println(Msg.MSG_SHOWING_KDXAPP(tabName)); } kdxAppTabs.addChangeListener(kdxAppTabsChangeListener); kdxAppTabs.setSelectedIndex(0); break; } }
From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java
private void checkForInvalidTraits() { SampleGroup db_smdata = curationData.getDatabaseSampleGroup(); if (db_smdata == null) { return;// www . j a v a 2 s . co m } Bag<Integer> traitIdCountsFromDatabase = new HashBag<>(); for (KdxSample sm : db_smdata.getSamples()) { traitIdCountsFromDatabase.add(sm.getTraitId()); } Set<Integer> errorTraitIds = new HashSet<>(traitIdCountsFromDatabase.uniqueSet()); Set<Integer> traitIds = CurationData.getTraitIds(curationData); errorTraitIds.removeAll(traitIds); if (!errorTraitIds.isEmpty()) { for (Integer id : errorTraitIds) { if (id == null) { continue; } Trait trait = this.traitProvider.apply(id); if (trait == null) { trait = new Trait(); trait.setTraitId(id); trait.setTraitName("Unknown Trait#" + id); } errorTraitsById.put(id, trait); } } }
From source file:net.sqs2.util.PathUtil.java
public static Set<File> getSharedSuperDirectorySet(Iterable<File> files) { Bag<File> bag = new HashBag<File>(); for (File file : files) { File superdir = file;/* w ww .j a v a2s . com*/ do { // System.err.print("SRC:"+file); bag.add(superdir); // System.err.print("\t"); // System.err.print(superdir); } while ((superdir = superdir.getParentFile()) != null); } Set<File> ret = new HashSet<File>(); for (File file : bag.uniqueSet()) { if (1 < bag.getCount(file)) { ret.add(file); } } return ret; }
From source file:trendanalisis.main.tools.weka.CoreWekaTFIDF.java
/** * Converts the instance w/o normalization. * //from w w w. ja va2s . c o m * @oaram instance the instance to convert * @param v * @return the conerted instance */ private int convertInstancewoDocNorm(Instance instance, ArrayList<Instance> v, int indexInstance) { // Convert the instance into a sorted set of indexes TreeMap<Integer, Double> contained = new TreeMap<Integer, Double>(); // Copy all non-converted attributes from input to output int firstCopy = 0; for (int i = 0; i < getInputFormat().numAttributes(); i++) { if (!m_SelectedRange.isInRange(i)) { if (getInputFormat().attribute(i).type() != Attribute.STRING && getInputFormat().attribute(i).type() != Attribute.RELATIONAL) { // Add simple nominal and numeric attributes directly if (instance.value(i) != 0.0) { contained.put(new Integer(firstCopy), new Double(instance.value(i))); } } else { if (instance.isMissing(i)) { contained.put(new Integer(firstCopy), new Double(Utils.missingValue())); } else if (getInputFormat().attribute(i).type() == Attribute.STRING) { // If this is a string attribute, we have to first add // this value to the range of possible values, then add // its new internal index. if (outputFormatPeek().attribute(firstCopy).numValues() == 0) { // Note that the first string value in a // SparseInstance doesn't get printed. outputFormatPeek().attribute(firstCopy) .addStringValue("Hack to defeat SparseInstance bug"); } int newIndex = outputFormatPeek().attribute(firstCopy) .addStringValue(instance.stringValue(i)); contained.put(new Integer(firstCopy), new Double(newIndex)); } else { // relational if (outputFormatPeek().attribute(firstCopy).numValues() == 0) { Instances relationalHeader = outputFormatPeek().attribute(firstCopy).relation(); // hack to defeat sparse instances bug outputFormatPeek().attribute(firstCopy).addRelation(relationalHeader); } int newIndex = outputFormatPeek().attribute(firstCopy) .addRelation(instance.relationalValue(i)); contained.put(new Integer(firstCopy), new Double(newIndex)); } } firstCopy++; } } Map<Integer, Integer> posMap = new HashMap<>(); Bag<String> contents = new HashBag(); for (int j = 0; j < instance.numAttributes(); j++) { // if ((getInputFormat().attribute(j).type() == Attribute.STRING) if (m_SelectedRange.isInRange(j) && (instance.isMissing(j) == false)) { m_Tokenizer.tokenize(instance.stringValue(j)); int posWord = 1; while (m_Tokenizer.hasMoreElements()) { String word = m_Tokenizer.nextElement(); if (this.m_lowerCaseTokens == true) { word = word.toLowerCase(); } word = m_Stemmer.stem(word); // System.out.println(posWord +":"+ word); Integer index = m_Dictionary.get(word); Words.put(index, word); contents.add(word); if (index != null) { if (m_OutputCounts) { // Separate if here rather than two lines down // to avoid hashtable lookup Double count = contained.get(index); if (count != null) { contained.put(index, new Double(count.doubleValue() + 1.0)); } else { contained.put(index, new Double(1)); } } else { contained.put(index, new Double(1)); } if (!posMap.containsKey(index)) { posMap.put(index, posWord); // posWord++; } } posWord++; } } } // Doing TFTransform // ArrayList<Integer> posList= new ArrayList<>(posMap.values()); // System.out.println(posList); /* * Fitur Subtittle * instance attribut ke 0 adalah judul * 1 adalah lokasi * 3 adalah tanggal */ String subtittle = ""; ArrayList<String> subtittles = null; if (ins_fitur_subtitle != null) { subtittle = ins_fitur_subtitle.get(indexInstance).stringValue(0); subtittles = new ArrayList<>(Arrays.asList(subtittle.split(" "))); // subtittles.retainAll(contents); } else { fitur_subtitle = false; } if (m_TFTransform == true) { Iterator<Integer> it = contained.keySet().iterator(); int set = 0; for (; it.hasNext();) { Integer index = it.next(); if (index.intValue() >= firstCopy) { double val = contained.get(index).doubleValue(); if (isBinary_transform()) { val = 1; } // val = (1 + Math.log(val)); contained.put(index, new Double(val)); set++; } } } // Doing IDFTransform double sum = 0; if (m_IDFTransform == true) { Iterator<Integer> it = contained.keySet().iterator(); int i = 0; for (; it.hasNext();) { Integer index = it.next(); if (index.intValue() >= firstCopy) { double val = contained.get(index).doubleValue(); double valIG = (FeatureSelection.InformationGain(m_DocsCounts[index.intValue()], m_NumInstances));// Math.abs(valIG); global_tf[index.intValue()] += val; df_prob[index.intValue()] = FeatureSelection.IdfProbability((double) m_NumInstances, m_DocsCounts[index.intValue()]); IG[index.intValue()] = valIG; if (isBinary_transform()) { val = 1; val = (Math.log(val)); } val = val * (1 + Math.log((double) m_NumInstances / (double) m_DocsCounts[index.intValue()])); if (isStat_pos_word()) { val = val + (1 / Math.sqrt(posMap.get(index))); } contained.put(index, new Double(val)); // global_tf[index.intValue()]= (1+ Math.log(m_NumInstances / (double) m_DocsCounts[index.intValue()])); i++; } } } // System.out.println("-------------------"); // Convert the set to structures needed to create a sparse instance. double[] values = new double[contained.size()]; int[] indices = new int[contained.size()]; Iterator<Integer> it = contained.keySet().iterator(); for (int i = 0; it.hasNext(); i++) { Integer index = it.next(); Double value = contained.get(index); values[i] = value.doubleValue(); indices[i] = index.intValue(); //df_prob[index.intValue()] = df_prob[index.intValue()]/m_DocsCounts[index.intValue()]; } Instance inst = new SparseInstance(instance.weight(), values, indices, outputFormatPeek().numAttributes()); inst.setDataset(outputFormatPeek()); v.add(inst); return firstCopy; }