gnu.trove.TIntArrayList Java Examples

The following examples show how to use gnu.trove.TIntArrayList. 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: KFoldEvaluatorRegression.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
protected HashMap<Short, TIntArrayList> splitPerCategory(IIndex index) {
    HashMap<Short, TIntArrayList> map = new HashMap<Short, TIntArrayList>();
    IShortIterator cats = index.getCategoryDB().getCategories();
    while (cats.hasNext()) {
        short catID = cats.next();
        IIntIterator docs = index.getClassificationDB().getCategoryDocuments(catID);
        TIntArrayList l = new TIntArrayList();
        map.put(catID, l);
        while (docs.hasNext()) {
            int docID = docs.next();
            assert (index.getClassificationDB().getDocumentCategoriesCount(docID) == 1);
            l.add(docID);
        }
    }

    return map;
}
 
Example #2
Source File: BestKNNNegativesChooser.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public TIntArrayListIterator selectNegatives(String category) {

        short catID = _index.getCategoryDB().getCategory(category);

        TreeSet<Item> best = _best.get(catID);
        assert (best != null);

        TIntArrayList neg = new TIntArrayList();
        Iterator<Item> it = best.iterator();
        while (it.hasNext()) {
            Item docS = it.next();
            assert (!neg.contains(docS.docID));
            neg.add(docS.docID);
        }

        neg.sort();

        return new TIntArrayListIterator(neg);
    }
 
Example #3
Source File: ALpoolRank.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
@Override
public TIntArrayList getFirstMacro(int n) {
    if (n == 1 && maxDocId >= 0) {
        return new TIntArrayList(new int[]{maxDocId});
    } else {
        if (ranking == null) {
            Ranker r = new Ranker();
            ranking = r.get(rankingMap);
        }
        if (1 < n && n < ranking.size()) {
            return ranking.subList(0, n);
        } else {
            return ranking;
        }
    }
}
 
Example #4
Source File: LogLogisticRegressionModel.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
protected void initializeParameterIndexes() {
	A = new Alphabet();
	V = new LDouble[PARAMETER_TABLE_INITIAL_CAPACITY];
	G = new LDouble[PARAMETER_TABLE_INITIAL_CAPACITY];
	m_trainingData = new ArrayList<TDoubleArrayList>(1000);
	m_trainingLabels = new TIntArrayList(1000);
	m_testData = new ArrayList<TDoubleArrayList>(100);
	m_testLabels = new TIntArrayList(100);
	m_devData = new ArrayList<TDoubleArrayList>(100);
	m_devLabels = new TIntArrayList(100);
	savedValues = new TObjectDoubleHashMap<String>(1000);
	m_savedFormulas = new ArrayList<LogFormula>(FORMULA_LIST_INITIAL_CAPACITY);
	m_current = 0;
	m_savedLLFormulas = new ArrayList<LazyLookupLogFormula>(LLFORMULA_LIST_INITIAL_CAPACITY);
	m_llcurrent = 0;
	mLookupChart = new THashMap<Integer,LogFormula>(PARAMETER_TABLE_INITIAL_CAPACITY);
}
 
Example #5
Source File: AddArrangementRuleAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  ArrangementMatchingRulesControl control = getRulesControl(e);
  if (control == null) {
    return;
  }

  control.hideEditor();
  TIntArrayList rows = control.getSelectedModelRows();
  ArrangementMatchingRulesModel model = control.getModel();
  int rowToEdit;
  if (rows.size() == 1) {
    rowToEdit = rows.get(0) + 1;
    model.insertRow(rowToEdit, new Object[] {createNewRule(control)});
  }
  else {
    rowToEdit = model.getSize();
    model.add(createNewRule(control));
  }
  showEditor(control, rowToEdit);
  control.getSelectionModel().setSelectionInterval(rowToEdit, rowToEdit);
  scrollRowToVisible(control, rowToEdit);
}
 
