List of usage examples for org.apache.lucene.analysis.tokenattributes OffsetAttributeImpl OffsetAttributeImpl
public OffsetAttributeImpl()
From source file:org.hibernate.search.test.serialization.SerializationTest.java
License:Open Source License
private List<List<AttributeImpl>> buildTokenSteamWithAttributes() { List<List<AttributeImpl>> tokens = new ArrayList<List<AttributeImpl>>(); tokens.add(new ArrayList<AttributeImpl>()); AnalysisRequestHandlerBase.TokenTrackingAttributeImpl attrImpl = new AnalysisRequestHandlerBase.TokenTrackingAttributeImpl(); attrImpl.reset(new int[] { 1, 2, 3 }, 4); tokens.get(0).add(attrImpl);// w w w .jav a 2 s . c o m CharTermAttributeImpl charAttr = new CharTermAttributeImpl(); charAttr.append("Wazzza"); tokens.get(0).add(charAttr); PayloadAttributeImpl payloadAttribute = new PayloadAttributeImpl(); payloadAttribute.setPayload(new Payload(new byte[] { 0, 1, 2, 3 })); tokens.get(0).add(payloadAttribute); KeywordAttributeImpl keywordAttr = new KeywordAttributeImpl(); keywordAttr.setKeyword(true); tokens.get(0).add(keywordAttr); PositionIncrementAttributeImpl posIncrAttr = new PositionIncrementAttributeImpl(); posIncrAttr.setPositionIncrement(3); tokens.get(0).add(posIncrAttr); FlagsAttributeImpl flagsAttr = new FlagsAttributeImpl(); flagsAttr.setFlags(435); tokens.get(0).add(flagsAttr); TypeAttributeImpl typeAttr = new TypeAttributeImpl(); typeAttr.setType("acronym"); tokens.get(0).add(typeAttr); OffsetAttributeImpl offsetAttr = new OffsetAttributeImpl(); offsetAttr.setOffset(4, 7); tokens.get(0).add(offsetAttr); return tokens; }
From source file:org.hibernate.search.test.util.SerializationTestHelper.java
License:LGPL
public static List<List<AttributeImpl>> buildTokenStreamWithAttributes() { List<List<AttributeImpl>> tokens = new ArrayList<>(); tokens.add(new ArrayList<AttributeImpl>()); CharTermAttributeImpl charAttr = new CharTermAttributeImpl(); charAttr.append("Wazzza"); tokens.get(0).add(charAttr);/*from w ww . j av a 2 s . c o m*/ PayloadAttributeImpl payloadAttribute = new PayloadAttributeImpl(); payloadAttribute.setPayload(new BytesRef(new byte[] { 0, 1, 2, 3 })); tokens.get(0).add(payloadAttribute); KeywordAttributeImpl keywordAttr = new KeywordAttributeImpl(); keywordAttr.setKeyword(true); tokens.get(0).add(keywordAttr); PositionIncrementAttributeImpl posIncrAttr = new PositionIncrementAttributeImpl(); posIncrAttr.setPositionIncrement(3); tokens.get(0).add(posIncrAttr); FlagsAttributeImpl flagsAttr = new FlagsAttributeImpl(); flagsAttr.setFlags(435); tokens.get(0).add(flagsAttr); TypeAttributeImpl typeAttr = new TypeAttributeImpl(); typeAttr.setType("acronym"); tokens.get(0).add(typeAttr); OffsetAttributeImpl offsetAttr = new OffsetAttributeImpl(); offsetAttr.setOffset(4, 7); tokens.get(0).add(offsetAttr); return tokens; }
From source file:org.tallison.lucene.search.concordance.charoffsets.DocTokenOffsets.java
License:Apache License
public void addOffset(int start, int end) { OffsetAttributeImpl offset = new OffsetAttributeImpl(); offset.setOffset(start, end);/* w w w.ja va 2 s.c om*/ offsets.add(offset); }
From source file:org.tallison.lucene.search.concordance.classic.WindowBuilder.java
License:Apache License
private OffsetAttribute buildOffsetAttribute(int start, int end) { OffsetAttribute off = new OffsetAttributeImpl(); off.setOffset(start, end);// ww w . j a v a 2s . c o m return off; }
From source file:org.tallison.lucene.search.concordance.windowvisitor.NGrammer.java
License:Apache License
private List<OffsetAttribute> getGramOffsets(List<String> strings) { List<OffsetAttribute> ret = new ArrayList<>(); for (int i = 0; i < strings.size(); i++) { for (int j = i + getMinGram() - 1; j < i + getMaxGram() && j < strings.size(); j++) { OffsetAttribute off = new OffsetAttributeImpl(); off.setOffset(i, j);/*w w w .j a v a 2 s . c o m*/ ret.add(off); } } return ret; }
From source file:org.tallison.lucene.search.concordance.windowvisitor.WGrammer.java
License:Apache License
private List<OffsetAttribute> getGramOffsets(List<String> strings, int min, int max) { //for now, copy strings to terms List<Term> terms = new ArrayList<>(); for (String s : strings) { terms.add(new Term(fieldName, s)); }/* ww w .j a v a2 s . co m*/ List<OffsetAttribute> ret = new ArrayList<>(); for (int i = 0; i < strings.size(); i++) { if (ConcordanceArrayWindow.isStopOrFieldSeparator(strings.get(i))) { continue; } else if (!tokenBlackList.accept(terms.get(i))) { continue; } int nonStops = 0; for (int j = i; nonStops < max && j < strings.size(); j++) { String tmp = strings.get(j); if (ConcordanceArrayWindow.isStop(tmp) || !tokenBlackList.accept(terms.get(j)) || (allowFieldSeparators == true && ConcordanceArrayWindow.isFieldSeparator(tmp))) { continue; } else if (allowFieldSeparators == false && ConcordanceArrayWindow.isFieldSeparator(tmp)) { break; } nonStops++; if (nonStops >= min) { OffsetAttribute offset = new OffsetAttributeImpl(); offset.setOffset(i, j); ret.add(offset); } } } return ret; }