本文整理汇总了Java中org.apache.lucene.analysis.tokenattributes.PayloadAttribute类的典型用法代码示例。如果您正苦于以下问题:Java PayloadAttribute类的具体用法?Java PayloadAttribute怎么用?Java PayloadAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PayloadAttribute类属于org.apache.lucene.analysis.tokenattributes包,在下文中一共展示了PayloadAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PrefixAwareTokenFilter
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
public PrefixAwareTokenFilter(TokenStream prefix, TokenStream suffix) {
super(suffix);
this.suffix = suffix;
this.prefix = prefix;
prefixExhausted = false;
termAtt = addAttribute(CharTermAttribute.class);
posIncrAtt = addAttribute(PositionIncrementAttribute.class);
payloadAtt = addAttribute(PayloadAttribute.class);
offsetAtt = addAttribute(OffsetAttribute.class);
typeAtt = addAttribute(TypeAttribute.class);
flagsAtt = addAttribute(FlagsAttribute.class);
p_termAtt = prefix.addAttribute(CharTermAttribute.class);
p_posIncrAtt = prefix.addAttribute(PositionIncrementAttribute.class);
p_payloadAtt = prefix.addAttribute(PayloadAttribute.class);
p_offsetAtt = prefix.addAttribute(OffsetAttribute.class);
p_typeAtt = prefix.addAttribute(TypeAttribute.class);
p_flagsAtt = prefix.addAttribute(FlagsAttribute.class);
}
示例2: copyTo
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
@Override
public void copyTo(AttributeImpl target) {
if (target instanceof Token) {
final Token to = (Token) target;
to.reinit(this);
// reinit shares the payload, so clone it:
if (payload !=null) {
to.payload = payload.clone();
}
} else {
super.copyTo(target);
((OffsetAttribute) target).setOffset(startOffset, endOffset);
((PositionIncrementAttribute) target).setPositionIncrement(positionIncrement);
((PayloadAttribute) target).setPayload((payload == null) ? null : payload.clone());
((FlagsAttribute) target).setFlags(flags);
((TypeAttribute) target).setType(type);
}
}
示例3: testTypeForPayload1
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
/** verify that payload gets picked up for 1st group of tokens */
public void testTypeForPayload1() throws IOException {
TokenTypeJoinFilter ttjf = new TokenTypeJoinFilter(new TokenArrayTokenizer(tokensWithPayloads), new String[] {"normalized", "filing", "prefix"},
"joined", "normalized", "!", false, false);
CharTermAttribute termAtt = ttjf.getAttribute(CharTermAttribute.class);
TypeAttribute typeAtt = ttjf.getAttribute(TypeAttribute.class);
PayloadAttribute payloadAtt = ttjf.getAttribute(PayloadAttribute.class);
ttjf.reset();
assertTrue(ttjf.incrementToken());
assertEquals("unconsoled!Unconsoled!The ", termAtt.toString());
assertEquals("joined", typeAtt.type());
assertEquals("payload1", payloadAtt.getPayload().utf8ToString());
assertTrue(ttjf.incrementToken());
assertEquals("room with a view!Room With A View!A ", termAtt.toString());
assertEquals("joined", typeAtt.type());
assertNull(payloadAtt.getPayload());
assertFalse(ttjf.incrementToken());
}
示例4: testTypeForPayload2
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
/** verify that payload gets picked up for 2nd group of tokens */
public void testTypeForPayload2() throws IOException {
TokenTypeJoinFilter ttjf = new TokenTypeJoinFilter(new TokenArrayTokenizer(tokensWithPayloads), new String[] {"normalized", "filing", "prefix"},
"joined", "filing", "!", false, false);
CharTermAttribute termAtt = ttjf.getAttribute(CharTermAttribute.class);
TypeAttribute typeAtt = ttjf.getAttribute(TypeAttribute.class);
PayloadAttribute payloadAtt = ttjf.getAttribute(PayloadAttribute.class);
ttjf.reset();
assertTrue(ttjf.incrementToken());
assertEquals("unconsoled!Unconsoled!The ", termAtt.toString());
assertEquals("joined", typeAtt.type());
assertNull(payloadAtt.getPayload());
assertTrue(ttjf.incrementToken());
assertEquals("room with a view!Room With A View!A ", termAtt.toString());
assertEquals("joined", typeAtt.type());
assertEquals("payload2", payloadAtt.getPayload().utf8ToString());
assertFalse(ttjf.incrementToken());
}
示例5: testShorthand2
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
@Test
public void testShorthand2() throws IOException {
JsonReferencePayloadTokenizer tokenizer = new JsonReferencePayloadTokenizer();
tokenizer.setReader(new StringReader("{\"filing\": \"something\", \"prefix\": \"The \"}"));
tokenizer.reset();
assertTrue(tokenizer.incrementToken());
assertEquals("something", tokenizer.getAttribute(CharTermAttribute.class).toString());
assertEquals(JsonReferencePayloadTokenizer.TYPE_FILING, tokenizer.getAttribute(TypeAttribute.class).type());
assertEquals(1, tokenizer.getAttribute(PositionIncrementAttribute.class).getPositionIncrement());
assertNull(tokenizer.getAttribute(PayloadAttribute.class).getPayload());
assertTrue(tokenizer.incrementToken());
assertEquals("The ", tokenizer.getAttribute(CharTermAttribute.class).toString());
assertEquals(JsonReferencePayloadTokenizer.TYPE_PREFIX, tokenizer.getAttribute(TypeAttribute.class).type());
assertEquals(0, tokenizer.getAttribute(PositionIncrementAttribute.class).getPositionIncrement());
assertNull(tokenizer.getAttribute(PayloadAttribute.class).getPayload());
assertFalse(tokenizer.incrementToken());
}
示例6: testShorthand3
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
@Test
public void testShorthand3() throws IOException {
JsonReferencePayloadTokenizer tokenizer = new JsonReferencePayloadTokenizer();
tokenizer.setReader(new StringReader("{\"prefix\": \"The \", \"filing\": \"something\"}"));
tokenizer.reset();
assertTrue(tokenizer.incrementToken());
assertEquals("something", tokenizer.getAttribute(CharTermAttribute.class).toString());
assertEquals(JsonReferencePayloadTokenizer.TYPE_FILING, tokenizer.getAttribute(TypeAttribute.class).type());
assertEquals(1, tokenizer.getAttribute(PositionIncrementAttribute.class).getPositionIncrement());
assertNull(tokenizer.getAttribute(PayloadAttribute.class).getPayload());
assertTrue(tokenizer.incrementToken());
assertEquals("The ", tokenizer.getAttribute(CharTermAttribute.class).toString());
assertEquals(JsonReferencePayloadTokenizer.TYPE_PREFIX, tokenizer.getAttribute(TypeAttribute.class).type());
assertEquals(0, tokenizer.getAttribute(PositionIncrementAttribute.class).getPositionIncrement());
assertNull(tokenizer.getAttribute(PayloadAttribute.class).getPayload());
assertFalse(tokenizer.incrementToken());
}
示例7: testDelimitedPayloads
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
@Test
public void testDelimitedPayloads() throws Exception {
String test = "The quick|JJ red|JJ fox|NN jumped|VB over the lazy|JJ brown|JJ dogs|NN";
MockTokenizer mockTokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);
mockTokenizer.setReader(new StringReader(test));
DelimitedPayloadTokenFilter filter = new DelimitedPayloadTokenFilter(mockTokenizer,
DelimitedPayloadTokenFilter.DEFAULT_DELIMITER, new IdentityEncoder());
filter.reset();
CharTermAttribute termAtt = filter.getAttribute(CharTermAttribute.class);
PayloadAttribute payAtt = filter.getAttribute(PayloadAttribute.class);
assertTermEquals("The", filter, termAtt, payAtt, null);
assertTermEquals("quick", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertTermEquals("red", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertTermEquals("fox", filter, termAtt, payAtt, "NN".getBytes("UTF-8"));
assertTermEquals("jumped", filter, termAtt, payAtt, "VB".getBytes("UTF-8"));
assertTermEquals("over", filter, termAtt, payAtt, null);
assertTermEquals("the", filter, termAtt, payAtt, null);
assertTermEquals("lazy", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertTermEquals("brown", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertTermEquals("dogs", filter, termAtt, payAtt, "NN".getBytes("UTF-8"));
assertFalse(filter.incrementToken());
}
示例8: testKeepPayloads
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
@Test
public void testKeepPayloads() throws Exception {
String test = "The quick|JJ red|JJ fox|NN jumped|VB over the lazy|JJ brown|JJ dogs|NN";
MockTokenizer mockTokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);
mockTokenizer.setReader(new StringReader(test));
DelimitedPayloadTokenFilter baseFilter = new DelimitedPayloadTokenFilter(mockTokenizer,
DelimitedPayloadTokenFilter.DEFAULT_DELIMITER, new IdentityEncoder());
byte[][] payloads = {
"VB".getBytes(StandardCharsets.UTF_8),
"NN".getBytes(StandardCharsets.UTF_8)
};
FilterPayloadsFilter filter = new FilterPayloadsFilter(baseFilter, payloads, true);
filter.reset();
CharTermAttribute termAtt = filter.getAttribute(CharTermAttribute.class);
PayloadAttribute payAtt = filter.getAttribute(PayloadAttribute.class);
assertTermEquals("fox", filter, termAtt, payAtt, "NN".getBytes("UTF-8"));
assertTermEquals("jumped", filter, termAtt, payAtt, "VB".getBytes("UTF-8"));
assertTermEquals("dogs", filter, termAtt, payAtt, "NN".getBytes("UTF-8"));
assertFalse(filter.incrementToken());
}
示例9: testFilterPayloads
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
@Test
public void testFilterPayloads() throws Exception {
String test = "The quick|JJ red|JJ fox|NN jumped|VB over the lazy|JJ brown|JJ dogs|NN";
MockTokenizer mockTokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);
mockTokenizer.setReader(new StringReader(test));
DelimitedPayloadTokenFilter baseFilter = new DelimitedPayloadTokenFilter(mockTokenizer,
DelimitedPayloadTokenFilter.DEFAULT_DELIMITER, new IdentityEncoder());
byte[][] payloads = {
"VB".getBytes("UTF-8"),
"NN".getBytes("UTF-8")
};
FilterPayloadsFilter filter = new FilterPayloadsFilter(baseFilter, payloads, false);
filter.reset();
CharTermAttribute termAtt = filter.getAttribute(CharTermAttribute.class);
PayloadAttribute payAtt = filter.getAttribute(PayloadAttribute.class);
assertTermEquals("The", filter, termAtt, payAtt, null);
assertTermEquals("quick", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertTermEquals("red", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertTermEquals("over", filter, termAtt, payAtt, null);
assertTermEquals("the", filter, termAtt, payAtt, null);
assertTermEquals("lazy", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertTermEquals("brown", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));
assertFalse(filter.incrementToken());
}
示例10: testStripPayloads
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
@Test
public void testStripPayloads() throws Exception {
String test = "The quick|JJ red|JJ fox|NN jumped|VB over the lazy|JJ brown|JJ dogs|NN";
MockTokenizer mockTokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);
mockTokenizer.setReader(new StringReader(test));
DelimitedPayloadTokenFilter baseFilter = new DelimitedPayloadTokenFilter(mockTokenizer,
DelimitedPayloadTokenFilter.DEFAULT_DELIMITER, new IdentityEncoder());
StripPayloadsTokenFilter filter = new StripPayloadsTokenFilter(baseFilter);
filter.reset();
CharTermAttribute termAtt = filter.getAttribute(CharTermAttribute.class);
PayloadAttribute payAtt = filter.getAttribute(PayloadAttribute.class);
assertTermPayload("The", filter, termAtt, payAtt);
assertTermPayload("quick", filter, termAtt, payAtt);
assertTermPayload("red", filter, termAtt, payAtt);
assertTermPayload("fox", filter, termAtt, payAtt);
assertTermPayload("jumped", filter, termAtt, payAtt);
assertTermPayload("over", filter, termAtt, payAtt);
assertTermPayload("the", filter, termAtt, payAtt);
assertTermPayload("lazy", filter, termAtt, payAtt);
assertTermPayload("brown", filter, termAtt, payAtt);
assertTermPayload("dogs", filter, termAtt, payAtt);
assertFalse(filter.incrementToken());
}
示例11: walkTerms
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
void walkTerms(TokenStream ts, String op, String[] terms, String[] tags) throws IOException {
int i = 0;
while (ts.incrementToken()) {
CharTermAttribute termAtt = ts.getAttribute(CharTermAttribute.class);
String word = termAtt.toString();
if (terms != null) {
assertEquals(terms[i], word);
}
if (tags != null) {
if (tags[i] != null) {
PayloadAttribute p = ts.getAttribute(PayloadAttribute.class);
BytesRef payload = p.getPayload();
//Arrays.copyOfRange(payload.bytes, payload.offset, payload.offset + payload.length);
byte[] data = payload.bytes;
assertEquals(tags[i], (data != null) ? new String(data, "UTF-8") : null);
}
}
i++;
}
if (terms != null) {
assertEquals(terms.length, i);
}
}
示例12: testEncoder
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
public void testEncoder() throws Exception {
Reader reader = new StringReader("the|0.1 quick|0.1 red|0.1");
TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
stream = tokenFilterFactory("DelimitedPayload", "encoder", "float").create(stream);
stream.reset();
while (stream.incrementToken()) {
PayloadAttribute payAttr = stream.getAttribute(PayloadAttribute.class);
assertNotNull(payAttr);
byte[] payData = payAttr.getPayload().bytes;
assertNotNull(payData);
float payFloat = PayloadHelper.decodeFloat(payData);
assertEquals(0.1f, payFloat, 0.0f);
}
stream.end();
stream.close();
}
示例13: testDelim
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
public void testDelim() throws Exception {
Reader reader = new StringReader("the*0.1 quick*0.1 red*0.1");
TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
stream = tokenFilterFactory("DelimitedPayload",
"encoder", "float",
"delimiter", "*").create(stream);
stream.reset();
while (stream.incrementToken()) {
PayloadAttribute payAttr = stream.getAttribute(PayloadAttribute.class);
assertNotNull(payAttr);
byte[] payData = payAttr.getPayload().bytes;
assertNotNull(payData);
float payFloat = PayloadHelper.decodeFloat(payData);
assertEquals(0.1f, payFloat, 0.0f);
}
stream.end();
stream.close();
}
示例14: testPayloads
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
public void testPayloads() throws Exception {
String test = "The quick|JJ red|JJ fox|NN jumped|VB over the lazy|JJ brown|JJ dogs|NN";
DelimitedPayloadTokenFilter filter = new DelimitedPayloadTokenFilter
(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false),
DelimitedPayloadTokenFilter.DEFAULT_DELIMITER, new IdentityEncoder());
CharTermAttribute termAtt = filter.getAttribute(CharTermAttribute.class);
PayloadAttribute payAtt = filter.getAttribute(PayloadAttribute.class);
filter.reset();
assertTermEquals("The", filter, termAtt, payAtt, null);
assertTermEquals("quick", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));
assertTermEquals("red", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));
assertTermEquals("fox", filter, termAtt, payAtt, "NN".getBytes(StandardCharsets.UTF_8));
assertTermEquals("jumped", filter, termAtt, payAtt, "VB".getBytes(StandardCharsets.UTF_8));
assertTermEquals("over", filter, termAtt, payAtt, null);
assertTermEquals("the", filter, termAtt, payAtt, null);
assertTermEquals("lazy", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));
assertTermEquals("brown", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));
assertTermEquals("dogs", filter, termAtt, payAtt, "NN".getBytes(StandardCharsets.UTF_8));
assertFalse(filter.incrementToken());
filter.end();
filter.close();
}
示例15: testFloatEncoding
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入依赖的package包/类
public void testFloatEncoding() throws Exception {
String test = "The quick|1.0 red|2.0 fox|3.5 jumped|0.5 over the lazy|5 brown|99.3 dogs|83.7";
DelimitedPayloadTokenFilter filter = new DelimitedPayloadTokenFilter(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false), '|', new FloatEncoder());
CharTermAttribute termAtt = filter.getAttribute(CharTermAttribute.class);
PayloadAttribute payAtt = filter.getAttribute(PayloadAttribute.class);
filter.reset();
assertTermEquals("The", filter, termAtt, payAtt, null);
assertTermEquals("quick", filter, termAtt, payAtt, PayloadHelper.encodeFloat(1.0f));
assertTermEquals("red", filter, termAtt, payAtt, PayloadHelper.encodeFloat(2.0f));
assertTermEquals("fox", filter, termAtt, payAtt, PayloadHelper.encodeFloat(3.5f));
assertTermEquals("jumped", filter, termAtt, payAtt, PayloadHelper.encodeFloat(0.5f));
assertTermEquals("over", filter, termAtt, payAtt, null);
assertTermEquals("the", filter, termAtt, payAtt, null);
assertTermEquals("lazy", filter, termAtt, payAtt, PayloadHelper.encodeFloat(5.0f));
assertTermEquals("brown", filter, termAtt, payAtt, PayloadHelper.encodeFloat(99.3f));
assertTermEquals("dogs", filter, termAtt, payAtt, PayloadHelper.encodeFloat(83.7f));
assertFalse(filter.incrementToken());
filter.end();
filter.close();
}