Example #6
Source File: TroveContentDB.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public TroveContentDB(IDocumentDB documentsDB, IFeatureDB featuresDB) {
    super();
    _documentsDB = documentsDB;
    _featuresDB = featuresDB;

    int size = documentsDB.getDocumentsCount();
    _documentsFeatures = new Vector<TIntArrayList>(size);
    _documentsFrequencies = new Vector<TIntArrayList>(size);
    for (int i = 0; i < size; ++i) {
        _documentsFeatures.add(new TIntArrayList());
        _documentsFrequencies.add(new TIntArrayList());
    }

    _documentLenghts = new TIntIntHashMap();
    _featureDocumentsCount = new TIntIntHashMap();
    _name = "generic";
}
 
Example #7
Source File: TroveClassificationILDBBuilder.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
protected void addCategoryHierarchicaly(int document, short category, boolean primary) {
    TIntArrayList docs = _classificationDB._categoriesDocuments.get(category);
    Vector<Boolean> docsPrimary = _classificationDB._categoriesDocumentsPrimary.get(category);
    int pos = docs.binarySearch(document);
    if (pos < 0) {
        docs.insert(-pos - 1, document);
        docsPrimary.insertElementAt(primary, -pos - 1);
    } else {
        if (primary) {
            docsPrimary.set(pos, true);
        }
    }

    IShortIterator parents = _classificationDB.getCategoryDB().getParentCategories(category);
    while (parents.hasNext())
        addCategoryHierarchicaly(document, parents.next(), primary);
}
 
Example #8
Source File: Reindexer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private int[] discard(int[] needed, int[] toDiscard, int arrayIndex) {
  myOriginalLengths[arrayIndex] = toDiscard.length;
  int[] sorted1 = createSorted(needed);
  TIntArrayList discarded = new TIntArrayList(toDiscard.length);
  TIntArrayList oldIndecies = new TIntArrayList(toDiscard.length);
  for (int i = 0; i < toDiscard.length; i++) {
    int index = toDiscard[i];
    if (Arrays.binarySearch(sorted1, index) >= 0) {
      discarded.add(index);
      oldIndecies.add(i);
    }
  }
  myOldIndecies[arrayIndex] = oldIndecies.toNativeArray();
  myDiscardedLengths[arrayIndex] = discarded.size();
  return discarded.toNativeArray();
}
 
Example #9
Source File: DuplicatesIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void save(@Nonnull DataOutput out, TIntArrayList list) throws IOException {
  if (list.size() == 2) {
    DataInputOutputUtil.writeINT(out, list.getQuick(0));
    DataInputOutputUtil.writeINT(out, list.getQuick(1));
  }
  else {
    DataInputOutputUtil.writeINT(out, -list.size());
    int prev = 0;
    for (int i = 0, len = list.size(); i < len; i+=2) {
      int value = list.getQuick(i);
      DataInputOutputUtil.writeINT(out, value - prev);
      prev = value;
      DataInputOutputUtil.writeINT(out, list.getQuick(i + 1));
    }
  }
}
 
Example #10
Source File: TroveClassificationFullDB.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public TroveClassificationFullDB(IDocumentDB documentsDB, ICategoryDB categoriesDB) {
    super();
    _name = "generic";
    _documentsDB = documentsDB;
    _categoriesDB = categoriesDB;
    int docsize = documentsDB.getDocumentsCount();
    _documentsCategories = new Vector<TShortArrayList>(docsize);
    _documentsCatsPrimary = new Vector<Vector<Boolean>>();
    for (int i = 0; i < docsize; ++i) {
        _documentsCategories.add(new TShortArrayList());
        _documentsCatsPrimary.add(new Vector<Boolean>());
    }

    int catsize = categoriesDB.getCategoriesCount();
    _categoriesDocuments = new Vector<TIntArrayList>(catsize);
    for (int i = 0; i < catsize; ++i)
        _categoriesDocuments.add(new TIntArrayList());
}
 
Example #11
Source File: TroveContentILDB.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public TroveContentILDB(IDocumentDB documentsDB, IFeatureDB featuresDB) {
    super();
    _documentsDB = documentsDB;
    _featuresDB = featuresDB;

    int size = featuresDB.getFeaturesCount();
    _featuresDocuments = new Vector<TIntArrayList>(size);
    _featuresFrequencies = new Vector<TIntArrayList>(size);
    for (int i = 0; i < size; ++i) {
        _featuresDocuments.add(new TIntArrayList());
        _featuresFrequencies.add(new TIntArrayList());
    }

    _documentLenghts = new TIntIntHashMap();
    _documentFeaturesCount = new TIntIntHashMap();
    _name = "generic";
}
 
