本文整理汇总了Java中org.apache.lucene.util.AttributeImpl类的典型用法代码示例。如果您正苦于以下问题:Java AttributeImpl类的具体用法?Java AttributeImpl怎么用?Java AttributeImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeImpl类属于org.apache.lucene.util包,在下文中一共展示了AttributeImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyTo
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
@Override
public void copyTo(AttributeImpl target) {
if (target instanceof PackedTokenAttributeImpl) {
final PackedTokenAttributeImpl to = (PackedTokenAttributeImpl) target;
to.copyBuffer(buffer(), 0, length());
to.positionIncrement = positionIncrement;
to.positionLength = positionLength;
to.startOffset = startOffset;
to.endOffset = endOffset;
to.type = type;
} else {
super.copyTo(target);
((OffsetAttribute) target).setOffset(startOffset, endOffset);
((PositionIncrementAttribute) target).setPositionIncrement(positionIncrement);
((PositionLengthAttribute) target).setPositionLength(positionLength);
((TypeAttribute) target).setType(type);
}
}
示例2: copyTo
import org.apache.lucene.util.AttributeImpl; //导入依赖的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: getTokens
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
/**
* Returns the list of tokens extracted from the query string using the specified analyzer.
*
* @param field document field.
*
* @param queryTerms query string.
*
* @param distinctTokens if true, return the distinct tokens in the query string.
*
* @return the list of tokens extracted from the given query.
*
* @throws IOException
*/
List<String> getTokens(String field, String queryTerms, boolean distinctTokens) throws IOException {
List<String> tokens = new ArrayList<String>();
StringReader topicTitleReader = new StringReader(queryTerms);
Set<String> seenTokens = new TreeSet<String>();
TokenStream tok;
tok = analyzer.tokenStream(field, topicTitleReader);
tok.reset();
while (tok.incrementToken()) {
Iterator<AttributeImpl> atts = tok.getAttributeImplsIterator();
AttributeImpl token = atts.next();
String text = "" + token;
if (seenTokens.contains(text) && distinctTokens) {
continue;
}
seenTokens.add(text);
tokens.add(text);
}
tok.close();
return tokens;
}
示例4: copyTo
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
/**
* We just want to create a new array if the length differs.
*/
@Override
public void copyTo(AttributeImpl input) {
StemmingBufferAttributeImpl copyAttributeImpl = (StemmingBufferAttributeImpl) input;
if (copyAttributeImpl.stemmedToken.length < stemmedTokenLength) {
copyAttributeImpl.stemmedToken = new char[stemmedTokenLength];
}
System.arraycopy(stemmedToken, 0, copyAttributeImpl.stemmedToken, 0, stemmedTokenLength);
if (copyAttributeImpl.originalToken.length < originalTokenLength) {
copyAttributeImpl.originalToken = new char[originalTokenLength];
}
System.arraycopy(originalToken, 0, copyAttributeImpl.originalToken, 0, originalTokenLength);
copyAttributeImpl.stemmedTokenLength = stemmedTokenLength;
copyAttributeImpl.originalTokenLength = originalTokenLength;
copyAttributeImpl.stemmedTokenHasBeenEmitted = stemmedTokenHasBeenEmitted;
}
示例5: createComponents
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
@Override
public TokenStreamComponents createComponents(String fieldName, Reader reader) {
Tokenizer ts = new Tokenizer(Token.TOKEN_ATTRIBUTE_FACTORY, reader) {
final AttributeImpl reusableToken = (AttributeImpl) addAttribute(CharTermAttribute.class);
int p = 0;
@Override
public boolean incrementToken() {
if( p >= tokens.length ) return false;
clearAttributes();
tokens[p++].copyTo(reusableToken);
return true;
}
@Override
public void reset() throws IOException {
super.reset();
this.p = 0;
}
};
return new TokenStreamComponents(ts);
}
示例6: test
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
public void test() throws IOException {
Token token = new Token();
SingleTokenTokenStream ts = new SingleTokenTokenStream(token);
AttributeImpl tokenAtt = (AttributeImpl) ts.addAttribute(CharTermAttribute.class);
assertTrue(tokenAtt instanceof Token);
ts.reset();
assertTrue(ts.incrementToken());
assertEquals(token, tokenAtt);
assertFalse(ts.incrementToken());
token = new Token("hallo", 10, 20, "someType");
ts.setToken(token);
ts.reset();
assertTrue(ts.incrementToken());
assertEquals(token, tokenAtt);
assertFalse(ts.incrementToken());
}
示例7: copyTo
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
@Override
public void copyTo(AttributeImpl target) {
final List<CompiledAutomaton> targetAutomata =
((LevenshteinAutomataAttribute) target).automata();
targetAutomata.clear();
targetAutomata.addAll(automata);
}
示例8: addSinkTokenStream
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
/**
* Adds a {@link SinkTokenStream} created by another <code>TeeSinkTokenFilter</code>
* to this one. The supplied stream will also receive all consumed tokens.
* This method can be used to pass tokens from two different tees to one sink.
*/
public void addSinkTokenStream(final SinkTokenStream sink) {
// check that sink has correct factory
if (!this.getAttributeFactory().equals(sink.getAttributeFactory())) {
throw new IllegalArgumentException("The supplied sink is not compatible to this tee");
}
// add eventually missing attribute impls to the existing sink
for (Iterator<AttributeImpl> it = this.cloneAttributes().getAttributeImplsIterator(); it.hasNext(); ) {
sink.addAttributeImpl(it.next());
}
this.sinks.add(new WeakReference<>(sink));
}
示例9: delegatingAttributeFactory
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
/** Make this tokenizer get attributes from the delegate token stream. */
private static final AttributeFactory delegatingAttributeFactory(final AttributeSource source) {
return new AttributeFactory() {
@Override
public AttributeImpl createAttributeInstance(Class<? extends Attribute> attClass) {
return (AttributeImpl) source.addAttribute(attClass);
}
};
}
示例10: copyTo
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
@Override
public void copyTo(AttributeImpl target) {
AdditionalTermAttribute t = (AdditionalTermAttribute) target;
for(int inx=0;inx < additionalTerms.size(); inx++) {
String term = additionalTerms.get(inx);
String type = types.get(inx);
@SuppressWarnings("rawtypes")
List synonyms = this.synonyms;
int[] offset = offsets.get(inx);
int subLength = this.subLength;
t.addAdditionalTerm(term, type, synonyms, subLength, offset[0], offset[1]);
}
}
示例11: copyTo
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
@Override
public void copyTo(AttributeImpl target) {
List<StringBuilder> cloned = null;
if (tags != null) {
cloned = new ArrayList<>(tags.size());
for (StringBuilder b : tags) {
cloned.add(new StringBuilder(b));
}
}
((MorphosyntacticTagsAttribute) target).setTags(cloned);
}
示例12: copyTo
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
@Override
public void copyTo(AttributeImpl target) {
if (!(target instanceof UniqueFieldAttributeImpl)) {
throw new IllegalArgumentException(
"cannot copy the values from attribute UniqueFieldAttribute to an instance of "
+ target.getClass().getName());
}
UniqueFieldAttributeImpl uniqueFieldAttr = (UniqueFieldAttributeImpl) target;
uniqueFieldAttr.uniqueField = uniqueField.toString();
}
示例13: createAttributeInstance
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
@Override
public AttributeImpl createAttributeInstance(Class<? extends Attribute> attClass) {
if (attClass == TermToBytesRefAttribute.class)
return new MyTermAttributeImpl();
if (CharTermAttribute.class.isAssignableFrom(attClass))
throw new IllegalArgumentException("no");
return delegate.createAttributeInstance(attClass);
}
示例14: assertCloneIsEqual
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
public static <T extends AttributeImpl> T assertCloneIsEqual(T att) {
@SuppressWarnings("unchecked")
T clone = (T) att.clone();
assertEquals("Clone must be equal", att, clone);
assertEquals("Clone's hashcode must be equal", att.hashCode(), clone.hashCode());
return clone;
}
示例15: assertCopyIsEqual
import org.apache.lucene.util.AttributeImpl; //导入依赖的package包/类
public static <T extends AttributeImpl> T assertCopyIsEqual(T att) throws Exception {
@SuppressWarnings("unchecked")
T copy = (T) att.getClass().newInstance();
att.copyTo(copy);
assertEquals("Copied instance must be equal", att, copy);
assertEquals("Copied instance's hashcode must be equal", att.hashCode(), copy.hashCode());
return copy;
}