List of usage examples for com.google.common.collect Table get
V get(@Nullable Object rowKey, @Nullable Object columnKey);
From source file:umd.twittertools.download.DataForHua.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("string").hasArg().withDescription("host").create(HOST_OPTION)); options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file containing topics in TREC format").create(QUERIES_OPTION)); options.addOption(/*from ww w .j a v a 2s. c om*/ OptionBuilder.withArgName("string").hasArg().withDescription("qrels file").create(QRELS_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of results to return") .create(NUM_RESULTS_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("group id").create(GROUP_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("access token").create(TOKEN_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("runtag").create(RUNTAG_OPTION)); options.addOption(new Option(VERBOSE_OPTION, "print out complete document")); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(HOST_OPTION) || !cmdline.hasOption(PORT_OPTION) || !cmdline.hasOption(QUERIES_OPTION) || !cmdline.hasOption(QRELS_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(DataForHua.class.getName(), options); System.exit(-1); } String queryFile = cmdline.getOptionValue(QUERIES_OPTION); if (!new File(queryFile).exists()) { System.err.println("Error: " + queryFile + " doesn't exist!"); System.exit(-1); } String runtag = cmdline.hasOption(RUNTAG_OPTION) ? cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG; TrecTopicSet topicsFile = TrecTopicSet.fromFile(new File(queryFile)); int numResults = 10000; try { if (cmdline.hasOption(NUM_RESULTS_OPTION)) { numResults = Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION)); } } catch (NumberFormatException e) { System.err.println("Invalid " + NUM_RESULTS_OPTION + ": " + cmdline.getOptionValue(NUM_RESULTS_OPTION)); System.exit(-1); } String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null; String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null; boolean verbose = cmdline.hasOption(VERBOSE_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); TrecSearchThriftClient client = new TrecSearchThriftClient(cmdline.getOptionValue(HOST_OPTION), Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)), group, token); TweetAnalyzer tokenizer = new TweetAnalyzer(Version.LUCENE_43, false); // no stemming Joiner joiner = Joiner.on(' '); String qrelsFile = cmdline.getOptionValue(QRELS_OPTION); Table<Integer, Long, Integer> groundTruth = RunTemporalModel.loadGroundTruth(qrelsFile); for (cc.twittertools.search.TrecTopic query : topicsFile) { List<TResult> results = client.search(query.getQuery(), query.getQueryTweetTime(), numResults); int i = 1; Set<Long> tweetIds = new HashSet<Long>(); for (TResult result : results) { if (!tweetIds.contains(result.id)) { // The TREC official qrels don't have the "MB" prefix and trailing zeros, so we perform // this transformation so that trec_eval doesn't complain. tweetIds.add(result.id); Integer qid = Integer.parseInt(query.getId().replaceFirst("^MB0*", "")); if (groundTruth.contains(qid, result.id)) { String qtext = joiner.join(LuceneTokenizer .tokenize(tokenizer.tokenStream("text", new StringReader(query.getQuery())))); String tweetText = joiner.join(LuceneTokenizer .tokenize(tokenizer.tokenStream("text", new StringReader(result.text)))); int label = groundTruth.get(qid, result.id); out.println(String.format("%d@%d@%d@%f@%s@%s", qid, result.id, label, result.rsv, qtext, tweetText)); } i++; } } } out.close(); }
From source file:org.caleydo.core.util.function.Functions2.java
/** * create a lookup function based on a table * * @param table/* w w w. j a v a2 s . c o m*/ * @return */ public static <F1, F2, T> Function2<F1, F2, T> fromTable(final Table<F1, F2, T> table) { return new Function2<F1, F2, T>() { @Override public T apply(F1 input1, F2 input2) { return table.get(input1, input2); } }; }
From source file:org.sonar.api.batch.rule.internal.DefaultRules.java
private static void addToTable(Table<String, String, List<Rule>> table, DefaultRule r) { if (r.internalKey() == null) { return;/*www. j a va 2 s . c om*/ } List<Rule> ruleList = table.get(r.key().repository(), r.internalKey()); if (ruleList == null) { ruleList = new LinkedList<>(); } ruleList.add(r); table.put(r.key().repository(), r.internalKey(), ruleList); }
From source file:org.opennms.netmgt.measurements.filters.impl.Utils.java
public static TableLimits getRowsWithValues(Table<Long, String, Double> table, String... columnNames) { TableLimits limits = new TableLimits(); for (long k : table.rowKeySet()) { for (String columnName : columnNames) { Double value = table.get(k, columnName); if (value != null && !Double.isNaN(value)) { if (limits.firstRowWithValues < 0) { limits.firstRowWithValues = k; }/* w ww.j a v a2 s . c o m*/ limits.lastRowWithValues = k; } } } return limits; }
From source file:org.opennms.netmgt.jasper.analytics.DataSourceUtils.java
public static Point getRowsWithValues(Table<Integer, String, Double> table, String... columnNames) { int firstRowWithValues = -1, lastRowWithValues = -1; for (int k : table.rowKeySet()) { for (String columnName : columnNames) { Double value = table.get(k, columnName); if (value != null && !Double.isNaN(value)) { if (firstRowWithValues < 0) { firstRowWithValues = k; }//ww w .ja v a 2 s .c o m lastRowWithValues = k; } } } return new Point(firstRowWithValues, lastRowWithValues); }
From source file:de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.StatisticsTableCreator.java
public static void saveTableToCsv(Table<String, String, Long> table, OutputStream outputStream) { PrintWriter pw = new PrintWriter(outputStream); pw.write(";"); for (String columnKey : table.columnKeySet()) { pw.printf("%s;", columnKey); }//from w ww . ja va 2 s . co m pw.println(); for (String rowKey : table.rowKeySet()) { pw.printf("%s;", rowKey); for (String columnKey : table.columnKeySet()) { Long value = table.get(rowKey, columnKey); pw.printf("%d;", value != null ? value : 0); } pw.println(); } IOUtils.closeQuietly(pw); }
From source file:org.splevo.jamopp.diffing.postprocessor.DifferenceStatisticLogger.java
/** * Write a log file about matched and unmatched resources. * * @param comparison/* ww w . ja v a2s. com*/ * model * @param logFilePath * the filename */ @SuppressWarnings("rawtypes") private static void logDiffingStatistics(Comparison comparison, String logFilePath) { Table<Class, DifferenceKind, Integer> statistics = HashBasedTable.create(); for (Diff diff : comparison.getDifferences()) { Integer current = statistics.get(diff.getClass(), diff.getKind()); if (current == null) { current = 0; } current++; statistics.put(diff.getClass(), diff.getKind(), current); } BufferedWriter writer = null; try { File logFile = new File(logFilePath); FileUtils.forceMkdir(logFile.getParentFile()); writer = new BufferedWriter(new FileWriter(logFile)); writer.write("Type , Kind , Count \n"); for (Class rowKey : statistics.rowKeySet()) { Map<DifferenceKind, Integer> row = statistics.row(rowKey); for (DifferenceKind kind : row.keySet()) { writer.write(rowKey.getSimpleName() + "," + kind.getLiteral() + "," + row.get(kind) + "\n"); } } } catch (IOException e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.android.tools.idea.uibuilder.property.NlProperties.java
private static void initStarState(@NotNull Table<String, String, NlPropertyItem> properties) { for (String starredProperty : getStarredProperties()) { Pair<String, String> property = split(starredProperty); NlPropertyItem item = properties.get(property.getFirst(), property.getSecond()); if (item != null) { item.setInitialStarred();/* w w w .j a v a2 s. c om*/ } } }
From source file:com.android.tools.idea.uibuilder.property.NlProperties.java
private static void setUpDesignProperties(@NotNull Table<String, String, NlPropertyItem> properties) { List<String> designProperties = new ArrayList<>(properties.row(TOOLS_URI).keySet()); for (String propertyName : designProperties) { NlPropertyItem item = properties.get(AUTO_URI, propertyName); if (item == null) { item = properties.get(ANDROID_URI, propertyName); }//from w w w . ja va 2 s .co m if (item != null) { NlPropertyItem designItem = item.getDesignTimeProperty(); properties.put(TOOLS_URI, propertyName, designItem); } } }
From source file:com.android.tools.idea.uibuilder.property.NlProperties.java
private static void setUpSrcCompat(@NotNull Table<String, String, NlPropertyItem> properties, @NotNull AndroidFacet facet, @NotNull List<NlComponent> components, @NotNull GradleDependencyManager dependencyManager) { NlPropertyItem srcProperty = properties.get(ANDROID_URI, ATTR_SRC); if (srcProperty != null && shouldAddSrcCompat(facet, components, dependencyManager)) { AttributeDefinition srcDefinition = srcProperty.getDefinition(); assert srcDefinition != null; AttributeDefinition srcCompatDefinition = new AttributeDefinition(ATTR_SRC_COMPAT, null, srcDefinition.getFormats()); srcCompatDefinition.getParentStyleables().addAll(srcDefinition.getParentStyleables()); NlPropertyItem srcCompatProperty = new NlPropertyItem(components, AUTO_URI, srcCompatDefinition); properties.put(AUTO_URI, ATTR_SRC_COMPAT, srcCompatProperty); }/* w w w . j a va 2 s. c o m*/ }