Example #12
Source File: ArrangementMatchingRulesControl.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @return    selected model rows sorted in descending order
 */
@Nonnull
public TIntArrayList getSelectedModelRows() {
  mySelectedRows.clear();
  int min = selectionModel.getMinSelectionIndex();
  if (min >= 0) {
    for (int i = selectionModel.getMaxSelectionIndex();  i >= min; i--) {
      if ((myEditorRow >= 0 && i == myEditorRow - 1)
          || (i != myEditorRow && selectionModel.isSelectedIndex(i)))
      {
        mySelectedRows.add(i);
      }
    }
  }
  else if (myEditorRow > 0) {
    mySelectedRows.add(myEditorRow - 1);
  }
  return mySelectedRows;
}
 
Example #13
Source File: IndexPatternSearcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected static void executeImpl(IndexPatternSearch.SearchParameters queryParameters, Processor<? super IndexPatternOccurrence> consumer) {
  final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
  final PsiFile file = queryParameters.getFile();
  final CharSequence chars = file.getViewProvider().getContents();
  boolean multiLine = queryParameters.isMultiLine();
  List<CommentRange> commentRanges = findCommentTokenRanges(file, chars, queryParameters.getRange(), multiLine);
  TIntArrayList occurrences = new TIntArrayList(1);
  IndexPattern[] patterns = patternProvider != null ? patternProvider.getIndexPatterns() : new IndexPattern[]{queryParameters.getPattern()};

  for (int i = 0; i < commentRanges.size(); i++) {
    occurrences.resetQuick();

    for (int j = patterns.length - 1; j >= 0; --j) {
      if (!collectPatternMatches(patterns, patterns[j], chars, commentRanges, i, file, queryParameters.getRange(), consumer, occurrences, multiLine)) {
        return;
      }
    }
  }
}
 
Example #14
Source File: TreeNode.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @param alevel Level (depth) of the desired ancestor
 * @param ancPath A list to be populated with indices of nodes searched (starting with the current node), provided that an ancestor node at the specified level exists; or null.
 * @param alreadySearched Indices of nodes which have already been searched. If non-null, 'this' will be returned if (and only if) a member of this set is encountered in the ancestor path. 
 * @return Ancestor node of the current node whose level is 'alevel', or null if no such ancestor exists. A node is not considered to be its own ancestor.
 * @author Nathan Schneider (nschneid)
 */
@SuppressWarnings("unchecked")
public T getAncestorAtLevel(int alevel, TIntArrayList ancPath, TIntHashSet alreadySearched) {
	if (alevel < 0 || alevel >= this.depth)	// A node at this level is not strictly an ancestor
		return null;
	
	TreeNode<T> node = this;
	for (int d=this.depth; d>alevel; d--) {
		if (ancPath!=null)
			ancPath.add(node.index);
		if (alreadySearched!=null && alreadySearched.contains(node.index))
			return (T)this;
		node = node.getParent();
	}
	return (T)node;
}
 
Example #15
Source File: TroveClassificationFullDBBuilder.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
protected void addCategoryHierarchicaly(int document, short category, boolean primary) {
    TShortArrayList cats = _classificationDB._documentsCategories.get(document);
    Vector<Boolean> catsPrimary = _classificationDB._documentsCatsPrimary.get(document);
    int pos = cats.binarySearch(category);
    if (pos < 0) {
        cats.insert(-pos - 1, category);
        catsPrimary.insertElementAt(primary, -pos - 1);
    } else {

        if (primary) {
            catsPrimary.set(pos, true);
        }
    }

    TIntArrayList docs = _classificationDB._categoriesDocuments.get(category);
    pos = docs.binarySearch(document);
    if (pos < 0) {
        docs.insert(-pos - 1, document);
    }

    IShortIterator parents = _classificationDB.getCategoryDB().getParentCategories(category);
    while (parents.hasNext())
        addCategoryHierarchicaly(document, parents.next(), primary);
}
 
