Java Code Examples for org.apache.lucene.util.AttributeReflector

The following examples show how to use org.apache.lucene.util.AttributeReflector. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: TransportAnalyzeAction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * other attribute extract object.
 * Extracted object group by AttributeClassName
 *
 * @param stream current TokenStream
 * @param includeAttributes filtering attributes
 * @return Map<key value>
 */
private static Map<String, Object> extractExtendedAttributes(TokenStream stream, final Set<String> includeAttributes) {
    final Map<String, Object> extendedAttributes = new TreeMap<>();

    stream.reflectWith(new AttributeReflector() {
        @Override
        public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
            if (CharTermAttribute.class.isAssignableFrom(attClass))
                return;
            if (PositionIncrementAttribute.class.isAssignableFrom(attClass))
                return;
            if (OffsetAttribute.class.isAssignableFrom(attClass))
                return;
            if (TypeAttribute.class.isAssignableFrom(attClass))
                return;
            if (includeAttributes == null || includeAttributes.isEmpty() || includeAttributes.contains(key.toLowerCase(Locale.ROOT))) {
                if (value instanceof BytesRef) {
                    final BytesRef p = (BytesRef) value;
                    value = p.toString();
                }
                extendedAttributes.put(key, value);
            }
        }
    });

    return extendedAttributes;
}
 
Example 2
Source Project: lucene-solr   Source File: ReadingAttributeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  String reading = getReading();
  String readingEN = reading == null ? null : ToStringUtil.getRomanization(reading);
  String pronunciation = getPronunciation();
  String pronunciationEN = pronunciation == null ? null : ToStringUtil.getRomanization(pronunciation);
  reflector.reflect(ReadingAttribute.class, "reading", reading);
  reflector.reflect(ReadingAttribute.class, "reading (en)", readingEN);
  reflector.reflect(ReadingAttribute.class, "pronunciation", pronunciation);
  reflector.reflect(ReadingAttribute.class, "pronunciation (en)", pronunciationEN);
}
 
Example 3
Source Project: lucene-solr   Source File: PartOfSpeechAttributeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  String partOfSpeech = getPartOfSpeech();
  String partOfSpeechEN = partOfSpeech == null ? null : ToStringUtil.getPOSTranslation(partOfSpeech);
  reflector.reflect(PartOfSpeechAttribute.class, "partOfSpeech", partOfSpeech);
  reflector.reflect(PartOfSpeechAttribute.class, "partOfSpeech (en)", partOfSpeechEN);
}
 
Example 4
Source Project: lucene-solr   Source File: InflectionAttributeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  String type = getInflectionType();
  String typeEN = type == null ? null : ToStringUtil.getInflectionTypeTranslation(type);
  reflector.reflect(InflectionAttribute.class, "inflectionType", type);
  reflector.reflect(InflectionAttribute.class, "inflectionType (en)", typeEN);
  String form = getInflectionForm();
  String formEN = form == null ? null : ToStringUtil.getInflectedFormTranslation(form);
  reflector.reflect(InflectionAttribute.class, "inflectionForm", form);
  reflector.reflect(InflectionAttribute.class, "inflectionForm (en)", formEN);
}
 
Example 5
Source Project: lucene-solr   Source File: ScriptAttributeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  // when wordbreaking CJK, we use the 15924 code Japanese (Han+Hiragana+Katakana) to 
  // mark runs of Chinese/Japanese. our use is correct (as for chinese Han is a subset), 
  // but this is just to help prevent confusion.
  String name = code == UScript.JAPANESE ? "Chinese/Japanese" : getName();
  reflector.reflect(ScriptAttribute.class, "script", name);
}
 
Example 6
Source Project: lucene-solr   Source File: PartOfSpeechAttributeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  String posName = getPOSType() == null ? null : getPOSType().name();
  String rightPOS = getRightPOS() == null ? null : getRightPOS().name() + "(" + getRightPOS().description() + ")";
  String leftPOS = getLeftPOS() == null ? null : getLeftPOS().name() + "(" + getLeftPOS().description() + ")";
  reflector.reflect(PartOfSpeechAttribute.class, "posType", posName);
  reflector.reflect(PartOfSpeechAttribute.class, "leftPOS", leftPOS);
  reflector.reflect(PartOfSpeechAttribute.class, "rightPOS", rightPOS);
  reflector.reflect(PartOfSpeechAttribute.class, "morphemes", displayMorphemes(getMorphemes()));
}
 
Example 7
Source Project: lucene-solr   Source File: PackedTokenAttributeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  super.reflectWith(reflector);
  reflector.reflect(OffsetAttribute.class, "startOffset", startOffset);
  reflector.reflect(OffsetAttribute.class, "endOffset", endOffset);
  reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", positionIncrement);
  reflector.reflect(PositionLengthAttribute.class, "positionLength", positionLength);
  reflector.reflect(TypeAttribute.class, "type", type);
  reflector.reflect(TermFrequencyAttribute.class, "termFrequency", termFrequency);
}
 
Example 8
Source Project: lucene-solr   Source File: LegacyNumericTokenStream.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TermToBytesRefAttribute.class, "bytes", getBytesRef());
  reflector.reflect(LegacyNumericTermAttribute.class, "shift", shift);
  reflector.reflect(LegacyNumericTermAttribute.class, "rawValue", getRawValue());
  reflector.reflect(LegacyNumericTermAttribute.class, "valueSize", valueSize);
}
 
