org.apache.lucene.util.AttributeReflector Java Examples

The following examples show how to use org.apache.lucene.util.AttributeReflector. 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 File: PackedTokenAttributeImpl.java    From lucene-solr with 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 #2
Source File: TransportAnalyzeAction.java    From Elasticsearch with 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 #3
Source File: ReadingAttributeImpl.java    From lucene-solr with 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 #4
Source File: PartOfSpeechAttributeImpl.java    From lucene-solr with 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 #5
Source File: InflectionAttributeImpl.java    From lucene-solr with 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 #6
Source File: ScriptAttributeImpl.java    From lucene-solr with 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 #7
Source File: LegacyNumericTokenStream.java    From lucene-solr with 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 #8
Source File: PartOfSpeechAttributeImpl.java    From lucene-solr with 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 #9
Source File: TransportExtendedAnalyzeAction.java    From elasticsearch-extended-analyze with Apache License 2.0 5 votes vote down vote up
/**
 * 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 File: Test2BTerms.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TermToBytesRefAttribute.class, "bytes", getBytesRef());
}
 
Example #11
Source File: Token.java    From lucene-solr with 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 #12
Source File: OffsetAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(OffsetAttribute.class, "startOffset", startOffset);
  reflector.reflect(OffsetAttribute.class, "endOffset", endOffset);
}
 
Example #13
Source File: TypeAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TypeAttribute.class, "type", type);
}
 
Example #14
Source File: PositionIncrementAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", positionIncrement);
}
 
Example #15
Source File: CharTermAttributeImpl.java    From lucene-solr with 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());
}
 
Example #16
Source File: TermFrequencyAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TermFrequencyAttribute.class, "termFrequency", termFrequency);
}
 
Example #17
Source File: PositionLengthAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(PositionLengthAttribute.class, "positionLength", positionLength);
}
 
Example #18
Source File: TestToken.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {}
 
Example #19
Source File: TaggingAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TaggingAttribute.class, "taggable", isTaggable());
}
 
Example #20
Source File: AnalysisRequestHandlerBase.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TokenTrackingAttribute.class, "position", position);
  // convert to Integer[] array, as only such one can be serialized by ResponseWriters
  reflector.reflect(TokenTrackingAttribute.class, "positionHistory", ArrayUtils.toObject(getPositions()));
}
 
Example #21
Source File: KeywordAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(KeywordAttribute.class, "keyword", keyword);
}
 
Example #22
Source File: ScriptAttributeImpl.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
    String name = code == UScript.JAPANESE ? "Chinese/Japanese" : getName();
    reflector.reflect(ScriptAttribute.class, "script", name);
}
 
Example #23
Source File: TaggingAttributeImpl.java    From SolrTextTagger with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(TaggingAttribute.class, "taggable", isTaggable());
}
 
Example #24
Source File: PartOfSpeechAttributeImpl.java    From mecab-ko-lucene-analyzer with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {                        
  reflector.reflect(PartOfSpeechAttribute.class, "partOfSpeech", partOfSpeech());
}
 
Example #25
Source File: SemanticClassAttributeImpl.java    From mecab-ko-lucene-analyzer with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {                        
  reflector.reflect(SemanticClassAttribute.class, "semanticClass", semanticClass());
}
 
Example #26
Source File: Token.java    From lucene-solr with 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 #27
Source File: TokenizedFieldsAttributeImpl.java    From datawave with 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 #28
Source File: BaseFormAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(BaseFormAttribute.class, "baseForm", getBaseForm());
}
 
Example #29
Source File: ReadingAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(ReadingAttribute.class, "reading", getReading());
}
 
Example #30
Source File: MorphosyntacticTagsAttributeImpl.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void reflectWith(AttributeReflector reflector) {
  reflector.reflect(MorphosyntacticTagsAttribute.class, "tags", tags);
}