Example #16
Source File: TroveClassificationFullDBBuilder.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public void setDocumentCategory(int document, short category, boolean primary) {
    if (document >= 0 && category >= 0) {
        int docsize = _classificationDB._documentsCategories.size();
        if (document >= docsize) {
            for (int i = docsize; i <= document; ++i) {
                _classificationDB._documentsCategories.add(new TShortArrayList());
                _classificationDB._documentsCatsPrimary.add(new Vector<Boolean>());
            }
        }
        int catsize = _classificationDB._categoriesDocuments.size();
        if (category >= catsize) {
            for (int i = catsize; i <= document; ++i)
                _classificationDB._categoriesDocuments.add(new TIntArrayList());
        }
        addCategoryHierarchicaly(document, category, primary);
    }
}
 
Example #17
Source File: StringPrefixTSR.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void computeTSR(IIndex index) {
	TextualProgressBar bar = new TextualProgressBar(
			"Compute TSR with by using regex matcher");
	int total = index.getFeatureDB().getFeaturesCount();
	int step = 0;

	TIntArrayList toRemove = new TIntArrayList();

	IIntIterator it = index.getFeatureDB().getFeatures();
	while (it.hasNext()) {
		int featID = it.next();
		String featName = index.getFeatureDB().getFeatureName(featID);
		if (!featName.matches(regexPatternMatching)) {
			toRemove.add(featID);
		}

		step++;
		bar.signal((step * 100) / total);
	}

	bar.signal(100);

	toRemove.sort();

	// Remove the worst features.
	JatecsLogger.status().print("Removing worst features...");
	TIntArrayListIterator toRemoveIT = new TIntArrayListIterator(toRemove);
	index.removeFeatures(toRemoveIT);
	JatecsLogger.status().println(
			"done. Now the DB contains "
					+ index.getFeatureDB().getFeaturesCount()
					+ " feature(s).");
}
 
Example #18
Source File: GlobalThresholdTSR.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public void computeTSR(IIndex index) {
    TextualProgressBar bar = new TextualProgressBar(
            "Compute global threshold ("
                    + Os.generateDoubleString(_threshold, 3)
                    + ") TSR with " + _function.getClass().getName());
    int total = index.getFeatureDB().getFeaturesCount();
    int step = 0;

    TIntArrayList toRemove = new TIntArrayList();

    IIntIterator it = index.getFeatureDB().getFeatures();
    while (it.hasNext()) {
        int featID = it.next();

        double score = _function.compute((short) 0, featID, index);

        if (score < _threshold)
            toRemove.add(featID);

        step++;
        bar.signal((step * 100) / total);
    }

    bar.signal(100);

    toRemove.sort();

    // Remove the worst features.
    JatecsLogger.status().print(
            "Removing " + toRemove.size() + " features...");
    index.removeFeatures(new TIntArrayListIterator(toRemove));
    JatecsLogger.status().println(
            "done. Now the DB contains "
                    + index.getFeatureDB().getFeaturesCount()
                    + " feature(s).");
}
 
Example #19
Source File: TreeRecommenderLearner.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
protected IIndex selectPositives(short catID, IIndex training) {
    // First create a new index.
    IIndex idx = training.cloneIndex();

    IShortIterator childCats = getAllChildsCategoriesFor(idx, catID);
    short nextCatID = Short.MIN_VALUE;
    if (childCats.hasNext())
        nextCatID = childCats.next();

    // Remove unwanted categories.
    TShortArrayList toRemove = new TShortArrayList();
    for (short i = 0; i < training.getCategoryDB().getCategoriesCount(); i++) {
        if (i == nextCatID) {
            if (childCats.hasNext())
                nextCatID = childCats.next();
            continue;
        }

        toRemove.add(i);
    }
    toRemove.sort();
    idx.removeCategories(new TShortArrayListIterator(toRemove));

    // Remove unwanted documents.
    TIntArrayList docsToRemove = new TIntArrayList();
    IIntIterator docs = idx.getDocumentDB().getDocuments();
    while (docs.hasNext()) {
        int docID = docs.next();
        IShortIterator curCats = idx.getClassificationDB()
                .getDocumentCategories(docID);
        if (!curCats.hasNext())
            docsToRemove.add(docID);
    }

    docsToRemove.sort();
    idx.removeDocuments(new TIntArrayListIterator(docsToRemove), false);

    return idx;
}
 
