use of org.apache.lucene.util.IntsRefBuilder in project lucene-solr by apache.
the class TestAutomaton method intsRef.
private static IntsRef intsRef(String s) {
IntsRefBuilder intsBuilder = new IntsRefBuilder();
Util.toIntsRef(new BytesRef(s), intsBuilder);
return intsBuilder.toIntsRef();
}
use of org.apache.lucene.util.IntsRefBuilder in project lucene-solr by apache.
the class FiniteStringsIteratorTest method testSingleString.
public void testSingleString() {
Automaton a = new Automaton();
int start = a.createState();
int end = a.createState();
a.setAccept(end, true);
a.addTransition(start, end, 'a', 'a');
a.finishState();
Set<IntsRef> accepted = TestOperations.getFiniteStrings(a);
assertEquals(1, accepted.size());
IntsRefBuilder intsRef = new IntsRefBuilder();
intsRef.append('a');
assertTrue(accepted.contains(intsRef.toIntsRef()));
}
use of org.apache.lucene.util.IntsRefBuilder in project lucene-solr by apache.
the class FiniteStringsIteratorTest method testFiniteStringsBasic.
/**
* Basic test for getFiniteStrings
*/
public void testFiniteStringsBasic() {
Automaton a = Operations.union(Automata.makeString("dog"), Automata.makeString("duck"));
a = MinimizationOperations.minimize(a, DEFAULT_MAX_DETERMINIZED_STATES);
FiniteStringsIterator iterator = new FiniteStringsIterator(a);
List<IntsRef> actual = getFiniteStrings(iterator);
assertFiniteStringsRecursive(a, actual);
assertEquals(2, actual.size());
IntsRefBuilder dog = new IntsRefBuilder();
Util.toIntsRef(new BytesRef("dog"), dog);
assertTrue(actual.contains(dog.get()));
IntsRefBuilder duck = new IntsRefBuilder();
Util.toIntsRef(new BytesRef("duck"), duck);
assertTrue(actual.contains(duck.get()));
}
use of org.apache.lucene.util.IntsRefBuilder in project lucene-solr by apache.
the class LimitedFiniteStringsIteratorTest method testSingleton.
public void testSingleton() {
Automaton a = Automata.makeString("foobar");
List<IntsRef> actual = getFiniteStrings(new LimitedFiniteStringsIterator(a, 1));
assertEquals(1, actual.size());
IntsRefBuilder scratch = new IntsRefBuilder();
Util.toUTF32("foobar".toCharArray(), 0, 6, scratch);
assertTrue(actual.contains(scratch.get()));
}
use of org.apache.lucene.util.IntsRefBuilder in project lucene-solr by apache.
the class TestFSTsMisc method testListOfOutputs.
public void testListOfOutputs() throws Exception {
PositiveIntOutputs _outputs = PositiveIntOutputs.getSingleton();
ListOfOutputs<Long> outputs = new ListOfOutputs<>(_outputs);
final Builder<Object> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
final IntsRefBuilder scratch = new IntsRefBuilder();
// Add the same input more than once and the outputs
// are merged:
builder.add(Util.toIntsRef(new BytesRef("a"), scratch), 1L);
builder.add(Util.toIntsRef(new BytesRef("a"), scratch), 3L);
builder.add(Util.toIntsRef(new BytesRef("a"), scratch), 0L);
builder.add(Util.toIntsRef(new BytesRef("b"), scratch), 17L);
final FST<Object> fst = builder.finish();
Object output = Util.get(fst, new BytesRef("a"));
assertNotNull(output);
List<Long> outputList = outputs.asList(output);
assertEquals(3, outputList.size());
assertEquals(1L, outputList.get(0).longValue());
assertEquals(3L, outputList.get(1).longValue());
assertEquals(0L, outputList.get(2).longValue());
output = Util.get(fst, new BytesRef("b"));
assertNotNull(output);
outputList = outputs.asList(output);
assertEquals(1, outputList.size());
assertEquals(17L, outputList.get(0).longValue());
}
Aggregations