You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2013/07/04 01:26:45 UTC
svn commit: r1499601 [3/20] - in /lucene/dev/branches/security: ./
dev-tools/ dev-tools/eclipse/ dev-tools/idea/.idea/libraries/
dev-tools/idea/solr/core/src/test/ dev-tools/maven/ dev-tools/maven/lucene/
dev-tools/maven/lucene/analysis/stempel/ dev-to...
Modified: lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilter.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilter.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilter.java Wed Jul 3 23:26:32 2013
@@ -35,12 +35,26 @@ import org.apache.lucene.analysis.tokena
* </p>
*/
public final class NorwegianMinimalStemFilter extends TokenFilter {
- private final NorwegianMinimalStemmer stemmer = new NorwegianMinimalStemmer();
+ private final NorwegianMinimalStemmer stemmer;
private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);
+ /**
+ * Calls {@link #NorwegianMinimalStemFilter(TokenStream, int)
+ * NorwegianMinimalStemFilter(input, BOKMAAL)}
+ */
public NorwegianMinimalStemFilter(TokenStream input) {
+ this(input, NorwegianLightStemmer.BOKMAAL);
+ }
+
+ /**
+ * Creates a new NorwegianLightStemFilter
+ * @param flags set to {@link NorwegianLightStemmer#BOKMAAL},
+ * {@link NorwegianLightStemmer#NYNORSK}, or both.
+ */
+ public NorwegianMinimalStemFilter(TokenStream input, int flags) {
super(input);
+ this.stemmer = new NorwegianMinimalStemmer(flags);
}
@Override
Modified: lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilterFactory.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilterFactory.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemFilterFactory.java Wed Jul 3 23:26:32 2013
@@ -23,6 +23,9 @@ import org.apache.lucene.analysis.TokenS
import org.apache.lucene.analysis.no.NorwegianMinimalStemFilter;
import org.apache.lucene.analysis.util.TokenFilterFactory;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.BOKMAAL;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.NYNORSK;
+
/**
* Factory for {@link NorwegianMinimalStemFilter}.
* <pre class="prettyprint">
@@ -30,15 +33,27 @@ import org.apache.lucene.analysis.util.T
* <analyzer>
* <tokenizer class="solr.StandardTokenizerFactory"/>
* <filter class="solr.LowerCaseFilterFactory"/>
- * <filter class="solr.NorwegianMinimalStemFilterFactory"/>
+ * <filter class="solr.NorwegianMinimalStemFilterFactory" variant="nb"/>
* </analyzer>
* </fieldType></pre>
*/
public class NorwegianMinimalStemFilterFactory extends TokenFilterFactory {
+ private final int flags;
+
/** Creates a new NorwegianMinimalStemFilterFactory */
public NorwegianMinimalStemFilterFactory(Map<String,String> args) {
super(args);
+ String variant = get(args, "variant");
+ if (variant == null || "nb".equals(variant)) {
+ flags = BOKMAAL;
+ } else if ("nn".equals(variant)) {
+ flags = NYNORSK;
+ } else if ("no".equals(variant)) {
+ flags = BOKMAAL | NYNORSK;
+ } else {
+ throw new IllegalArgumentException("invalid variant: " + variant);
+ }
if (!args.isEmpty()) {
throw new IllegalArgumentException("Unknown parameters: " + args);
}
@@ -46,6 +61,6 @@ public class NorwegianMinimalStemFilterF
@Override
public TokenStream create(TokenStream input) {
- return new NorwegianMinimalStemFilter(input);
+ return new NorwegianMinimalStemFilter(input, flags);
}
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemmer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemmer.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemmer.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianMinimalStemmer.java Wed Jul 3 23:26:32 2013
@@ -53,31 +53,52 @@ package org.apache.lucene.analysis.no;
*/
import static org.apache.lucene.analysis.util.StemmerUtil.*;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.BOKMAAL;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.NYNORSK;
/**
- * Minimal Stemmer for Norwegian bokmål (no-nb)
+ * Minimal Stemmer for Norwegian Bokmål (no-nb) and Nynorsk (no-nn)
* <p>
* Stems known plural forms for Norwegian nouns only, together with genitiv -s
*/
public class NorwegianMinimalStemmer {
+ final boolean useBokmaal;
+ final boolean useNynorsk;
- public int stem(char s[], int len) {
+ /**
+ * Creates a new NorwegianMinimalStemmer
+ * @param flags set to {@link NorwegianLightStemmer#BOKMAAL},
+ * {@link NorwegianLightStemmer#NYNORSK}, or both.
+ */
+ public NorwegianMinimalStemmer(int flags) {
+ if (flags <= 0 || flags > BOKMAAL + NYNORSK) {
+ throw new IllegalArgumentException("invalid flags");
+ }
+ useBokmaal = (flags & BOKMAAL) != 0;
+ useNynorsk = (flags & NYNORSK) != 0;
+ }
+
+ public int stem(char s[], int len) {
// Remove genitiv s
if (len > 4 && s[len-1] == 's')
len--;
if (len > 5 &&
- endsWith(s, len, "ene") // masc/fem/neutr pl definite (hus-ene)
- )
+ (endsWith(s, len, "ene") || // masc/fem/neutr pl definite (hus-ene)
+ (endsWith(s, len, "ane") &&
+ useNynorsk // masc pl definite (gut-ane)
+ )))
return len - 3;
-
+
if (len > 4 &&
- (endsWith(s, len, "er") || // masc/fem indefinite
- endsWith(s, len, "en") || // masc/fem definite
- endsWith(s, len, "et") // neutr definite
- ))
+ (endsWith(s, len, "er") || // masc/fem indefinite
+ endsWith(s, len, "en") || // masc/fem definite
+ endsWith(s, len, "et") || // neutr definite
+ (endsWith(s, len, "ar") &&
+ useNynorsk // masc pl indefinite
+ )))
return len - 2;
-
+
if (len > 3)
switch(s[len-1]) {
case 'a': // fem definite
Modified: lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/tr/TurkishLowerCaseFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/tr/TurkishLowerCaseFilter.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/tr/TurkishLowerCaseFilter.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/tr/TurkishLowerCaseFilter.java Wed Jul 3 23:26:32 2013
@@ -57,7 +57,7 @@ public final class TurkishLowerCaseFilte
final char[] buffer = termAtt.buffer();
int length = termAtt.length();
for (int i = 0; i < length;) {
- final int ch = Character.codePointAt(buffer, i);
+ final int ch = Character.codePointAt(buffer, i, length);
iOrAfter = (ch == LATIN_CAPITAL_LETTER_I ||
(iOrAfter && Character.getType(ch) == Character.NON_SPACING_MARK));
@@ -100,7 +100,7 @@ public final class TurkishLowerCaseFilte
*/
private boolean isBeforeDot(char s[], int pos, int len) {
for (int i = pos; i < len;) {
- final int ch = Character.codePointAt(s, i);
+ final int ch = Character.codePointAt(s, i, len);
if (Character.getType(ch) != Character.NON_SPACING_MARK)
return false;
if (ch == COMBINING_DOT_ABOVE)
Modified: lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharArrayMap.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharArrayMap.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharArrayMap.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharArrayMap.java Wed Jul 3 23:26:32 2013
@@ -262,7 +262,7 @@ public class CharArrayMap<V> extends Abs
if (ignoreCase) {
for(int i=0;i<len;) {
final int codePointAt = charUtils.codePointAt(text1, off+i, limit);
- if (Character.toLowerCase(codePointAt) != charUtils.codePointAt(text2, i))
+ if (Character.toLowerCase(codePointAt) != charUtils.codePointAt(text2, i, text2.length))
return false;
i += Character.charCount(codePointAt);
}
@@ -282,7 +282,7 @@ public class CharArrayMap<V> extends Abs
if (ignoreCase) {
for(int i=0;i<len;) {
final int codePointAt = charUtils.codePointAt(text1, i);
- if (Character.toLowerCase(codePointAt) != charUtils.codePointAt(text2, i))
+ if (Character.toLowerCase(codePointAt) != charUtils.codePointAt(text2, i, text2.length))
return false;
i += Character.charCount(codePointAt);
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharTokenizer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharTokenizer.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharTokenizer.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharTokenizer.java Wed Jul 3 23:26:32 2013
@@ -100,7 +100,8 @@ public abstract class CharTokenizer exte
while (true) {
if (bufferIndex >= dataLen) {
offset += dataLen;
- if(!charUtils.fill(ioBuffer, input)) { // read supplementary char aware with CharacterUtils
+ charUtils.fill(ioBuffer, input); // read supplementary char aware with CharacterUtils
+ if (ioBuffer.getLength() == 0) {
dataLen = 0; // so next offset += dataLen won't decrement offset
if (length > 0) {
break;
@@ -113,7 +114,7 @@ public abstract class CharTokenizer exte
bufferIndex = 0;
}
// use CharacterUtils here to support < 3.1 UTF-16 code unit behavior if the char based methods are gone
- final int c = charUtils.codePointAt(ioBuffer.getBuffer(), bufferIndex);
+ final int c = charUtils.codePointAt(ioBuffer.getBuffer(), bufferIndex, ioBuffer.getLength());
final int charCount = Character.charCount(c);
bufferIndex += charCount;
Modified: lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharacterUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharacterUtils.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharacterUtils.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/CharacterUtils.java Wed Jul 3 23:26:32 2013
@@ -52,27 +52,6 @@ public abstract class CharacterUtils {
}
/**
- * Returns the code point at the given index of the char array.
- * Depending on the {@link Version} passed to
- * {@link CharacterUtils#getInstance(Version)} this method mimics the behavior
- * of {@link Character#codePointAt(char[], int)} as it would have been
- * available on a Java 1.4 JVM or on a later virtual machine version.
- *
- * @param chars
- * a character array
- * @param offset
- * the offset to the char values in the chars array to be converted
- *
- * @return the Unicode code point at the given index
- * @throws NullPointerException
- * - if the array is null.
- * @throws IndexOutOfBoundsException
- * - if the value offset is negative or not less than the length of
- * the char array.
- */
- public abstract int codePointAt(final char[] chars, final int offset);
-
- /**
* Returns the code point at the given index of the {@link CharSequence}.
* Depending on the {@link Version} passed to
* {@link CharacterUtils#getInstance(Version)} this method mimics the behavior
@@ -116,7 +95,10 @@ public abstract class CharacterUtils {
* the char array.
*/
public abstract int codePointAt(final char[] chars, final int offset, final int limit);
-
+
+ /** Return the number of characters in <code>seq</code>. */
+ public abstract int codePointCount(CharSequence seq);
+
/**
* Creates a new {@link CharacterBuffer} and allocates a <code>char[]</code>
* of the given bufferSize.
@@ -140,51 +122,105 @@ public abstract class CharacterUtils {
* @param offset the offset to start at
* @param limit the max char in the buffer to lower case
*/
- public void toLowerCase(final char[] buffer, final int offset, final int limit) {
+ public final void toLowerCase(final char[] buffer, final int offset, final int limit) {
assert buffer.length >= limit;
assert offset <=0 && offset <= buffer.length;
for (int i = offset; i < limit;) {
i += Character.toChars(
Character.toLowerCase(
- codePointAt(buffer, i)), buffer, i);
+ codePointAt(buffer, i, limit)), buffer, i);
}
}
-
+
+ /** Converts a sequence of Java characters to a sequence of unicode code points.
+ * @return the number of code points written to the destination buffer */
+ public final int toCodePoints(char[] src, int srcOff, int srcLen, int[] dest, int destOff) {
+ if (srcLen < 0) {
+ throw new IllegalArgumentException("srcLen must be >= 0");
+ }
+ int codePointCount = 0;
+ for (int i = 0; i < srcLen; ) {
+ final int cp = codePointAt(src, srcOff + i, srcOff + srcLen);
+ final int charCount = Character.charCount(cp);
+ dest[destOff + codePointCount++] = cp;
+ i += charCount;
+ }
+ return codePointCount;
+ }
+
+ /** Converts a sequence of unicode code points to a sequence of Java characters.
+ * @return the number of chars written to the destination buffer */
+ public final int toChars(int[] src, int srcOff, int srcLen, char[] dest, int destOff) {
+ if (srcLen < 0) {
+ throw new IllegalArgumentException("srcLen must be >= 0");
+ }
+ int written = 0;
+ for (int i = 0; i < srcLen; ++i) {
+ written += Character.toChars(src[srcOff + i], dest, destOff + written);
+ }
+ return written;
+ }
+
/**
* Fills the {@link CharacterBuffer} with characters read from the given
- * reader {@link Reader}. This method tries to read as many characters into
- * the {@link CharacterBuffer} as possible, each call to fill will start
- * filling the buffer from offset <code>0</code> up to the length of the size
- * of the internal character array.
+ * reader {@link Reader}. This method tries to read <code>numChars</code>
+ * characters into the {@link CharacterBuffer}, each call to fill will start
+ * filling the buffer from offset <code>0</code> up to <code>numChars</code>.
+ * In case code points can span across 2 java characters, this method may
+ * only fill <code>numChars - 1</code> characters in order not to split in
+ * the middle of a surrogate pair, even if there are remaining characters in
+ * the {@link Reader}.
* <p>
* Depending on the {@link Version} passed to
* {@link CharacterUtils#getInstance(Version)} this method implements
* supplementary character awareness when filling the given buffer. For all
- * {@link Version} > 3.0 {@link #fill(CharacterBuffer, Reader)} guarantees
+ * {@link Version} > 3.0 {@link #fill(CharacterBuffer, Reader, int)} guarantees
* that the given {@link CharacterBuffer} will never contain a high surrogate
* character as the last element in the buffer unless it is the last available
* character in the reader. In other words, high and low surrogate pairs will
* always be preserved across buffer boarders.
* </p>
+ * <p>
+ * A return value of <code>false</code> means that this method call exhausted
+ * the reader, but there may be some bytes which have been read, which can be
+ * verified by checking whether <code>buffer.getLength() > 0</code>.
+ * </p>
*
* @param buffer
* the buffer to fill.
* @param reader
* the reader to read characters from.
- * @return <code>true</code> if and only if no more characters are available
- * in the reader, otherwise <code>false</code>.
+ * @param numChars
+ * the number of chars to read
+ * @return <code>false</code> if and only if reader.read returned -1 while trying to fill the buffer
* @throws IOException
* if the reader throws an {@link IOException}.
*/
- public abstract boolean fill(CharacterBuffer buffer, Reader reader) throws IOException;
+ public abstract boolean fill(CharacterBuffer buffer, Reader reader, int numChars) throws IOException;
- private static final class Java5CharacterUtils extends CharacterUtils {
- Java5CharacterUtils() {
+ /** Convenience method which calls <code>fill(buffer, reader, buffer.buffer.length)</code>. */
+ public final boolean fill(CharacterBuffer buffer, Reader reader) throws IOException {
+ return fill(buffer, reader, buffer.buffer.length);
+ }
+
+ /** Return the index within <code>buf[start:start+count]</code> which is by <code>offset</code>
+ * code points from <code>index</code>. */
+ public abstract int offsetByCodePoints(char[] buf, int start, int count, int index, int offset);
+
+ static int readFully(Reader reader, char[] dest, int offset, int len) throws IOException {
+ int read = 0;
+ while (read < len) {
+ final int r = reader.read(dest, offset + read, len - read);
+ if (r == -1) {
+ break;
+ }
+ read += r;
}
+ return read;
+ }
- @Override
- public int codePointAt(final char[] chars, final int offset) {
- return Character.codePointAt(chars, offset);
+ private static final class Java5CharacterUtils extends CharacterUtils {
+ Java5CharacterUtils() {
}
@Override
@@ -198,7 +234,11 @@ public abstract class CharacterUtils {
}
@Override
- public boolean fill(final CharacterBuffer buffer, final Reader reader) throws IOException {
+ public boolean fill(final CharacterBuffer buffer, final Reader reader, int numChars) throws IOException {
+ assert buffer.buffer.length >= 2;
+ if (numChars < 2 || numChars > buffer.buffer.length) {
+ throw new IllegalArgumentException("numChars must be >= 2 and <= the buffer size");
+ }
final char[] charBuffer = buffer.buffer;
buffer.offset = 0;
final int offset;
@@ -206,47 +246,36 @@ public abstract class CharacterUtils {
// Install the previously saved ending high surrogate:
if (buffer.lastTrailingHighSurrogate != 0) {
charBuffer[0] = buffer.lastTrailingHighSurrogate;
+ buffer.lastTrailingHighSurrogate = 0;
offset = 1;
} else {
offset = 0;
}
- final int read = reader.read(charBuffer,
- offset,
- charBuffer.length - offset);
- if (read == -1) {
- buffer.length = offset;
- buffer.lastTrailingHighSurrogate = 0;
- return offset != 0;
- }
- assert read > 0;
- buffer.length = read + offset;
-
- // If we read only a single char, and that char was a
- // high surrogate, read again:
- if (buffer.length == 1
- && Character.isHighSurrogate(charBuffer[buffer.length - 1])) {
- final int read2 = reader.read(charBuffer,
- 1,
- charBuffer.length - 1);
- if (read2 == -1) {
- // NOTE: mal-formed input (ended on a high
- // surrogate)! Consumer must deal with it...
- return true;
- }
- assert read2 > 0;
+ final int read = readFully(reader, charBuffer, offset, numChars - offset);
- buffer.length += read2;
+ buffer.length = offset + read;
+ final boolean result = buffer.length == numChars;
+ if (buffer.length < numChars) {
+ // We failed to fill the buffer. Even if the last char is a high
+ // surrogate, there is nothing we can do
+ return result;
}
- if (buffer.length > 1
- && Character.isHighSurrogate(charBuffer[buffer.length - 1])) {
+ if (Character.isHighSurrogate(charBuffer[buffer.length - 1])) {
buffer.lastTrailingHighSurrogate = charBuffer[--buffer.length];
- } else {
- buffer.lastTrailingHighSurrogate = 0;
}
+ return result;
+ }
- return true;
+ @Override
+ public int codePointCount(CharSequence seq) {
+ return Character.codePointCount(seq, 0, seq.length());
+ }
+
+ @Override
+ public int offsetByCodePoints(char[] buf, int start, int count, int index, int offset) {
+ return Character.offsetByCodePoints(buf, start, count, index, offset);
}
}
@@ -255,11 +284,6 @@ public abstract class CharacterUtils {
}
@Override
- public int codePointAt(final char[] chars, final int offset) {
- return chars[offset];
- }
-
- @Override
public int codePointAt(final CharSequence seq, final int offset) {
return seq.charAt(offset);
}
@@ -272,13 +296,31 @@ public abstract class CharacterUtils {
}
@Override
- public boolean fill(final CharacterBuffer buffer, final Reader reader) throws IOException {
+ public boolean fill(CharacterBuffer buffer, Reader reader, int numChars)
+ throws IOException {
+ assert buffer.buffer.length >= 1;
+ if (numChars < 1 || numChars > buffer.buffer.length) {
+ throw new IllegalArgumentException("numChars must be >= 1 and <= the buffer size");
+ }
buffer.offset = 0;
- final int read = reader.read(buffer.buffer);
- if(read == -1)
- return false;
+ final int read = readFully(reader, buffer.buffer, 0, numChars);
buffer.length = read;
- return true;
+ buffer.lastTrailingHighSurrogate = 0;
+ return read == numChars;
+ }
+
+ @Override
+ public int codePointCount(CharSequence seq) {
+ return seq.length();
+ }
+
+ @Override
+ public int offsetByCodePoints(char[] buf, int start, int count, int index, int offset) {
+ final int result = index + offset;
+ if (result < 0 || result > count) {
+ throw new IndexOutOfBoundsException();
+ }
+ return result;
}
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory Wed Jul 3 23:26:32 2013
@@ -66,6 +66,8 @@ org.apache.lucene.analysis.miscellaneous
org.apache.lucene.analysis.miscellaneous.StemmerOverrideFilterFactory
org.apache.lucene.analysis.miscellaneous.TrimFilterFactory
org.apache.lucene.analysis.miscellaneous.WordDelimiterFilterFactory
+org.apache.lucene.analysis.miscellaneous.ScandinavianFoldingFilterFactory
+org.apache.lucene.analysis.miscellaneous.ScandinavianNormalizationFilterFactory
org.apache.lucene.analysis.ngram.EdgeNGramFilterFactory
org.apache.lucene.analysis.ngram.NGramFilterFactory
org.apache.lucene.analysis.no.NorwegianLightStemFilterFactory
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAnalyzers.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAnalyzers.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAnalyzers.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAnalyzers.java Wed Jul 3 23:26:32 2013
@@ -170,8 +170,6 @@ public class TestAnalyzers extends BaseT
char[] termBuffer = filter.getAttribute(CharTermAttribute.class).buffer();
int length = highSurEndingLower.length();
assertEquals('\ud801', termBuffer[length - 1]);
- assertEquals('\udc3e', termBuffer[length]);
-
}
public void testLowerCaseTokenizer() throws IOException {
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellDictionaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellDictionaryTest.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellDictionaryTest.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellDictionaryTest.java Wed Jul 3 23:26:32 2013
@@ -20,7 +20,9 @@ package org.apache.lucene.analysis.hunsp
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.Assert;
@@ -131,12 +133,30 @@ public class HunspellDictionaryTest exte
assertEquals(3, dictionary.lookupSuffix(new char[]{'e'}, 0, 1).size());
assertEquals(1, dictionary.lookupPrefix(new char[]{'s'}, 0, 1).size());
assertEquals(1, dictionary.lookupWord(new char[]{'o', 'l', 'r'}, 0, 3).size());
-
+ assertEquals("Wrong number of flags for lucen", 1, dictionary.lookupWord(new char[]{'l', 'u', 'c', 'e', 'n'}, 0, 5).get(0).getFlags().length);
+
affixStream.close();
dictStream.close();
}
@Test
+ public void testHunspellDictionary_multipleDictWithOverride() throws IOException, ParseException {
+ InputStream affixStream = getClass().getResourceAsStream("test.aff");
+ List<InputStream> dictStreams = new ArrayList<InputStream>();
+ dictStreams.add(getClass().getResourceAsStream("test.dic"));
+ dictStreams.add(getClass().getResourceAsStream("testOverride.dic"));
+
+ HunspellDictionary dictionary = new HunspellDictionary(affixStream, dictStreams, TEST_VERSION_CURRENT, false);
+ assertEquals("Wrong number of flags for lucen", 3, dictionary.lookupWord(new char[]{'l', 'u', 'c', 'e', 'n'}, 0, 5).get(0).getFlags().length);
+ assertEquals("Wrong number of flags for bar", 1, dictionary.lookupWord(new char[]{'b', 'a', 'r'}, 0, 3).get(0).getFlags().length);
+
+ affixStream.close();
+ for(InputStream dstream : dictStreams) {
+ dstream.close();
+ }
+ }
+
+ @Test
public void testCompressedHunspellDictionary_loadDicAff() throws IOException, ParseException {
InputStream affixStream = getClass().getResourceAsStream("testCompressed.aff");
InputStream dictStream = getClass().getResourceAsStream("testCompressed.dic");
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellStemmerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellStemmerTest.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellStemmerTest.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/HunspellStemmerTest.java Wed Jul 3 23:26:32 2013
@@ -94,17 +94,21 @@ public class HunspellStemmerTest extends
assertEquals(1, stems.size());
assertEquals("foo", stems.get(0).getStemString());
- stems = stemmer.stem("food");
+ stems = stemmer.stem("mood");
assertEquals(1, stems.size());
- assertEquals("foo", stems.get(0).getStemString());
+ assertEquals("moo", stems.get(0).getStemString());
stems = stemmer.stem("Foos");
assertEquals(1, stems.size());
assertEquals("foo", stems.get(0).getStemString());
-
+
+ // The "Foo" rule gets overridden by the "foo" rule, and we don't merge
stems = stemmer.stem("Food");
+ assertEquals(0, stems.size());
+
+ stems = stemmer.stem("Mood");
assertEquals(1, stems.size());
- assertEquals("foo", stems.get(0).getStemString());
+ assertEquals("moo", stems.get(0).getStemString());
}
@Test
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/test.dic
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/test.dic?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/test.dic (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/test.dic Wed Jul 3 23:26:32 2013
@@ -1,9 +1,10 @@
-6
+9
lucen/A
lucene
mahout/A
olr/B
ab/C
Apach/A
+Foo/E
foo/D
-Foo/E
\ No newline at end of file
+Moo/E
\ No newline at end of file
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestStemmerOverrideFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestStemmerOverrideFilter.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestStemmerOverrideFilter.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestStemmerOverrideFilter.java Wed Jul 3 23:26:32 2013
@@ -78,7 +78,7 @@ public class TestStemmerOverrideFilter e
char[] charArray = randomRealisticUnicodeString.toCharArray();
StringBuilder builder = new StringBuilder();
for (int j = 0; j < charArray.length;) {
- int cp = Character.codePointAt(charArray, j);
+ int cp = Character.codePointAt(charArray, j, charArray.length);
if (!Character.isWhitespace(cp)) {
builder.appendCodePoint(cp);
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilterTest.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilterTest.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilterTest.java Wed Jul 3 23:26:32 2013
@@ -32,8 +32,10 @@ import org.apache.lucene.analysis.core.K
import org.apache.lucene.analysis.core.LetterTokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.apache.lucene.analysis.shingle.ShingleFilter;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
-import org.apache.lucene.util.Version;
+import org.apache.lucene.util._TestUtil;
/**
* Tests {@link EdgeNGramTokenFilter} for correctness.
@@ -192,9 +194,9 @@ public class EdgeNGramTokenFilterTest ex
}
public void testGraphs() throws IOException {
- TokenStream tk = new LetterTokenizer(Version.LUCENE_44, new StringReader("abc d efgh ij klmno p q"));
+ TokenStream tk = new LetterTokenizer(TEST_VERSION_CURRENT, new StringReader("abc d efgh ij klmno p q"));
tk = new ShingleFilter(tk);
- tk = new EdgeNGramTokenFilter(Version.LUCENE_44, tk, 7, 10);
+ tk = new EdgeNGramTokenFilter(TEST_VERSION_CURRENT, tk, 7, 10);
tk.reset();
assertTokenStreamContents(tk,
new String[] { "efgh ij", "ij klmn", "ij klmno", "klmno p" },
@@ -205,4 +207,25 @@ public class EdgeNGramTokenFilterTest ex
23
);
}
+
+ public void testSupplementaryCharacters() throws IOException {
+ final String s = _TestUtil.randomUnicodeString(random(), 10);
+ final int codePointCount = s.codePointCount(0, s.length());
+ final int minGram = _TestUtil.nextInt(random(), 1, 3);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 10);
+ TokenStream tk = new KeywordTokenizer(new StringReader(s));
+ tk = new EdgeNGramTokenFilter(TEST_VERSION_CURRENT, tk, minGram, maxGram);
+ final CharTermAttribute termAtt = tk.addAttribute(CharTermAttribute.class);
+ final OffsetAttribute offsetAtt = tk.addAttribute(OffsetAttribute.class);
+ tk.reset();
+ for (int i = minGram; i <= Math.min(codePointCount, maxGram); ++i) {
+ assertTrue(tk.incrementToken());
+ assertEquals(0, offsetAtt.startOffset());
+ assertEquals(s.length(), offsetAtt.endOffset());
+ final int end = Character.offsetByCodePoints(s, 0, i);
+ assertEquals(s.substring(0, end), termAtt.toString());
+ }
+ assertFalse(tk.incrementToken());
+ }
+
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenizerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenizerTest.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenizerTest.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/EdgeNGramTokenizerTest.java Wed Jul 3 23:26:32 2013
@@ -21,15 +21,15 @@ package org.apache.lucene.analysis.ngram
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
+import java.util.Arrays;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.Tokenizer;
-import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
-import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
-import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.util._TestUtil;
+import com.carrotsearch.randomizedtesting.generators.RandomStrings;
+
/**
* Tests {@link EdgeNGramTokenizer} for correctness.
*/
@@ -120,25 +120,60 @@ public class EdgeNGramTokenizerTest exte
false);
}
+ private static void testNGrams(int minGram, int maxGram, int length, final String nonTokenChars) throws IOException {
+ final String s = RandomStrings.randomAsciiOfLength(random(), length);
+ testNGrams(minGram, maxGram, s, nonTokenChars);
+ }
+
+ private static void testNGrams(int minGram, int maxGram, String s, String nonTokenChars) throws IOException {
+ NGramTokenizerTest.testNGrams(minGram, maxGram, s, nonTokenChars, true);
+ }
+
public void testLargeInput() throws IOException {
- final String input = _TestUtil.randomSimpleString(random(), 1024 * 5);
- final int minGram = _TestUtil.nextInt(random(), 1, 1024);
- final int maxGram = _TestUtil.nextInt(random(), minGram, 5 * 1024);
- EdgeNGramTokenizer tk = new EdgeNGramTokenizer(TEST_VERSION_CURRENT, new StringReader(input), minGram, maxGram);
- final CharTermAttribute charTermAtt = tk.addAttribute(CharTermAttribute.class);
- final OffsetAttribute offsetAtt = tk.addAttribute(OffsetAttribute.class);
- final PositionIncrementAttribute posIncAtt = tk.addAttribute(PositionIncrementAttribute.class);
- tk.reset();
- for (int i = minGram; i <= maxGram && i <= input.length(); ++i) {
- assertTrue(tk.incrementToken());
- assertEquals(0, offsetAtt.startOffset());
- assertEquals(i, offsetAtt.endOffset());
- assertEquals(1, posIncAtt.getPositionIncrement());
- assertEquals(input.substring(0, i), charTermAtt.toString());
+ // test sliding
+ final int minGram = _TestUtil.nextInt(random(), 1, 100);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 3 * 1024, 4 * 1024), "");
+ }
+
+ public void testLargeMaxGram() throws IOException {
+ // test sliding with maxGram > 1024
+ final int minGram = _TestUtil.nextInt(random(), 1290, 1300);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 1300);
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 3 * 1024, 4 * 1024), "");
+ }
+
+ public void testPreTokenization() throws IOException {
+ final int minGram = _TestUtil.nextInt(random(), 1, 100);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 0, 4 * 1024), "a");
+ }
+
+ public void testHeavyPreTokenization() throws IOException {
+ final int minGram = _TestUtil.nextInt(random(), 1, 100);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 0, 4 * 1024), "abcdef");
+ }
+
+ public void testFewTokenChars() throws IOException {
+ final char[] chrs = new char[_TestUtil.nextInt(random(), 4000, 5000)];
+ Arrays.fill(chrs, ' ');
+ for (int i = 0; i < chrs.length; ++i) {
+ if (random().nextFloat() < 0.1) {
+ chrs[i] = 'a';
+ }
}
- assertFalse(tk.incrementToken());
- tk.end();
- assertEquals(input.length(), offsetAtt.startOffset());
+ final int minGram = _TestUtil.nextInt(random(), 1, 2);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 2);
+ testNGrams(minGram, maxGram, new String(chrs), " ");
+ }
+
+ public void testFullUTF8Range() throws IOException {
+ final int minGram = _TestUtil.nextInt(random(), 1, 100);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
+ final String s = _TestUtil.randomUnicodeString(random(), 4 * 1024);
+ testNGrams(minGram, maxGram, s, "");
+ testNGrams(minGram, maxGram, s, "abcdef");
}
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenFilterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenFilterTest.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenFilterTest.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenFilterTest.java Wed Jul 3 23:26:32 2013
@@ -26,7 +26,10 @@ import org.apache.lucene.analysis.Tokeni
import org.apache.lucene.analysis.core.KeywordTokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.util.Version;
+import org.apache.lucene.util._TestUtil;
import java.io.IOException;
import java.io.Reader;
@@ -177,4 +180,27 @@ public class NGramTokenFilterTest extend
);
}
+ public void testSupplementaryCharacters() throws IOException {
+ final String s = _TestUtil.randomUnicodeString(random(), 10);
+ final int codePointCount = s.codePointCount(0, s.length());
+ final int minGram = _TestUtil.nextInt(random(), 1, 3);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 10);
+ TokenStream tk = new KeywordTokenizer(new StringReader(s));
+ tk = new NGramTokenFilter(TEST_VERSION_CURRENT, tk, minGram, maxGram);
+ final CharTermAttribute termAtt = tk.addAttribute(CharTermAttribute.class);
+ final OffsetAttribute offsetAtt = tk.addAttribute(OffsetAttribute.class);
+ tk.reset();
+ for (int start = 0; start < codePointCount; ++start) {
+ for (int end = start + minGram; end <= Math.min(codePointCount, start + maxGram); ++end) {
+ assertTrue(tk.incrementToken());
+ assertEquals(0, offsetAtt.startOffset());
+ assertEquals(s.length(), offsetAtt.endOffset());
+ final int startIndex = Character.offsetByCodePoints(s, 0, start);
+ final int endIndex = Character.offsetByCodePoints(s, 0, end);
+ assertEquals(s.substring(startIndex, endIndex), termAtt.toString());
+ }
+ }
+ assertFalse(tk.incrementToken());
+ }
+
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenizerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenizerTest.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenizerTest.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/NGramTokenizerTest.java Wed Jul 3 23:26:32 2013
@@ -18,9 +18,12 @@ package org.apache.lucene.analysis.ngram
*/
+import static org.apache.lucene.analysis.ngram.NGramTokenizerTest.isTokenChar;
+
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
+import java.util.Arrays;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
@@ -115,23 +118,74 @@ public class NGramTokenizerTest extends
checkRandomData(random(), a, 50*RANDOM_MULTIPLIER, 1027, false, false);
}
- private void testNGrams(int minGram, int maxGram, int length) throws IOException {
+ private static void testNGrams(int minGram, int maxGram, int length, final String nonTokenChars) throws IOException {
final String s = RandomStrings.randomAsciiOfLength(random(), length);
- final TokenStream grams = new NGramTokenizer(TEST_VERSION_CURRENT, new StringReader(s), minGram, maxGram);
+ testNGrams(minGram, maxGram, s, nonTokenChars);
+ }
+
+ private static void testNGrams(int minGram, int maxGram, String s, String nonTokenChars) throws IOException {
+ testNGrams(minGram, maxGram, s, nonTokenChars, false);
+ }
+
+ static int[] toCodePoints(CharSequence s) {
+ final int[] codePoints = new int[Character.codePointCount(s, 0, s.length())];
+ for (int i = 0, j = 0; i < s.length(); ++j) {
+ codePoints[j] = Character.codePointAt(s, i);
+ i += Character.charCount(codePoints[j]);
+ }
+ return codePoints;
+ }
+
+ static boolean isTokenChar(String nonTokenChars, int codePoint) {
+ for (int i = 0; i < nonTokenChars.length(); ) {
+ final int cp = nonTokenChars.codePointAt(i);
+ if (cp == codePoint) {
+ return false;
+ }
+ i += Character.charCount(cp);
+ }
+ return true;
+ }
+
+ static void testNGrams(int minGram, int maxGram, String s, final String nonTokenChars, boolean edgesOnly) throws IOException {
+ // convert the string to code points
+ final int[] codePoints = toCodePoints(s);
+ final int[] offsets = new int[codePoints.length + 1];
+ for (int i = 0; i < codePoints.length; ++i) {
+ offsets[i+1] = offsets[i] + Character.charCount(codePoints[i]);
+ }
+ final TokenStream grams = new NGramTokenizer(TEST_VERSION_CURRENT, new StringReader(s), minGram, maxGram, edgesOnly) {
+ @Override
+ protected boolean isTokenChar(int chr) {
+ return nonTokenChars.indexOf(chr) < 0;
+ }
+ };
final CharTermAttribute termAtt = grams.addAttribute(CharTermAttribute.class);
final PositionIncrementAttribute posIncAtt = grams.addAttribute(PositionIncrementAttribute.class);
final PositionLengthAttribute posLenAtt = grams.addAttribute(PositionLengthAttribute.class);
final OffsetAttribute offsetAtt = grams.addAttribute(OffsetAttribute.class);
grams.reset();
- for (int start = 0; start < s.length(); ++start) {
- for (int end = start + minGram; end <= start + maxGram && end <= s.length(); ++end) {
+ for (int start = 0; start < codePoints.length; ++start) {
+ nextGram:
+ for (int end = start + minGram; end <= start + maxGram && end <= codePoints.length; ++end) {
+ if (edgesOnly && start > 0 && isTokenChar(nonTokenChars, codePoints[start - 1])) {
+ // not on an edge
+ continue nextGram;
+ }
+ for (int j = start; j < end; ++j) {
+ if (!isTokenChar(nonTokenChars, codePoints[j])) {
+ continue nextGram;
+ }
+ }
assertTrue(grams.incrementToken());
- assertEquals(s.substring(start, end), termAtt.toString());
+ assertArrayEquals(Arrays.copyOfRange(codePoints, start, end), toCodePoints(termAtt));
assertEquals(1, posIncAtt.getPositionIncrement());
- assertEquals(start, offsetAtt.startOffset());
- assertEquals(end, offsetAtt.endOffset());
+ assertEquals(1, posLenAtt.getPositionLength());
+ assertEquals(offsets[start], offsetAtt.startOffset());
+ assertEquals(offsets[end], offsetAtt.endOffset());
}
}
+ assertFalse(grams.incrementToken());
grams.end();
assertEquals(s.length(), offsetAtt.startOffset());
assertEquals(s.length(), offsetAtt.endOffset());
@@ -141,14 +195,47 @@ public class NGramTokenizerTest extends
// test sliding
final int minGram = _TestUtil.nextInt(random(), 1, 100);
final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
- testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 3 * 1024, 4 * 1024));
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 3 * 1024, 4 * 1024), "");
}
public void testLargeMaxGram() throws IOException {
// test sliding with maxGram > 1024
- final int minGram = _TestUtil.nextInt(random(), 1200, 1300);
+ final int minGram = _TestUtil.nextInt(random(), 1290, 1300);
final int maxGram = _TestUtil.nextInt(random(), minGram, 1300);
- testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 3 * 1024, 4 * 1024));
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 3 * 1024, 4 * 1024), "");
+ }
+
+ public void testPreTokenization() throws IOException {
+ final int minGram = _TestUtil.nextInt(random(), 1, 100);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 0, 4 * 1024), "a");
+ }
+
+ public void testHeavyPreTokenization() throws IOException {
+ final int minGram = _TestUtil.nextInt(random(), 1, 100);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
+ testNGrams(minGram, maxGram, _TestUtil.nextInt(random(), 0, 4 * 1024), "abcdef");
+ }
+
+ public void testFewTokenChars() throws IOException {
+ final char[] chrs = new char[_TestUtil.nextInt(random(), 4000, 5000)];
+ Arrays.fill(chrs, ' ');
+ for (int i = 0; i < chrs.length; ++i) {
+ if (random().nextFloat() < 0.1) {
+ chrs[i] = 'a';
+ }
+ }
+ final int minGram = _TestUtil.nextInt(random(), 1, 2);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 2);
+ testNGrams(minGram, maxGram, new String(chrs), " ");
+ }
+
+ public void testFullUTF8Range() throws IOException {
+ final int minGram = _TestUtil.nextInt(random(), 1, 100);
+ final int maxGram = _TestUtil.nextInt(random(), minGram, 100);
+ final String s = _TestUtil.randomUnicodeString(random(), 4 * 1024);
+ testNGrams(minGram, maxGram, s, "");
+ testNGrams(minGram, maxGram, s, "abcdef");
}
}
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilter.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilter.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilter.java Wed Jul 3 23:26:32 2013
@@ -32,6 +32,9 @@ import org.apache.lucene.analysis.miscel
import org.apache.lucene.analysis.util.CharArraySet;
import static org.apache.lucene.analysis.VocabularyAssert.*;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.BOKMAAL;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.NYNORSK;
+
/**
* Simple tests for {@link NorwegianLightStemFilter}
@@ -42,7 +45,7 @@ public class TestNorwegianLightStemFilte
protected TokenStreamComponents createComponents(String fieldName,
Reader reader) {
Tokenizer source = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
- return new TokenStreamComponents(source, new NorwegianLightStemFilter(source));
+ return new TokenStreamComponents(source, new NorwegianLightStemFilter(source, BOKMAAL));
}
};
@@ -51,6 +54,18 @@ public class TestNorwegianLightStemFilte
assertVocabulary(analyzer, new FileInputStream(getDataFile("nb_light.txt")));
}
+ /** Test against a Nynorsk vocabulary file */
+ public void testNynorskVocabulary() throws IOException {
+ Analyzer analyzer = new Analyzer() {
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer source = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
+ return new TokenStreamComponents(source, new NorwegianLightStemFilter(source, NYNORSK));
+ }
+ };
+ assertVocabulary(analyzer, new FileInputStream(getDataFile("nn_light.txt")));
+ }
+
public void testKeyword() throws IOException {
final CharArraySet exclusionSet = new CharArraySet(TEST_VERSION_CURRENT, asSet("sekretæren"), false);
Analyzer a = new Analyzer() {
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilterFactory.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilterFactory.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianLightStemFilterFactory.java Wed Jul 3 23:26:32 2013
@@ -34,7 +34,23 @@ public class TestNorwegianLightStemFilte
stream = tokenFilterFactory("NorwegianLightStem").create(stream);
assertTokenStreamContents(stream, new String[] { "epl", "epl" });
}
-
+
+ /** Test stemming with variant set explicitly to Bokmål */
+ public void testBokmaalStemming() throws Exception {
+ Reader reader = new StringReader("epler eple");
+ TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
+ stream = tokenFilterFactory("NorwegianLightStem", "variant", "nb").create(stream);
+ assertTokenStreamContents(stream, new String[] { "epl", "epl" });
+ }
+
+ /** Test stemming with variant set explicitly to Nynorsk */
+ public void testNynorskStemming() throws Exception {
+ Reader reader = new StringReader("gutar gutane");
+ TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
+ stream = tokenFilterFactory("NorwegianLightStem", "variant", "nn").create(stream);
+ assertTokenStreamContents(stream, new String[] { "gut", "gut" });
+ }
+
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
try {
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilter.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilter.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilter.java Wed Jul 3 23:26:32 2013
@@ -32,6 +32,8 @@ import org.apache.lucene.analysis.miscel
import org.apache.lucene.analysis.util.CharArraySet;
import static org.apache.lucene.analysis.VocabularyAssert.*;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.BOKMAAL;
+import static org.apache.lucene.analysis.no.NorwegianLightStemmer.NYNORSK;
/**
* Simple tests for {@link NorwegianMinimalStemFilter}
@@ -42,15 +44,27 @@ public class TestNorwegianMinimalStemFil
protected TokenStreamComponents createComponents(String fieldName,
Reader reader) {
Tokenizer source = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
- return new TokenStreamComponents(source, new NorwegianMinimalStemFilter(source));
+ return new TokenStreamComponents(source, new NorwegianMinimalStemFilter(source, BOKMAAL));
}
};
- /** Test against a vocabulary file */
+ /** Test against a Bokmål vocabulary file */
public void testVocabulary() throws IOException {
assertVocabulary(analyzer, new FileInputStream(getDataFile("nb_minimal.txt")));
}
+ /** Test against a Nynorsk vocabulary file */
+ public void testNynorskVocabulary() throws IOException {
+ Analyzer analyzer = new Analyzer() {
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer source = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
+ return new TokenStreamComponents(source, new NorwegianMinimalStemFilter(source, NYNORSK));
+ }
+ };
+ assertVocabulary(analyzer, new FileInputStream(getDataFile("nn_minimal.txt")));
+ }
+
public void testKeyword() throws IOException {
final CharArraySet exclusionSet = new CharArraySet(TEST_VERSION_CURRENT, asSet("sekretæren"), false);
Analyzer a = new Analyzer() {
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilterFactory.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilterFactory.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/no/TestNorwegianMinimalStemFilterFactory.java Wed Jul 3 23:26:32 2013
@@ -35,6 +35,22 @@ public class TestNorwegianMinimalStemFil
assertTokenStreamContents(stream, new String[] { "epl", "epl", "epl", "epl", "epl", "epl" });
}
+ /** Test stemming with variant set explicitly to Bokmål */
+ public void testBokmaalStemming() throws Exception {
+ Reader reader = new StringReader("eple eplet epler eplene eplets eplenes");
+ TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
+ stream = tokenFilterFactory("NorwegianMinimalStem", "variant", "nb").create(stream);
+ assertTokenStreamContents(stream, new String[] { "epl", "epl", "epl", "epl", "epl", "epl" });
+ }
+
+ /** Test stemming with variant set explicitly to Nynorsk */
+ public void testNynorskStemming() throws Exception {
+ Reader reader = new StringReader("gut guten gutar gutane gutens gutanes");
+ TokenStream stream = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
+ stream = tokenFilterFactory("NorwegianMinimalStem", "variant", "nn").create(stream);
+ assertTokenStreamContents(stream, new String[] { "gut", "gut", "gut", "gut", "gut", "gut" });
+ }
+
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
try {
Modified: lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharacterUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharacterUtils.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharacterUtils.java (original)
+++ lucene/dev/branches/security/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharacterUtils.java Wed Jul 3 23:26:32 2013
@@ -20,10 +20,11 @@ package org.apache.lucene.analysis.util;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
+import java.util.Arrays;
import org.apache.lucene.analysis.util.CharacterUtils.CharacterBuffer;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.Version;
+import org.apache.lucene.util._TestUtil;
import org.junit.Test;
/**
@@ -32,32 +33,6 @@ import org.junit.Test;
public class TestCharacterUtils extends LuceneTestCase {
@Test
- public void testCodePointAtCharArrayInt() {
- CharacterUtils java4 = CharacterUtils.getJava4Instance();
- char[] cpAt3 = "Abc\ud801\udc1c".toCharArray();
- char[] highSurrogateAt3 = "Abc\ud801".toCharArray();
- assertEquals((int) 'A', java4.codePointAt(cpAt3, 0));
- assertEquals((int) '\ud801', java4.codePointAt(cpAt3, 3));
- assertEquals((int) '\ud801', java4.codePointAt(highSurrogateAt3, 3));
- try {
- java4.codePointAt(highSurrogateAt3, 4);
- fail("array index out of bounds");
- } catch (IndexOutOfBoundsException e) {
- }
-
- CharacterUtils java5 = CharacterUtils.getInstance(TEST_VERSION_CURRENT);
- assertEquals((int) 'A', java5.codePointAt(cpAt3, 0));
- assertEquals(Character.toCodePoint('\ud801', '\udc1c'), java5.codePointAt(
- cpAt3, 3));
- assertEquals((int) '\ud801', java5.codePointAt(highSurrogateAt3, 3));
- try {
- java5.codePointAt(highSurrogateAt3, 4);
- fail("array index out of bounds");
- } catch (IndexOutOfBoundsException e) {
- }
- }
-
- @Test
public void testCodePointAtCharSequenceInt() {
CharacterUtils java4 = CharacterUtils.getJava4Instance();
String cpAt3 = "Abc\ud801\udc1c";
@@ -98,7 +73,68 @@ public class TestCharacterUtils extends
assertEquals(Character.toCodePoint('\ud801', '\udc1c'), java5.codePointAt(
cpAt3, 3, 5));
assertEquals((int) '\ud801', java5.codePointAt(highSurrogateAt3, 3, 4));
+ }
+
+ @Test
+ public void testCodePointCount() {
+ CharacterUtils java4 = CharacterUtils.getJava4Instance();
+ CharacterUtils java5 = CharacterUtils.getInstance(TEST_VERSION_CURRENT);
+ final String s = _TestUtil.randomUnicodeString(random());
+ assertEquals(s.length(), java4.codePointCount(s));
+ assertEquals(Character.codePointCount(s, 0, s.length()), java5.codePointCount(s));
+ }
+
+ @Test
+ public void testOffsetByCodePoint() {
+ CharacterUtils java4 = CharacterUtils.getJava4Instance();
+ CharacterUtils java5 = CharacterUtils.getInstance(TEST_VERSION_CURRENT);
+ for (int i = 0; i < 10; ++i) {
+ final char[] s = _TestUtil.randomUnicodeString(random()).toCharArray();
+ final int index = _TestUtil.nextInt(random(), 0, s.length);
+ final int offset = random().nextInt(7) - 3;
+ try {
+ final int o = java4.offsetByCodePoints(s, 0, s.length, index, offset);
+ assertEquals(o, index + offset);
+ } catch (IndexOutOfBoundsException e) {
+ assertTrue((index + offset) < 0 || (index + offset) > s.length);
+ }
+
+ int o;
+ try {
+ o = java5.offsetByCodePoints(s, 0, s.length, index, offset);
+ } catch (IndexOutOfBoundsException e) {
+ try {
+ Character.offsetByCodePoints(s, 0, s.length, index, offset);
+ fail();
+ } catch (IndexOutOfBoundsException e2) {
+ // OK
+ }
+ o = -1;
+ }
+ if (o >= 0) {
+ assertEquals(Character.offsetByCodePoints(s, 0, s.length, index, offset), o);
+ }
+ }
+ }
+
+ public void testConversions() {
+ CharacterUtils java4 = CharacterUtils.getJava4Instance();
+ CharacterUtils java5 = CharacterUtils.getInstance(TEST_VERSION_CURRENT);
+ testConversions(java4);
+ testConversions(java5);
+ }
+ private void testConversions(CharacterUtils charUtils) {
+ final char[] orig = _TestUtil.randomUnicodeString(random(), 100).toCharArray();
+ final int[] buf = new int[orig.length];
+ final char[] restored = new char[buf.length];
+ final int o1 = _TestUtil.nextInt(random(), 0, Math.min(5, orig.length));
+ final int o2 = _TestUtil.nextInt(random(), 0, o1);
+ final int o3 = _TestUtil.nextInt(random(), 0, o1);
+ final int codePointCount = charUtils.toCodePoints(orig, o1, orig.length - o1, buf, o2);
+ final int charCount = charUtils.toChars(buf, o2, codePointCount, restored, o3);
+ assertEquals(orig.length - o1, charCount);
+ assertArrayEquals(Arrays.copyOfRange(orig, o1, o1 + charCount), Arrays.copyOfRange(restored, o3, o3 + charCount));
}
@Test
@@ -132,7 +168,7 @@ public class TestCharacterUtils extends
assertEquals(0, buffer.getOffset());
assertEquals(6, buffer.getLength());
assertEquals("hellow", new String(buffer.getBuffer()));
- assertTrue(instance.fill(buffer,reader));
+ assertFalse(instance.fill(buffer,reader));
assertEquals(4, buffer.getLength());
assertEquals(0, buffer.getOffset());
@@ -159,15 +195,12 @@ public class TestCharacterUtils extends
assertEquals(4, buffer.getLength());
assertEquals("123\ud801", new String(buffer.getBuffer(),
buffer.getOffset(), buffer.getLength()));
- assertTrue(instance.fill(buffer, reader));
- assertEquals(2, buffer.getLength());
- assertEquals("\ud801\udc1c", new String(buffer.getBuffer(), buffer
- .getOffset(), buffer.getLength()));
- assertTrue(instance.fill(buffer, reader));
- assertEquals(1, buffer.getLength());
- assertEquals("\ud801", new String(buffer.getBuffer(), buffer
+ assertFalse(instance.fill(buffer, reader));
+ assertEquals(3, buffer.getLength());
+ assertEquals("\ud801\udc1c\ud801", new String(buffer.getBuffer(), buffer
.getOffset(), buffer.getLength()));
assertFalse(instance.fill(buffer, reader));
+ assertEquals(0, buffer.getLength());
}
@Test
Modified: lucene/dev/branches/security/lucene/analysis/icu/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/icu/build.xml?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/icu/build.xml (original)
+++ lucene/dev/branches/security/lucene/analysis/icu/build.xml Wed Jul 3 23:26:32 2013
@@ -23,6 +23,8 @@
Analysis integration with ICU (International Components for Unicode).
</description>
+ <property name="rat.additional-includes" value="src/tools/**"/>
+
<import file="../analysis-module-build.xml"/>
<path id="icujar">
@@ -59,7 +61,7 @@
<property name="gennorm2.src.files"
value="nfc.txt nfkc.txt nfkc_cf.txt BasicFoldings.txt DiacriticFolding.txt DingbatFolding.txt HanRadicalFolding.txt NativeDigitFolding.txt"/>
<property name="gennorm2.tmp" value="${build.dir}/gennorm2/utr30.tmp"/>
- <property name="gennorm2.dst" value="src/resources/org/apache/lucene/analysis/icu/utr30.nrm"/>
+ <property name="gennorm2.dst" value="${resources.dir}/org/apache/lucene/analysis/icu/utr30.nrm"/>
<target name="gennorm2" depends="gen-utr30-data-files">
<echo>Note that the gennorm2 and icupkg tools must be on your PATH. These tools
are part of the ICU4C package. See http://site.icu-project.org/ </echo>
@@ -82,7 +84,7 @@ are part of the ICU4C package. See http:
</target>
<property name="rbbi.src.dir" location="src/data/uax29"/>
- <property name="rbbi.dst.dir" location="src/resources/org/apache/lucene/analysis/icu/segmentation"/>
+ <property name="rbbi.dst.dir" location="${resources.dir}/org/apache/lucene/analysis/icu/segmentation"/>
<target name="genrbbi" depends="compile-tools">
<mkdir dir="${rbbi.dst.dir}"/>
Modified: lucene/dev/branches/security/lucene/analysis/kuromoji/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/kuromoji/build.xml?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/kuromoji/build.xml (original)
+++ lucene/dev/branches/security/lucene/analysis/kuromoji/build.xml Wed Jul 3 23:26:32 2013
@@ -26,6 +26,7 @@
<!-- currently whether rat detects this as binary or not
is platform dependent?! -->
<property name="rat.excludes" value="**/*.txt,**/bocchan.utf-8"/>
+ <property name="rat.additional-includes" value="src/tools/**"/>
<!-- we don't want to pull in ipadic/naist etc -->
<property name="ivy.default.configuration" value="default"/>
@@ -45,7 +46,7 @@
<property name="dict.encoding" value="euc-jp"/>
<property name="dict.format" value="ipadic"/>
<property name="dict.normalize" value="false"/>
- <property name="dict.target.dir" location="./src/resources"/>
+ <property name="dict.target.dir" location="${resources.dir}"/>
<available type="dir" file="${build.dir}/${ipadic.version}" property="dict.available"/>
@@ -83,7 +84,7 @@
<target name="build-dict" depends="compile-tools, download-dict">
<sequential>
<delete verbose="true">
- <fileset dir="src/resources/org/apache/lucene/analysis/ja/dict" includes="**/*"/>
+ <fileset dir="${resources.dir}/org/apache/lucene/analysis/ja/dict" includes="**/*"/>
</delete>
<!-- TODO: optimize the dictionary construction a bit so that you don't need 1G -->
<java fork="true" failonerror="true" maxmemory="1g" classname="org.apache.lucene.analysis.ja.util.DictionaryBuilder">
Modified: lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/TokenInfoDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/TokenInfoDictionary.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/TokenInfoDictionary.java (original)
+++ lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/TokenInfoDictionary.java Wed Jul 3 23:26:32 2013
@@ -44,7 +44,7 @@ public final class TokenInfoDictionary e
try {
is = getResource(FST_FILENAME_SUFFIX);
is = new BufferedInputStream(is);
- fst = new FST<Long>(new InputStreamDataInput(is), PositiveIntOutputs.getSingleton(true));
+ fst = new FST<Long>(new InputStreamDataInput(is), PositiveIntOutputs.getSingleton());
} catch (IOException ioe) {
priorE = ioe;
} finally {
Modified: lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/UserDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/UserDictionary.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/UserDictionary.java (original)
+++ lucene/dev/branches/security/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/UserDictionary.java Wed Jul 3 23:26:32 2013
@@ -88,7 +88,7 @@ public final class UserDictionary implem
List<String> data = new ArrayList<String>(featureEntries.size());
List<int[]> segmentations = new ArrayList<int[]>(featureEntries.size());
- PositiveIntOutputs fstOutput = PositiveIntOutputs.getSingleton(true);
+ PositiveIntOutputs fstOutput = PositiveIntOutputs.getSingleton();
Builder<Long> fstBuilder = new Builder<Long>(FST.INPUT_TYPE.BYTE2, fstOutput);
IntsRef scratch = new IntsRef();
long ord = 0;
Modified: lucene/dev/branches/security/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/TokenInfoDictionaryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/TokenInfoDictionaryBuilder.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/TokenInfoDictionaryBuilder.java (original)
+++ lucene/dev/branches/security/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/TokenInfoDictionaryBuilder.java Wed Jul 3 23:26:32 2013
@@ -131,7 +131,7 @@ public class TokenInfoDictionaryBuilder
System.out.println(" encode...");
- PositiveIntOutputs fstOutput = PositiveIntOutputs.getSingleton(true);
+ PositiveIntOutputs fstOutput = PositiveIntOutputs.getSingleton();
Builder<Long> fstBuilder = new Builder<Long>(FST.INPUT_TYPE.BYTE2, 0, 0, true, true, Integer.MAX_VALUE, fstOutput, null, true, PackedInts.DEFAULT, true, 15);
IntsRef scratch = new IntsRef();
long ord = -1; // first ord will be 0
Modified: lucene/dev/branches/security/lucene/analysis/morfologik/ivy.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/morfologik/ivy.xml?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/morfologik/ivy.xml (original)
+++ lucene/dev/branches/security/lucene/analysis/morfologik/ivy.xml Wed Jul 3 23:26:32 2013
@@ -19,9 +19,9 @@
<ivy-module version="2.0">
<info organisation="org.apache.lucene" module="analyzers-morfologik"/>
<dependencies>
- <dependency org="org.carrot2" name="morfologik-polish" rev="1.5.5" transitive="false"/>
- <dependency org="org.carrot2" name="morfologik-fsa" rev="1.5.5" transitive="false"/>
- <dependency org="org.carrot2" name="morfologik-stemming" rev="1.5.5" transitive="false"/>
+ <dependency org="org.carrot2" name="morfologik-polish" rev="1.6.0" transitive="false"/>
+ <dependency org="org.carrot2" name="morfologik-fsa" rev="1.6.0" transitive="false"/>
+ <dependency org="org.carrot2" name="morfologik-stemming" rev="1.6.0" transitive="false"/>
<exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
</dependencies>
</ivy-module>
Modified: lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikAnalyzer.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikAnalyzer.java (original)
+++ lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikAnalyzer.java Wed Jul 3 23:26:32 2013
@@ -26,38 +26,21 @@ import org.apache.lucene.analysis.standa
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.util.Version;
-import morfologik.stemming.PolishStemmer.DICTIONARY;
-
/**
* {@link org.apache.lucene.analysis.Analyzer} using Morfologik library.
* @see <a href="http://morfologik.blogspot.com/">Morfologik project page</a>
*/
public class MorfologikAnalyzer extends Analyzer {
-
- private final DICTIONARY dictionary;
private final Version version;
/**
- * Builds an analyzer for a given PolishStemmer.DICTIONARY enum.
- *
- * @param vers
- * lucene compatibility version
- * @param dict
- * A constant specifying which dictionary to choose. See the
- * Morfologik documentation for details or use the default.
- */
- public MorfologikAnalyzer(final Version vers, final DICTIONARY dict) {
- this.version = vers;
- this.dictionary = dict;
- }
-
- /**
- * Builds an analyzer for an original MORFOLOGIK dictionary.
+ * Builds an analyzer with the default Morfologik's dictionary (polimorf).
*
- * @param vers lucene compatibility version
+ * @param version
+ * Lucene compatibility version
*/
- public MorfologikAnalyzer(final Version vers) {
- this(vers, DICTIONARY.MORFOLOGIK);
+ public MorfologikAnalyzer(final Version version) {
+ this.version = version;
}
/**
@@ -78,7 +61,7 @@ public class MorfologikAnalyzer extends
final Tokenizer src = new StandardTokenizer(this.version, reader);
return new TokenStreamComponents(
- src,
- new MorfologikFilter(new StandardFilter(this.version, src), this.dictionary, this.version));
+ src,
+ new MorfologikFilter(new StandardFilter(this.version, src), this.version));
}
}
Modified: lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilter.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilter.java (original)
+++ lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilter.java Wed Jul 3 23:26:32 2013
@@ -22,20 +22,21 @@ import java.io.IOException;
import java.util.*;
import morfologik.stemming.*;
-import morfologik.stemming.PolishStemmer.DICTIONARY;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.KeywordAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.util.CharacterUtils;
import org.apache.lucene.util.*;
/**
- * {@link TokenFilter} using Morfologik library.
+ * {@link TokenFilter} using Morfologik library to transform input tokens into lemma and
+ * morphosyntactic (POS) tokens. Applies to Polish only.
*
- * MorfologikFilter contains a {@link MorphosyntacticTagsAttribute}, which provides morphosyntactic
- * annotations for produced lemmas. See the Morfologik documentation for details.
+ * <p>MorfologikFilter contains a {@link MorphosyntacticTagsAttribute}, which provides morphosyntactic
+ * annotations for produced lemmas. See the Morfologik documentation for details.</p>
*
* @see <a href="http://morfologik.blogspot.com/">Morfologik project page</a>
*/
@@ -44,6 +45,7 @@ public class MorfologikFilter extends To
private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
private final MorphosyntacticTagsAttribute tagsAtt = addAttribute(MorphosyntacticTagsAttribute.class);
private final PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class);
+ private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);
private final CharsRef scratch = new CharsRef(0);
private final CharacterUtils charUtils;
@@ -58,13 +60,11 @@ public class MorfologikFilter extends To
private int lemmaListIndex;
/**
- * Builds a filter for given PolishStemmer.DICTIONARY enum.
- *
+ * Creates MorfologikFilter
* @param in input token stream
- * @param dict PolishStemmer.DICTIONARY enum
* @param version Lucene version compatibility for lowercasing.
*/
- public MorfologikFilter(final TokenStream in, final DICTIONARY dict, final Version version) {
+ public MorfologikFilter(final TokenStream in, final Version version) {
super(in);
this.input = in;
@@ -73,7 +73,7 @@ public class MorfologikFilter extends To
ClassLoader cl = me.getContextClassLoader();
try {
me.setContextClassLoader(PolishStemmer.class.getClassLoader());
- this.stemmer = new PolishStemmer(dict);
+ this.stemmer = new PolishStemmer();
this.charUtils = CharacterUtils.getInstance(version);
this.lemmaList = Collections.emptyList();
} finally {
@@ -81,29 +81,57 @@ public class MorfologikFilter extends To
}
}
+ /**
+ * The tag encoding format has been changing in Morfologik from version
+ * to version. Let's keep both variants and determine which one to run
+ * based on this flag.
+ */
+ private final static boolean multipleTagsPerLemma = true;
+
private void popNextLemma() {
- // Collect all tags for the next unique lemma.
- CharSequence currentStem;
- int tags = 0;
- do {
+ if (multipleTagsPerLemma) {
+ // One tag (concatenated) per lemma.
final WordData lemma = lemmaList.get(lemmaListIndex++);
- currentStem = lemma.getStem();
- final CharSequence tag = lemma.getTag();
+ termAtt.setEmpty().append(lemma.getStem());
+ CharSequence tag = lemma.getTag();
if (tag != null) {
- if (tagsList.size() <= tags) {
- tagsList.add(new StringBuilder());
+ String[] tags = tag.toString().split("\\+|\\|");
+ for (int i = 0; i < tags.length; i++) {
+ if (tagsList.size() <= i) {
+ tagsList.add(new StringBuilder());
+ }
+ StringBuilder buffer = tagsList.get(i);
+ buffer.setLength(0);
+ buffer.append(tags[i]);
}
-
- final StringBuilder buffer = tagsList.get(tags++);
- buffer.setLength(0);
- buffer.append(lemma.getTag());
+ tagsAtt.setTags(tagsList.subList(0, tags.length));
+ } else {
+ tagsAtt.setTags(Collections.<StringBuilder> emptyList());
}
- } while (lemmaListIndex < lemmaList.size() &&
- equalCharSequences(lemmaList.get(lemmaListIndex).getStem(), currentStem));
+ } else {
+ // One tag (concatenated) per stem (lemma repeated).
+ CharSequence currentStem;
+ int tags = 0;
+ do {
+ final WordData lemma = lemmaList.get(lemmaListIndex++);
+ currentStem = lemma.getStem();
+ final CharSequence tag = lemma.getTag();
+ if (tag != null) {
+ if (tagsList.size() <= tags) {
+ tagsList.add(new StringBuilder());
+ }
+
+ final StringBuilder buffer = tagsList.get(tags++);
+ buffer.setLength(0);
+ buffer.append(lemma.getTag());
+ }
+ } while (lemmaListIndex < lemmaList.size() &&
+ equalCharSequences(lemmaList.get(lemmaListIndex).getStem(), currentStem));
- // Set the lemma's base form and tags as attributes.
- termAtt.setEmpty().append(currentStem);
- tagsAtt.setTags(tagsList.subList(0, tags));
+ // Set the lemma's base form and tags as attributes.
+ termAtt.setEmpty().append(currentStem);
+ tagsAtt.setTags(tagsList.subList(0, tags));
+ }
}
/**
@@ -140,7 +168,8 @@ public class MorfologikFilter extends To
popNextLemma();
return true;
} else if (this.input.incrementToken()) {
- if (lookupSurfaceForm(termAtt) || lookupSurfaceForm(toLowercase(termAtt))) {
+ if (!keywordAttr.isKeyword() &&
+ (lookupSurfaceForm(termAtt) || lookupSurfaceForm(toLowercase(termAtt)))) {
current = captureState();
popNextLemma();
} else {
Modified: lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilterFactory.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilterFactory.java (original)
+++ lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorfologikFilterFactory.java Wed Jul 3 23:26:32 2013
@@ -17,12 +17,8 @@ package org.apache.lucene.analysis.morfo
* limitations under the License.
*/
-import java.util.Arrays;
-import java.util.Locale;
import java.util.Map;
-import morfologik.stemming.PolishStemmer.DICTIONARY;
-
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.util.TokenFilterFactory;
@@ -32,39 +28,28 @@ import org.apache.lucene.analysis.util.T
* <fieldType name="text_polish" class="solr.TextField" positionIncrementGap="100">
* <analyzer>
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
- * <filter class="solr.MorfologikFilterFactory" dictionary="MORFOLOGIK" />
+ * <filter class="solr.MorfologikFilterFactory" />
* </analyzer>
* </fieldType></pre>
*
- * <p>Any of Morfologik dictionaries can be used, these are at the moment:
- * <code>MORFOLOGIK</code> (Morfologik's original dictionary),
- * <code>MORFEUSZ</code> (Morfeusz-SIAT),
- * <code>COMBINED</code> (both of the dictionaries above, combined).
- *
* @see <a href="http://morfologik.blogspot.com/">Morfologik web site</a>
*/
public class MorfologikFilterFactory extends TokenFilterFactory {
- /** Dictionary. */
- private DICTIONARY dictionary = DICTIONARY.MORFOLOGIK;
-
/** Schema attribute. */
+ @Deprecated
public static final String DICTIONARY_SCHEMA_ATTRIBUTE = "dictionary";
-
+
/** Creates a new MorfologikFilterFactory */
public MorfologikFilterFactory(Map<String,String> args) {
super(args);
+
+ // Be specific about no-longer-supported dictionary attribute.
String dictionaryName = get(args, DICTIONARY_SCHEMA_ATTRIBUTE);
if (dictionaryName != null && !dictionaryName.isEmpty()) {
- try {
- DICTIONARY dictionary = DICTIONARY.valueOf(dictionaryName.toUpperCase(Locale.ROOT));
- assert dictionary != null;
- this.dictionary = dictionary;
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException("The " + DICTIONARY_SCHEMA_ATTRIBUTE + " attribute accepts the "
- + "following constants: " + Arrays.toString(DICTIONARY.values()) + ", this value is invalid: "
- + dictionaryName);
- }
+ throw new IllegalArgumentException("The " + DICTIONARY_SCHEMA_ATTRIBUTE + " attribute is no "
+ + "longer supported (Morfologik has one dictionary): " + dictionaryName);
}
+
if (!args.isEmpty()) {
throw new IllegalArgumentException("Unknown parameters: " + args);
}
@@ -72,6 +57,6 @@ public class MorfologikFilterFactory ext
@Override
public TokenStream create(TokenStream ts) {
- return new MorfologikFilter(ts, dictionary, luceneMatchVersion);
+ return new MorfologikFilter(ts, luceneMatchVersion);
}
}
Modified: lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorphosyntacticTagsAttribute.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorphosyntacticTagsAttribute.java?rev=1499601&r1=1499600&r2=1499601&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorphosyntacticTagsAttribute.java (original)
+++ lucene/dev/branches/security/lucene/analysis/morfologik/src/java/org/apache/lucene/analysis/morfologik/MorphosyntacticTagsAttribute.java Wed Jul 3 23:26:32 2013
@@ -23,9 +23,9 @@ import java.util.List;
import org.apache.lucene.util.Attribute;
/**
- * Morfologik dictionaries provide morphosyntactic annotations for
+ * Morfologik provides morphosyntactic annotations for
* surface forms. For the exact format and description of these,
- * see the project's documentation (annotations vary by dictionary!).
+ * see the project's documentation.
*/
public interface MorphosyntacticTagsAttribute extends Attribute {
/**
@@ -36,7 +36,9 @@ public interface MorphosyntacticTagsAttr
public void setTags(List<StringBuilder> tags);
/**
- * Returns the POS tag of the term.
+ * Returns the POS tag of the term. A single word may have multiple POS tags,
+ * depending on the interpretation (context disambiguation is typically needed
+ * to determine which particular tag is appropriate).
*/
public List<StringBuilder> getTags();