Example #20
Source File: TrigramBuilderTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testBuilder() {
  final Ref<Integer> trigramCountRef = new Ref<Integer>();
  final TIntArrayList list = new TIntArrayList();

  TrigramBuilder.processTrigrams("String$CharData", new TrigramBuilder.TrigramProcessor() {
    @Override
    public boolean execute(int value) {
      list.add(value);
      return true;
    }

    @Override
    public boolean consumeTrigramsCount(int count) {
      trigramCountRef.set(count);
      return true;
    }
  });

  list.sort();
  Integer trigramCount = trigramCountRef.get();
  assertNotNull(trigramCount);

  int expectedTrigramCount = 13;
  assertEquals(expectedTrigramCount, (int)trigramCount);
  assertEquals(expectedTrigramCount, list.size());

  int[] expected = {buildTrigram("$Ch"), buildTrigram("arD"), buildTrigram("ata"), 6514785, 6578548, 6759523, 6840690, 6909543, 7235364, 7496801, 7498094, 7566450, 7631465, };
  for(int i = 0; i < expectedTrigramCount; ++i) assertEquals(expected[i], list.getQuick(i));
}
 
Example #21
Source File: SingleLabelTreeBoostLearner.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
protected IIndex selectPositives(short catID, IIndex training) {
    // First create a new index.
    IIndex idx = training.cloneIndex();

    IShortIterator childCats = getAllChildsCategoriesFor(idx, catID);
    short nextCatID = Short.MIN_VALUE;
    if (childCats.hasNext())
        nextCatID = childCats.next();

    // Remove unwanted categories.
    TShortArrayList toRemove = new TShortArrayList();
    for (short i = 0; i < training.getCategoryDB().getCategoriesCount(); i++) {
        if (i == nextCatID) {
            if (childCats.hasNext())
                nextCatID = childCats.next();
            continue;
        }

        toRemove.add(i);
    }
    toRemove.sort();
    idx.removeCategories(new TShortArrayListIterator(toRemove));

    // Remove unwanted documents.
    TIntArrayList docsToRemove = new TIntArrayList();
    IIntIterator docs = idx.getDocumentDB().getDocuments();
    while (docs.hasNext()) {
        int docID = docs.next();
        IShortIterator curCats = idx.getClassificationDB()
                .getDocumentCategories(docID);
        if (!curCats.hasNext())
            docsToRemove.add(docID);
    }

    docsToRemove.sort();
    idx.removeDocuments(new TIntArrayListIterator(docsToRemove), false);

    return idx;
}
 
Example #22
Source File: Incremental.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public TIntArrayList nextMacroRank(ContingencyTableSet oldEvaluation, ContingencyTableSet newEvaluation) {
    nextMacroTable(oldEvaluation, newEvaluation);
    if (macroRank == null) {
        macroRank = getMacroRank();
    }
    return macroRank;
}
 
Example #23
Source File: ByLine.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static FairDiffIterable compareSmart(@Nonnull List<Line> lines1,
                                             @Nonnull List<Line> lines2,
                                             @Nonnull ProgressIndicator indicator) {
  int threshold = Registry.intValue("diff.unimportant.line.char.count");
  if (threshold == 0) return diff(lines1, lines2, indicator);

  Pair<List<Line>, TIntArrayList> bigLines1 = getBigLines(lines1, threshold);
  Pair<List<Line>, TIntArrayList> bigLines2 = getBigLines(lines2, threshold);

  FairDiffIterable changes = diff(bigLines1.first, bigLines2.first, indicator);
  return new ChangeCorrector.SmartLineChangeCorrector(bigLines1.second, bigLines2.second, lines1, lines2, changes, indicator).build();
}
 
Example #24
Source File: ChangeCorrector.java    From consulo with Apache License 2.0 5 votes vote down vote up
public SmartLineChangeCorrector(@Nonnull TIntArrayList indexes1,
                                @Nonnull TIntArrayList indexes2,
                                @Nonnull List<Line> lines1,
                                @Nonnull List<Line> lines2,
                                @Nonnull FairDiffIterable changes,
                                @Nonnull ProgressIndicator indicator) {
  super(lines1.size(), lines2.size(), changes, indicator);
  myIndexes1 = indexes1;
  myIndexes2 = indexes2;
  myLines1 = lines1;
  myLines2 = lines2;
}
 
