List of usage examples for org.apache.commons.collections BidiMap inverseBidiMap
BidiMap inverseBidiMap();
From source file:gov.nih.nci.lmp.mimGpml.ImporterHelper.java
/** * Convert arrow head./*from w ww. j av a 2 s . c om*/ * * @param mimArrowHead * the MIM arrow head * @return the GPML arrowhead type */ private static String convertArrowHead(String mimArrowHead) { BidiMap arrowHash = getGpmlToMimVisArrowHeadMap(); String gpmlArrowHead; // Default to LINE if (arrowHash.inverseBidiMap().get(mimArrowHead) != null) { gpmlArrowHead = arrowHash.inverseBidiMap().get(mimArrowHead).toString(); } else { gpmlArrowHead = "Line"; Logger.log.info("Pathway contains an arrow not supported in MIM: " + gpmlArrowHead); } return gpmlArrowHead; }
From source file:org.dkpro.tc.ml.svmhmm.report.SVMHMMOutcomeIDReport.java
@Override public void execute() throws Exception { // load gold and predicted labels loadGoldAndPredictedLabels();/*from w ww. j a v a 2s . com*/ File testFile = locateTestFile(); // original tokens List<String> originalTokens = SVMHMMUtils.extractOriginalTokens(testFile); // sequence IDs List<Integer> sequenceIDs = SVMHMMUtils.extractOriginalSequenceIDs(testFile); // sanity check if (goldLabels.size() != originalTokens.size() || goldLabels.size() != sequenceIDs.size()) { throw new IllegalStateException("Gold labels, original tokens or sequenceIDs differ in size!"); } File evaluationFolder = getContext().getFolder("", AccessMode.READWRITE); File evaluationFile = new File(evaluationFolder, ID_OUTCOME_KEY); File mappingFile = getContext().getFile(SVMHMMUtils.LABELS_TO_INTEGERS_MAPPING_FILE_NAME, AccessMode.READONLY); BidiMap id2label = SVMHMMUtils.loadMapping(mappingFile); String header = buildHeader(id2label); Properties prop = new SortedKeyProperties(); BidiMap label2id = id2label.inverseBidiMap(); for (int idx = 0; idx < goldLabels.size(); idx++) { String gold = goldLabels.get(idx); String pred = predictedLabels.get(idx); int g = (int) label2id.getKey(gold); int p = (int) label2id.getKey(pred); // we decrement all gold/pred labels by one because the evaluation modules seems to // expect that the numbering starts with 0 which is seemingly a problem for SVMHMM - // thus we decrement all labels and shifting the entire outcome numbering by one g--; p--; prop.setProperty("" + String.format("%05d", idx), p + SEPARATOR_CHAR + g + SEPARATOR_CHAR + THRESHOLD_DUMMY_CONSTANT); } OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(evaluationFile), "utf-8"); prop.store(osw, header); osw.close(); }
From source file:org.LexGrid.LexBIG.example.ScoreTerm.java
/** * Display results to the user.//from w ww . j a va 2 s . c o m * * @param result */ protected void printReport(BidiMap result) { final String Dash6 = "------"; final String Dash10 = "----------"; final String Dash60 = "------------------------------------------------------------"; Formatter f = new Formatter(); // Print header. String format = "%-5.5s|%-10.10s|%-60.60s\n"; Object[] hSep = new Object[] { Dash6, Dash10, Dash60 }; f.format(format, hSep); f.format(format, new Object[] { "Score", "Code", "Term" }); f.format(format, hSep); // Iterate over the result. for (MapIterator items = result.inverseBidiMap().mapIterator(); items.hasNext();) { ScoredTerm st = (ScoredTerm) items.next(); String code = (String) items.getValue(); // Evaluate code if (code != null && code.length() > 10) code = code.substring(0, 7) + "..."; // Evaluate term (wrap if necessary) String term = st.term; if (term != null && term.length() < 60) f.format(format, new Object[] { st.score, code, term }); else { String sub = term.substring(0, 60); f.format(format, new Object[] { st.score, code, sub }); int begin = 60; int end = term.length(); while (begin < end) { sub = term.substring(begin, Math.min(begin + 60, end)); f.format(format, new Object[] { "", "", sub }); begin += 60; } } } Util.displayMessage(f.out().toString()); }