Java 类org.apache.lucene.util.AttributeImpl 实例源码

项目:lams    文件:PackedTokenAttributeImpl.java   
@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);
  }
}
项目:fastcatsearch3    文件:Token.java   
@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);
  }
}
项目:lucene4ir    文件:Retriever.java   
/**
 * 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;
}
项目:solr-analyzers    文件:StemmingBufferAttributeImpl.java   
/**
 * 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;
}
项目:search    文件:IndexTimeSynonymTest.java   
@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);
}
项目:search    文件:PackedTokenAttributeImpl.java   
@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);
  }
}
项目:read-open-source-code    文件:Token.java   
@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);
  }
}
项目:NYBC    文件:IndexTimeSynonymTest.java   
@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);
}
项目:NYBC    文件:TestSingleTokenTokenFilter.java   
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());
}
项目:NYBC    文件:Token.java   
@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);
  }
}
项目:read-open-source-code    文件:Token.java   
@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);
  }
}
项目:lams    文件:FuzzyTermsEnum.java   
@Override
public void copyTo(AttributeImpl target) {
  final List<CompiledAutomaton> targetAutomata =
    ((LevenshteinAutomataAttribute) target).automata();
  targetAutomata.clear();
  targetAutomata.addAll(automata);
}
项目:lams    文件:TeeSinkTokenFilter.java   
/**
 * 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));
}
项目:Elasticsearch    文件:NumericTokenizer.java   
/** 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);
        }
    };
}
项目:fastcatsearch3    文件:AdditionalTermAttributeImpl.java   
@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]);
    }
}
项目:search    文件:MorphosyntacticTagsAttributeImpl.java   
@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);
}
项目:search    文件:TeeSinkTokenFilter.java   
/**
 * 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));
}
项目:search    文件:UniqueFieldAttributeImpl.java   
@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();

}
项目:search    文件:FuzzyTermsEnum.java   
@Override
public void copyTo(AttributeImpl target) {
  final List<CompiledAutomaton> targetAutomata =
    ((LevenshteinAutomataAttribute) target).automata();
  targetAutomata.clear();
  targetAutomata.addAll(automata);
}
项目:search    文件:Test2BTerms.java   
@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);
}
项目:search    文件:TestCharTermAttributeImpl.java   
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;
}
项目:search    文件:TestCharTermAttributeImpl.java   
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;
}
项目:lucenelab    文件:XMLParsingTokenizer.java   
/** 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);
        }
    };
}
项目:auto-phrase-tokenfilter    文件:AutoPhrasingTokenFilter.java   
private OffsetAttribute getOffsetAttribute( ) {
   // get char term attr from current state
Iterator<AttributeImpl> attrIt = getAttributeImplsIterator();
while (attrIt != null && attrIt.hasNext() ) {
  AttributeImpl attrImp = attrIt.next();
  if (attrImp instanceof OffsetAttribute) {
    return (OffsetAttribute)attrImp;
     }
}

return null;
 }
项目:auto-phrase-tokenfilter    文件:AutoPhrasingTokenFilter.java   
private PositionIncrementAttribute getPositionIncrementAttribute( ) {
   // get char term attr from current state
Iterator<AttributeImpl> attrIt = getAttributeImplsIterator();
while (attrIt != null && attrIt.hasNext() ) {
  AttributeImpl attrImp = attrIt.next();
  if (attrImp instanceof PositionIncrementAttribute) {
    return (PositionIncrementAttribute)attrImp;
     }
}

return null;
 }
项目:read-open-source-code    文件:ICUCollationAttributeFactory.java   
@Override
public AttributeImpl createAttributeInstance(
    Class<? extends Attribute> attClass) {
  return attClass.isAssignableFrom(ICUCollatedTermAttributeImpl.class)
    ? new ICUCollatedTermAttributeImpl(collator)
    : delegate.createAttributeInstance(attClass);
}
项目:read-open-source-code    文件:MorphosyntacticTagsAttributeImpl.java   
@Override
public void copyTo(AttributeImpl target) {
  List<StringBuilder> cloned = null;
  if (tags != null) {
    cloned = new ArrayList<StringBuilder>(tags.size());
    for (StringBuilder b : tags) {
      cloned.add(new StringBuilder(b));
    }
  }
  ((MorphosyntacticTagsAttribute) target).setTags(cloned);
}
项目:NYBC    文件:ICUCollationAttributeFactory.java   
@Override
public AttributeImpl createAttributeInstance(
    Class<? extends Attribute> attClass) {
  return attClass.isAssignableFrom(ICUCollatedTermAttributeImpl.class)
    ? new ICUCollatedTermAttributeImpl(collator)
    : delegate.createAttributeInstance(attClass);
}
项目:NYBC    文件:MorphosyntacticTagsAttributeImpl.java   
@Override
public void copyTo(AttributeImpl target) {
  List<StringBuilder> cloned = null;
  if (tags != null) {
    cloned = new ArrayList<StringBuilder>(tags.size());
    for (StringBuilder b : tags) {
      cloned.add(new StringBuilder(b));
    }
  }
  ((MorphosyntacticTagsAttribute) target).setTags(cloned);
}
项目:read-open-source-code    文件:CollationAttributeFactory.java   
@Override
public AttributeImpl createAttributeInstance(
    Class<? extends Attribute> attClass) {
  return attClass.isAssignableFrom(CollatedTermAttributeImpl.class)
  ? new CollatedTermAttributeImpl(collator)
  : delegate.createAttributeInstance(attClass);
}
项目:NYBC    文件:MockBytesAttributeFactory.java   
@Override
public AttributeImpl createAttributeInstance(
    Class<? extends Attribute> attClass) {
  return attClass.isAssignableFrom(MockUTF16TermAttributeImpl.class)
    ? new MockUTF16TermAttributeImpl()
    : delegate.createAttributeInstance(attClass);
}
项目:NYBC    文件:FuzzyTermsEnum.java   
@Override
public void copyTo(AttributeImpl target) {
  final List<CompiledAutomaton> targetAutomata =
    ((LevenshteinAutomataAttribute) target).automata();
  targetAutomata.clear();
  targetAutomata.addAll(automata);
}
项目:read-open-source-code    文件:FuzzyTermsEnum.java   
@Override
public void copyTo(AttributeImpl target) {
  final List<CompiledAutomaton> targetAutomata =
    ((LevenshteinAutomataAttribute) target).automata();
  targetAutomata.clear();
  targetAutomata.addAll(automata);
}
项目:NYBC    文件:TestToken.java   
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;
}
项目:NYBC    文件:TestToken.java   
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;
}
项目:elasticsearch-plugin-bundle    文件:AutoPhrasingTokenFilter.java   
private CharTermAttribute getTermAttribute() {
    Iterator<AttributeImpl> attrIt = getAttributeImplsIterator();
    while (attrIt != null && attrIt.hasNext()) {
        AttributeImpl attrImp = attrIt.next();
        if (attrImp instanceof CharTermAttribute) {
            return (CharTermAttribute) attrImp;
        }
    }
    return null;
}
项目:elasticsearch-plugin-bundle    文件:AutoPhrasingTokenFilter.java   
private OffsetAttribute getOffsetAttribute() {
    Iterator<AttributeImpl> attrIt = getAttributeImplsIterator();
    while (attrIt != null && attrIt.hasNext()) {
        AttributeImpl attrImp = attrIt.next();
        if (attrImp instanceof OffsetAttribute) {
            return (OffsetAttribute) attrImp;
        }
    }
    return null;
}
项目:elasticsearch-plugin-bundle    文件:AutoPhrasingTokenFilter.java   
private PositionIncrementAttribute getPositionIncrementAttribute() {
    Iterator<AttributeImpl> attrIt = getAttributeImplsIterator();
    while (attrIt != null && attrIt.hasNext()) {
        AttributeImpl attrImp = attrIt.next();
        if (attrImp instanceof PositionIncrementAttribute) {
            return (PositionIncrementAttribute) attrImp;
        }
    }
    return null;
}
项目:read-open-source-code    文件:FuzzyTermsEnum.java   
@Override
public void copyTo(AttributeImpl target) {
  final List<CompiledAutomaton> targetAutomata =
    ((LevenshteinAutomataAttribute) target).automata();
  targetAutomata.clear();
  targetAutomata.addAll(automata);
}
项目:read-open-source-code    文件:TeeSinkTokenFilter.java   
/**
 * 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<SinkTokenStream>(sink));
}