Example #25
Source File: FoldingTransformation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FoldingTransformation(Editor editor) {
  myEditor = editor;
  FoldRegion[] foldRegions = myEditor.getFoldingModel().getAllFoldRegions();
  Arrays.sort(foldRegions, RangeMarker.BY_START_OFFSET);
  TIntArrayList foldBeginings = new TIntArrayList();
  for (FoldRegion foldRegion : foldRegions) {
    if (!foldRegion.isValid() || foldRegion.isExpanded()) continue;
    foldBeginings.add(getStartLine(foldRegion));
    myCollapsed.add(foldRegion);
  }
  myFoldBeginings = foldBeginings.toNativeArray();
}
 
Example #26
Source File: AllNegativesChooser.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public TIntArrayListIterator selectNegatives(String category) {
    TIntArrayList l = new TIntArrayList();

    short catID = _index.getCategoryDB().getCategory(category);
    IIntIterator it = _index.getDocumentDB().getDocuments();
    while (it.hasNext()) {
        int docID = it.next();
        if (_index.getClassificationDB().hasDocumentCategory(docID, catID))
            continue;

        l.add(docID);
    }

    return new TIntArrayListIterator(l);
}
 
Example #27
Source File: TroveContentILDBBuilder.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public void setDocumentFeatureFrequency(int document, int feature,
                                        int frequency) {
    if (feature >= 0) {
        int size = _contentDB._featuresDocuments.size();
        if (feature >= size) {
            for (int i = size; i <= feature; ++i) {
                _contentDB._featuresDocuments.add(new TIntArrayList());
                _contentDB._featuresFrequencies.add(new TIntArrayList());
            }
        }
        if (document >= 0) {
            TIntArrayList docs = _contentDB._featuresDocuments.get(feature);
            TIntArrayList freqs = _contentDB._featuresFrequencies
                    .get(feature);
            int pos = docs.binarySearch(document);
            if (pos < 0 && frequency > 0) {
                pos = -pos - 1;
                docs.insert(pos, document);
                freqs.insert(pos, frequency);
            } else {
                if (frequency > 0) {
                    freqs.setQuick(pos, frequency);
                } else {
                    docs.remove(pos);
                    freqs.remove(pos);
                }
            }
        }
    }
}
 
Example #28
Source File: ByChar.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static CharOffsets getPunctuationChars(@Nonnull CharSequence text) {
  TIntArrayList chars = new TIntArrayList(text.length());
  TIntArrayList offsets = new TIntArrayList(text.length());

  for (int i = 0; i < text.length(); i++) {
    char c = text.charAt(i);
    if (isPunctuation(c)) {
      chars.add(c);
      offsets.add(i);
    }
  }

  return new CharOffsets(chars.toNativeArray(), offsets.toNativeArray());
}
 
Example #29
Source File: TroveContentDBBuilder.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public void setDocumentFeatureFrequency(int document, int feature, int frequency) {
    if (document >= 0) {
        int size = _contentDB._documentsFeatures.size();
        if (document >= size) {
            for (int i = size; i <= document; ++i) {
                _contentDB._documentsFeatures.add(new TIntArrayList());
                _contentDB._documentsFrequencies.add(new TIntArrayList());
            }
        }
        if (feature >= 0) {
            TIntArrayList feats = _contentDB._documentsFeatures.get(document);
            TIntArrayList freqs = _contentDB._documentsFrequencies.get(document);
            int pos = feats.binarySearch(feature);
            if (pos < 0 && frequency > 0) {
                pos = -pos - 1;
                feats.insert(pos, feature);
                freqs.insert(pos, frequency);
            } else {
                if (frequency > 0) {
                    freqs.setQuick(pos, frequency);
                } else {
                    feats.remove(pos);
                    freqs.remove(pos);
                }
            }
        }
    }
}
 
Example #30
Source File: StringSearcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public int[] findAllOccurrences(@Nonnull CharSequence text) {
  int end = text.length();
  TIntArrayList result = new TIntArrayList();
  for (int index = 0; index < end; index++) {
    //noinspection AssignmentToForLoopParameter
    index = scan(text, index, end);
    if (index < 0) break;
    result.add(index);
  }
  return result.toNativeArray();
}