com.google.common.collect.Table.Cell Java Examples
The following examples show how to use
com.google.common.collect.Table.Cell.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * A factory that chooses the most space-efficient representation of the * table. */ private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) { Set<R> rowSpaceBuilder = new LinkedHashSet<R>(); Set<C> columnSpaceBuilder = new LinkedHashSet<C>(); ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells); for (Cell<R, C, V> cell : cells) { rowSpaceBuilder.add(cell.getRowKey()); columnSpaceBuilder.add(cell.getColumnKey()); } ImmutableSet<R> rowSpace = (rowComparator == null) ? ImmutableSet.copyOf(rowSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder)); ImmutableSet<C> columnSpace = (columnComparator == null) ? ImmutableSet.copyOf(columnSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder)); // use a dense table if more than half of the cells have values // TODO(gak): tune this condition based on empirical evidence return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace); }
Example #2
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * A factory that chooses the most space-efficient representation of the * table. */ private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) { Set<R> rowSpaceBuilder = new LinkedHashSet<R>(); Set<C> columnSpaceBuilder = new LinkedHashSet<C>(); ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells); for (Cell<R, C, V> cell : cells) { rowSpaceBuilder.add(cell.getRowKey()); columnSpaceBuilder.add(cell.getColumnKey()); } ImmutableSet<R> rowSpace = (rowComparator == null) ? ImmutableSet.copyOf(rowSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder)); ImmutableSet<C> columnSpace = (columnComparator == null) ? ImmutableSet.copyOf(columnSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder)); // use a dense table if more than half of the cells have values // TODO(gak): tune this condition based on empirical evidence return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace); }
Example #3
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * A factory that chooses the most space-efficient representation of the * table. */ private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) { Set<R> rowSpaceBuilder = new LinkedHashSet<R>(); Set<C> columnSpaceBuilder = new LinkedHashSet<C>(); ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells); for (Cell<R, C, V> cell : cells) { rowSpaceBuilder.add(cell.getRowKey()); columnSpaceBuilder.add(cell.getColumnKey()); } ImmutableSet<R> rowSpace = (rowComparator == null) ? ImmutableSet.copyOf(rowSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder)); ImmutableSet<C> columnSpace = (columnComparator == null) ? ImmutableSet.copyOf(columnSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder)); // use a dense table if more than half of the cells have values // TODO(gak): tune this condition based on empirical evidence return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace); }
Example #4
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * A factory that chooses the most space-efficient representation of the * table. */ private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) { Set<R> rowSpaceBuilder = new LinkedHashSet<R>(); Set<C> columnSpaceBuilder = new LinkedHashSet<C>(); ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells); for (Cell<R, C, V> cell : cells) { rowSpaceBuilder.add(cell.getRowKey()); columnSpaceBuilder.add(cell.getColumnKey()); } ImmutableSet<R> rowSpace = (rowComparator == null) ? ImmutableSet.copyOf(rowSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder)); ImmutableSet<C> columnSpace = (columnComparator == null) ? ImmutableSet.copyOf(columnSpaceBuilder) : ImmutableSet.copyOf(Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder)); // use a dense table if more than half of the cells have values // TODO(gak): tune this condition based on empirical evidence return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace); }
Example #5
Source File: ParallelCorpusReader.java From EasySRL with Apache License 2.0 | 6 votes |
private static Collection<SRLParse> getPropbankSection(final String section) throws IOException { final Table<String, Integer, TreebankParse> PTB = new PennTreebank().readCorpus(WSJ); final Table<String, Integer, SRLParse> srlParses = SRLParse.parseCorpus(PTB, Util.readFileLineByLine(new File(PROPBANK, "prop.txt")), USING_NOMBANK ? Util.readFileLineByLine(NOMBANK) : null); final Table<String, Integer, SRLParse> goldParses = TreeBasedTable.create(); for (final Cell<String, Integer, TreebankParse> cell : PTB.cellSet()) { // Propbank files skip sentences with no SRL deps. Add a default // empty parse for all sentences. goldParses.put(cell.getRowKey(), cell.getColumnKey(), new SRLParse(cell.getValue().getWords())); } goldParses.putAll(srlParses); final Collection<SRLParse> result = new ArrayList<>(); for (final Cell<String, Integer, SRLParse> entry : goldParses.cellSet()) { if (entry.getRowKey().startsWith("wsj_" + section)) { result.add(entry.getValue()); } } return result; }
Example #6
Source File: IDESolver.java From JAADAS with GNU General Public License v3.0 | 6 votes |
public void run() { int sectionSize = (int) Math.floor(values.length / numThreads) + numThreads; for(int i = sectionSize * num; i < Math.min(sectionSize * (num+1),values.length); i++) { N n = values[i]; for(N sP: icfg.getStartPointsOf(icfg.getMethodOf(n))) { Set<Cell<D, D, EdgeFunction<V>>> lookupByTarget; lookupByTarget = jumpFn.lookupByTarget(n); for(Cell<D, D, EdgeFunction<V>> sourceValTargetValAndFunction : lookupByTarget) { D dPrime = sourceValTargetValAndFunction.getRowKey(); D d = sourceValTargetValAndFunction.getColumnKey(); EdgeFunction<V> fPrime = sourceValTargetValAndFunction.getValue(); synchronized (val) { setVal(n,d,valueLattice.join(val(n,d),fPrime.computeTarget(val(sP,dPrime)))); } flowFunctionApplicationCount++; } } } }
Example #7
Source File: JimpleIDESolver.java From JAADAS with GNU General Public License v3.0 | 6 votes |
public void dumpResults() { try { PrintWriter out = new PrintWriter(new FileOutputStream("ideSolverDump"+System.currentTimeMillis()+".csv")); List<String> res = new ArrayList<String>(); for(Cell<Unit, D, V> entry: val.cellSet()) { SootMethod methodOf = (SootMethod) icfg.getMethodOf(entry.getRowKey()); PatchingChain<Unit> units = methodOf.getActiveBody().getUnits(); int i=0; for (Unit unit : units) { if(unit==entry.getRowKey()) break; i++; } res.add(methodOf+";"+entry.getRowKey()+"@"+i+";"+entry.getColumnKey()+";"+entry.getValue()); } Collections.sort(res); for (String string : res) { out.println(string); } out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
Example #8
Source File: AbstractParser.java From EasySRL with Apache License 2.0 | 6 votes |
public AbstractParser(final ParserBuilder<?> builder) { this.unaryRules = builder.getUnaryRules(); this.seenRules = builder.getSeenRules(); this.lexicalCategories = builder.getLexicalCategories(); this.possibleRootCategories = ImmutableSet.copyOf(builder.getValidRootCategories()); this.nbest = builder.getNbest(); this.maxLength = builder.getMaxSentenceLength(); this.binaryRules = builder.getCombinators(); this.allowUnseenRules = builder.getAllowUnseenRules(); this.normalForm = builder.getNormalForm(); this.nbestBeam = builder.getNbestBeam(); for (final Cell<Category, Category, List<RuleProduction>> entry : seenRules.ruleTable().cellSet()) { // Cache out all the rules in advance. getRules(entry.getRowKey(), entry.getColumnKey()); } }
Example #9
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean contains(@Nullable Object object) { if (object instanceof Cell) { Cell<?, ?, ?> cell = (Cell<?, ?, ?>) object; Object value = RegularImmutableTable.this.get(cell.getRowKey(), cell.getColumnKey()); return value != null && value.equals(cell.getValue()); } return false; }
Example #10
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
static <R, C, V> RegularImmutableTable<R, C, V> forCells(List<Cell<R, C, V>> cells, @Nullable final Comparator<? super R> rowComparator, @Nullable final Comparator<? super C> columnComparator) { checkNotNull(cells); if (rowComparator != null || columnComparator != null) { /* * This sorting logic leads to a cellSet() ordering that may not be expected and that isn't * documented in the Javadoc. If a row Comparator is provided, cellSet() iterates across the * columns in the first row, the columns in the second row, etc. If a column Comparator is * provided but a row Comparator isn't, cellSet() iterates across the rows in the first * column, the rows in the second column, etc. */ Comparator<Cell<R, C, V>> comparator = new Comparator<Cell<R, C, V>>() { @Override public int compare(Cell<R, C, V> cell1, Cell<R, C, V> cell2) { int rowCompare = (rowComparator == null) ? 0 : rowComparator.compare(cell1.getRowKey(), cell2.getRowKey()); if (rowCompare != 0) { return rowCompare; } return (columnComparator == null) ? 0 : columnComparator.compare(cell1.getColumnKey(), cell2.getColumnKey()); } }; Collections.sort(cells, comparator); } return forCellsInternal(cells, rowComparator, columnComparator); }
Example #11
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
static <R, C, V> RegularImmutableTable<R, C, V> forCells(List<Cell<R, C, V>> cells, @Nullable final Comparator<? super R> rowComparator, @Nullable final Comparator<? super C> columnComparator) { checkNotNull(cells); if (rowComparator != null || columnComparator != null) { /* * This sorting logic leads to a cellSet() ordering that may not be expected and that isn't * documented in the Javadoc. If a row Comparator is provided, cellSet() iterates across the * columns in the first row, the columns in the second row, etc. If a column Comparator is * provided but a row Comparator isn't, cellSet() iterates across the rows in the first * column, the rows in the second column, etc. */ Comparator<Cell<R, C, V>> comparator = new Comparator<Cell<R, C, V>>() { @Override public int compare(Cell<R, C, V> cell1, Cell<R, C, V> cell2) { int rowCompare = (rowComparator == null) ? 0 : rowComparator.compare(cell1.getRowKey(), cell2.getRowKey()); if (rowCompare != 0) { return rowCompare; } return (columnComparator == null) ? 0 : columnComparator.compare(cell1.getColumnKey(), cell2.getColumnKey()); } }; Collections.sort(cells, comparator); } return forCellsInternal(cells, rowComparator, columnComparator); }
Example #12
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean contains(@Nullable Object object) { if (object instanceof Cell) { Cell<?, ?, ?> cell = (Cell<?, ?, ?>) object; Object value = RegularImmutableTable.this.get(cell.getRowKey(), cell.getColumnKey()); return value != null && value.equals(cell.getValue()); } return false; }
Example #13
Source File: Tables.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof Cell) { Cell<?, ?, ?> other = (Cell<?, ?, ?>) obj; return Objects.equal(getRowKey(), other.getRowKey()) && Objects.equal(getColumnKey(), other.getColumnKey()) && Objects.equal(getValue(), other.getValue()); } return false; }
Example #14
Source File: Tables.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof Cell) { Cell<?, ?, ?> other = (Cell<?, ?, ?>) obj; return Objects.equal(getRowKey(), other.getRowKey()) && Objects.equal(getColumnKey(), other.getColumnKey()) && Objects.equal(getValue(), other.getValue()); } return false; }
Example #15
Source File: SimpleFileProviderBackend.java From incubator-sentry with Apache License 2.0 | 5 votes |
private void mergeResult(Table<String, String, Set<String>> groupRolePrivilegeTableTemp) { for (Cell<String, String, Set<String>> cell : groupRolePrivilegeTableTemp.cellSet()) { String groupName = cell.getRowKey(); String roleName = cell.getColumnKey(); Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName); if (privileges == null) { privileges = new HashSet<String>(); groupRolePrivilegeTable.put(groupName, roleName, privileges); } privileges.addAll(cell.getValue()); } }
Example #16
Source File: Tables.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
Function<Cell<R, C, V1>, Cell<R, C, V2>> cellFunction() { return new Function<Cell<R, C, V1>, Cell<R, C, V2>>() { @Override public Cell<R, C, V2> apply(Cell<R, C, V1> cell) { return immutableCell(cell.getRowKey(), cell.getColumnKey(), function.apply(cell.getValue())); } }; }
Example #17
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean contains(@Nullable Object object) { if (object instanceof Cell) { Cell<?, ?, ?> cell = (Cell<?, ?, ?>) object; Object value = RegularImmutableTable.this.get(cell.getRowKey(), cell.getColumnKey()); return value != null && value.equals(cell.getValue()); } return false; }
Example #18
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
static <R, C, V> RegularImmutableTable<R, C, V> forCells(List<Cell<R, C, V>> cells, @Nullable final Comparator<? super R> rowComparator, @Nullable final Comparator<? super C> columnComparator) { checkNotNull(cells); if (rowComparator != null || columnComparator != null) { /* * This sorting logic leads to a cellSet() ordering that may not be expected and that isn't * documented in the Javadoc. If a row Comparator is provided, cellSet() iterates across the * columns in the first row, the columns in the second row, etc. If a column Comparator is * provided but a row Comparator isn't, cellSet() iterates across the rows in the first * column, the rows in the second column, etc. */ Comparator<Cell<R, C, V>> comparator = new Comparator<Cell<R, C, V>>() { @Override public int compare(Cell<R, C, V> cell1, Cell<R, C, V> cell2) { int rowCompare = (rowComparator == null) ? 0 : rowComparator.compare(cell1.getRowKey(), cell2.getRowKey()); if (rowCompare != 0) { return rowCompare; } return (columnComparator == null) ? 0 : columnComparator.compare(cell1.getColumnKey(), cell2.getColumnKey()); } }; Collections.sort(cells, comparator); } return forCellsInternal(cells, rowComparator, columnComparator); }
Example #19
Source File: Tables.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof Cell) { Cell<?, ?, ?> other = (Cell<?, ?, ?>) obj; return Objects.equal(getRowKey(), other.getRowKey()) && Objects.equal(getColumnKey(), other.getColumnKey()) && Objects.equal(getValue(), other.getValue()); } return false; }
Example #20
Source File: TreeShaker.java From j2objc with Apache License 2.0 | 5 votes |
public static void writeCodeReferenceMapInfo(BufferedWriter writer, CodeReferenceMap map) throws IOException { writer.write("Dead Classes:\n"); for (String clazz : map.getReferencedClasses()) { writer.write(clazz + "\n"); } //TODO(malvania): Add output formatting that can be easily read by the parser in translator. writer.write("Dead Methods:\n"); for (Cell<String, String, ImmutableSet<String>> cell : map.getReferencedMethods().cellSet()) { writer.write(cell.toString() + "\n"); } }
Example #21
Source File: Tables.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
Function<Cell<R, C, V1>, Cell<R, C, V2>> cellFunction() { return new Function<Cell<R, C, V1>, Cell<R, C, V2>>() { @Override public Cell<R, C, V2> apply(Cell<R, C, V1> cell) { return immutableCell(cell.getRowKey(), cell.getColumnKey(), function.apply(cell.getValue())); } }; }
Example #22
Source File: ParserAStar.java From easyccg with MIT License | 5 votes |
private SeenRules(File file) throws IOException { if (file == null) { seen = null; numberOfSeenCategories = 0; } else if (!file.exists()) { System.err.println("No 'seenRules' file available for model. Allowing all CCG-legal rules."); seen = null; numberOfSeenCategories = 0; } else { Table<Category, Category, Boolean> tab = HashBasedTable.create(); int maxID = 0; for (String line : Util.readFile(file)) { // Assumes the file has the format: // cat1 cat2 if (!line.startsWith("#") && !line.isEmpty()) { String[] fields = line.split(" "); Category left = Category.valueOf(fields[0]); Category right = Category.valueOf(fields[1]); maxID = Math.max(left.getID(), maxID); maxID = Math.max(right.getID(), maxID); tab.put(simplify(left), simplify(right), true); } } seen = new boolean[maxID + 1][maxID + 1]; for (Cell<Category, Category, Boolean> entry : tab.cellSet()) { seen[entry.getRowKey().getID()][entry.getColumnKey().getID()] = true; } numberOfSeenCategories = seen.length; } }
Example #23
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean contains(@Nullable Object object) { if (object instanceof Cell) { Cell<?, ?, ?> cell = (Cell<?, ?, ?>) object; Object value = RegularImmutableTable.this.get(cell.getRowKey(), cell.getColumnKey()); return value != null && value.equals(cell.getValue()); } return false; }
Example #24
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
static <R, C, V> RegularImmutableTable<R, C, V> forCells(List<Cell<R, C, V>> cells, @Nullable final Comparator<? super R> rowComparator, @Nullable final Comparator<? super C> columnComparator) { checkNotNull(cells); if (rowComparator != null || columnComparator != null) { /* * This sorting logic leads to a cellSet() ordering that may not be expected and that isn't * documented in the Javadoc. If a row Comparator is provided, cellSet() iterates across the * columns in the first row, the columns in the second row, etc. If a column Comparator is * provided but a row Comparator isn't, cellSet() iterates across the rows in the first * column, the rows in the second column, etc. */ Comparator<Cell<R, C, V>> comparator = new Comparator<Cell<R, C, V>>() { @Override public int compare(Cell<R, C, V> cell1, Cell<R, C, V> cell2) { int rowCompare = (rowComparator == null) ? 0 : rowComparator.compare(cell1.getRowKey(), cell2.getRowKey()); if (rowCompare != 0) { return rowCompare; } return (columnComparator == null) ? 0 : columnComparator.compare(cell1.getColumnKey(), cell2.getColumnKey()); } }; Collections.sort(cells, comparator); } return forCellsInternal(cells, rowComparator, columnComparator); }
Example #25
Source File: ImmutableTableCodec.java From bazel with Apache License 2.0 | 5 votes |
@Override public void serialize( SerializationContext context, ImmutableTable<R, C, V> object, CodedOutputStream codedOut) throws SerializationException, IOException { Set<Cell<R, C, V>> cellSet = object.cellSet(); codedOut.writeInt32NoTag(cellSet.size()); for (Cell<R, C, V> cell : cellSet) { context.serialize(cell.getRowKey(), codedOut); context.serialize(cell.getColumnKey(), codedOut); context.serialize(cell.getValue(), codedOut); } }
Example #26
Source File: Tables.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
Function<Cell<R, C, V1>, Cell<R, C, V2>> cellFunction() { return new Function<Cell<R, C, V1>, Cell<R, C, V2>>() { @Override public Cell<R, C, V2> apply(Cell<R, C, V1> cell) { return immutableCell( cell.getRowKey(), cell.getColumnKey(), function.apply(cell.getValue())); } }; }
Example #27
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean contains(@Nullable Object object) { if (object instanceof Cell) { Cell<?, ?, ?> cell = (Cell<?, ?, ?>) object; Object value = RegularImmutableTable.this.get(cell.getRowKey(), cell.getColumnKey()); return value != null && value.equals(cell.getValue()); } return false; }
Example #28
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
static <R, C, V> RegularImmutableTable<R, C, V> forCells( List<Cell<R, C, V>> cells, @Nullable final Comparator<? super R> rowComparator, @Nullable final Comparator<? super C> columnComparator) { checkNotNull(cells); if (rowComparator != null || columnComparator != null) { /* * This sorting logic leads to a cellSet() ordering that may not be expected and that isn't * documented in the Javadoc. If a row Comparator is provided, cellSet() iterates across the * columns in the first row, the columns in the second row, etc. If a column Comparator is * provided but a row Comparator isn't, cellSet() iterates across the rows in the first * column, the rows in the second column, etc. */ Comparator<Cell<R, C, V>> comparator = new Comparator<Cell<R, C, V>>() { @Override public int compare(Cell<R, C, V> cell1, Cell<R, C, V> cell2) { int rowCompare = (rowComparator == null) ? 0 : rowComparator.compare(cell1.getRowKey(), cell2.getRowKey()); if (rowCompare != 0) { return rowCompare; } return (columnComparator == null) ? 0 : columnComparator.compare(cell1.getColumnKey(), cell2.getColumnKey()); } }; Collections.sort(cells, comparator); } return forCellsInternal(cells, rowComparator, columnComparator); }
Example #29
Source File: RegularImmutableTable.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** * A factory that chooses the most space-efficient representation of the * table. */ private static final <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal( Iterable<Cell<R, C, V>> cells, @Nullable Comparator<? super R> rowComparator, @Nullable Comparator<? super C> columnComparator) { Set<R> rowSpaceBuilder = new LinkedHashSet<R>(); Set<C> columnSpaceBuilder = new LinkedHashSet<C>(); ImmutableList<Cell<R, C, V>> cellList = ImmutableList.copyOf(cells); for (Cell<R, C, V> cell : cells) { rowSpaceBuilder.add(cell.getRowKey()); columnSpaceBuilder.add(cell.getColumnKey()); } ImmutableSet<R> rowSpace = (rowComparator == null) ? ImmutableSet.copyOf(rowSpaceBuilder) : ImmutableSet.copyOf( Ordering.from(rowComparator).immutableSortedCopy(rowSpaceBuilder)); ImmutableSet<C> columnSpace = (columnComparator == null) ? ImmutableSet.copyOf(columnSpaceBuilder) : ImmutableSet.copyOf( Ordering.from(columnComparator).immutableSortedCopy(columnSpaceBuilder)); // use a dense table if more than half of the cells have values // TODO(gak): tune this condition based on empirical evidence return (cellList.size() > (((long) rowSpace.size() * columnSpace.size()) / 2)) ? new DenseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace) : new SparseImmutableTable<R, C, V>(cellList, rowSpace, columnSpace); }
Example #30
Source File: AbstractParser.java From EasySRL with Apache License 2.0 | 5 votes |
@Deprecated private AbstractParser(final Collection<Category> lexicalCategories, final int maxSentenceLength, final int nbest, final List<Category> validRootCategories, final File unaryRulesFile, final File extraCombinatorsFile, final File markedupFile, final File seenRulesFile) throws IOException { this.maxLength = maxSentenceLength; this.nbest = nbest; this.lexicalCategories = lexicalCategories; this.unaryRules = loadUnaryRules(unaryRulesFile); Coindexation.parseMarkedUpFile(markedupFile); final List<Combinator> combinators = new ArrayList<>(Combinator.STANDARD_COMBINATORS); if (extraCombinatorsFile != null && extraCombinatorsFile.exists()) { combinators.addAll(Combinator.loadSpecialCombinators(extraCombinatorsFile)); } this.binaryRules = ImmutableList.copyOf(combinators); possibleRootCategories = ImmutableSet.copyOf(validRootCategories); this.seenRules = new SeenRules(seenRulesFile, lexicalCategories); for (final Cell<Category, Category, List<RuleProduction>> entry : seenRules.ruleTable().cellSet()) { // Cache out all the rules in advance. getRules(entry.getRowKey(), entry.getColumnKey()); } // Get default arguments for newer parameters. final ParserBuilder builder = new ParserBuilder() { @Override public AbstractParser build2() { return null; } }; this.nbestBeam = builder.getNbestBeam(); this.allowUnseenRules = builder.getAllowUnseenRules(); this.normalForm = builder.getNormalForm(); }