use of org.apache.lucene.util.IntsRef in project lucene-solr by apache.
the class TestAutomaton method testReverseRandom2.
public void testReverseRandom2() throws Exception {
int ITERS = atLeast(100);
for (int iter = 0; iter < ITERS; iter++) {
//System.out.println("TEST: iter=" + iter);
Automaton a = AutomatonTestUtil.randomAutomaton(random());
if (random().nextBoolean()) {
a = Operations.removeDeadStates(a);
}
Automaton ra = Operations.reverse(a);
Automaton rda = Operations.determinize(ra, Integer.MAX_VALUE);
if (Operations.isEmpty(a)) {
assertTrue(Operations.isEmpty(rda));
continue;
}
RandomAcceptedStrings ras = new RandomAcceptedStrings(a);
for (int iter2 = 0; iter2 < 20; iter2++) {
// Find string accepted by original automaton
int[] s = ras.getRandomAcceptedString(random());
// Reverse it
for (int j = 0; j < s.length / 2; j++) {
int x = s[j];
s[j] = s[s.length - j - 1];
s[s.length - j - 1] = x;
}
//System.out.println("TEST: iter2=" + iter2 + " s=" + Arrays.toString(s));
// Make sure reversed automaton accepts it
assertTrue(Operations.run(rda, new IntsRef(s, 0, s.length)));
}
}
}
use of org.apache.lucene.util.IntsRef in project lucene-solr by apache.
the class TestUTF32ToUTF8 method testSingleton.
public void testSingleton() throws Exception {
int iters = atLeast(100);
for (int iter = 0; iter < iters; iter++) {
String s = TestUtil.randomRealisticUnicodeString(random());
Automaton a = Automata.makeString(s);
Automaton utf8 = new UTF32ToUTF8().convert(a);
IntsRefBuilder ints = new IntsRefBuilder();
Util.toIntsRef(new BytesRef(s), ints);
Set<IntsRef> set = new HashSet<>();
set.add(ints.get());
assertEquals(set, TestOperations.getFiniteStrings(utf8));
}
}
use of org.apache.lucene.util.IntsRef in project lucene-solr by apache.
the class TestFSTs method testRejectNoLimits.
public void testRejectNoLimits() throws IOException {
final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
final Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, outputs);
final IntsRefBuilder scratch = new IntsRefBuilder();
builder.add(Util.toIntsRef(new BytesRef("aab"), scratch), 22L);
builder.add(Util.toIntsRef(new BytesRef("aac"), scratch), 7L);
builder.add(Util.toIntsRef(new BytesRef("adcd"), scratch), 17L);
builder.add(Util.toIntsRef(new BytesRef("adcde"), scratch), 17L);
builder.add(Util.toIntsRef(new BytesRef("ax"), scratch), 17L);
final FST<Long> fst = builder.finish();
final AtomicInteger rejectCount = new AtomicInteger();
Util.TopNSearcher<Long> searcher = new Util.TopNSearcher<Long>(fst, 2, 6, minLongComparator) {
@Override
protected boolean acceptResult(IntsRef input, Long output) {
boolean accept = output.intValue() == 7;
if (!accept) {
rejectCount.incrementAndGet();
}
return accept;
}
};
searcher.addStartPaths(fst.getFirstArc(new FST.Arc<Long>()), outputs.getNoOutput(), true, new IntsRefBuilder());
Util.TopResults<Long> res = searcher.search();
assertEquals(rejectCount.get(), 4);
// rejected(4) + topN(2) <= maxQueueSize(6)
assertTrue(res.isComplete);
assertEquals(1, res.topN.size());
assertEquals(Util.toIntsRef(new BytesRef("aac"), scratch), res.topN.get(0).input);
assertEquals(7L, res.topN.get(0).output.longValue());
rejectCount.set(0);
searcher = new Util.TopNSearcher<Long>(fst, 2, 5, minLongComparator) {
@Override
protected boolean acceptResult(IntsRef input, Long output) {
boolean accept = output.intValue() == 7;
if (!accept) {
rejectCount.incrementAndGet();
}
return accept;
}
};
searcher.addStartPaths(fst.getFirstArc(new FST.Arc<Long>()), outputs.getNoOutput(), true, new IntsRefBuilder());
res = searcher.search();
assertEquals(rejectCount.get(), 4);
// rejected(4) + topN(2) > maxQueueSize(5)
assertFalse(res.isComplete);
}
Aggregations