Example 9
/**
 * other attribute extract object.<br/>
 * Extracted object group by AttributeClassName
 *
 * @param stream current TokenStream
 * @param includeAttributes filtering attributes
 * @param shortAttrName if true, return short attribute name
 * @return Nested Object : Map<attrClass, Map<key, value>>
 */
private Map<String, Map<String, Object>> extractExtendedAttributes(TokenStream stream, final Set<String> includeAttributes, final boolean shortAttrName) {
    final Map<String, Map<String, Object>> extendedAttributes = new TreeMap<>();

    stream.reflectWith(new AttributeReflector() {
        @Override
        public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
            if (CharTermAttribute.class.isAssignableFrom(attClass))
                return;
            if (PositionIncrementAttribute.class.isAssignableFrom(attClass))
                return;
            if (OffsetAttribute.class.isAssignableFrom(attClass))
                return;
            if (TypeAttribute.class.isAssignableFrom(attClass))
                return;
            if (includeAttributes == null || includeAttributes.isEmpty() || includeAttributes.contains(attClass.getSimpleName().toLowerCase())) {
                Map<String, Object> currentAttributes = extendedAttributes.get(attClass.getName());
                if (currentAttributes == null) {
                    currentAttributes = new HashMap<>();
                }

                if (value instanceof BytesRef) {
                    final BytesRef p = (BytesRef) value;
                    value = p.toString();
                }
                currentAttributes.put(key, value);
                if (shortAttrName) {
                    extendedAttributes.put(attClass.getName().substring(attClass.getName().lastIndexOf(".")+1), currentAttributes);
                } else {
                    extendedAttributes.put(attClass.getName(), currentAttributes);
                }
            }
        }
    });

    return extendedAttributes;
}
 
Example 10
Source Project: datawave   Source File: TruncateAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
    reflector.reflect(TruncateAttribute.class, "truncated", isTruncated());
    reflector.reflect(TruncateAttribute.class, "originalLength", getOriginalLength());
}
 
Example 11
Source Project: datawave   Source File: TokenizedFieldsAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
    reflector.reflect(TokenizedFieldsAttribute.class, "tokenizedFields", getTokenizedFields());
    reflector.reflect(TokenizedFieldsAttribute.class, "tokenizeUnfieldedQueriesEnabled", isTokenizeUnfieldedQueriesEnabled());
    reflector.reflect(TokenizedFieldsAttribute.class, "skipTokenizeUnfieldedFields", getSkipTokenizeUnfieldedFields());
}
 
Example 12
Source Project: lucene-solr   Source File: BaseFormAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(BaseFormAttribute.class, "baseForm", getBaseForm());
}
 
Example 13
Source Project: lucene-solr   Source File: ReadingAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(ReadingAttribute.class, "reading", getReading());
}
 
Example 14
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(MorphosyntacticTagsAttribute.class, "tags", tags);
}
 
Example 15
Source Project: lucene-solr   Source File: ConcatenateGraphFilter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TermToBytesRefAttribute.class, "bytes", getBytesRef());
}
 
Example 16
Source Project: lucene-solr   Source File: TestCompoundWordTokenFilter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(MockRetainAttribute.class, "retain", retain);
}
 
Example 17
Source Project: lucene-solr   Source File: BaseTermVectorsFormatTestCase.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(OffsetAttribute.class, "startOffset", start);
  reflector.reflect(OffsetAttribute.class, "endOffset", end);
}
 
Example 18
Source Project: lucene-solr   Source File: BaseTokenStreamTestCase.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(CheckClearAttributesAttribute.class, "clearCalled", clearCalled);
}
 
Example 19
Source Project: lucene-solr   Source File: Token.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  super.reflectWith(reflector);
  reflector.reflect(FlagsAttribute.class, "flags", flags);
  reflector.reflect(PayloadAttribute.class, "payload", payload);
}
 
Example 20
Source Project: lucene-solr   Source File: UniqueFieldAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(UniqueFieldAttribute.class, "uniqueField", uniqueField);
}
 
Example 21
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(MaxNonCompetitiveBoostAttribute.class, "maxNonCompetitiveBoost", maxNonCompetitiveBoost);
  reflector.reflect(MaxNonCompetitiveBoostAttribute.class, "competitiveTerm", competitiveTerm);
}
 
Example 22
Source Project: lucene-solr   Source File: BoostAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(BoostAttribute.class, "boost", boost);
}
 
Example 23
Source Project: lucene-solr   Source File: FuzzyTermsEnum.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  throw new UnsupportedOperationException();
}
 
Example 24
Source Project: lucene-solr   Source File: KeywordAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(KeywordAttribute.class, "keyword", keyword);
}
 
Example 25
Source Project: lucene-solr   Source File: FlagsAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(FlagsAttribute.class, "flags", flags);
}
 
Example 26
Source Project: lucene-solr   Source File: PayloadAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(PayloadAttribute.class, "payload", payload);
}
 
Example 27
Source Project: lucene-solr   Source File: BytesTermAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TermToBytesRefAttribute.class, "bytes", bytes);
}
 
Example 28
Source Project: lucene-solr   Source File: PositionLengthAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(PositionLengthAttribute.class, "positionLength", positionLength);
}
 
Example 29
Source Project: lucene-solr   Source File: TermFrequencyAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TermFrequencyAttribute.class, "termFrequency", termFrequency);
}
 
Example 30
Source Project: lucene-solr   Source File: CharTermAttributeImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(CharTermAttribute.class, "term", toString());
  reflector.reflect(TermToBytesRefAttribute.class, "bytes", getBytesRef());
}