Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-3305: add Kuromoji Japanese morphological analyzer

Robert Muircd372bdc8383
diff --git a/dev-tools/eclipse/dot.classpath b/dev-tools/eclipse/dot.classpath
index 7f99e4a2885..f95959a1ada 100644
--- a/dev-tools/eclipse/dot.classpath
+++ b/dev-tools/eclipse/dot.classpath
@@ -24,6 +24,9 @@
<classpathentry kind="src" path="modules/analysis/icu/src/java"/>
<classpathentry kind="src" path="modules/analysis/icu/src/resources"/>
<classpathentry kind="src" path="modules/analysis/icu/src/test"/>
+ <classpathentry kind="src" path="modules/analysis/kuromoji/src/java"/>
+ <classpathentry kind="src" path="modules/analysis/kuromoji/src/resources"/>
+ <classpathentry kind="src" path="modules/analysis/kuromoji/src/test"/>
<classpathentry kind="src" path="modules/analysis/phonetic/src/java"/>
<classpathentry kind="src" path="modules/analysis/phonetic/src/test"/>
<classpathentry kind="src" path="modules/analysis/smartcn/src/java"/>
diff --git a/lucene/contrib/contrib-build.xml b/lucene/contrib/contrib-build.xml
index e2eb4bd262c..ce0156013aa 100644
--- a/lucene/contrib/contrib-build.xml
+++ b/lucene/contrib/contrib-build.xml
@@ -196,6 +196,17 @@
<property name="analyzers-stempel.uptodate" value="true"/>
</target>
+ <property name="analyzers-kuromoji.jar" value="${common.dir}/../modules/analysis/build/kuromoji/lucene-analyzers-kuromoji-${version}.jar"/>
+ <target name="check-analyzers-kuromoji-uptodate" unless="analyzers-kuromoji.uptodate">
+ <module-uptodate name="analysis/kuromoji" jarfile="${analyzers-kuromoji.jar}" property="analyzers-kuromoji.uptodate"/>
+ </target>
+ <target name="jar-analyzers-kuromoji" unless="analyzers-kuromoji.uptodate" depends="check-analyzers-kuromoji-uptodate">
+ <ant dir="${common.dir}/../modules/analysis/kuromoji" target="jar-core" inheritAll="false">
+ <propertyset refid="uptodate.and.compiled.properties"/>
+ </ant>
+ <property name="analyzers-kuromoji.uptodate" value="true"/>
+ </target>
+
<property name="grouping.jar" value="${common.dir}/../modules/grouping/build/lucene-grouping-${version}.jar"/>
<target name="check-grouping-uptodate" unless="grouping.uptodate">
<module-uptodate name="grouping" jarfile="${grouping.jar}" property="grouping.uptodate"/>
diff --git a/modules/analysis/CHANGES.txt b/modules/analysis/CHANGES.txt
index 24599552002..27433bd0aa7 100644
--- a/modules/analysis/CHANGES.txt
+++ b/modules/analysis/CHANGES.txt
@@ -42,6 +42,11 @@ API Changes
since they prevent reuse. Both Analyzers should be configured at instantiation.
(Chris Male)
+ * LUCENE-3305: Added SegmentingTokenizerBase, which breaks text into sentences
+ with BreakIterator and allows subclasses to decompose sentences into words, or
+ use the sentence boundary information for other reasons (e.g. attribute/position increment)
+ (Robert Muir)
+
New Features
* LUCENE-2341: A new analyzer/ filter: Morfologik - a dictionary-driven lemmatizer
@@ -109,6 +114,9 @@ New Features
* LUCENE-3414: Added HunspellStemFilter which uses a provided pure Java implementation of the
Hunspell algorithm. (Chris Male)
+ * LUCENE-3305: Added Kuromoji morphological analyzer for Japanese.
+ (Christian Moen, Masaru Hasegawa, Simon Willnauer, Uwe Schindler, Robert Muir)
+
Build
* LUCENE-2413: All analyzers in contrib/analyzers and contrib/icu were moved to the
diff --git a/modules/analysis/NOTICE.txt b/modules/analysis/NOTICE.txt
index 61d1022ff7a..3a991168551 100644
--- a/modules/analysis/NOTICE.txt
+++ b/modules/analysis/NOTICE.txt
@@ -71,3 +71,86 @@ LGPL and Creative Commons ShareAlike.
Morfologic includes data from BSD-licensed dictionary of Polish (SGJP)
(http://sgjp.pl/morfeusz/)
+
+===========================================================================
+Kuromoji Japanese Morphological Analyzer - Apache Lucene Integration
+===========================================================================
+
+This software includes a binary and/or source version of data from
+
+ mecab-ipadic-2.7.0-20070801
+
+which can be obtained from
+
+ http://atilika.com/releases/mecab-ipadic/mecab-ipadic-2.7.0-20070801.tar.gz
+
+or
+
+ http://jaist.dl.sourceforge.net/project/mecab/mecab-ipadic/2.7.0-20070801/mecab-ipadic-2.7.0-20070801.tar.gz
+
+===========================================================================
+mecab-ipadic-2.7.0-20070801 Notice
+===========================================================================
+
+Nara Institute of Science and Technology (NAIST),
+the copyright holders, disclaims all warranties with regard to this
+software, including all implied warranties of merchantability and
+fitness, in no event shall NAIST be liable for
+any special, indirect or consequential damages or any damages
+whatsoever resulting from loss of use, data or profits, whether in an
+action of contract, negligence or other tortuous action, arising out
+of or in connection with the use or performance of this software.
+
+A large portion of the dictionary entries
+originate from ICOT Free Software. The following conditions for ICOT
+Free Software applies to the current dictionary as well.
+
+Each User may also freely distribute the Program, whether in its
+original form or modified, to any third party or parties, PROVIDED
+that the provisions of Section 3 ("NO WARRANTY") will ALWAYS appear
+on, or be attached to, the Program, which is distributed substantially
+in the same form as set out herein and that such intended
+distribution, if actually made, will neither violate or otherwise
+contravene any of the laws and regulations of the countries having
+jurisdiction over the User or the intended distribution itself.
+
+NO WARRANTY
+
+The program was produced on an experimental basis in the course of the
+research and development conducted during the project and is provided
+to users as so produced on an experimental basis. Accordingly, the
+program is provided without any warranty whatsoever, whether express,
+implied, statutory or otherwise. The term "warranty" used herein
+includes, but is not limited to, any warranty of the quality,
+performance, merchantability and fitness for a particular purpose of
+the program and the nonexistence of any infringement or violation of
+any right of any third party.
+
+Each user of the program will agree and understand, and be deemed to
+have agreed and understood, that there is no warranty whatsoever for
+the program and, accordingly, the entire risk arising from or
+otherwise connected with the program is assumed by the user.
+
+Therefore, neither ICOT, the copyright holder, or any other
+organization that participated in or was otherwise related to the
+development of the program and their respective officials, directors,
+officers and other employees shall be held liable for any and all
+damages, including, without limitation, general, special, incidental
+and consequential damages, arising out of or otherwise in connection
+with the use or inability to use the program or any product, material
+or result produced or otherwise obtained by using the program,
+regardless of whether they have been advised of, or otherwise had
+knowledge of, the possibility of such damages at any time during the
+project or thereafter. Each user will be deemed to have agreed to the
+foregoing by his or her commencement of use of the program. The term
+"use" as used herein includes, but is not limited to, the use,
+modification, copying and distribution of the program and the
+production of secondary products from the program.
+
+In the case where the program, whether in its original form or
+modified, was distributed or delivered to or received by a user from
+any person, organization or entity other than ICOT, unless it makes or
+grants independently of ICOT any specific warranty to the user in
+writing, such person, organization or entity, will also be exempted
+from and not be held liable to the user for any such damages as noted
+above as far as the program is concerned.
diff --git a/modules/analysis/README.txt b/modules/analysis/README.txt
index 2642268a8c8..797911a7874 100644
--- a/modules/analysis/README.txt
+++ b/modules/analysis/README.txt
@@ -22,6 +22,12 @@ lucene-analyzers-icu-XX.jar
International Components for Unicode (ICU). Note: this module depends on
the ICU4j jar file (version >= 4.6.0)
+lucene-analyzers-kuromoji-XX.jar
+ An analyzer with morphological analysis for Japanese.
+
+lucene-analyzers-morfologik-XX.jar
+ An analyzer using the Morfologik stemming library.
+
lucene-analyzers-phonetic-XX.jar
An add-on analysis library that provides phonetic encoders via Apache
Commons-Codec. Note: this module depends on the commons-codec jar
@@ -35,21 +41,20 @@ lucene-analyzers-stempel-XX.jar
An add-on analysis library that contains a universal algorithmic stemmer,
including tables for the Polish language.
-lucene-analyzers-morfologik-XX.jar
- An analyzer using the Morfologik stemming library.
-
common/src/java
icu/src/java
+kuromoji/src/java
+morfologik/src/java
phonetic/src/java
smartcn/src/java
stempel/src/java
-morfologik/src/java
- The source code for the ffve libraries.
+ The source code for the libraries.
common/src/test
icu/src/test
+kuromoji/src/test
+morfologik/src/test
phonetic/src/test
smartcn/src/test
stempel/src/test
-morfologik/src/test
- Unit tests for the five libraries.
+ Unit tests for the libraries.
diff --git a/modules/analysis/build.xml b/modules/analysis/build.xml
index 5292da2b959..7df7f1ae917 100644
--- a/modules/analysis/build.xml
+++ b/modules/analysis/build.xml
@@ -23,9 +23,10 @@
Additional Analyzers
- common: Additional Analyzers
- icu: Analyzers that use functionality from ICU
+ - kuromoji: Japanese Morphological Analyzer
+ - morfologik: Morfologik Stemmer
- smartcn: Smart Analyzer for Simplified Chinese Text
- stempel: Algorithmic Stemmer for Polish
- - morfologik: Morfologik Stemmer
</description>
<target name="common">
@@ -36,6 +37,14 @@
<ant dir="icu" />
</target>
+ <target name="kuromoji">
+ <ant dir="kuromoji" />
+ </target>
+
+ <target name="morfologik">
+ <ant dir="morfologik" />
+ </target>
+
<target name="phonetic">
<ant dir="phonetic" />
</target>
@@ -48,52 +57,53 @@
<ant dir="stempel" />
</target>
- <target name="morfologik">
- <ant dir="morfologik" />
- </target>
-
<target name="default" depends="compile"/>
- <target name="compile" depends="common,icu,phonetic,smartcn,stempel,morfologik" />
+ <target name="compile" depends="common,icu,kuromoji,morfologik,phonetic,smartcn,stempel" />
<target name="clean">
<ant dir="common" target="clean" />
<ant dir="icu" target="clean" />
+ <ant dir="kuromoji" target="clean"/>
+ <ant dir="morfologik" target="clean" />
<ant dir="phonetic" target="clean" />
<ant dir="smartcn" target="clean" />
<ant dir="stempel" target="clean" />
- <ant dir="morfologik" target="clean" />
</target>
<target name="validate">
<ant dir="common" target="validate" />
<ant dir="icu" target="validate" />
+ <ant dir="kuromoji" target="validate" />
+ <ant dir="morfologik" target="validate" />
<ant dir="phonetic" target="validate" />
<ant dir="smartcn" target="validate" />
<ant dir="stempel" target="validate" />
- <ant dir="morfologik" target="validate" />
</target>
<target name="compile-core">
<ant dir="common" target="compile-core" />
<ant dir="icu" target="compile-core" />
+ <ant dir="kuromoji" target="compile-core" />
+ <ant dir="morfologik" target="compile-core" />
<ant dir="phonetic" target="compile-core" />
<ant dir="smartcn" target="compile-core" />
<ant dir="stempel" target="compile-core" />
- <ant dir="morfologik" target="compile-core" />
</target>
<target name="compile-test">
<ant dir="common" target="compile-test" />
<ant dir="icu" target="compile-test" />
+ <ant dir="kuromoji" target="compile-test" />
+ <ant dir="morfologik" target="compile-test" />
<ant dir="phonetic" target="compile-test" />
<ant dir="smartcn" target="compile-test" />
<ant dir="stempel" target="compile-test" />
- <ant dir="morfologik" target="compile-test" />
</target>
<target name="test">
<ant dir="common" target="test" />
<ant dir="icu" target="test" />
+ <ant dir="kuromoji" target="test" />
+ <ant dir="morfologik" target="test" />
<ant dir="phonetic" target="test" />
<ant dir="smartcn" target="test" />
<ant dir="stempel" target="test" />
- <ant dir="morfologik" target="test" />
</target>
<target name="build-artifacts-and-tests" depends="default,compile-test" />
@@ -101,28 +111,31 @@
<target name="dist-maven" depends="default,javadocs">
<ant dir="common" target="dist-maven" />
<ant dir="icu" target="dist-maven" />
+ <ant dir="kuromoji" target="dist-maven" />
+ <ant dir="morfologik" target="dist-maven" />
<ant dir="phonetic" target="dist-maven" />
<ant dir="smartcn" target="dist-maven" />
<ant dir="stempel" target="dist-maven" />
- <ant dir="morfologik" target="dist-maven" />
</target>
<target name="javadocs">
<ant dir="common" target="javadocs" />
<ant dir="icu" target="javadocs" />
+ <ant dir="kuromoji" target="javadocs" />
+ <ant dir="morfologik" target="javadocs" />
<ant dir="phonetic" target="javadocs" />
<ant dir="smartcn" target="javadocs" />
<ant dir="stempel" target="javadocs" />
- <ant dir="morfologik" target="javadocs" />
</target>
<target name="javadocs-index.html">
<ant dir="common" target="javadocs-index.html" />
<ant dir="icu" target="javadocs-index.html" />
+ <ant dir="kuromoji" target="javadocs-index.html" />
+ <ant dir="morfologik" target="javadocs-index.html" />
<ant dir="phonetic" target="javadocs-index.html" />
<ant dir="smartcn" target="javadocs-index.html" />
<ant dir="stempel" target="javadocs-index.html" />
- <ant dir="morfologik" target="javadocs-index.html" />
</target>
</project>
diff --git a/modules/analysis/common/src/java/org/apache/lucene/analysis/util/SegmentingTokenizerBase.java b/modules/analysis/common/src/java/org/apache/lucene/analysis/util/SegmentingTokenizerBase.java
new file mode 100644
index 00000000000..67004d330f1
--- /dev/null
+++ b/modules/analysis/common/src/java/org/apache/lucene/analysis/util/SegmentingTokenizerBase.java
@@ -0,0 +1,180 @@
+package org.apache.lucene.analysis.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.Reader;
+
+import java.text.BreakIterator;
+
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
+
+/**
+ * Breaks text into sentences with a {@link BreakIterator} and
+ * allows subclasses to decompose these sentences into words.
+ * <p>
+ * This can be used by subclasses that need sentence context
+ * for tokenization purposes, such as CJK segmenters.
+ * <p>
+ * Additionally it can be used by subclasses that want to mark
+ * sentence boundaries (with a custom attribute, extra token, position
+ * increment, etc) for downstream processing.
+ *
+ * @lucene.experimental
+ */
+public abstract class SegmentingTokenizerBase extends Tokenizer {
+ protected static final int BUFFERMAX = 4096;
+ protected final char buffer[] = new char[BUFFERMAX];
+ /** true length of text in the buffer */
+ private int length = 0;
+ /** length in buffer that can be evaluated safely, up to a safe end point */
+ private int usableLength = 0;
+ /** accumulated offset of previous buffers for this reader, for offsetAtt */
+ protected int offset = 0;
+
+ private final BreakIterator iterator;
+ private final CharArrayIterator wrapper = CharArrayIterator.newSentenceInstance();
+
+ private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
+
+ /**
+ * Construct a new SegmenterBase from the given Reader, using
+ * the provided BreakIterator for sentence segmentation.
+ * <p>
+ * Note that you should never share BreakIterators across different
+ * TokenStreams, instead a newly created or cloned one should always
+ * be provided to this constructor.
+ */
+ public SegmentingTokenizerBase(Reader input, BreakIterator iterator) {
+ super(input);
+ this.iterator = iterator;
+ }
+
+ @Override
+ public final boolean incrementToken() throws IOException {
+ if (length == 0 || !incrementWord()) {
+ while (!incrementSentence()) {
+ refill();
+ if (length <= 0) // no more bytes to read;
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void reset() throws IOException {
+ wrapper.setText(buffer, 0, 0);
+ iterator.setText(wrapper);
+ length = usableLength = offset = 0;
+ }
+
+ @Override
+ public void reset(Reader input) throws IOException {
+ this.input = input;
+ reset();
+ }
+
+ @Override
+ public final void end() throws IOException {
+ final int finalOffset = correctOffset(length < 0 ? offset : offset + length);
+ offsetAtt.setOffset(finalOffset, finalOffset);
+ }
+
+ /** Returns the last unambiguous break position in the text. */
+ private int findSafeEnd() {
+ for (int i = length - 1; i >= 0; i--)
+ if (isSafeEnd(buffer[i]))
+ return i + 1;
+ return -1;
+ }
+
+ /** For sentence tokenization, these are the unambiguous break positions. */
+ protected boolean isSafeEnd(char ch) {
+ switch(ch) {
+ case 0x000D:
+ case 0x000A:
+ case 0x0085:
+ case 0x2028:
+ case 0x2029:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Refill the buffer, accumulating the offset and setting usableLength to the
+ * last unambiguous break position
+ */
+ private void refill() throws IOException {
+ offset += usableLength;
+ int leftover = length - usableLength;
+ System.arraycopy(buffer, usableLength, buffer, 0, leftover);
+ int requested = buffer.length - leftover;
+ int returned = input.read(buffer, leftover, requested);
+ length = returned < 0 ? leftover : returned + leftover;
+ if (returned < requested) /* reader has been emptied, process the rest */
+ usableLength = length;
+ else { /* still more data to be read, find a safe-stopping place */
+ usableLength = findSafeEnd();
+ if (usableLength < 0)
+ usableLength = length; /*
+ * more than IOBUFFER of text without breaks,
+ * gonna possibly truncate tokens
+ */
+ }
+
+ wrapper.setText(buffer, 0, Math.max(0, usableLength));
+ iterator.setText(wrapper);
+ }
+
+ /**
+ * return true if there is a token from the buffer, or null if it is
+ * exhausted.
+ */
+ private boolean incrementSentence() throws IOException {
+ if (length == 0) // we must refill the buffer
+ return false;
+
+ while (true) {
+ int start = iterator.current();
+
+ if (start == BreakIterator.DONE)
+ return false; // BreakIterator exhausted
+
+ // find the next set of boundaries
+ int end = iterator.next();
+
+ if (end == BreakIterator.DONE)
+ return false; // BreakIterator exhausted
+
+ setNextSentence(start, end);
+ if (incrementWord()) {
+ return true;
+ }
+ }
+ }
+
+ /** Provides the next input sentence for analysis */
+ protected abstract void setNextSentence(int sentenceStart, int sentenceEnd);
+ /** Returns true if another word is available */
+ protected abstract boolean incrementWord();
+}
diff --git a/modules/analysis/common/src/test/org/apache/lucene/analysis/util/TestSegmentingTokenizerBase.java b/modules/analysis/common/src/test/org/apache/lucene/analysis/util/TestSegmentingTokenizerBase.java
new file mode 100644
index 00000000000..d5a1c68bac9
--- /dev/null
+++ b/modules/analysis/common/src/test/org/apache/lucene/analysis/util/TestSegmentingTokenizerBase.java
@@ -0,0 +1,224 @@
+package org.apache.lucene.analysis.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.Reader;
+import java.text.BreakIterator;
+import java.util.Arrays;
+import java.util.Locale;
+
+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;
+
+/** Basic tests for {@link SegmentingTokenizerBase} */
+public class TestSegmentingTokenizerBase extends BaseTokenStreamTestCase {
+ private Analyzer sentence = new Analyzer() {
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer tokenizer = new WholeSentenceTokenizer(reader);
+ return new TokenStreamComponents(tokenizer, tokenizer);
+ }
+ };
+
+ private Analyzer sentenceAndWord = new Analyzer() {
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer tokenizer = new SentenceAndWordTokenizer(reader);
+ return new TokenStreamComponents(tokenizer, tokenizer);
+ }
+ };
+
+ /** Some simple examples, just outputting the whole sentence boundaries as "terms" */
+ public void testBasics() throws IOException {
+ assertAnalyzesTo(sentence, "The acronym for United States is U.S. but this doesn't end a sentence",
+ new String[] { "The acronym for United States is U.S. but this doesn't end a sentence"}
+ );
+ assertAnalyzesTo(sentence, "He said, \"Are you going?\" John shook his head.",
+ new String[] { "He said, \"Are you going?\" ",
+ "John shook his head." }
+ );
+ }
+
+ /** Test a subclass that sets some custom attribute values */
+ public void testCustomAttributes() throws IOException {
+ assertAnalyzesTo(sentenceAndWord, "He said, \"Are you going?\" John shook his head.",
+ new String[] { "He", "said", "Are", "you", "going", "John", "shook", "his", "head" },
+ new int[] { 0, 3, 10, 14, 18, 26, 31, 37, 41 },
+ new int[] { 2, 7, 13, 17, 23, 30, 36, 40, 45 },
+ new int[] { 1, 1, 1, 1, 1, 2, 1, 1, 1 }
+ );
+ }
+
+ /** Tests tokenstream reuse */
+ public void testReuse() throws IOException {
+ assertAnalyzesToReuse(sentenceAndWord, "He said, \"Are you going?\"",
+ new String[] { "He", "said", "Are", "you", "going" },
+ new int[] { 0, 3, 10, 14, 18 },
+ new int[] { 2, 7, 13, 17, 23 },
+ new int[] { 1, 1, 1, 1, 1,}
+ );
+ assertAnalyzesToReuse(sentenceAndWord, "John shook his head.",
+ new String[] { "John", "shook", "his", "head" },
+ new int[] { 0, 5, 11, 15 },
+ new int[] { 4, 10, 14, 19 },
+ new int[] { 1, 1, 1, 1 }
+ );
+ }
+
+ /** Tests TokenStream.end() */
+ public void testEnd() throws IOException {
+ // BaseTokenStreamTestCase asserts that end() is set to our StringReader's length for us here.
+ // we add some junk whitespace to the end just to test it.
+ assertAnalyzesTo(sentenceAndWord, "John shook his head ",
+ new String[] { "John", "shook", "his", "head" }
+ );
+ assertAnalyzesTo(sentenceAndWord, "John shook his head. ",
+ new String[] { "John", "shook", "his", "head" }
+ );
+ }
+
+ /** Tests terms which span across boundaries */
+ public void testHugeDoc() throws IOException {
+ StringBuilder sb = new StringBuilder();
+ char whitespace[] = new char[4094];
+ Arrays.fill(whitespace, '\n');
+ sb.append(whitespace);
+ sb.append("testing 1234");
+ String input = sb.toString();
+ assertAnalyzesTo(sentenceAndWord, input, new String[] { "testing", "1234" });
+ }
+
+ /** Tests the handling of binary/malformed data */
+ public void testHugeTerm() throws IOException {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 40960; i++) {
+ sb.append('a');
+ }
+ String input = sb.toString();
+ char token[] = new char[4096];
+ Arrays.fill(token, 'a');
+ String expectedToken = new String(token);
+ String expected[] = {
+ expectedToken, expectedToken, expectedToken,
+ expectedToken, expectedToken, expectedToken,
+ expectedToken, expectedToken, expectedToken,
+ expectedToken
+ };
+ assertAnalyzesTo(sentence, input, expected);
+ }
+
+ /** blast some random strings through the analyzer */
+ public void testRandomStrings() throws Exception {
+ checkRandomData(random, sentence, 10000*RANDOM_MULTIPLIER);
+ checkRandomData(random, sentenceAndWord, 10000*RANDOM_MULTIPLIER);
+ }
+
+ // some tokenizers for testing
+
+ /** silly tokenizer that just returns whole sentences as tokens */
+ static class WholeSentenceTokenizer extends SegmentingTokenizerBase {
+ int sentenceStart, sentenceEnd;
+ boolean hasSentence;
+
+ private CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+ private OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
+
+ public WholeSentenceTokenizer(Reader input) {
+ super(input, BreakIterator.getSentenceInstance(new Locale("")));
+ }
+
+ @Override
+ protected void setNextSentence(int sentenceStart, int sentenceEnd) {
+ this.sentenceStart = sentenceStart;
+ this.sentenceEnd = sentenceEnd;
+ hasSentence = true;
+ }
+
+ @Override
+ protected boolean incrementWord() {
+ if (hasSentence) {
+ hasSentence = false;
+ clearAttributes();
+ termAtt.copyBuffer(buffer, sentenceStart, sentenceEnd-sentenceStart);
+ offsetAtt.setOffset(offset+sentenceStart, offset+sentenceEnd);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * simple tokenizer, that bumps posinc + 1 for tokens after a
+ * sentence boundary to inhibit phrase queries without slop.
+ */
+ static class SentenceAndWordTokenizer extends SegmentingTokenizerBase {
+ int sentenceStart, sentenceEnd;
+ int wordStart, wordEnd;
+ int posBoost = -1; // initially set to -1 so the first word in the document doesn't get a pos boost
+
+ private CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+ private OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
+ private PositionIncrementAttribute posIncAtt = addAttribute(PositionIncrementAttribute.class);
+
+ public SentenceAndWordTokenizer(Reader input) {
+ super(input, BreakIterator.getSentenceInstance(new Locale("")));
+ }
+
+ @Override
+ protected void setNextSentence(int sentenceStart, int sentenceEnd) {
+ this.wordStart = this.wordEnd = this.sentenceStart = sentenceStart;
+ this.sentenceEnd = sentenceEnd;
+ posBoost++;
+ }
+
+ @Override
+ public void reset() throws IOException {
+ super.reset();
+ posBoost = -1;
+ }
+
+ @Override
+ protected boolean incrementWord() {
+ wordStart = wordEnd;
+ while (wordStart < sentenceEnd) {
+ if (Character.isLetterOrDigit(buffer[wordStart]))
+ break;
+ wordStart++;
+ }
+
+ if (wordStart == sentenceEnd) return false;
+
+ wordEnd = wordStart+1;
+ while (wordEnd < sentenceEnd && Character.isLetterOrDigit(buffer[wordEnd]))
+ wordEnd++;
+
+ clearAttributes();
+ termAtt.copyBuffer(buffer, wordStart, wordEnd-wordStart);
+ offsetAtt.setOffset(offset+wordStart, offset+wordEnd);
+ posIncAtt.setPositionIncrement(posIncAtt.getPositionIncrement() + posBoost);
+ posBoost = 0;
+ return true;
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/build.xml b/modules/analysis/kuromoji/build.xml
new file mode 100644
index 00000000000..84c2115ad6a
--- /dev/null
+++ b/modules/analysis/kuromoji/build.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<project name="analyzers-kuromoji" default="default">
+
+ <description>
+ Kuromoji Japanese Morphological Analyzer
+ </description>
+
+ <property name="build.dir" location="../build/kuromoji" />
+ <property name="dist.dir" location="../dist/kuromoji" />
+ <property name="ipadic.version" value="mecab-ipadic-2.7.0-20070801" />
+ <property name="dict.src.file" value="${ipadic.version}.tar.gz" />
+ <!-- <property name="dict.url" value="http://atilika.com/releases/mecab-ipadic/${dict.src.file}" /> -->
+ <property name="dict.url" value="http://mecab.googlecode.com/files/${dict.src.file}"/>
+ <property name="dict.src.dir" value="${build.dir}/${ipadic.version}" />
+ <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"/>
+ <import file="../../../lucene/contrib/contrib-build.xml"/>
+
+ <available type="dir" file="${build.dir}/${ipadic.version}" property="dict.available"/>
+
+ <path id="classpath">
+ <pathelement path="${analyzers-common.jar}"/>
+ <path refid="base.classpath"/>
+ </path>
+
+ <target name="compile-core" depends="jar-analyzers-common, common.compile-core" />
+ <target name="download-dict" unless="dict.available">
+ <get src="${dict.url}" dest="${build.dir}/${dict.src.file}"/>
+ <gunzip src="${build.dir}/${dict.src.file}"/>
+ <untar src="${build.dir}/${ipadic.version}.tar" dest="${build.dir}"/>
+ </target>
+
+ <path id="tools.dependencies">
+ <fileset dir="../icu/lib" includes="icu4j-*.jar"/>
+ </path>
+
+ <path id="tools.classpath">
+ <path refid="classpath"/>
+ <path refid="tools.dependencies"/>
+ <pathelement location="${build.dir}/classes/java"/>
+ <pathelement location="${build.dir}/classes/tools"/>
+ </path>
+
+ <path id="tools.test.classpath">
+ <path refid="tools.classpath"/>
+ <path refid="test.base.classpath"/>
+ <pathelement location="${build.dir}/classes/tools-test"/>
+ </path>
+
+ <target name="build-dict" depends="compile-tools, download-dict">
+ <sequential>
+ <delete verbose="true">
+ <fileset dir="src/resources/org/apache/lucene/analysis/kuromoji/dict" includes="**/*"/>
+ </delete>
+ <java fork="true" failonerror="true" maxmemory="512m" classname="org.apache.lucene.analysis.kuromoji.util.DictionaryBuilder">
+ <classpath>
+ <path refid="tools.classpath"/>
+ <pathelement path="${build.dir}/classes/tools"/>
+ </classpath>
+ <assertions>
+ <enable package="org.apache.lucene"/>
+ </assertions>
+ <arg value="${dict.format}"/>
+ <arg value="${dict.src.dir}"/>
+ <arg value="${dict.target.dir}"/>
+ <arg value="${dict.encoding}"/>
+ <arg value="${dict.normalize}"/>
+ </java>
+ </sequential>
+ </target>
+
+ <target name="compile-tools" depends="compile-core, common.compile-tools">
+ <compile
+ srcdir="src/tools/java"
+ destdir="${build.dir}/classes/tools">
+ <classpath>
+ <path refid="tools.classpath"/>
+ <pathelement path="src/tools/java"/>
+ </classpath>
+ </compile>
+ </target>
+
+ <target name="compile-tools-tests" depends="compile-tools">
+ <compile
+ srcdir="src/tools/test"
+ destdir="${build.dir}/classes/tools-test">
+ <classpath>
+ <path refid="tools.test.classpath"/>
+ <pathelement path="src/tools/test"/>
+ </classpath>
+ </compile>
+ </target>
+
+ <target name="test-tools" depends="compile-tools-tests">
+ <test-macro dataDir="src/tools/test" junit.classpath="tools.test.classpath"/>
+ </target>
+
+ <target name="compile-test" depends="contrib-build.compile-test, compile-tools-tests"/>
+ <target name="test" depends="contrib-build.test, test-tools"/>
+
+</project>
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiAnalyzer.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiAnalyzer.java
new file mode 100644
index 00000000000..257f9971c1a
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiAnalyzer.java
@@ -0,0 +1,91 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.cjk.CJKWidthFilter;
+import org.apache.lucene.analysis.core.LowerCaseFilter;
+import org.apache.lucene.analysis.core.StopFilter;
+import org.apache.lucene.analysis.util.CharArraySet;
+import org.apache.lucene.analysis.util.StopwordAnalyzerBase;
+import org.apache.lucene.util.Version;
+
+public class KuromojiAnalyzer extends StopwordAnalyzerBase {
+ private final Segmenter segmenter;
+ private final Set<String> stoptags;
+
+ public KuromojiAnalyzer(Version matchVersion) {
+ this(matchVersion, new Segmenter(), DefaultSetHolder.DEFAULT_STOP_SET, DefaultSetHolder.DEFAULT_STOP_TAGS);
+ }
+
+ public KuromojiAnalyzer(Version matchVersion, Segmenter segmenter, Set<?> stopwords, Set<String> stoptags) {
+ super(matchVersion, stopwords);
+ this.segmenter = segmenter;
+ this.stoptags = stoptags;
+ }
+
+ public static Set<?> getDefaultStopSet(){
+ return DefaultSetHolder.DEFAULT_STOP_SET;
+ }
+
+ public static Set<String> getDefaultStopTags(){
+ return DefaultSetHolder.DEFAULT_STOP_TAGS;
+ }
+
+ /**
+ * Atomically loads DEFAULT_STOP_SET, DEFAULT_STOP_TAGS in a lazy fashion once the
+ * outer class accesses the static final set the first time.
+ */
+ private static class DefaultSetHolder {
+ static final Set<?> DEFAULT_STOP_SET;
+ static final Set<String> DEFAULT_STOP_TAGS;
+
+ static {
+ try {
+ DEFAULT_STOP_SET = loadStopwordSet(false, KuromojiAnalyzer.class, "stopwords.txt", "#");
+ final CharArraySet tagset = loadStopwordSet(false, KuromojiAnalyzer.class, "stoptags.txt", "#");
+ DEFAULT_STOP_TAGS = new HashSet<String>();
+ for (Object element : tagset) {
+ char chars[] = (char[]) element;
+ DEFAULT_STOP_TAGS.add(new String(chars));
+ }
+ } catch (IOException ex) {
+ // default set should always be present as it is part of the
+ // distribution (JAR)
+ throw new RuntimeException("Unable to load default stopword set");
+ }
+ }
+ }
+
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer tokenizer = new KuromojiTokenizer(this.segmenter, reader);
+ TokenStream stream = new LowerCaseFilter(matchVersion, tokenizer);
+ stream = new CJKWidthFilter(stream);
+ stream = new KuromojiPartOfSpeechStopFilter(true, stream, stoptags);
+ stream = new StopFilter(matchVersion, stream, stopwords);
+ stream = new KuromojiBaseFormFilter(stream);
+ return new TokenStreamComponents(tokenizer, stream);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiBaseFormFilter.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiBaseFormFilter.java
new file mode 100644
index 00000000000..f993a870064
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiBaseFormFilter.java
@@ -0,0 +1,62 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.analysis.TokenFilter;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.kuromoji.tokenattributes.BaseFormAttribute;
+import org.apache.lucene.analysis.miscellaneous.KeywordMarkerFilter;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.KeywordAttribute;
+
+/**
+ * Replaces term text with the {@link BaseFormAttribute}.
+ * <p>
+ * This acts as a lemmatizer for verbs and adjectives.
+ * <p>
+ * To prevent terms from being stemmed use an instance of
+ * {@link KeywordMarkerFilter} or a custom {@link TokenFilter} that sets
+ * the {@link KeywordAttribute} before this {@link TokenStream}.
+ * </p>
+ */
+public final class KuromojiBaseFormFilter extends TokenFilter {
+ private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+ private final BaseFormAttribute basicFormAtt = addAttribute(BaseFormAttribute.class);
+ private final KeywordAttribute keywordAtt = addAttribute(KeywordAttribute.class);
+
+ public KuromojiBaseFormFilter(TokenStream input) {
+ super(input);
+ }
+
+ @Override
+ public boolean incrementToken() throws IOException {
+ if (input.incrementToken()) {
+ if (!keywordAtt.isKeyword()) {
+ String baseForm = basicFormAtt.getBaseForm();
+ if (baseForm != null) {
+ termAtt.setEmpty().append(basicFormAtt.getBaseForm());
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiPartOfSpeechStopFilter.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiPartOfSpeechStopFilter.java
new file mode 100644
index 00000000000..fe30891f751
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiPartOfSpeechStopFilter.java
@@ -0,0 +1,44 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.lucene.analysis.kuromoji.tokenattributes.PartOfSpeechAttribute;
+import org.apache.lucene.analysis.util.FilteringTokenFilter;
+import org.apache.lucene.analysis.TokenStream;
+
+/**
+ * Removes tokens that match a set of POS tags.
+ */
+public final class KuromojiPartOfSpeechStopFilter extends FilteringTokenFilter {
+ private final Set<String> stopTags;
+ private final PartOfSpeechAttribute posAtt = addAttribute(PartOfSpeechAttribute.class);
+
+ public KuromojiPartOfSpeechStopFilter(boolean enablePositionIncrements, TokenStream input, Set<String> stopTags) {
+ super(enablePositionIncrements, input);
+ this.stopTags = stopTags;
+ }
+
+ @Override
+ protected boolean accept() throws IOException {
+ final String pos = posAtt.getPartOfSpeech();
+ return pos == null || !stopTags.contains(pos);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiTokenizer.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiTokenizer.java
new file mode 100644
index 00000000000..87575e1a51a
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/KuromojiTokenizer.java
@@ -0,0 +1,83 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.Reader;
+import java.text.BreakIterator;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.lucene.analysis.kuromoji.tokenattributes.BaseFormAttribute;
+import org.apache.lucene.analysis.kuromoji.tokenattributes.InflectionAttribute;
+import org.apache.lucene.analysis.kuromoji.tokenattributes.PartOfSpeechAttribute;
+import org.apache.lucene.analysis.kuromoji.tokenattributes.ReadingAttribute;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
+import org.apache.lucene.analysis.util.SegmentingTokenizerBase;
+
+public final class KuromojiTokenizer extends SegmentingTokenizerBase {
+ private static final BreakIterator proto = BreakIterator.getSentenceInstance(Locale.JAPAN);
+ private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+ private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
+ private final BaseFormAttribute basicFormAtt = addAttribute(BaseFormAttribute.class);
+ private final PartOfSpeechAttribute posAtt = addAttribute(PartOfSpeechAttribute.class);
+ private final ReadingAttribute readingAtt = addAttribute(ReadingAttribute.class);
+ private final InflectionAttribute inflectionAtt = addAttribute(InflectionAttribute.class);
+ private final Segmenter segmenter;
+
+ private List<Token> tokens;
+ private int tokenIndex = 0;
+ private int sentenceStart = 0;
+
+ public KuromojiTokenizer(Reader input) {
+ this(new Segmenter(), input);
+ }
+
+ public KuromojiTokenizer(Segmenter segmenter, Reader input) {
+ super(input, (BreakIterator) proto.clone());
+ this.segmenter = segmenter;
+ }
+
+ @Override
+ protected void setNextSentence(int sentenceStart, int sentenceEnd) {
+ this.sentenceStart = sentenceStart;
+ // TODO: maybe don't pass 0 here, so kuromoji tracks offsets for us?
+ tokens = segmenter.doTokenize(0, buffer, sentenceStart, sentenceEnd-sentenceStart, true);
+ tokenIndex = 0;
+ }
+
+ @Override
+ protected boolean incrementWord() {
+ if (tokenIndex == tokens.size()) {
+ return false;
+ }
+ Token token = tokens.get(tokenIndex);
+ int position = token.getPosition();
+ int length = token.getLength();
+ clearAttributes();
+ termAtt.copyBuffer(buffer, sentenceStart + position, length);
+ int startOffset = offset + sentenceStart + position;
+ offsetAtt.setOffset(correctOffset(startOffset), correctOffset(startOffset+length));
+ basicFormAtt.setToken(token);
+ posAtt.setToken(token);
+ readingAtt.setToken(token);
+ inflectionAtt.setToken(token);
+ tokenIndex++;
+ return true;
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/Segmenter.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/Segmenter.java
new file mode 100644
index 00000000000..0719ddbf0b0
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/Segmenter.java
@@ -0,0 +1,214 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+
+import org.apache.lucene.analysis.kuromoji.dict.*;
+import org.apache.lucene.analysis.kuromoji.viterbi.GraphvizFormatter;
+import org.apache.lucene.analysis.kuromoji.viterbi.Viterbi;
+import org.apache.lucene.analysis.kuromoji.viterbi.ViterbiNode;
+import org.apache.lucene.analysis.kuromoji.viterbi.ViterbiNode.Type;
+
+/**
+ * Tokenizer main class.
+ * Thread safe.
+ */
+public class Segmenter {
+ public static enum Mode {
+ NORMAL, SEARCH, EXTENDED
+ }
+
+ private final Viterbi viterbi;
+
+ private final EnumMap<Type, Dictionary> dictionaryMap = new EnumMap<Type, Dictionary>(Type.class);
+
+ private final boolean split;
+
+ public Segmenter() {
+ this(null, Mode.NORMAL, false);
+ }
+
+ public Segmenter(UserDictionary userDictionary, Mode mode) {
+ this(userDictionary, mode, false);
+ }
+
+ public Segmenter(UserDictionary userDictionary) {
+ this(userDictionary, Mode.NORMAL, false);
+ }
+
+ public Segmenter(Mode mode) {
+ this(null, mode, false);
+ }
+
+ public Segmenter(UserDictionary userDictionary, Mode mode, boolean split) {
+
+ final TokenInfoDictionary dict = TokenInfoDictionary.getInstance();
+ final UnknownDictionary unknownDict = UnknownDictionary.getInstance();
+ this.viterbi = new Viterbi(dict,
+ unknownDict,
+ ConnectionCosts.getInstance(),
+ userDictionary,
+ mode);
+
+ this.split = split;
+
+ dictionaryMap.put(Type.KNOWN, dict);
+ dictionaryMap.put(Type.UNKNOWN, unknownDict);
+ dictionaryMap.put(Type.USER, userDictionary);
+ }
+
+ /**
+ * Tokenize input text
+ * @param text
+ * @return list of Token
+ */
+ public List<Token> tokenize(String text) {
+
+ if (!split) {
+ return doTokenize(0, text);
+ }
+
+ List<Integer> splitPositions = getSplitPositions(text);
+
+ if(splitPositions.size() == 0) {
+ return doTokenize(0, text);
+ }
+
+ ArrayList<Token> result = new ArrayList<Token>();
+ int offset = 0;
+ for(int position : splitPositions) {
+ result.addAll(doTokenize(offset, text.substring(offset, position + 1)));
+ offset = position + 1;
+ }
+
+ if(offset < text.length()) {
+ result.addAll(doTokenize(offset, text.substring(offset)));
+ }
+
+ return result;
+ }
+
+ /**
+ * Split input text at 句読点, which is 。 and 、
+ * @param text
+ * @return list of split position
+ */
+ private List<Integer> getSplitPositions(String text) {
+ ArrayList<Integer> splitPositions = new ArrayList<Integer>();
+
+ int position = 0;
+ int currentPosition = 0;
+
+ while(true) {
+ int indexOfMaru = text.indexOf("。", currentPosition);
+ int indexOfTen = text.indexOf("、", currentPosition);
+
+ if(indexOfMaru < 0 || indexOfTen < 0) {
+ position = Math.max(indexOfMaru, indexOfTen);;
+ } else {
+ position = Math.min(indexOfMaru, indexOfTen);
+ }
+
+ if(position >= 0) {
+ splitPositions.add(position);
+ currentPosition = position + 1;
+ } else {
+ break;
+ }
+ }
+
+ return splitPositions;
+ }
+
+ private List<Token> doTokenize(int offset, String sentence) {
+ char text[] = sentence.toCharArray();
+ return doTokenize(offset, text, 0, text.length, false);
+ }
+
+ /**
+ * Tokenize input sentence.
+ * @param offset offset of sentence in original input text
+ * @param sentence sentence to tokenize
+ * @return list of Token
+ */
+ public List<Token> doTokenize(int offset, char[] sentence, int sentenceOffset, int sentenceLength, boolean discardPunctuation) {
+ ArrayList<Token> result = new ArrayList<Token>();
+
+ ViterbiNode[][][] lattice;
+ try {
+ lattice = viterbi.build(sentence, sentenceOffset, sentenceLength);
+ } catch (IOException impossible) {
+ throw new RuntimeException(impossible);
+ }
+ List<ViterbiNode> bestPath = viterbi.search(lattice);
+ for (ViterbiNode node : bestPath) {
+ int wordId = node.getWordId();
+ if (node.getType() == Type.KNOWN && wordId == -1){ // Do not include BOS/EOS
+ continue;
+ } else if (discardPunctuation && node.getLength() > 0 && isPunctuation(node.getSurfaceForm()[node.getOffset()])) {
+ continue; // Do not emit punctuation
+ }
+ Token token = new Token(wordId, node.getSurfaceForm(), node.getOffset(), node.getLength(), node.getType(), offset + node.getStartIndex(), dictionaryMap.get(node.getType())); // Pass different dictionary based on the type of node
+ result.add(token);
+ }
+
+ return result;
+ }
+
+ /** returns a Graphviz String */
+ public String debugTokenize(String text) {
+ ViterbiNode[][][] lattice;
+ try {
+ lattice = this.viterbi.build(text.toCharArray(), 0, text.length());
+ } catch (IOException impossible) {
+ throw new RuntimeException(impossible);
+ }
+ List<ViterbiNode> bestPath = this.viterbi.search(lattice);
+
+ return new GraphvizFormatter(ConnectionCosts.getInstance())
+ .format(lattice[0], lattice[1], bestPath);
+ }
+
+ static final boolean isPunctuation(char ch) {
+ switch(Character.getType(ch)) {
+ case Character.SPACE_SEPARATOR:
+ case Character.LINE_SEPARATOR:
+ case Character.PARAGRAPH_SEPARATOR:
+ case Character.CONTROL:
+ case Character.FORMAT:
+ case Character.DASH_PUNCTUATION:
+ case Character.START_PUNCTUATION:
+ case Character.END_PUNCTUATION:
+ case Character.CONNECTOR_PUNCTUATION:
+ case Character.OTHER_PUNCTUATION:
+ case Character.MATH_SYMBOL:
+ case Character.CURRENCY_SYMBOL:
+ case Character.MODIFIER_SYMBOL:
+ case Character.OTHER_SYMBOL:
+ case Character.INITIAL_QUOTE_PUNCTUATION:
+ case Character.FINAL_QUOTE_PUNCTUATION:
+ return true;
+ default:
+ return false;
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/Token.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/Token.java
new file mode 100644
index 00000000000..caa9f14f3f8
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/Token.java
@@ -0,0 +1,147 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.dict.Dictionary;
+import org.apache.lucene.analysis.kuromoji.viterbi.ViterbiNode.Type;
+
+public class Token {
+ private final Dictionary dictionary;
+
+ private final int wordId;
+
+ private final char[] surfaceForm;
+ private final int offset;
+ private final int length;
+
+ private final int position;
+
+ private final Type type;
+
+ public Token(int wordId, char[] surfaceForm, int offset, int length, Type type, int position, Dictionary dictionary) {
+ this.wordId = wordId;
+ this.surfaceForm = surfaceForm;
+ this.offset = offset;
+ this.length = length;
+ this.type = type;
+ this.position = position;
+ this.dictionary = dictionary;
+ }
+
+ /**
+ * @return surfaceForm
+ */
+ public char[] getSurfaceForm() {
+ return surfaceForm;
+ }
+
+ /**
+ * @return offset into surfaceForm
+ */
+ public int getOffset() {
+ return offset;
+ }
+
+ /**
+ * @return length of surfaceForm
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * @return surfaceForm as a String
+ */
+ public String getSurfaceFormString() {
+ return new String(surfaceForm, offset, length);
+ }
+
+ /**
+ * @return reading. null if token doesn't have reading.
+ */
+ public String getReading() {
+ return dictionary.getReading(wordId);
+ }
+
+ /**
+ * @return pronunciation. null if token doesn't have pronunciation.
+ */
+ public String getPronunciation() {
+ return dictionary.getPronunciation(wordId);
+ }
+
+ /**
+ * @return part of speech.
+ */
+ public String getPartOfSpeech() {
+ return dictionary.getPartOfSpeech(wordId);
+ }
+
+ /**
+ * @return inflection type or null
+ */
+ public String getInflectionType() {
+ return dictionary.getInflectionType(wordId);
+ }
+
+ /**
+ * @return inflection form or null
+ */
+ public String getInflectionForm() {
+ return dictionary.getInflectionForm(wordId);
+ }
+
+ /**
+ * @return base form or null if token is not inflected
+ */
+ public String getBaseForm() {
+ return dictionary.getBaseForm(wordId);
+ }
+
+ /**
+ * Returns true if this token is known word
+ * @return true if this token is in standard dictionary. false if not.
+ */
+ public boolean isKnown() {
+ return type == Type.KNOWN;
+ }
+
+ /**
+ * Returns true if this token is unknown word
+ * @return true if this token is unknown word. false if not.
+ */
+ public boolean isUnknown() {
+ return type == Type.UNKNOWN;
+ }
+
+ /**
+ * Returns true if this token is defined in user dictionary
+ * @return true if this token is in user dictionary. false if not.
+ */
+ public boolean isUser() {
+ return type == Type.USER;
+ }
+
+ /**
+ * Get index of this token in input text
+ * @return position of token
+ */
+ public int getPosition() {
+ return position;
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/BinaryDictionary.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/BinaryDictionary.java
new file mode 100644
index 00000000000..6b19d2a500f
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/BinaryDictionary.java
@@ -0,0 +1,291 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.InputStreamDataInput;
+import org.apache.lucene.util.CodecUtil;
+import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.IOUtils;
+
+public abstract class BinaryDictionary implements Dictionary {
+
+ public static final String DICT_FILENAME_SUFFIX = "$buffer.dat";
+ public static final String TARGETMAP_FILENAME_SUFFIX = "$targetMap.dat";
+ public static final String POSDICT_FILENAME_SUFFIX = "$posDict.dat";
+ public static final String INFLDICT_FILENAME_SUFFIX = "$inflDict.dat";
+
+ public static final String DICT_HEADER = "kuromoji_dict";
+ public static final String TARGETMAP_HEADER = "kuromoji_dict_map";
+ public static final String POSDICT_HEADER = "kuromoji_dict_pos";
+ public static final String INFLDICT_HEADER = "kuromoji_dict_infl";
+ public static final int VERSION = 1;
+
+ private final ByteBuffer buffer;
+ private final int[] targetMapOffsets, targetMap;
+ private final String[] posDict;
+ private final String[] inflTypeDict;
+ private final String[] inflFormDict;
+
+ protected BinaryDictionary() throws IOException {
+ InputStream mapIS = null, dictIS = null, posIS = null, inflIS = null;
+ IOException priorE = null;
+ int[] targetMapOffsets = null, targetMap = null;
+ String[] posDict = null;
+ String[] inflFormDict = null;
+ String[] inflTypeDict = null;
+ ByteBuffer buffer = null;
+ try {
+ mapIS = getResource(TARGETMAP_FILENAME_SUFFIX);
+ mapIS = new BufferedInputStream(mapIS);
+ DataInput in = new InputStreamDataInput(mapIS);
+ CodecUtil.checkHeader(in, TARGETMAP_HEADER, VERSION, VERSION);
+ targetMap = new int[in.readVInt()];
+ targetMapOffsets = new int[in.readVInt()];
+ int accum = 0, sourceId = 0;
+ for (int ofs = 0; ofs < targetMap.length; ofs++) {
+ final int val = in.readVInt();
+ if ((val & 0x01) != 0) {
+ targetMapOffsets[sourceId] = ofs;
+ sourceId++;
+ }
+ accum += val >>> 1;
+ targetMap[ofs] = accum;
+ }
+ if (sourceId + 1 != targetMapOffsets.length)
+ throw new IOException("targetMap file format broken");
+ targetMapOffsets[sourceId] = targetMap.length;
+ mapIS.close(); mapIS = null;
+
+ posIS = getResource(POSDICT_FILENAME_SUFFIX);
+ posIS = new BufferedInputStream(posIS);
+ in = new InputStreamDataInput(posIS);
+ CodecUtil.checkHeader(in, POSDICT_HEADER, VERSION, VERSION);
+ posDict = new String[in.readVInt()];
+ for (int j = 0; j < posDict.length; j++) {
+ posDict[j] = in.readString();
+ }
+ posIS.close(); posIS = null;
+
+ inflIS = getResource(INFLDICT_FILENAME_SUFFIX);
+ inflIS = new BufferedInputStream(inflIS);
+ in = new InputStreamDataInput(inflIS);
+ CodecUtil.checkHeader(in, INFLDICT_HEADER, VERSION, VERSION);
+ int length = in.readVInt();
+ inflTypeDict = new String[length];
+ inflFormDict = new String[length];
+ for (int j = 0; j < length; j++) {
+ inflTypeDict[j] = in.readString();
+ inflFormDict[j] = in.readString();
+ }
+ inflIS.close(); inflIS = null;
+
+ dictIS = getResource(DICT_FILENAME_SUFFIX);
+ // no buffering here, as we load in one large buffer
+ in = new InputStreamDataInput(dictIS);
+ CodecUtil.checkHeader(in, DICT_HEADER, VERSION, VERSION);
+ final int size = in.readVInt();
+ final ByteBuffer tmpBuffer = ByteBuffer.allocateDirect(size);
+ final ReadableByteChannel channel = Channels.newChannel(dictIS);
+ final int read = channel.read(tmpBuffer);
+ if (read != size) {
+ throw new EOFException("Cannot read whole dictionary");
+ }
+ dictIS.close(); dictIS = null;
+ buffer = tmpBuffer.asReadOnlyBuffer();
+ } catch (IOException ioe) {
+ priorE = ioe;
+ } finally {
+ IOUtils.closeWhileHandlingException(priorE, mapIS, posIS, inflIS, dictIS);
+ }
+
+ this.targetMap = targetMap;
+ this.targetMapOffsets = targetMapOffsets;
+ this.posDict = posDict;
+ this.inflTypeDict = inflTypeDict;
+ this.inflFormDict = inflFormDict;
+ this.buffer = buffer;
+ }
+
+ protected final InputStream getResource(String suffix) throws IOException {
+ return getClassResource(getClass(), suffix);
+ }
+
+ // util, reused by ConnectionCosts and CharacterDefinition
+ public static final InputStream getClassResource(Class<?> clazz, String suffix) throws IOException {
+ final InputStream is = clazz.getResourceAsStream(clazz.getSimpleName() + suffix);
+ if (is == null)
+ throw new FileNotFoundException("Not in classpath: " + clazz.getName().replace('.','/') + suffix);
+ return is;
+ }
+
+ public void lookupWordIds(int sourceId, IntsRef ref) {
+ ref.ints = targetMap;
+ ref.offset = targetMapOffsets[sourceId];
+ // targetMapOffsets always has one more entry pointing behind last:
+ ref.length = targetMapOffsets[sourceId + 1] - ref.offset;
+ }
+
+ @Override
+ public int getLeftId(int wordId) {
+ return buffer.getShort(wordId);
+ }
+
+ @Override
+ public int getRightId(int wordId) {
+ return buffer.getShort(wordId + 2); // Skip left id
+ }
+
+ @Override
+ public int getWordCost(int wordId) {
+ return buffer.getShort(wordId + 4); // Skip left id and right id
+ }
+
+ @Override
+ public String getBaseForm(int wordId) {
+ int offset = baseFormOffset(wordId);
+ int length = (buffer.get(offset++) & 0xff) >>> 1;
+ if (length == 0) {
+ return null; // same as surface form
+ } else {
+ return readString(offset, length, false);
+ }
+ }
+
+ @Override
+ public String getReading(int wordId) {
+ int offset = readingOffset(wordId);
+ int readingData = buffer.get(offset++) & 0xff;
+ return readString(offset, readingData >>> 1, (readingData & 1) == 1);
+ }
+
+ @Override
+ public String getPartOfSpeech(int wordId) {
+ int posIndex = buffer.get(posOffset(wordId)) & 0xff; // read index into posDict
+ return posDict[posIndex >>> 1];
+ }
+
+ @Override
+ public String getPronunciation(int wordId) {
+ if (hasPronunciationData(wordId)) {
+ int offset = pronunciationOffset(wordId);
+ int pronunciationData = buffer.get(offset++) & 0xff;
+ return readString(offset, pronunciationData >>> 1, (pronunciationData & 1) == 1);
+ } else {
+ return getReading(wordId); // same as the reading
+ }
+ }
+
+ @Override
+ public String getInflectionType(int wordId) {
+ int index = getInflectionIndex(wordId);
+ return index < 0 ? null : inflTypeDict[index];
+ }
+
+ @Override
+ public String getInflectionForm(int wordId) {
+ int index = getInflectionIndex(wordId);
+ return index < 0 ? null : inflFormDict[index];
+ }
+
+ private static int posOffset(int wordId) {
+ return wordId + 6;
+ }
+
+ private static int baseFormOffset(int wordId) {
+ return wordId + 7;
+ }
+
+ private int readingOffset(int wordId) {
+ int offset = baseFormOffset(wordId);
+ int baseFormLength = buffer.get(offset++) & 0xfe; // mask away pronunciation bit
+ return offset + baseFormLength;
+ }
+
+ private int pronunciationOffset(int wordId) {
+ int offset = readingOffset(wordId);
+ int readingData = buffer.get(offset++) & 0xff;
+ final int readingLength;
+ if ((readingData & 1) == 0) {
+ readingLength = readingData & 0xfe; // UTF-16: mask off kana bit
+ } else {
+ readingLength = readingData >>> 1;
+ }
+ return offset + readingLength;
+ }
+
+ private boolean hasPronunciationData(int wordId) {
+ int baseFormData = buffer.get(baseFormOffset(wordId)) & 0xff;
+ return (baseFormData & 1) == 0;
+ }
+
+ private boolean hasInflectionData(int wordId) {
+ int posData = buffer.get(posOffset(wordId)) & 0xff;
+ return (posData & 1) == 1;
+ }
+
+ private int getInflectionIndex(int wordId) {
+ if (!hasInflectionData(wordId)) {
+ return -1; // common case: no inflection data
+ }
+
+ // skip past reading/pronunciation at the end
+ int offset = hasPronunciationData(wordId) ? pronunciationOffset(wordId) : readingOffset(wordId);
+ int endData = buffer.get(offset++) & 0xff;
+
+ final int endLength;
+ if ((endData & 1) == 0) {
+ endLength = endData & 0xfe; // UTF-16: mask off kana bit
+ } else {
+ endLength = endData >>> 1;
+ }
+
+ offset += endLength;
+
+ byte b = buffer.get(offset++);
+ int i = b & 0x7F;
+ if ((b & 0x80) == 0) return i;
+ b = buffer.get(offset++);
+ i |= (b & 0x7F) << 7;
+ assert ((b & 0x80) == 0);
+ return i;
+ }
+
+ private String readString(int offset, int length, boolean kana) {
+ char text[] = new char[length];
+ if (kana) {
+ for (int i = 0; i < length; i++) {
+ text[i] = (char) (0x30A0 + (buffer.get(offset + i) & 0xff));
+ }
+ } else {
+ for (int i = 0; i < length; i++) {
+ text[i] = buffer.getChar(offset + (i << 1));
+ }
+ }
+ return new String(text);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/CharacterDefinition.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/CharacterDefinition.java
new file mode 100644
index 00000000000..f548a9dd5e0
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/CharacterDefinition.java
@@ -0,0 +1,117 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.InputStreamDataInput;
+import org.apache.lucene.util.CodecUtil;
+import org.apache.lucene.util.IOUtils;
+
+public final class CharacterDefinition {
+
+ public static final String FILENAME_SUFFIX = ".dat";
+ public static final String HEADER = "kuromoji_cd";
+ public static final int VERSION = 1;
+
+ public static final int CLASS_COUNT = CharacterClass.values().length;
+
+ // only used internally for lookup:
+ private static enum CharacterClass {
+ NGRAM, DEFAULT, SPACE, SYMBOL, NUMERIC, ALPHA, CYRILLIC, GREEK, HIRAGANA, KATAKANA, KANJI, KANJINUMERIC;
+ }
+
+ private final byte[] characterCategoryMap = new byte[0x10000];
+
+ private final boolean[] invokeMap = new boolean[CLASS_COUNT];
+ private final boolean[] groupMap = new boolean[CLASS_COUNT];
+
+ // the classes:
+ public static final byte NGRAM = (byte) CharacterClass.NGRAM.ordinal();
+ public static final byte DEFAULT = (byte) CharacterClass.DEFAULT.ordinal();
+ public static final byte SPACE = (byte) CharacterClass.SPACE.ordinal();
+ public static final byte SYMBOL = (byte) CharacterClass.SYMBOL.ordinal();
+ public static final byte NUMERIC = (byte) CharacterClass.NUMERIC.ordinal();
+ public static final byte ALPHA = (byte) CharacterClass.ALPHA.ordinal();
+ public static final byte CYRILLIC = (byte) CharacterClass.CYRILLIC.ordinal();
+ public static final byte GREEK = (byte) CharacterClass.GREEK.ordinal();
+ public static final byte HIRAGANA = (byte) CharacterClass.HIRAGANA.ordinal();
+ public static final byte KATAKANA = (byte) CharacterClass.KATAKANA.ordinal();
+ public static final byte KANJI = (byte) CharacterClass.KANJI.ordinal();
+ public static final byte KANJINUMERIC = (byte) CharacterClass.KANJINUMERIC.ordinal();
+
+ private CharacterDefinition() throws IOException {
+ IOException priorE = null;
+ InputStream is = null;
+ try {
+ is = BinaryDictionary.getClassResource(getClass(), FILENAME_SUFFIX);
+ is = new BufferedInputStream(is);
+ final DataInput in = new InputStreamDataInput(is);
+ CodecUtil.checkHeader(in, HEADER, VERSION, VERSION);
+ in.readBytes(characterCategoryMap, 0, characterCategoryMap.length);
+ for (int i = 0; i < CLASS_COUNT; i++) {
+ final byte b = in.readByte();
+ invokeMap[i] = (b & 0x01) != 0;
+ groupMap[i] = (b & 0x02) != 0;
+ }
+ } catch (IOException ioe) {
+ priorE = ioe;
+ } finally {
+ IOUtils.closeWhileHandlingException(priorE, is);
+ }
+ }
+
+ public byte getCharacterClass(char c) {
+ return characterCategoryMap[c];
+ }
+
+ public boolean isInvoke(char c) {
+ return invokeMap[characterCategoryMap[c]];
+ }
+
+ public boolean isGroup(char c) {
+ return groupMap[characterCategoryMap[c]];
+ }
+
+ public boolean isKanji(char c) {
+ final byte characterClass = characterCategoryMap[c];
+ return characterClass == KANJI || characterClass == KANJINUMERIC;
+ }
+
+ public static byte lookupCharacterClass(String characterClassName) {
+ return (byte) CharacterClass.valueOf(characterClassName).ordinal();
+ }
+
+ public static CharacterDefinition getInstance() {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder {
+ static final CharacterDefinition INSTANCE;
+ static {
+ try {
+ INSTANCE = new CharacterDefinition();
+ } catch (IOException ioe) {
+ throw new RuntimeException("Cannot load CharacterDefinition.", ioe);
+ }
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java
new file mode 100644
index 00000000000..55f56914c14
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java
@@ -0,0 +1,86 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.InputStreamDataInput;
+import org.apache.lucene.util.CodecUtil;
+import org.apache.lucene.util.IOUtils;
+
+public final class ConnectionCosts {
+
+ public static final String FILENAME_SUFFIX = ".dat";
+ public static final String HEADER = "kuromoji_cc";
+ public static final int VERSION = 1;
+
+ private final short[][] costs; // array is backward IDs first since get is called using the same backward ID consecutively. maybe doesn't matter.
+
+ private ConnectionCosts() throws IOException {
+ IOException priorE = null;
+ InputStream is = null;
+ short[][] costs = null;
+ try {
+ is = BinaryDictionary.getClassResource(getClass(), FILENAME_SUFFIX);
+ is = new BufferedInputStream(is);
+ final DataInput in = new InputStreamDataInput(is);
+ CodecUtil.checkHeader(in, HEADER, VERSION, VERSION);
+ int forwardSize = in.readVInt();
+ int backwardSize = in.readVInt();
+ costs = new short[backwardSize][forwardSize];
+ int accum = 0;
+ for (int j = 0; j < costs.length; j++) {
+ final short[] a = costs[j];
+ for (int i = 0; i < a.length; i++) {
+ int raw = in.readVInt();
+ accum += (raw >>> 1) ^ -(raw & 1);
+ a[i] = (short)accum;
+ }
+ }
+ } catch (IOException ioe) {
+ priorE = ioe;
+ } finally {
+ IOUtils.closeWhileHandlingException(priorE, is);
+ }
+
+ this.costs = costs;
+ }
+
+ public int get(int forwardId, int backwardId) {
+ return costs[backwardId][forwardId];
+ }
+
+ public static ConnectionCosts getInstance() {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder {
+ static final ConnectionCosts INSTANCE;
+ static {
+ try {
+ INSTANCE = new ConnectionCosts();
+ } catch (IOException ioe) {
+ throw new RuntimeException("Cannot load ConnectionCosts.", ioe);
+ }
+ }
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/Dictionary.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/Dictionary.java
new file mode 100644
index 00000000000..2e87b428f33
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/Dictionary.java
@@ -0,0 +1,88 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface Dictionary {
+
+ public static final String INTERNAL_SEPARATOR = "\u0000";
+
+ /**
+ * Get left id of specified word
+ * @param wordId
+ * @return left id
+ */
+ public int getLeftId(int wordId);
+
+ /**
+ * Get right id of specified word
+ * @param wordId
+ * @return left id
+ */
+ public int getRightId(int wordId);
+
+ /**
+ * Get word cost of specified word
+ * @param wordId
+ * @return left id
+ */
+ public int getWordCost(int wordId);
+
+ /**
+ * Get Part-Of-Speech of tokens
+ * @param wordId word ID of token
+ * @return Part-Of-Speech of the token
+ */
+ public String getPartOfSpeech(int wordId);
+
+ /**
+ * Get reading of tokens
+ * @param wordId word ID of token
+ * @return Reading of the token
+ */
+ public String getReading(int wordId);
+
+ /**
+ * Get base form of word
+ * @param wordId word ID of token
+ * @return Base form (only different for inflected words, otherwise null)
+ */
+ public String getBaseForm(int wordId);
+
+ /**
+ * Get pronunciation of tokens
+ * @param wordId word ID of token
+ * @return Pronunciation of the token
+ */
+ public String getPronunciation(int wordId);
+
+ /**
+ * Get inflection type of tokens
+ * @param wordId word ID of token
+ * @return inflection type, or null
+ */
+ public String getInflectionType(int wordId);
+
+ /**
+ * Get inflection form of tokens
+ * @param wordId word ID of token
+ * @return inflection form, or null
+ */
+ public String getInflectionForm(int wordId);
+ // TODO: maybe we should have a optimal method, a non-typesafe
+ // 'getAdditionalData' if other dictionaries like unidic have additional data
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java
new file mode 100644
index 00000000000..68075072ed7
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java
@@ -0,0 +1,72 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.lucene.store.InputStreamDataInput;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.PositiveIntOutputs;
+
+public final class TokenInfoDictionary extends BinaryDictionary {
+
+ public static final String FST_FILENAME_SUFFIX = "$fst.dat";
+
+ private final TokenInfoFST fst;
+
+ private TokenInfoDictionary() throws IOException {
+ super();
+ IOException priorE = null;
+ InputStream is = null;
+ FST<Long> fst = null;
+ try {
+ is = getResource(FST_FILENAME_SUFFIX);
+ is = new BufferedInputStream(is);
+ fst = new FST<Long>(new InputStreamDataInput(is), PositiveIntOutputs.getSingleton(true));
+ } catch (IOException ioe) {
+ priorE = ioe;
+ } finally {
+ IOUtils.closeWhileHandlingException(priorE, is);
+ }
+ // TODO: some way to configure?
+ this.fst = new TokenInfoFST(fst, true);
+ }
+
+ public TokenInfoFST getFST() {
+ return fst;
+ }
+
+ public static TokenInfoDictionary getInstance() {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder {
+ static final TokenInfoDictionary INSTANCE;
+ static {
+ try {
+ INSTANCE = new TokenInfoDictionary();
+ } catch (IOException ioe) {
+ throw new RuntimeException("Cannot load TokenInfoDictionary.", ioe);
+ }
+ }
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoFST.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoFST.java
new file mode 100644
index 00000000000..0ee9786ffbe
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoFST.java
@@ -0,0 +1,82 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FST.Arc;
+
+public final class TokenInfoFST {
+ private final FST<Long> fst;
+
+ // depending upon fasterButMoreRam, we cache root arcs for either
+ // kana (0x3040-0x30FF) or kana + han (0x3040-0x9FFF)
+ // false: 191 arcs
+ // true: 28,607 arcs (costs ~1.5MB)
+ private final int cacheCeiling;
+ private final FST.Arc<Long> rootCache[];
+
+ public final Long NO_OUTPUT;
+
+ public TokenInfoFST(FST<Long> fst, boolean fasterButMoreRam) throws IOException {
+ this.fst = fst;
+ this.cacheCeiling = fasterButMoreRam ? 0x9FFF : 0x30FF;
+ NO_OUTPUT = fst.outputs.getNoOutput();
+ rootCache = cacheRootArcs();
+ }
+
+ @SuppressWarnings("unchecked")
+ private FST.Arc<Long>[] cacheRootArcs() throws IOException {
+ FST.Arc<Long> rootCache[] = new FST.Arc[1+(cacheCeiling-0x3040)];
+ FST.Arc<Long> firstArc = new FST.Arc<Long>();
+ fst.getFirstArc(firstArc);
+ FST.Arc<Long> arc = new FST.Arc<Long>();
+ // TODO: jump to 3040, readNextRealArc to ceiling? (just be careful we don't add bugs)
+ for (int i = 0; i < rootCache.length; i++) {
+ if (fst.findTargetArc(0x3040 + i, firstArc, arc) != null) {
+ rootCache[i] = new FST.Arc<Long>().copyFrom(arc);
+ }
+ }
+ return rootCache;
+ }
+
+ public FST.Arc<Long> findTargetArc(int ch, FST.Arc<Long> follow, FST.Arc<Long> arc, boolean useCache) throws IOException {
+ if (useCache && ch >= 0x3040 && ch <= cacheCeiling) {
+ assert ch != FST.END_LABEL;
+ final Arc<Long> result = rootCache[ch - 0x3040];
+ if (result == null) {
+ return null;
+ } else {
+ arc.copyFrom(result);
+ return arc;
+ }
+ } else {
+ return fst.findTargetArc(ch, follow, arc);
+ }
+ }
+
+ public Arc<Long> getFirstArc(FST.Arc<Long> arc) {
+ return fst.getFirstArc(arc);
+ }
+
+ /** @lucene.internal for testing only */
+ FST<Long> getInternalFST() {
+ return fst;
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary.java
new file mode 100644
index 00000000000..0692f3e6b12
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary.java
@@ -0,0 +1,83 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+public final class UnknownDictionary extends BinaryDictionary {
+
+ private final CharacterDefinition characterDefinition = CharacterDefinition.getInstance();
+
+ private UnknownDictionary() throws IOException {
+ super();
+ }
+
+ public int lookup(char[] text, int offset, int len) {
+ if(!characterDefinition.isGroup(text[offset])) {
+ return 1;
+ }
+
+ // Extract unknown word. Characters with the same character class are considered to be part of unknown word
+ byte characterIdOfFirstCharacter = characterDefinition.getCharacterClass(text[offset]);
+ int length = 1;
+ for (int i = 1; i < len; i++) {
+ if (characterIdOfFirstCharacter == characterDefinition.getCharacterClass(text[offset+i])){
+ length++;
+ } else {
+ break;
+ }
+ }
+
+ return length;
+ }
+
+ public CharacterDefinition getCharacterDefinition() {
+ return characterDefinition;
+ }
+
+ @Override
+ public String getReading(int wordId) {
+ return null;
+ }
+
+ @Override
+ public String getInflectionType(int wordId) {
+ return null;
+ }
+
+ @Override
+ public String getInflectionForm(int wordId) {
+ return null;
+ }
+
+ public static UnknownDictionary getInstance() {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder {
+ static final UnknownDictionary INSTANCE;
+ static {
+ try {
+ INSTANCE = new UnknownDictionary();
+ } catch (IOException ioe) {
+ throw new RuntimeException("Cannot load UnknownDictionary.", ioe);
+ }
+ }
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java
new file mode 100644
index 00000000000..83fa5be31ad
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java
@@ -0,0 +1,258 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.lucene.analysis.kuromoji.util.CSVUtil;
+import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.fst.Builder;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.PositiveIntOutputs;
+
+public final class UserDictionary implements Dictionary {
+
+ // phrase text -> phrase ID
+ private final TokenInfoFST fst;
+
+ // holds wordid, length, length... indexed by phrase ID
+ private final int segmentations[][];
+
+ // holds readings and POS, indexed by wordid
+ private final String data[];
+
+ private static final int CUSTOM_DICTIONARY_WORD_ID_OFFSET = 100000000;
+
+ public static final int WORD_COST = -100000;
+
+ public static final int LEFT_ID = 5;
+
+ public static final int RIGHT_ID = 5;
+
+ public UserDictionary(Reader reader) throws IOException {
+ BufferedReader br = new BufferedReader(reader);
+ String line = null;
+ int wordId = CUSTOM_DICTIONARY_WORD_ID_OFFSET;
+ List<String[]> featureEntries = new ArrayList<String[]>();
+
+ // text, segmentation, readings, POS
+ while ((line = br.readLine()) != null) {
+ // Remove comments
+ line = line.replaceAll("#.*$", "");
+
+ // Skip empty lines or comment lines
+ if (line.trim().length() == 0) {
+ continue;
+ }
+ String[] values = CSVUtil.parse(line);
+ featureEntries.add(values);
+ }
+
+ // TODO: should we allow multiple segmentations per input 'phrase'?
+ // the old treemap didn't support this either, and i'm not sure if its needed/useful?
+
+ Collections.sort(featureEntries, new Comparator<String[]>() {
+ @Override
+ public int compare(String[] left, String[] right) {
+ return left[0].compareTo(right[0]);
+ }
+ });
+
+ List<String> data = new ArrayList<String>(featureEntries.size());
+ List<int[]> segmentations = new ArrayList<int[]>(featureEntries.size());
+
+ PositiveIntOutputs fstOutput = PositiveIntOutputs.getSingleton(true);
+ Builder<Long> fstBuilder = new Builder<Long>(FST.INPUT_TYPE.BYTE2, fstOutput);
+ IntsRef scratch = new IntsRef();
+ long ord = 0;
+
+ for (String[] values : featureEntries) {
+ String[] segmentation = values[1].replaceAll(" *", " ").split(" ");
+ String[] readings = values[2].replaceAll(" *", " ").split(" ");
+ String pos = values[3];
+
+ if (segmentation.length != readings.length) {
+ // FIXME: Should probably deal with this differently. Exception?
+ System.out.println("This entry is not properly formatted : " + line);
+ }
+
+ int[] wordIdAndLength = new int[segmentation.length + 1]; // wordId offset, length, length....
+ wordIdAndLength[0] = wordId;
+ for (int i = 0; i < segmentation.length; i++) {
+ wordIdAndLength[i + 1] = segmentation[i].length();
+ data.add(readings[i] + INTERNAL_SEPARATOR + pos);
+ wordId++;
+ }
+ // add mapping to FST
+ String token = values[0];
+ scratch.grow(token.length());
+ scratch.length = token.length();
+ for (int i = 0; i < token.length(); i++) {
+ scratch.ints[i] = (int) token.charAt(i);
+ }
+ fstBuilder.add(scratch, fstOutput.get(ord));
+ segmentations.add(wordIdAndLength);
+ ord++;
+ }
+ this.fst = new TokenInfoFST(fstBuilder.finish(), false);
+ this.data = data.toArray(new String[data.size()]);
+ this.segmentations = segmentations.toArray(new int[segmentations.size()][]);
+ }
+
+ /**
+ * Lookup words in text
+ * @param chars text
+ * @param off offset into text
+ * @param len length of text
+ * @return array of {wordId, position, length}
+ */
+ public int[][] lookup(char[] chars, int off, int len) throws IOException {
+ // TODO: can we avoid this treemap/toIndexArray?
+ TreeMap<Integer, int[]> result = new TreeMap<Integer, int[]>(); // index, [length, length...]
+ boolean found = false; // true if we found any results
+
+ FST.Arc<Long> arc = new FST.Arc<Long>();
+ int end = off + len;
+ for (int startOffset = off; startOffset < end; startOffset++) {
+ arc = fst.getFirstArc(arc);
+ int output = 0;
+ int remaining = end - startOffset;
+ for (int i = 0; i < remaining; i++) {
+ int ch = chars[startOffset+i];
+ if (fst.findTargetArc(ch, arc, arc, i == 0) == null) {
+ break; // continue to next position
+ }
+ output += arc.output.intValue();
+ if (arc.isFinal()) {
+ output += arc.nextFinalOutput.intValue();
+ result.put(startOffset-off, segmentations[output]);
+ found = true;
+ }
+ }
+ }
+
+ return found ? toIndexArray(result) : EMPTY_RESULT;
+ }
+
+ private static final int[][] EMPTY_RESULT = new int[0][];
+
+ /**
+ * Convert Map of index and wordIdAndLength to array of {wordId, index, length}
+ * @param input
+ * @return array of {wordId, index, length}
+ */
+ private int[][] toIndexArray(Map<Integer, int[]> input) {
+ ArrayList<int[]> result = new ArrayList<int[]>();
+ for (int i : input.keySet()) {
+ int[] wordIdAndLength = input.get(i);
+ int wordId = wordIdAndLength[0];
+ // convert length to index
+ int current = i;
+ for (int j = 1; j < wordIdAndLength.length; j++) { // first entry is wordId offset
+ int[] token = { wordId + j - 1, current, wordIdAndLength[j] };
+ result.add(token);
+ current += wordIdAndLength[j];
+ }
+ }
+ return result.toArray(new int[result.size()][]);
+ }
+
+ @Override
+ public int getLeftId(int wordId) {
+ return LEFT_ID;
+ }
+
+ @Override
+ public int getRightId(int wordId) {
+ return RIGHT_ID;
+ }
+
+ @Override
+ public int getWordCost(int wordId) {
+ return WORD_COST;
+ }
+
+ @Override
+ public String getReading(int wordId) {
+ return getFeature(wordId, 0);
+ }
+
+ @Override
+ public String getPartOfSpeech(int wordId) {
+ return getFeature(wordId, 1);
+ }
+
+ @Override
+ public String getBaseForm(int wordId) {
+ return null; // TODO: add support?
+ }
+
+ @Override
+ public String getPronunciation(int wordId) {
+ return null; // TODO: add support?
+ }
+
+ @Override
+ public String getInflectionType(int wordId) {
+ return null; // TODO: add support?
+ }
+
+ @Override
+ public String getInflectionForm(int wordId) {
+ return null; // TODO: add support?
+ }
+
+ private String[] getAllFeaturesArray(int wordId) {
+ String allFeatures = data[wordId-CUSTOM_DICTIONARY_WORD_ID_OFFSET];
+ if(allFeatures == null) {
+ return null;
+ }
+
+ return allFeatures.split(INTERNAL_SEPARATOR);
+ }
+
+
+ private String getFeature(int wordId, int... fields) {
+ String[] allFeatures = getAllFeaturesArray(wordId);
+ if (allFeatures == null) {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ if (fields.length == 0) { // All features
+ for (String feature : allFeatures) {
+ sb.append(CSVUtil.quoteEscape(feature)).append(",");
+ }
+ } else if (fields.length == 1) { // One feature doesn't need to escape value
+ sb.append(allFeatures[fields[0]]).append(",");
+ } else {
+ for (int field : fields){
+ sb.append(CSVUtil.quoteEscape(allFeatures[field])).append(",");
+ }
+ }
+ return sb.deleteCharAt(sb.length() - 1).toString();
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/BaseFormAttribute.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/BaseFormAttribute.java
new file mode 100644
index 00000000000..ee2445983ab
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/BaseFormAttribute.java
@@ -0,0 +1,32 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.util.Attribute;
+
+/**
+ * Attribute for {@link Token#getBaseForm()}.
+ * <p>
+ * Note: depending on part of speech, this value may not be applicable,
+ * and will be null.
+ */
+public interface BaseFormAttribute extends Attribute {
+ public String getBaseForm();
+ public void setToken(Token token);
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/BaseFormAttributeImpl.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/BaseFormAttributeImpl.java
new file mode 100644
index 00000000000..e090f7ab1ba
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/BaseFormAttributeImpl.java
@@ -0,0 +1,50 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.util.AttributeImpl;
+import org.apache.lucene.util.AttributeReflector;
+
+public class BaseFormAttributeImpl extends AttributeImpl implements BaseFormAttribute, Cloneable {
+ private Token token;
+
+ public String getBaseForm() {
+ return token == null ? null : token.getBaseForm();
+ }
+
+ public void setToken(Token token) {
+ this.token = token;
+ }
+
+ @Override
+ public void clear() {
+ token = null;
+ }
+
+ @Override
+ public void copyTo(AttributeImpl target) {
+ BaseFormAttribute t = (BaseFormAttribute) target;
+ t.setToken(token);
+ }
+
+ @Override
+ public void reflectWith(AttributeReflector reflector) {
+ reflector.reflect(BaseFormAttribute.class, "baseForm", getBaseForm());
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/InflectionAttribute.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/InflectionAttribute.java
new file mode 100644
index 00000000000..3205db04f75
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/InflectionAttribute.java
@@ -0,0 +1,33 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.util.Attribute;
+
+/**
+ * Attribute for Kuromoji inflection data.
+ * <p>
+ * Note: in some cases this value may not be applicable,
+ * and will be null.
+ */
+public interface InflectionAttribute extends Attribute {
+ public String getInflectionType();
+ public String getInflectionForm();
+ public void setToken(Token token);
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/InflectionAttributeImpl.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/InflectionAttributeImpl.java
new file mode 100644
index 00000000000..9c9bd9675d7
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/InflectionAttributeImpl.java
@@ -0,0 +1,62 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.analysis.kuromoji.util.ToStringUtil;
+import org.apache.lucene.util.AttributeImpl;
+import org.apache.lucene.util.AttributeReflector;
+
+public class InflectionAttributeImpl extends AttributeImpl implements InflectionAttribute, Cloneable {
+ private Token token;
+
+ public String getInflectionType() {
+ return token == null ? null : token.getInflectionType();
+ }
+
+ public String getInflectionForm() {
+ return token == null ? null : token.getInflectionForm();
+ }
+
+ public void setToken(Token token) {
+ this.token = token;
+ }
+
+ @Override
+ public void clear() {
+ token = null;
+ }
+
+ @Override
+ public void copyTo(AttributeImpl target) {
+ InflectionAttribute t = (InflectionAttribute) target;
+ t.setToken(token);
+ }
+
+ @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);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/PartOfSpeechAttribute.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/PartOfSpeechAttribute.java
new file mode 100644
index 00000000000..3f040d01e7f
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/PartOfSpeechAttribute.java
@@ -0,0 +1,29 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.util.Attribute;
+
+/**
+ * Attribute for {@link Token#getPartOfSpeech()}.
+ */
+public interface PartOfSpeechAttribute extends Attribute {
+ public String getPartOfSpeech();
+ public void setToken(Token token);
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/PartOfSpeechAttributeImpl.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/PartOfSpeechAttributeImpl.java
new file mode 100644
index 00000000000..e83578fe834
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/PartOfSpeechAttributeImpl.java
@@ -0,0 +1,54 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.analysis.kuromoji.util.ToStringUtil;
+import org.apache.lucene.util.AttributeImpl;
+import org.apache.lucene.util.AttributeReflector;
+
+public class PartOfSpeechAttributeImpl extends AttributeImpl implements PartOfSpeechAttribute, Cloneable {
+ private Token token;
+
+ public String getPartOfSpeech() {
+ return token == null ? null : token.getPartOfSpeech();
+ }
+
+ public void setToken(Token token) {
+ this.token = token;
+ }
+
+ @Override
+ public void clear() {
+ token = null;
+ }
+
+ @Override
+ public void copyTo(AttributeImpl target) {
+ PartOfSpeechAttribute t = (PartOfSpeechAttribute) target;
+ t.setToken(token);
+ }
+
+ @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);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/ReadingAttribute.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/ReadingAttribute.java
new file mode 100644
index 00000000000..8bda4f1e12a
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/ReadingAttribute.java
@@ -0,0 +1,33 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.util.Attribute;
+
+/**
+ * Attribute for Kuromoji reading data
+ * <p>
+ * Note: in some cases this value may not be applicable,
+ * and will be null.
+ */
+public interface ReadingAttribute extends Attribute {
+ public String getReading();
+ public String getPronunciation();
+ public void setToken(Token token);
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/ReadingAttributeImpl.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/ReadingAttributeImpl.java
new file mode 100644
index 00000000000..8bc998a267e
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/tokenattributes/ReadingAttributeImpl.java
@@ -0,0 +1,62 @@
+package org.apache.lucene.analysis.kuromoji.tokenattributes;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.Token;
+import org.apache.lucene.analysis.kuromoji.util.ToStringUtil;
+import org.apache.lucene.util.AttributeImpl;
+import org.apache.lucene.util.AttributeReflector;
+
+public class ReadingAttributeImpl extends AttributeImpl implements ReadingAttribute, Cloneable {
+ private Token token;
+
+ public String getReading() {
+ return token == null ? null : token.getReading();
+ }
+
+ public String getPronunciation() {
+ return token == null ? null : token.getPronunciation();
+ }
+
+ public void setToken(Token token) {
+ this.token = token;
+ }
+
+ @Override
+ public void clear() {
+ token = null;
+ }
+
+ @Override
+ public void copyTo(AttributeImpl target) {
+ ReadingAttribute t = (ReadingAttribute) target;
+ t.setToken(token);
+ }
+
+ @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);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/util/CSVUtil.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/util/CSVUtil.java
new file mode 100644
index 00000000000..f0ee6ef8cef
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/util/CSVUtil.java
@@ -0,0 +1,102 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public final class CSVUtil {
+ private static final char QUOTE = '"';
+
+ private static final char COMMA = ',';
+
+ private static final Pattern QUOTE_REPLACE_PATTERN = Pattern.compile("^\"([^\"]+)\"$");
+
+ private static final String ESCAPED_QUOTE = "\"\"";
+
+ private CSVUtil() {} // no instance!!!
+
+ /**
+ * Parse CSV line
+ * @param line
+ * @return Array of values
+ */
+ public static String[] parse(String line) {
+ boolean insideQuote = false;
+ ArrayList<String> result = new ArrayList<String>();
+ int quoteCount = 0;
+ StringBuilder sb = new StringBuilder();
+ for(int i = 0; i < line.length(); i++) {
+ char c = line.charAt(i);
+
+ if(c == QUOTE) {
+ insideQuote = !insideQuote;
+ quoteCount++;
+ }
+
+ if(c == COMMA && !insideQuote) {
+ String value = sb.toString();
+ value = unQuoteUnEscape(value);
+ result.add(value);
+ sb = new StringBuilder();
+ continue;
+ }
+
+ sb.append(c);
+ }
+
+ result.add(sb.toString());
+
+ // Validate
+ if(quoteCount % 2 != 0) {
+ return new String[0];
+ }
+
+ return result.toArray(new String[result.size()]);
+ }
+
+ private static String unQuoteUnEscape(String original) {
+ String result = original;
+
+ // Unquote
+ Matcher m = QUOTE_REPLACE_PATTERN.matcher(original);
+ if(m.matches()) {
+ result = m.group(1);
+ }
+
+ // Unescape
+ result = result.replaceAll(ESCAPED_QUOTE, "\"");
+
+ return result;
+
+ }
+
+ /**
+ * Quote and escape input value for CSV
+ * @param original
+ */
+ public static String quoteEscape(String original) {
+ String result = original.replaceAll("\"", ESCAPED_QUOTE);
+ if(result.indexOf(COMMA) >= 0) {
+ result = "\"" + result + "\"";
+ }
+ return result;
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/util/ToStringUtil.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/util/ToStringUtil.java
new file mode 100644
index 00000000000..7d2e792cb99
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/util/ToStringUtil.java
@@ -0,0 +1,1023 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+
+public class ToStringUtil {
+ // a translation map for parts of speech, only used for reflectWith
+ private static final HashMap<String,String> posTranslations = new HashMap<String,String>();
+ static {
+ posTranslations.put("名詞", "noun");
+ posTranslations.put("名詞-一般", "noun-common");
+ posTranslations.put("名詞-固有名詞", "noun-proper");
+ posTranslations.put("名詞-固有名詞-一般", "noun-proper-misc");
+ posTranslations.put("名詞-固有名詞-人名", "noun-proper-person");
+ posTranslations.put("名詞-固有名詞-人名-一般", "noun-proper-person-misc");
+ posTranslations.put("名詞-固有名詞-人名-姓", "noun-proper-person-surname");
+ posTranslations.put("名詞-固有名詞-人名-名", "noun-proper-person-given_name");
+ posTranslations.put("名詞-固有名詞-組織", "noun-proper-organization");
+ posTranslations.put("名詞-固有名詞-地域", "noun-proper-place");
+ posTranslations.put("名詞-固有名詞-地域-一般", "noun-proper-place-misc");
+ posTranslations.put("名詞-固有名詞-地域-国", "noun-proper-place-country");
+ posTranslations.put("名詞-代名詞", "noun-pronoun");
+ posTranslations.put("名詞-代名詞-一般", "noun-pronoun-misc");
+ posTranslations.put("名詞-代名詞-縮約", "noun-pronoun-contraction");
+ posTranslations.put("名詞-副詞可能", "noun-adverbial");
+ posTranslations.put("名詞-サ変接続", "noun-verbal");
+ posTranslations.put("名詞-形容動詞語幹", "noun-adjective-base");
+ posTranslations.put("名詞-数", "noun-numeric");
+ posTranslations.put("名詞-非自立", "noun-affix");
+ posTranslations.put("名詞-非自立-一般", "noun-affix-misc");
+ posTranslations.put("名詞-非自立-副詞可能", "noun-affix-adverbial");
+ posTranslations.put("名詞-非自立-助動詞語幹", "noun-affix-aux");
+ posTranslations.put("名詞-非自立-形容動詞語幹", "noun-affix-adjective-base");
+ posTranslations.put("名詞-特殊", "noun-special");
+ posTranslations.put("名詞-特殊-助動詞語幹", "noun-special-aux");
+ posTranslations.put("名詞-接尾", "noun-suffix");
+ posTranslations.put("名詞-接尾-一般", "noun-suffix-misc");
+ posTranslations.put("名詞-接尾-人名", "noun-suffix-person");
+ posTranslations.put("名詞-接尾-地域", "noun-suffix-place");
+ posTranslations.put("名詞-接尾-サ変接続", "noun-suffix-verbal");
+ posTranslations.put("名詞-接尾-助動詞語幹", "noun-suffix-aux");
+ posTranslations.put("名詞-接尾-形容動詞語幹", "noun-suffix-adjective-base");
+ posTranslations.put("名詞-接尾-副詞可能", "noun-suffix-adverbial");
+ posTranslations.put("名詞-接尾-助数詞", "noun-suffix-classifier");
+ posTranslations.put("名詞-接尾-特殊", "noun-suffix-special");
+ posTranslations.put("名詞-接続詞的", "noun-suffix-conjunctive");
+ posTranslations.put("名詞-動詞非自立的", "noun-verbal_aux");
+ posTranslations.put("名詞-引用文字列", "noun-quotation");
+ posTranslations.put("名詞-ナイ形容詞語幹", "noun-nai_adjective");
+ posTranslations.put("接頭詞", "prefix");
+ posTranslations.put("接頭詞-名詞接続", "prefix-nominal");
+ posTranslations.put("接頭詞-動詞接続", "prefix-verbal");
+ posTranslations.put("接頭詞-形容詞接続", "prefix-adjectival");
+ posTranslations.put("接頭詞-数接続", "prefix-numerical");
+ posTranslations.put("動詞", "verb");
+ posTranslations.put("動詞-自立", "verb-main");
+ posTranslations.put("動詞-非自立", "verb-auxiliary");
+ posTranslations.put("動詞-接尾", "verb-suffix");
+ posTranslations.put("形容詞", "adjective");
+ posTranslations.put("形容詞-自立", "adjective-main");
+ posTranslations.put("形容詞-非自立", "adjective-auxiliary");
+ posTranslations.put("形容詞-接尾", "adjective-suffix");
+ posTranslations.put("副詞", "adverb");
+ posTranslations.put("副詞-一般", "adverb-misc");
+ posTranslations.put("副詞-助詞類接続", "adverb-particle_conjunction");
+ posTranslations.put("連体詞", "adnominal");
+ posTranslations.put("接続詞", "conjunction");
+ posTranslations.put("助詞", "particle");
+ posTranslations.put("助詞-格助詞", "particle-case");
+ posTranslations.put("助詞-格助詞-一般", "particle-case-misc");
+ posTranslations.put("助詞-格助詞-引用", "particle-case-quote");
+ posTranslations.put("助詞-格助詞-連語", "particle-case-compound");
+ posTranslations.put("助詞-接続助詞", "particle-conjunctive");
+ posTranslations.put("助詞-係助詞", "particle-dependency");
+ posTranslations.put("助詞-副助詞", "particle-adverbial");
+ posTranslations.put("助詞-間投助詞", "particle-interjective");
+ posTranslations.put("助詞-並立助詞", "particle-coordinate");
+ posTranslations.put("助詞-終助詞", "particle-final");
+ posTranslations.put("助詞-副助詞/並立助詞/終助詞", "particle-adverbial/conjunctive/final");
+ posTranslations.put("助詞-連体化", "particle-adnominalizer");
+ posTranslations.put("助詞-副詞化", "particle-adnominalizer");
+ posTranslations.put("助詞-特殊", "particle-special");
+ posTranslations.put("助動詞", "auxiliary-verb");
+ posTranslations.put("感動詞", "interjection");
+ posTranslations.put("記号", "symbol");
+ posTranslations.put("記号-一般", "symbol-misc");
+ posTranslations.put("記号-句点", "symbol-period");
+ posTranslations.put("記号-読点", "symbol-comma");
+ posTranslations.put("記号-空白", "symbol-space");
+ posTranslations.put("記号-括弧開", "symbol-open_bracket");
+ posTranslations.put("記号-括弧閉", "symbol-close_bracket");
+ posTranslations.put("記号-アルファベット", "symbol-alphabetic");
+ posTranslations.put("その他", "other");
+ posTranslations.put("その他-間投", "other-interjection");
+ posTranslations.put("フィラー", "filler");
+ posTranslations.put("非言語音", "non-verbal");
+ posTranslations.put("語断片", "fragment");
+ posTranslations.put("未知語", "unknown");
+ }
+
+ /**
+ * Get the english form of a POS tag
+ */
+ public static String getPOSTranslation(String s) {
+ return posTranslations.get(s);
+ }
+
+ // a translation map for inflection types, only used for reflectWith
+ private static final HashMap<String,String> inflTypeTranslations = new HashMap<String,String>();
+ static {
+ inflTypeTranslations.put("*", "*");
+ inflTypeTranslations.put("形容詞・アウオ段", "adj-group-a-o-u");
+ inflTypeTranslations.put("形容詞・イ段", "adj-group-i");
+ inflTypeTranslations.put("形容詞・イイ", "adj-group-ii");
+ inflTypeTranslations.put("不変化型", "non-inflectional");
+ inflTypeTranslations.put("特殊・タ", "special-da");
+ inflTypeTranslations.put("特殊・ダ", "special-ta");
+ inflTypeTranslations.put("文語・ゴトシ", "classical-gotoshi");
+ inflTypeTranslations.put("特殊・ジャ", "special-ja");
+ inflTypeTranslations.put("特殊・ナイ", "special-nai");
+ inflTypeTranslations.put("五段・ラ行特殊", "5-row-cons-r-special");
+ inflTypeTranslations.put("特殊・ヌ", "special-nu");
+ inflTypeTranslations.put("文語・キ", "classical-ki");
+ inflTypeTranslations.put("特殊・タイ", "special-tai");
+ inflTypeTranslations.put("文語・ベシ", "classical-beshi");
+ inflTypeTranslations.put("特殊・ヤ", "special-ya");
+ inflTypeTranslations.put("文語・マジ", "classical-maji");
+ inflTypeTranslations.put("下二・タ行", "2-row-lower-cons-t");
+ inflTypeTranslations.put("特殊・デス", "special-desu");
+ inflTypeTranslations.put("特殊・マス", "special-masu");
+ inflTypeTranslations.put("五段・ラ行アル", "5-row-aru");
+ inflTypeTranslations.put("文語・ナリ", "classical-nari");
+ inflTypeTranslations.put("文語・リ", "classical-ri");
+ inflTypeTranslations.put("文語・ケリ", "classical-keri");
+ inflTypeTranslations.put("文語・ル", "classical-ru");
+ inflTypeTranslations.put("五段・カ行イ音便", "5-row-cons-k-i-onbin");
+ inflTypeTranslations.put("五段・サ行", "5-row-cons-s");
+ inflTypeTranslations.put("一段", "1-row");
+ inflTypeTranslations.put("五段・ワ行促音便", "5-row-cons-w-cons-onbin");
+ inflTypeTranslations.put("五段・マ行", "5-row-cons-m");
+ inflTypeTranslations.put("五段・タ行", "5-row-cons-t");
+ inflTypeTranslations.put("五段・ラ行", "5-row-cons-r");
+ inflTypeTranslations.put("サ変・−スル", "irregular-suffix-suru");
+ inflTypeTranslations.put("五段・ガ行", "5-row-cons-g");
+ inflTypeTranslations.put("サ変・−ズル", "irregular-suffix-zuru");
+ inflTypeTranslations.put("五段・バ行", "5-row-cons-b");
+ inflTypeTranslations.put("五段・ワ行ウ音便", "5-row-cons-w-u-onbin");
+ inflTypeTranslations.put("下二・ダ行", "2-row-lower-cons-d");
+ inflTypeTranslations.put("五段・カ行促音便ユク", "5-row-cons-k-cons-onbin-yuku");
+ inflTypeTranslations.put("上二・ダ行", "2-row-upper-cons-d");
+ inflTypeTranslations.put("五段・カ行促音便", "5-row-cons-k-cons-onbin");
+ inflTypeTranslations.put("一段・得ル", "1-row-eru");
+ inflTypeTranslations.put("四段・タ行", "4-row-cons-t");
+ inflTypeTranslations.put("五段・ナ行", "5-row-cons-n");
+ inflTypeTranslations.put("下二・ハ行", "2-row-lower-cons-h");
+ inflTypeTranslations.put("四段・ハ行", "4-row-cons-h");
+ inflTypeTranslations.put("四段・バ行", "4-row-cons-b");
+ inflTypeTranslations.put("サ変・スル", "irregular-suru");
+ inflTypeTranslations.put("上二・ハ行", "2-row-upper-cons-h");
+ inflTypeTranslations.put("下二・マ行", "2-row-lower-cons-m");
+ inflTypeTranslations.put("四段・サ行", "4-row-cons-s");
+ inflTypeTranslations.put("下二・ガ行", "2-row-lower-cons-g");
+ inflTypeTranslations.put("カ変・来ル", "kuru-kanji");
+ inflTypeTranslations.put("一段・クレル", "1-row-kureru");
+ inflTypeTranslations.put("下二・得", "2-row-lower-u");
+ inflTypeTranslations.put("カ変・クル", "kuru-kana");
+ inflTypeTranslations.put("ラ変", "irregular-cons-r");
+ inflTypeTranslations.put("下二・カ行", "2-row-lower-cons-k");
+ }
+
+ /**
+ * Get the english form of inflection type
+ */
+ public static String getInflectionTypeTranslation(String s) {
+ return inflTypeTranslations.get(s);
+ }
+
+ // a translation map for inflection forms, only used for reflectWith
+ private static final HashMap<String,String> inflFormTranslations = new HashMap<String,String>();
+ static {
+ inflFormTranslations.put("*", "*");
+ inflFormTranslations.put("基本形", "base");
+ inflFormTranslations.put("文語基本形", "classical-base");
+ inflFormTranslations.put("未然ヌ接続", "imperfective-nu-connection");
+ inflFormTranslations.put("未然ウ接続", "imperfective-u-connection");
+ inflFormTranslations.put("連用タ接続", "conjunctive-ta-connection");
+ inflFormTranslations.put("連用テ接続", "conjunctive-te-connection");
+ inflFormTranslations.put("連用ゴザイ接続", "conjunctive-gozai-connection");
+ inflFormTranslations.put("体言接続", "uninflected-connection");
+ inflFormTranslations.put("仮定形", "subjunctive");
+ inflFormTranslations.put("命令e", "imperative-e");
+ inflFormTranslations.put("仮定縮約1", "conditional-contracted-1");
+ inflFormTranslations.put("仮定縮約2", "conditional-contracted-2");
+ inflFormTranslations.put("ガル接続", "garu-connection");
+ inflFormTranslations.put("未然形", "imperfective");
+ inflFormTranslations.put("連用形", "conjunctive");
+ inflFormTranslations.put("音便基本形", "onbin-base");
+ inflFormTranslations.put("連用デ接続", "conjunctive-de-connection");
+ inflFormTranslations.put("未然特殊", "imperfective-special");
+ inflFormTranslations.put("命令i", "imperative-i");
+ inflFormTranslations.put("連用ニ接続", "conjunctive-ni-connection");
+ inflFormTranslations.put("命令yo", "imperative-yo");
+ inflFormTranslations.put("体言接続特殊", "adnominal-special");
+ inflFormTranslations.put("命令ro", "imperative-ro");
+ inflFormTranslations.put("体言接続特殊2", "uninflected-special-connection-2");
+ inflFormTranslations.put("未然レル接続", "imperfective-reru-connection");
+ inflFormTranslations.put("現代基本形", "modern-base");
+ inflFormTranslations.put("基本形-促音便", "base-onbin"); // not sure about this
+ }
+
+ /**
+ * Get the english form of inflected form
+ */
+ public static String getInflectedFormTranslation(String s) {
+ return inflFormTranslations.get(s);
+ }
+
+ /**
+ * Romanize katakana with modified hepburn
+ */
+ public static String getRomanization(String s) {
+ StringBuilder builder = new StringBuilder();
+ final int len = s.length();
+ for (int i = 0; i < len; i++) {
+ // maximum lookahead: 3
+ char ch = s.charAt(i);
+ char ch2 = (i < len - 1) ? s.charAt(i + 1) : 0;
+ char ch3 = (i < len - 2) ? s.charAt(i + 2) : 0;
+
+ main: switch (ch) {
+ case 'ッ':
+ switch (ch2) {
+ case 'カ':
+ case 'キ':
+ case 'ク':
+ case 'ケ':
+ case 'コ':
+ builder.append('k');
+ break main;
+ case 'サ':
+ case 'シ':
+ case 'ス':
+ case 'セ':
+ case 'ソ':
+ builder.append('s');
+ break main;
+ case 'タ':
+ case 'チ':
+ case 'ツ':
+ case 'テ':
+ case 'ト':
+ builder.append('t');
+ break main;
+ case 'パ':
+ case 'ピ':
+ case 'プ':
+ case 'ペ':
+ case 'ポ':
+ builder.append('p');
+ break main;
+ }
+ break;
+ case 'ア':
+ builder.append('a');
+ break;
+ case 'イ':
+ if (ch2 == 'ィ') {
+ builder.append("yi");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("ye");
+ i++;
+ } else {
+ builder.append('i');
+ }
+ break;
+ case 'ウ':
+ switch(ch2) {
+ case 'ァ':
+ builder.append("wa");
+ i++;
+ break;
+ case 'ィ':
+ builder.append("wi");
+ i++;
+ break;
+ case 'ゥ':
+ builder.append("wu");
+ i++;
+ break;
+ case 'ェ':
+ builder.append("we");
+ i++;
+ break;
+ case 'ォ':
+ builder.append("wo");
+ i++;
+ break;
+ case 'ュ':
+ builder.append("wyu");
+ i++;
+ break;
+ default:
+ builder.append('u');
+ break;
+ }
+ break;
+ case 'エ':
+ builder.append('e');
+ break;
+ case 'オ':
+ if (ch2 == 'ウ') {
+ builder.append('ō');
+ i++;
+ } else {
+ builder.append('o');
+ }
+ break;
+ case 'カ':
+ builder.append("ka");
+ break;
+ case 'キ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("kyō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("kyū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("kya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("kyo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("kyu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("kye");
+ i++;
+ } else {
+ builder.append("ki");
+ }
+ break;
+ case 'ク':
+ switch(ch2) {
+ case 'ァ':
+ builder.append("kwa");
+ i++;
+ break;
+ case 'ィ':
+ builder.append("kwi");
+ i++;
+ break;
+ case 'ェ':
+ builder.append("kwe");
+ i++;
+ break;
+ case 'ォ':
+ builder.append("kwo");
+ i++;
+ break;
+ case 'ヮ':
+ builder.append("kwa");
+ i++;
+ break;
+ default:
+ builder.append("ku");
+ break;
+ }
+ break;
+ case 'ケ':
+ builder.append("ke");
+ break;
+ case 'コ':
+ if (ch2 == 'ウ') {
+ builder.append("kō");
+ i++;
+ } else {
+ builder.append("ko");
+ }
+ break;
+ case 'サ':
+ builder.append("sa");
+ break;
+ case 'シ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("shō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("shū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("sha");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("sho");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("shu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("she");
+ i++;
+ } else {
+ builder.append("shi");
+ }
+ break;
+ case 'ス':
+ if (ch2 == 'ィ') {
+ builder.append("si");
+ i++;
+ } else {
+ builder.append("su");
+ }
+ break;
+ case 'セ':
+ builder.append("se");
+ break;
+ case 'ソ':
+ if (ch2 == 'ウ') {
+ builder.append("sō");
+ i++;
+ } else {
+ builder.append("so");
+ }
+ break;
+ case 'タ':
+ builder.append("ta");
+ break;
+ case 'チ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("chō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("chū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("cha");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("cho");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("chu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("che");
+ i++;
+ } else {
+ builder.append("chi");
+ }
+ break;
+ case 'ツ':
+ if (ch2 == 'ァ') {
+ builder.append("tsa");
+ i++;
+ } else if (ch2 == 'ィ') {
+ builder.append("tsi");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("tse");
+ i++;
+ } else if (ch2 == 'ォ') {
+ builder.append("tso");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("tsyu");
+ i++;
+ } else {
+ builder.append("tsu");
+ }
+ break;
+ case 'テ':
+ if (ch2 == 'ィ') {
+ builder.append("ti");
+ i++;
+ } else if (ch2 == 'ゥ') {
+ builder.append("tu");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("tyu");
+ i++;
+ } else {
+ builder.append("te");
+ }
+ break;
+ case 'ト':
+ if (ch2 == 'ウ') {
+ builder.append("tō");
+ i++;
+ } else {
+ builder.append("to");
+ }
+ break;
+ case 'ナ':
+ builder.append("na");
+ break;
+ case 'ニ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("nyō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("nyū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("nya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("nyo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("nyu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("nye");
+ i++;
+ } else {
+ builder.append("ni");
+ }
+ break;
+ case 'ヌ':
+ builder.append("nu");
+ break;
+ case 'ネ':
+ builder.append("ne");
+ break;
+ case 'ノ':
+ if (ch2 == 'ウ') {
+ builder.append("nō");
+ i++;
+ } else {
+ builder.append("no");
+ }
+ break;
+ case 'ハ':
+ builder.append("ha");
+ break;
+ case 'ヒ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("hyō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("hyū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("hya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("hyo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("hyu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("hye");
+ i++;
+ } else {
+ builder.append("hi");
+ }
+ break;
+ case 'フ':
+ if (ch2 == 'ャ') {
+ builder.append("fya");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("fyu");
+ i++;
+ } else if (ch2 == 'ィ' && ch3 == 'ェ') {
+ builder.append("fye");
+ i+=2;
+ } else if (ch2 == 'ョ') {
+ builder.append("fyo");
+ i++;
+ } else if (ch2 == 'ァ') {
+ builder.append("fa");
+ i++;
+ } else if (ch2 == 'ィ') {
+ builder.append("fi");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("fe");
+ i++;
+ } else if (ch2 == 'ォ') {
+ builder.append("fo");
+ i++;
+ } else {
+ builder.append("fu");
+ }
+ break;
+ case 'ヘ':
+ builder.append("he");
+ break;
+ case 'ホ':
+ if (ch2 == 'ウ') {
+ builder.append("hō");
+ i++;
+ } else if (ch2 == 'ゥ') {
+ builder.append("hu");
+ i++;
+ } else {
+ builder.append("ho");
+ }
+ break;
+ case 'マ':
+ builder.append("ma");
+ break;
+ case 'ミ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("myō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("myū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("mya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("myo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("myu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("mye");
+ i++;
+ } else {
+ builder.append("mi");
+ }
+ break;
+ case 'ム':
+ builder.append("mu");
+ break;
+ case 'メ':
+ builder.append("mi");
+ break;
+ case 'モ':
+ if (ch2 == 'ウ') {
+ builder.append("mō");
+ i++;
+ } else {
+ builder.append("mo");
+ }
+ break;
+ case 'ヤ':
+ builder.append("ya");
+ break;
+ case 'ユ':
+ builder.append("yu");
+ break;
+ case 'ヨ':
+ if (ch2 == 'ウ') {
+ builder.append("yō");
+ i++;
+ } else {
+ builder.append("yo");
+ }
+ break;
+ case 'ラ':
+ builder.append("ra");
+ break;
+ case 'リ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("ryō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("ryū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("rya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("ryo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("ryu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("rye");
+ i++;
+ } else {
+ builder.append("ri");
+ }
+ break;
+ case 'ル':
+ builder.append("ru");
+ break;
+ case 'レ':
+ builder.append("re");
+ break;
+ case 'ロ':
+ if (ch2 == 'ウ') {
+ builder.append("rō");
+ i++;
+ } else {
+ builder.append("ro");
+ }
+ break;
+ case 'ワ':
+ builder.append("wa");
+ break;
+ case 'ヰ':
+ builder.append("i");
+ break;
+ case 'ヱ':
+ builder.append("e");
+ break;
+ case 'ヲ':
+ builder.append("o");
+ break;
+ case 'ン':
+ switch (ch2) {
+ case 'バ':
+ case 'ビ':
+ case 'ブ':
+ case 'ベ':
+ case 'ボ':
+ case 'パ':
+ case 'ピ':
+ case 'プ':
+ case 'ペ':
+ case 'ポ':
+ case 'マ':
+ case 'ミ':
+ case 'ム':
+ case 'メ':
+ case 'モ':
+ builder.append('m');
+ break main;
+ case 'ヤ':
+ case 'ユ':
+ case 'ヨ':
+ case 'ア':
+ case 'イ':
+ case 'ウ':
+ case 'エ':
+ case 'オ':
+ builder.append("n'");
+ break main;
+ default:
+ builder.append("n");
+ break main;
+ }
+ case 'ガ':
+ builder.append("ga");
+ break;
+ case 'ギ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("gyō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("gyū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("gya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("gyo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("gyu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("gye");
+ i++;
+ } else {
+ builder.append("gi");
+ }
+ break;
+ case 'グ':
+ switch(ch2) {
+ case 'ァ':
+ builder.append("gwa");
+ i++;
+ break;
+ case 'ィ':
+ builder.append("gwi");
+ i++;
+ break;
+ case 'ェ':
+ builder.append("gwe");
+ i++;
+ break;
+ case 'ォ':
+ builder.append("gwo");
+ i++;
+ break;
+ case 'ヮ':
+ builder.append("gwa");
+ i++;
+ break;
+ default:
+ builder.append("gu");
+ break;
+ }
+ break;
+ case 'ゲ':
+ builder.append("ge");
+ break;
+ case 'ゴ':
+ if (ch2 == 'ウ') {
+ builder.append("gō");
+ i++;
+ } else {
+ builder.append("go");
+ }
+ break;
+ case 'ザ':
+ builder.append("za");
+ break;
+ case 'ジ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("jō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("jū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("ja");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("jo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("ju");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("je");
+ i++;
+ } else {
+ builder.append("ji");
+ }
+ break;
+ case 'ズ':
+ if (ch2 == 'ィ') {
+ builder.append("zi");
+ i++;
+ } else {
+ builder.append("zu");
+ }
+ break;
+ case 'ゼ':
+ builder.append("ze");
+ break;
+ case 'ゾ':
+ if (ch2 == 'ウ') {
+ builder.append("zō");
+ i++;
+ } else {
+ builder.append("zo");
+ }
+ break;
+ case 'ダ':
+ builder.append("da");
+ break;
+ case 'ヂ':
+ builder.append("ji");
+ break;
+ case 'ヅ':
+ builder.append("zu");
+ break;
+ case 'デ':
+ if (ch2 == 'ィ') {
+ builder.append("di");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("dyu");
+ i++;
+ } else {
+ builder.append("de");
+ }
+ break;
+ case 'ド':
+ if (ch2 == 'ウ') {
+ builder.append("dō");
+ i++;
+ } else if (ch2 == 'ゥ') {
+ builder.append("du");
+ i++;
+ } else {
+ builder.append("do");
+ }
+ break;
+ case 'バ':
+ builder.append("ba");
+ break;
+ case 'ビ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("byō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("byū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("bya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("byo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("byu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("bye");
+ i++;
+ } else {
+ builder.append("bi");
+ }
+ break;
+ case 'ブ':
+ builder.append("bu");
+ break;
+ case 'ベ':
+ builder.append("be");
+ break;
+ case 'ボ':
+ if (ch2 == 'ウ') {
+ builder.append("bō");
+ i++;
+ } else {
+ builder.append("bo");
+ }
+ break;
+ case 'パ':
+ builder.append("pa");
+ break;
+ case 'ピ':
+ if (ch2 == 'ョ' && ch3 == 'ウ') {
+ builder.append("pyō");
+ i += 2;
+ } else if (ch2 == 'ュ' && ch3 == 'ウ') {
+ builder.append("pyū");
+ i += 2;
+ } else if (ch2 == 'ャ') {
+ builder.append("pya");
+ i++;
+ } else if (ch2 == 'ョ') {
+ builder.append("pyo");
+ i++;
+ } else if (ch2 == 'ュ') {
+ builder.append("pyu");
+ i++;
+ } else if (ch2 == 'ェ') {
+ builder.append("pye");
+ i++;
+ } else {
+ builder.append("pi");
+ }
+ break;
+ case 'プ':
+ builder.append("pu");
+ break;
+ case 'ペ':
+ builder.append("pe");
+ break;
+ case 'ポ':
+ if (ch2 == 'ウ') {
+ builder.append("pō");
+ i++;
+ } else {
+ builder.append("po");
+ }
+ break;
+ case 'ヴ':
+ if (ch2 == 'ィ' && ch3 == 'ェ') {
+ builder.append("vye");
+ i+= 2;
+ } else {
+ builder.append('v');
+ }
+ break;
+ case 'ァ':
+ builder.append('a');
+ break;
+ case 'ィ':
+ builder.append('i');
+ break;
+ case 'ゥ':
+ builder.append('u');
+ break;
+ case 'ェ':
+ builder.append('e');
+ break;
+ case 'ォ':
+ builder.append('o');
+ break;
+ case 'ヮ':
+ builder.append("wa");
+ break;
+ case 'ャ':
+ builder.append("ya");
+ break;
+ case 'ュ':
+ builder.append("yu");
+ break;
+ case 'ョ':
+ builder.append("yo");
+ break;
+ case 'ー':
+ break;
+ default:
+ builder.append(ch);
+ }
+ }
+ return builder.toString();
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/GraphvizFormatter.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/GraphvizFormatter.java
new file mode 100644
index 00000000000..758efe9d25d
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/GraphvizFormatter.java
@@ -0,0 +1,226 @@
+package org.apache.lucene.analysis.kuromoji.viterbi;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.analysis.kuromoji.dict.ConnectionCosts;
+import org.apache.lucene.analysis.kuromoji.viterbi.ViterbiNode.Type;
+
+public class GraphvizFormatter {
+
+ private final static String BOS_LABEL = "BOS";
+
+ private final static String EOS_LABEL = "EOS";
+
+ private final static String FONT_NAME = "Helvetica";
+
+ private ConnectionCosts costs;
+
+ private Map<String, ViterbiNode> nodeMap;
+
+ private Map<String, String> bestPathMap;
+
+ private boolean foundBOS;
+
+ public GraphvizFormatter(ConnectionCosts costs) {
+ this.costs = costs;
+ this.nodeMap = new HashMap<String, ViterbiNode>();
+ this.bestPathMap = new HashMap<String, String>();
+ }
+
+ public String format(ViterbiNode[][] startsArray, ViterbiNode[][] endsArray) {
+ initBestPathMap(null);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(formatHeader());
+ sb.append(formatNodes(startsArray, endsArray));
+ sb.append(formatTrailer());
+ return sb.toString();
+ }
+
+ public String format(ViterbiNode[][] startsArray, ViterbiNode[][] endsArray, List<ViterbiNode> bestPath) {
+
+ // List<ViterbiNode> bestPathWithBOSAndEOS = new ArrayList<ViterbiNode>(bastPath);
+ initBestPathMap(bestPath);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(formatHeader());
+ sb.append(formatNodes(startsArray, endsArray));
+ sb.append(formatTrailer());
+ return sb.toString();
+
+ }
+
+ private void initBestPathMap(List<ViterbiNode> bestPath) {
+ this.bestPathMap.clear();
+
+ if (bestPath == null){
+ return;
+ }
+ for (int i = 0; i < bestPath.size() - 1; i++) {
+ ViterbiNode from = bestPath.get(i);
+ ViterbiNode to = bestPath.get(i + 1);
+
+ String fromId = getNodeId(from);
+ String toId = getNodeId(to);
+
+ assert this.bestPathMap.containsKey(fromId) == false;
+ assert this.bestPathMap.containsValue(toId) == false;
+ this.bestPathMap.put(fromId, toId);
+ }
+ }
+
+ private String formatNodes(ViterbiNode[][] startsArray, ViterbiNode[][] endsArray) {
+ this.nodeMap.clear();
+ this.foundBOS = false;
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 1; i < endsArray.length; i++) {
+ if(endsArray[i] == null || startsArray[i] == null) {
+ continue;
+ }
+ for (int j = 0; j < endsArray[i].length; j++) {
+ ViterbiNode from = endsArray[i][j];
+ if(from == null){
+ continue;
+ }
+ sb.append(formatNodeIfNew(from));
+ for (int k = 0; k < startsArray[i].length; k++) {
+ ViterbiNode to = startsArray[i][k];
+ if(to == null){
+ break;
+ }
+ sb.append(formatNodeIfNew(to));
+ sb.append(formatEdge(from, to));
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+ private String formatNodeIfNew(ViterbiNode node) {
+ String nodeId = getNodeId(node);
+ if (! this.nodeMap.containsKey(nodeId)) {
+ this.nodeMap.put(nodeId, node);
+ return formatNode(node);
+ } else {
+ return "";
+ }
+ }
+
+ private String formatHeader() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("digraph viterbi {\n");
+ sb.append("graph [ fontsize=30 labelloc=\"t\" label=\"\" splines=true overlap=false rankdir = \"LR\" ];\n");
+ sb.append("# A2 paper size\n");
+ sb.append("size = \"34.4,16.5\";\n");
+ sb.append("# try to fill paper\n");
+ sb.append("ratio = fill;\n");
+ sb.append("edge [ fontname=\"" + FONT_NAME + "\" fontcolor=\"red\" color=\"#606060\" ]\n");
+ sb.append("node [ style=\"filled\" fillcolor=\"#e8e8f0\" shape=\"Mrecord\" fontname=\"" + FONT_NAME + "\" ]\n");
+
+ return sb.toString();
+ }
+
+ private String formatTrailer() {
+ return "}";
+ }
+
+
+ private String formatEdge(ViterbiNode from, ViterbiNode to) {
+ if (this.bestPathMap.containsKey(getNodeId(from)) &&
+ this.bestPathMap.get(getNodeId(from)).equals(getNodeId(to))) {
+ return formatEdge(from, to, "color=\"#40e050\" fontcolor=\"#40a050\" penwidth=3 fontsize=20 ");
+
+ } else {
+ return formatEdge(from, to, "");
+ }
+ }
+
+
+ private String formatEdge(ViterbiNode from, ViterbiNode to, String attributes) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getNodeId(from));
+ sb.append(" -> ");
+ sb.append(getNodeId(to));
+ sb.append(" [ ");
+ sb.append("label=\"");
+ sb.append(getCost(from, to));
+ sb.append("\"");
+ sb.append(" ");
+ sb.append(attributes);
+ sb.append(" ");
+ sb.append(" ]");
+ sb.append("\n");
+ return sb.toString();
+ }
+
+ private String formatNode(ViterbiNode node) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("\"");
+ sb.append(getNodeId(node));
+ sb.append("\"");
+ sb.append(" [ ");
+ sb.append("label=");
+ sb.append(formatNodeLabel(node));
+ sb.append(" ]");
+ return sb.toString();
+ }
+
+ private String formatNodeLabel(ViterbiNode node) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<<table border=\"0\" cellborder=\"0\">");
+ sb.append("<tr><td>");
+ sb.append(getNodeLabel(node));
+ sb.append("</td></tr>");
+ sb.append("<tr><td>");
+ sb.append("<font color=\"blue\">");
+ sb.append(node.getWordCost());
+ sb.append("</font>");
+ sb.append("</td></tr>");
+ // sb.append("<tr><td>");
+ // sb.append(this.dictionary.get(node.getWordId()).getPosInfo());
+ // sb.append("</td></tr>");
+ sb.append("</table>>");
+ return sb.toString();
+ }
+
+ private String getNodeId(ViterbiNode node) {
+ return String.valueOf(node.hashCode());
+ }
+
+ private String getNodeLabel(ViterbiNode node) {
+ if (node.getType() == Type.KNOWN && node.getWordId() == 0) {
+ if (this.foundBOS) {
+ return EOS_LABEL;
+ } else {
+ this.foundBOS = true;
+ return BOS_LABEL;
+ }
+ } else {
+ return node.getSurfaceFormString();
+ }
+ }
+
+ private int getCost(ViterbiNode from, ViterbiNode to) {
+ return this.costs.get(from.getLeftId(), to.getRightId());
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java
new file mode 100644
index 00000000000..8de876ee77a
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java
@@ -0,0 +1,361 @@
+package org.apache.lucene.analysis.kuromoji.viterbi;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.lucene.analysis.kuromoji.Segmenter.Mode;
+import org.apache.lucene.analysis.kuromoji.dict.CharacterDefinition;
+import org.apache.lucene.analysis.kuromoji.dict.ConnectionCosts;
+import org.apache.lucene.analysis.kuromoji.dict.TokenInfoDictionary;
+import org.apache.lucene.analysis.kuromoji.dict.TokenInfoFST;
+import org.apache.lucene.analysis.kuromoji.dict.UnknownDictionary;
+import org.apache.lucene.analysis.kuromoji.dict.UserDictionary;
+import org.apache.lucene.analysis.kuromoji.viterbi.ViterbiNode.Type;
+import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.fst.FST;
+
+public class Viterbi {
+
+ private final TokenInfoFST fst;
+
+ private final TokenInfoDictionary dictionary;
+
+ private final UnknownDictionary unkDictionary;
+
+ private final ConnectionCosts costs;
+
+ private final UserDictionary userDictionary;
+
+ private final CharacterDefinition characterDefinition;
+
+ private final boolean useUserDictionary;
+
+ private final boolean searchMode;
+
+ private final boolean extendedMode;
+
+ private static final int DEFAULT_COST = 10000000;
+
+ private static final int SEARCH_MODE_LENGTH_KANJI = 3;
+
+ private static final int SEARCH_MODE_LENGTH = 7;
+
+ private static final int SEARCH_MODE_PENALTY = 10000;
+
+ private static final char[] BOS = "BOS".toCharArray();
+
+ private static final char[] EOS = "EOS".toCharArray();
+
+ /**
+ * Constructor
+ */
+ public Viterbi(TokenInfoDictionary dictionary,
+ UnknownDictionary unkDictionary,
+ ConnectionCosts costs,
+ UserDictionary userDictionary,
+ Mode mode) {
+ this.dictionary = dictionary;
+ this.fst = dictionary.getFST();
+ this.unkDictionary = unkDictionary;
+ this.costs = costs;
+ this.userDictionary = userDictionary;
+ if(userDictionary == null) {
+ this.useUserDictionary = false;
+ } else {
+ this.useUserDictionary = true;
+ }
+
+ switch(mode){
+ case SEARCH:
+ searchMode = true;
+ extendedMode = false;
+ break;
+ case EXTENDED:
+ searchMode = true;
+ extendedMode = true;
+ break;
+ default:
+ searchMode = false;
+ extendedMode = false;
+ break;
+ }
+
+ this.characterDefinition = unkDictionary.getCharacterDefinition();
+ }
+
+ /**
+ * Find best path from input lattice.
+ * @param lattice the result of build method
+ * @return List of ViterbiNode which consist best path
+ */
+ public List<ViterbiNode> search(ViterbiNode[][][] lattice) {
+ ViterbiNode[][] startIndexArr = lattice[0];
+ ViterbiNode[][] endIndexArr = lattice[1];
+
+ for (int i = 1; i < startIndexArr.length; i++){
+
+ if (startIndexArr[i] == null || endIndexArr[i] == null){ // continue since no array which contains ViterbiNodes exists. Or no previous node exists.
+ continue;
+ }
+
+ for (ViterbiNode node : startIndexArr[i]) {
+ if (node == null){ // If array doesn't contain ViterbiNode any more, continue to next index
+ break;
+ }
+
+ int backwardConnectionId = node.getLeftId();
+ int wordCost = node.getWordCost();
+ int leastPathCost = DEFAULT_COST;
+ for (ViterbiNode leftNode : endIndexArr[i]) {
+ if (leftNode == null){ // If array doesn't contain ViterbiNode any more, continue to next index
+ break;
+ }
+
+ int pathCost = leftNode.getPathCost() + costs.get(leftNode.getRightId(), backwardConnectionId) + wordCost; // cost = [total cost from BOS to previous node] + [connection cost between previous node and current node] + [word cost]
+
+ // "Search mode". Add extra costs if it is long node.
+ if (searchMode) {
+ // System.out.print(""); // If this line exists, kuromoji runs faster for some reason when searchMode == false.
+ char[] surfaceForm = node.getSurfaceForm();
+ int offset = node.getOffset();
+ int length = node.getLength();
+ if (length > SEARCH_MODE_LENGTH_KANJI) {
+ boolean allKanji = true;
+ // check if node consists of only kanji
+ for (int pos = 0; pos < length; pos++) {
+ if (!characterDefinition.isKanji(surfaceForm[offset+pos])){
+ allKanji = false;
+ break;
+ }
+ }
+
+ if (allKanji) { // Process only Kanji keywords
+ pathCost += (length - SEARCH_MODE_LENGTH_KANJI) * SEARCH_MODE_PENALTY;
+ } else if (length > SEARCH_MODE_LENGTH) {
+ pathCost += (length - SEARCH_MODE_LENGTH) * SEARCH_MODE_PENALTY;
+ }
+ }
+ }
+
+ if (pathCost < leastPathCost){ // If total cost is lower than before, set current previous node as best left node (previous means left).
+ leastPathCost = pathCost;
+ node.setPathCost(leastPathCost);
+ node.setLeftNode(leftNode);
+ }
+ }
+ }
+ }
+
+ // track best path
+ ViterbiNode node = endIndexArr[0][0]; // EOS
+ LinkedList<ViterbiNode> result = new LinkedList<ViterbiNode>();
+ result.add(node);
+ while (true) {
+ ViterbiNode leftNode = node.getLeftNode();
+ if (leftNode == null) {
+ break;
+ }
+
+ // EXTENDED mode convert unknown word into unigram node
+ if (extendedMode && leftNode.getType() == Type.UNKNOWN) {
+ byte unigramWordId = CharacterDefinition.NGRAM;
+ int unigramLeftId = unkDictionary.getLeftId(unigramWordId); // isn't required
+ int unigramRightId = unkDictionary.getLeftId(unigramWordId); // isn't required
+ int unigramWordCost = unkDictionary.getWordCost(unigramWordId); // isn't required
+ char[] surfaceForm = leftNode.getSurfaceForm();
+ int offset = leftNode.getOffset();
+ int length = leftNode.getLength();
+ for (int i = length - 1; i >= 0; i--) {
+ int charLen = 1;
+ if (i > 0 && Character.isLowSurrogate(surfaceForm[offset+i])) {
+ i--;
+ charLen = 2;
+ }
+ ViterbiNode uniGramNode = new ViterbiNode(unigramWordId, surfaceForm, offset + i, charLen, unigramLeftId, unigramRightId, unigramWordCost, leftNode.getStartIndex() + i, Type.UNKNOWN);
+ result.addFirst(uniGramNode);
+ }
+ } else {
+ result.addFirst(leftNode);
+ }
+ node = leftNode;
+ }
+
+ return result;
+ }
+
+ /**
+ * Build lattice from input text
+ * @param text
+ */
+ public ViterbiNode[][][] build(char text[], int offset, int length) throws IOException {
+ ViterbiNode[][] startIndexArr = new ViterbiNode[length + 2][]; // text length + BOS and EOS
+ ViterbiNode[][] endIndexArr = new ViterbiNode[length + 2][]; // text length + BOS and EOS
+ int[] startSizeArr = new int[length + 2]; // array to keep ViterbiNode count in startIndexArr
+ int[] endSizeArr = new int[length + 2]; // array to keep ViterbiNode count in endIndexArr
+ FST.Arc<Long> arc = new FST.Arc<Long>();
+ ViterbiNode bosNode = new ViterbiNode(-1, BOS, 0, BOS.length, 0, 0, 0, -1, Type.KNOWN);
+ addToArrays(bosNode, 0, 1, startIndexArr, endIndexArr, startSizeArr, endSizeArr);
+
+ // Process user dictionary;
+ if (useUserDictionary) {
+ processUserDictionary(text, offset, length, startIndexArr, endIndexArr, startSizeArr, endSizeArr);
+ }
+
+ int unknownWordEndIndex = -1; // index of the last character of unknown word
+
+ final IntsRef wordIdRef = new IntsRef();
+
+ for (int startIndex = 0; startIndex < length; startIndex++) {
+ // If no token ends where current token starts, skip this index
+ if (endSizeArr[startIndex + 1] == 0) {
+ continue;
+ }
+
+ int suffixStart = offset + startIndex;
+ int suffixLength = length - startIndex;
+
+ boolean found = false;
+ arc = fst.getFirstArc(arc);
+ int output = 0;
+ for (int endIndex = 1; endIndex < suffixLength + 1; endIndex++) {
+ int ch = text[suffixStart + endIndex - 1];
+
+ if (fst.findTargetArc(ch, arc, arc, endIndex == 1) == null) {
+ break; // continue to next position
+ }
+ output += arc.output.intValue();
+
+ if (arc.isFinal()) {
+ output += arc.nextFinalOutput.intValue();
+ found = true; // Don't produce unknown word starting from this index
+ dictionary.lookupWordIds(output, wordIdRef);
+ for (int ofs = 0; ofs < wordIdRef.length; ofs++) {
+ final int wordId = wordIdRef.ints[wordIdRef.offset + ofs];
+ ViterbiNode node = new ViterbiNode(wordId, text, suffixStart, endIndex, dictionary.getLeftId(wordId), dictionary.getRightId(wordId), dictionary.getWordCost(wordId), startIndex, Type.KNOWN);
+ addToArrays(node, startIndex + 1, startIndex + 1 + endIndex, startIndexArr, endIndexArr, startSizeArr, endSizeArr);
+ }
+ }
+ }
+
+ // In the case of normal mode, it doesn't process unknown word greedily.
+ if(!searchMode && unknownWordEndIndex > startIndex){
+ continue;
+ }
+
+ // Process Unknown Word: hmm what is this isInvoke logic (same no matter what)
+ int unknownWordLength = 0;
+ char firstCharacter = text[suffixStart];
+ boolean isInvoke = characterDefinition.isInvoke(firstCharacter);
+ if (isInvoke){ // Process "invoke"
+ unknownWordLength = unkDictionary.lookup(text, suffixStart, suffixLength);
+ } else if (found == false){ // Process not "invoke"
+ unknownWordLength = unkDictionary.lookup(text, suffixStart, suffixLength);
+ }
+
+ if (unknownWordLength > 0) { // found unknown word
+ final int characterId = characterDefinition.getCharacterClass(firstCharacter);
+ unkDictionary.lookupWordIds(characterId, wordIdRef); // characters in input text are supposed to be the same
+ for (int ofs = 0; ofs < wordIdRef.length; ofs++) {
+ final int wordId = wordIdRef.ints[wordIdRef.offset + ofs];
+ ViterbiNode node = new ViterbiNode(wordId, text, suffixStart, unknownWordLength, unkDictionary.getLeftId(wordId), unkDictionary.getRightId(wordId), unkDictionary.getWordCost(wordId), startIndex, Type.UNKNOWN);
+ addToArrays(node, startIndex + 1, startIndex + 1 + unknownWordLength, startIndexArr, endIndexArr, startSizeArr, endSizeArr);
+ }
+ unknownWordEndIndex = startIndex + unknownWordLength;
+ }
+ }
+
+ ViterbiNode eosNode = new ViterbiNode(-1, EOS, 0, EOS.length, 0, 0, 0, length + 1, Type.KNOWN);
+ addToArrays(eosNode, length + 1, 0, startIndexArr, endIndexArr, startSizeArr, endSizeArr); //Add EOS node to endIndexArr at index 0
+
+ ViterbiNode[][][] result = new ViterbiNode[][][]{startIndexArr, endIndexArr};
+
+ return result;
+ }
+
+ /**
+ * Find token(s) in input text and set found token(s) in arrays as normal tokens
+ * @param text
+ * @param startIndexArr
+ * @param endIndexArr
+ * @param startSizeArr
+ * @param endSizeArr
+ */
+ private void processUserDictionary(char text[], int offset, int len, ViterbiNode[][] startIndexArr, ViterbiNode[][] endIndexArr, int[] startSizeArr, int[] endSizeArr) throws IOException {
+ int[][] result = userDictionary.lookup(text, offset, len);
+ for(int[] segmentation : result) {
+ int wordId = segmentation[0];
+ int index = segmentation[1];
+ int length = segmentation[2];
+ ViterbiNode node = new ViterbiNode(wordId, text, offset + index, length, userDictionary.getLeftId(wordId), userDictionary.getRightId(wordId), userDictionary.getWordCost(wordId), index, Type.USER);
+ addToArrays(node, index + 1, index + 1 + length, startIndexArr, endIndexArr, startSizeArr, endSizeArr);
+ }
+ }
+
+ /**
+ * Add node to arrays and increment count in size array
+ * @param node
+ * @param startIndex
+ * @param endIndex
+ * @param startIndexArr
+ * @param endIndexArr
+ * @param startSizeArr
+ * @param endSizeArr
+ */
+ private void addToArrays(ViterbiNode node, int startIndex, int endIndex, ViterbiNode[][] startIndexArr, ViterbiNode[][] endIndexArr, int[] startSizeArr, int[] endSizeArr ) {
+ int startNodesCount = startSizeArr[startIndex];
+ int endNodesCount = endSizeArr[endIndex];
+
+ if (startNodesCount == 0) {
+ startIndexArr[startIndex] = new ViterbiNode[10];
+ }
+
+ if (endNodesCount == 0) {
+ endIndexArr[endIndex] = new ViterbiNode[10];
+ }
+
+ if (startIndexArr[startIndex].length <= startNodesCount){
+ startIndexArr[startIndex] = extendArray(startIndexArr[startIndex]);
+ }
+
+ if (endIndexArr[endIndex].length <= endNodesCount){
+ endIndexArr[endIndex] = extendArray(endIndexArr[endIndex]);
+ }
+
+ startIndexArr[startIndex][startNodesCount] = node;
+ endIndexArr[endIndex][endNodesCount] = node;
+
+ startSizeArr[startIndex] = startNodesCount + 1;
+ endSizeArr[endIndex] = endNodesCount + 1;
+ }
+
+
+ /**
+ * Return twice as big array which contains value of input array
+ * @param array
+ * @return
+ */
+ private ViterbiNode[] extendArray(ViterbiNode[] array) {
+ //extend array
+ ViterbiNode[] newArray = new ViterbiNode[array.length * 2];
+ System.arraycopy(array, 0, newArray, 0, array.length);
+ return newArray;
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/ViterbiNode.java b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/ViterbiNode.java
new file mode 100644
index 00000000000..06ae4cd2148
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/ViterbiNode.java
@@ -0,0 +1,147 @@
+package org.apache.lucene.analysis.kuromoji.viterbi;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public final class ViterbiNode {
+ public enum Type {
+ KNOWN,
+ UNKNOWN,
+ USER
+ }
+
+ private final int wordId;
+
+ private final char[] surfaceForm;
+ private final int offset;
+ private final int length;
+
+ private final int leftId;
+
+ private final int rightId;
+
+ /** word cost for this node */
+ private final int wordCost;
+
+ /** minimum path cost found thus far */
+ private int pathCost;
+
+ private ViterbiNode leftNode;
+
+ private final Type type;
+
+ private final int startIndex;
+
+ public ViterbiNode(int wordId, char[] surfaceForm, int offset, int length, int leftId, int rightId, int wordCost, int startIndex, Type type) {
+ this.wordId = wordId;
+ this.surfaceForm = surfaceForm;
+ this.offset = offset;
+ this.length = length;
+ this.leftId = leftId;
+ this.rightId = rightId;
+ this.wordCost = wordCost;
+ this.startIndex = startIndex;
+ this.type = type;
+ }
+
+
+ /**
+ * @return the wordId
+ */
+ public int getWordId() {
+ return wordId;
+ }
+
+ /**
+ * @return the surfaceForm
+ */
+ public char[] getSurfaceForm() {
+ return surfaceForm;
+ }
+
+ /**
+ * @return start offset into surfaceForm
+ */
+ public int getOffset() {
+ return offset;
+ }
+
+ /**
+ * @return length of surfaceForm
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * @return the surfaceForm as a String
+ */
+ public String getSurfaceFormString() {
+ return new String(surfaceForm, offset, length);
+ }
+
+ /**
+ * @return the leftId
+ */
+ public int getLeftId() {
+ return leftId;
+ }
+
+ /**
+ * @return the rightId
+ */
+ public int getRightId() {
+ return rightId;
+ }
+
+ /**
+ * @return the cost
+ */
+ public int getWordCost() {
+ return wordCost;
+ }
+
+ /**
+ * @return the cost
+ */
+ public int getPathCost() {
+ return pathCost;
+ }
+
+ /**
+ * param cost minimum path cost found this far
+ */
+ public void setPathCost(int pathCost) {
+ this.pathCost = pathCost;
+ }
+
+ public void setLeftNode(ViterbiNode node) {
+ leftNode = node;
+ }
+
+ public ViterbiNode getLeftNode() {
+ return leftNode;
+ }
+
+ public int getStartIndex() {
+ return startIndex;
+ }
+
+ public Type getType() {
+ return type;
+ }
+}
diff --git a/modules/analysis/kuromoji/src/java/overview.html b/modules/analysis/kuromoji/src/java/overview.html
new file mode 100644
index 00000000000..b466bc35e1a
--- /dev/null
+++ b/modules/analysis/kuromoji/src/java/overview.html
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+ <head>
+ <title>
+ analyzers-kuromoji
+ </title>
+ </head>
+ <body>
+ analyzers-kuromoji
+ </body>
+</html>
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/CharacterDefinition.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/CharacterDefinition.dat
new file mode 100644
index 00000000000..4b8bd4b5b84
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/CharacterDefinition.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.dat
new file mode 100644
index 00000000000..7679f14d8e3
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$buffer.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$buffer.dat
new file mode 100644
index 00000000000..03978a9dac7
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$buffer.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$fst.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$fst.dat
new file mode 100644
index 00000000000..dbb49c4f1ea
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$fst.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$inflDict.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$inflDict.dat
new file mode 100644
index 00000000000..9c994b8e035
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$inflDict.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$posDict.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$posDict.dat
new file mode 100644
index 00000000000..e8d69ddeb8b
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$posDict.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$targetMap.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$targetMap.dat
new file mode 100644
index 00000000000..39874d9c7b0
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary$targetMap.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$buffer.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$buffer.dat
new file mode 100644
index 00000000000..3ec707e8e09
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$buffer.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$inflDict.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$inflDict.dat
new file mode 100644
index 00000000000..1a46860b827
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$inflDict.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$posDict.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$posDict.dat
new file mode 100644
index 00000000000..cd5d4da2e2f
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$posDict.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$targetMap.dat b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$targetMap.dat
new file mode 100644
index 00000000000..41ea9ed971f
Binary files /dev/null and b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionary$targetMap.dat differ
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/stoptags.txt b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/stoptags.txt
new file mode 100644
index 00000000000..b9de0635370
--- /dev/null
+++ b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/stoptags.txt
@@ -0,0 +1,410 @@
+# set of default stop tags:
+# uncomment a part of speech to treat those words as stopwords.
+# the entire tagset is provided here for convenience.
+#
+#####
+# noun: unclassified nouns
+#名詞
+#
+# noun-common: Common nouns or nouns where the sub-classification is undefined
+#名詞-一般
+#
+# noun-proper: Proper nouns where the sub-classification is undefined
+#名詞-固有名詞
+#
+# noun-proper-misc: miscellaneous proper nouns
+#名詞-固有名詞-一般
+#
+# noun-proper-person: Personal names where the sub-classification is undefined
+#名詞-固有名詞-人名
+#
+# noun-proper-person-misc: names that cannot be divided into surname and
+# given name; foreign names; names where the surname or given name is unknown.
+# e.g. お市の方
+#名詞-固有名詞-人名-一般
+#
+# noun-proper-person-surname: Mainly Japanese surnames.
+# e.g. 山田
+#名詞-固有名詞-人名-姓
+#
+# noun-proper-person-given_name: Mainly Japanese given names.
+# e.g. 太郎
+#名詞-固有名詞-人名-名
+#
+# noun-proper-organization: Names representing organizations.
+# e.g. 通産省, NHK
+#名詞-固有名詞-組織
+#
+# noun-proper-place: Place names where the sub-classification is undefined
+#名詞-固有名詞-地域
+#
+# noun-proper-place-misc: Place names excluding countries.
+# e.g. アジア, バルセロナ, 京都
+#名詞-固有名詞-地域-一般
+#
+# noun-proper-place-country: Country names.
+# e.g. 日本, オーストラリア
+#名詞-固有名詞-地域-国
+#
+# noun-pronoun: Pronouns where the sub-classification is undefined
+#名詞-代名詞
+#
+# noun-pronoun-misc: miscellaneous pronouns:
+# e.g. それ, ここ, あいつ, あなた, あちこち, いくつ, どこか, なに, みなさん, みんな, わたくし, われわれ
+#名詞-代名詞-一般
+#
+# noun-pronoun-contraction: Spoken language contraction made by combining a
+# pronoun and the particle 'wa'.
+# e.g. ありゃ, こりゃ, こりゃあ, そりゃ, そりゃあ
+#名詞-代名詞-縮約
+#
+# noun-adverbial: Temporal nouns such as names of days or months that behave
+# like adverbs. Nouns that represent amount or ratios and can be used adverbially,
+# e.g. 金曜, 一月, 午後, 少量
+#名詞-副詞可能
+#
+# noun-verbal: Nouns that take arguments with case and can appear followed by
+# 'suru' and related verbs (する, できる, なさる, くださる)
+# e.g. インプット, 愛着, 悪化, 悪戦苦闘, 一安心, 下取り
+#名詞-サ変接続
+#
+# noun-adjective-base: The base form of adjectives, words that appear before な ("na")
+# e.g. 健康, 安易, 駄目, だめ
+#名詞-形容動詞語幹
+#
+# noun-numeric: Arabic numbers, Chinese numerals, and counters like 何 (回), 数.
+# e.g. 0, 1, 2, 何, 数, 幾
+#名詞-数
+#
+# noun-affix: noun affixes where the sub-classification is undefined
+#名詞-非自立
+#
+# noun-affix-misc: Of adnominalizers, the case-marker の ("no"), and words that
+# attach to the base form of inflectional words, words that cannot be classified
+# into any of the other categories below. This category includes indefinite nouns.
+# e.g. あかつき, 暁, かい, 甲斐, 気, きらい, 嫌い, くせ, 癖, こと, 事, ごと, 毎, しだい, 次第,
+# 順, せい, 所為, ついで, 序で, つもり, 積もり, 点, どころ, の, はず, 筈, はずみ, 弾み,
+# 拍子, ふう, ふり, 振り, ほう, 方, 旨, もの, 物, 者, ゆえ, 故, ゆえん, 所以, わけ, 訳,
+# わり, 割り, 割, ん-口語/, もん-口語/
+#名詞-非自立-一般
+#
+# noun-affix-adverbial: noun affixes that that can behave as adverbs.
+# e.g. あいだ, 間, あげく, 挙げ句, あと, 後, 余り, 以外, 以降, 以後, 以上, 以前, 一方, うえ,
+# 上, うち, 内, おり, 折り, かぎり, 限り, きり, っきり, 結果, ころ, 頃, さい, 際, 最中, さなか,
+# 最中, じたい, 自体, たび, 度, ため, 為, つど, 都度, とおり, 通り, とき, 時, ところ, 所,
+# とたん, 途端, なか, 中, のち, 後, ばあい, 場合, 日, ぶん, 分, ほか, 他, まえ, 前, まま,
+# 儘, 侭, みぎり, 矢先
+#名詞-非自立-副詞可能
+#
+# noun-affix-aux: noun affixes treated as 助動詞 ("auxiliary verb") in school grammars
+# with the stem よう(だ) ("you(da)").
+# e.g. よう, やう, 様 (よう)
+#名詞-非自立-助動詞語幹
+#
+# noun-affix-adjective-base: noun affixes that can connect to the indeclinable
+# connection form な (aux "da").
+# e.g. みたい, ふう
+#名詞-非自立-形容動詞語幹
+#
+# noun-special: special nouns where the sub-classification is undefined.
+#名詞-特殊
+#
+# noun-special-aux: The そうだ ("souda") stem form that is used for reporting news, is
+# treated as 助動詞 ("auxiliary verb") in school grammars, and attach to the base
+# form of inflectional words.
+# e.g. そう
+#名詞-特殊-助動詞語幹
+#
+# noun-suffix: noun suffixes where the sub-classification is undefined.
+#名詞-接尾
+#
+# noun-suffix-misc: Of the nouns or stem forms of other parts of speech that connect
+# to ガル or タイ and can combine into compound nouns, words that cannot be classified into
+# any of the other categories below. In general, this category is more inclusive than
+# 接尾語 ("suffix") and is usually the last element in a compound noun.
+# e.g. おき, かた, 方, 甲斐 (がい), がかり, ぎみ, 気味, ぐるみ, (~した) さ, 次第, 済 (ず) み,
+# よう, (でき)っこ, 感, 観, 性, 学, 類, 面, 用
+#名詞-接尾-一般
+#
+# noun-suffix-person: Suffixes that form nouns and attach to person names more often
+# than other nouns.
+# e.g. 君, 様, 著
+#名詞-接尾-人名
+#
+# noun-suffix-place: Suffixes that form nouns and attach to place names more often
+# than other nouns.
+# e.g. 町, 市, 県
+#名詞-接尾-地域
+#
+# noun-suffix-verbal: Of the suffixes that attach to nouns and form nouns, those that
+# can appear before スル ("suru").
+# e.g. 化, 視, 分け, 入り, 落ち, 買い
+#名詞-接尾-サ変接続
+#
+# noun-suffix-aux: The stem form of そうだ (様態) that is used to indicate conditions,
+# is treated as 助動詞 ("auxiliary verb") in school grammars, and attach to the
+# conjunctive form of inflectional words.
+# e.g. そう
+#名詞-接尾-助動詞語幹
+#
+# noun-suffix-adjective-base: Suffixes that attach to other nouns or the conjunctive
+# form of inflectional words and appear before the copula だ ("da").
+# e.g. 的, げ, がち
+#名詞-接尾-形容動詞語幹
+#
+# noun-suffix-adverbial: Suffixes that attach to other nouns and can behave as adverbs.
+# e.g. 後 (ご), 以後, 以降, 以前, 前後, 中, 末, 上, 時 (じ)
+#名詞-接尾-副詞可能
+#
+# noun-suffix-classifier: Suffixes that attach to numbers and form nouns. This category
+# is more inclusive than 助数詞 ("classifier") and includes common nouns that attach
+# to numbers.
+# e.g. 個, つ, 本, 冊, パーセント, cm, kg, カ月, か国, 区画, 時間, 時半
+#名詞-接尾-助数詞
+#
+# noun-suffix-special: Special suffixes that mainly attach to inflecting words.
+# e.g. (楽し) さ, (考え) 方
+#名詞-接尾-特殊
+#
+# noun-suffix-conjunctive: Nouns that behave like conjunctions and join two words
+# together.
+# e.g. (日本) 対 (アメリカ), 対 (アメリカ), (3) 対 (5), (女優) 兼 (主婦)
+#名詞-接続詞的
+#
+# noun-verbal_aux: Nouns that attach to the conjunctive particle て ("te") and are
+# semantically verb-like.
+# e.g. ごらん, ご覧, 御覧, 頂戴
+#名詞-動詞非自立的
+#
+# noun-quotation: text that cannot be segmented into words, proverbs, Chinese poetry,
+# dialects, English, etc. Currently, the only entry for 名詞 引用文字列 ("noun quotation")
+# is いわく ("iwaku").
+#名詞-引用文字列
+#
+# noun-nai_adjective: Words that appear before the auxiliary verb ない ("nai") and
+# behave like an adjective.
+# e.g. 申し訳, 仕方, とんでも, 違い
+#名詞-ナイ形容詞語幹
+#
+#####
+# prefix: unclassified prefixes
+接頭詞
+#
+# prefix-nominal: Prefixes that attach to nouns (including adjective stem forms)
+# excluding numerical expressions.
+# e.g. お (水), 某 (氏), 同 (社), 故 (~氏), 高 (品質), お (見事), ご (立派)
+接頭詞-名詞接続
+#
+# prefix-verbal: Prefixes that attach to the imperative form of a verb or a verb
+# in conjunctive form followed by なる/なさる/くださる.
+# e.g. お (読みなさい), お (座り)
+接頭詞-動詞接続
+#
+# prefix-adjectival: Prefixes that attach to adjectives.
+# e.g. お (寒いですねえ), バカ (でかい)
+接頭詞-形容詞接続
+#
+# prefix-numerical: Prefixes that attach to numerical expressions.
+# e.g. 約, およそ, 毎時
+接頭詞-数接続
+#
+#####
+# verb: unclassified verbs
+#動詞
+#
+# verb-main:
+#動詞-自立
+#
+# verb-auxiliary:
+動詞-非自立
+#
+# verb-suffix:
+#動詞-接尾
+#
+#####
+# adjective: unclassified adjectives
+#形容詞
+#
+# adjective-main:
+#形容詞-自立
+#
+# adjective-auxiliary:
+#形容詞-非自立
+#
+# adjective-suffix:
+#形容詞-接尾
+#
+#####
+# adverb: unclassified adverbs
+#副詞
+#
+# adverb-misc: Words that can be segmented into one unit and where adnominal
+# modification is not possible.
+# e.g. あいかわらず, 多分
+#副詞-一般
+#
+# adverb-particle_conjunction: Adverbs that can be followed by の, は, に,
+# な, する, だ, etc.
+# e.g. こんなに, そんなに, あんなに, なにか, なんでも
+#副詞-助詞類接続
+#
+#####
+# adnominal: Words that only have noun-modifying forms.
+# e.g. この, その, あの, どの, いわゆる, なんらかの, 何らかの, いろんな, こういう, そういう, ああいう,
+# どういう, こんな, そんな, あんな, どんな, 大きな, 小さな, おかしな, ほんの, たいした,
+# 「(, も) さる (ことながら)」, 微々たる, 堂々たる, 単なる, いかなる, 我が」「同じ, 亡き
+#連体詞
+#
+#####
+# conjunction: Conjunctions that can occur independently.
+# e.g. が, けれども, そして, じゃあ, それどころか
+接続詞
+#
+#####
+# particle: unclassified particles.
+助詞
+#
+# particle-case: case particles where the subclassification is undefined.
+助詞-格助詞
+#
+# particle-case-misc: Case particles.
+# e.g. から, が, で, と, に, へ, より, を, の, にて
+助詞-格助詞-一般
+#
+# particle-case-quote: the "to" that appears after nouns, a person’s speech,
+# quotation marks, expressions of decisions from a meeting, reasons, judgements,
+# conjectures, etc.
+# e.g. ( だ) と (述べた.), ( である) と (して執行猶予...)
+助詞-格助詞-引用
+#
+# particle-case-compound: Compounds of particles and verbs that mainly behave
+# like case particles.
+# e.g. という, といった, とかいう, として, とともに, と共に, でもって, にあたって, に当たって, に当って,
+# にあたり, に当たり, に当り, に当たる, にあたる, において, に於いて,に於て, における, に於ける,
+# にかけ, にかけて, にかんし, に関し, にかんして, に関して, にかんする, に関する, に際し,
+# に際して, にしたがい, に従い, に従う, にしたがって, に従って, にたいし, に対し, にたいして,
+# に対して, にたいする, に対する, について, につき, につけ, につけて, につれ, につれて, にとって,
+# にとり, にまつわる, によって, に依って, に因って, により, に依り, に因り, による, に依る, に因る,
+# にわたって, にわたる, をもって, を以って, を通じ, を通じて, を通して, をめぐって, をめぐり, をめぐる,
+# って-口語/, ちゅう-関西弁「という」/, (何) ていう (人)-口語/, っていう-口語/, といふ, とかいふ
+助詞-格助詞-連語
+#
+# particle-conjunctive:
+# e.g. から, からには, が, けれど, けれども, けど, し, つつ, て, で, と, ところが, どころか, とも, ども,
+# ながら, なり, ので, のに, ば, ものの, や ( した), やいなや, (ころん) じゃ(いけない)-口語/,
+# (行っ) ちゃ(いけない)-口語/, (言っ) たって (しかたがない)-口語/, (それがなく)ったって (平気)-口語/
+助詞-接続助詞
+#
+# particle-dependency:
+# e.g. こそ, さえ, しか, すら, は, も, ぞ
+助詞-係助詞
+#
+# particle-adverbial:
+# e.g. がてら, かも, くらい, 位, ぐらい, しも, (学校) じゃ(これが流行っている)-口語/,
+# (それ)じゃあ (よくない)-口語/, ずつ, (私) なぞ, など, (私) なり (に), (先生) なんか (大嫌い)-口語/,
+# (私) なんぞ, (先生) なんて (大嫌い)-口語/, のみ, だけ, (私) だって-口語/, だに,
+# (彼)ったら-口語/, (お茶) でも (いかが), 等 (とう), (今後) とも, ばかり, ばっか-口語/, ばっかり-口語/,
+# ほど, 程, まで, 迄, (誰) も (が)([助詞-格助詞] および [助詞-係助詞] の前に位置する「も」)
+助詞-副助詞
+#
+# particle-interjective: particles with interjective grammatical roles.
+# e.g. (松島) や
+助詞-間投助詞
+#
+# particle-coordinate:
+# e.g. と, たり, だの, だり, とか, なり, や, やら
+助詞-並立助詞
+#
+# particle-final:
+# e.g. かい, かしら, さ, ぜ, (だ)っけ-口語/, (とまってる) で-方言/, な, ナ, なあ-口語/, ぞ, ね, ネ,
+# ねぇ-口語/, ねえ-口語/, ねん-方言/, の, のう-口語/, や, よ, ヨ, よぉ-口語/, わ, わい-口語/
+助詞-終助詞
+#
+# particle-adverbial/conjunctive/final: The particle "ka" when unknown whether it is
+# adverbial, conjunctive, or sentence final. For example:
+# (a) 「A か B か」. Ex:「(国内で運用する) か,(海外で運用する) か (.)」
+# (b) Inside an adverb phrase. Ex:「(幸いという) か (, 死者はいなかった.)」
+# 「(祈りが届いたせい) か (, 試験に合格した.)」
+# (c) 「かのように」. Ex:「(何もなかった) か (のように振る舞った.)」
+# e.g. か
+助詞-副助詞/並立助詞/終助詞
+#
+# particle-adnominalizer: The "no" that attaches to nouns and modifies
+# non-inflectional words.
+助詞-連体化
+#
+# particle-adnominalizer: The "ni" and "to" that appear following nouns and adverbs
+# that are giongo, giseigo, or gitaigo.
+# e.g. に, と
+助詞-副詞化
+#
+# particle-special: A particle that does not fit into one of the above classifications.
+# This includes particles that are used in Tanka, Haiku, and other poetry.
+# e.g. かな, けむ, ( しただろう) に, (あんた) にゃ(わからん), (俺) ん (家)
+助詞-特殊
+#
+#####
+# auxiliary-verb:
+助動詞
+#
+#####
+# interjection: Greetings and other exclamations.
+# e.g. おはよう, おはようございます, こんにちは, こんばんは, ありがとう, どうもありがとう, ありがとうございます,
+# いただきます, ごちそうさま, さよなら, さようなら, はい, いいえ, ごめん, ごめんなさい
+感動詞
+#
+#####
+# symbol: unclassified Symbols.
+#記号
+#
+# symbol-misc: A general symbol not in one of the categories below.
+# e.g. [○◎@$〒→+]
+記号-一般
+#
+# symbol-comma: Commas
+# e.g. [,、]
+記号-読点
+#
+# symbol-period: Periods and full stops.
+# e.g. [..。]
+記号-句点
+#
+# symbol-space: Full-width whitespace.
+記号-空白
+#
+# symbol-open_bracket:
+# e.g. [({‘“『【]
+記号-括弧開
+#
+# symbol-close_bracket:
+# e.g. [)}’”』」】]
+記号-括弧閉
+#
+# symbol-alphabetic:
+#記号-アルファベット
+#
+#####
+# other: unclassified other
+#その他
+#
+# other-interjection: Words that are hard to classify as noun-suffixes or
+# sentence-final particles.
+# e.g. (だ)ァ
+その他-間投
+#
+#####
+# filler: Aizuchi that occurs during a conversation or sounds inserted as filler.
+# e.g. あの, うんと, えと
+フィラー
+#
+#####
+# non-verbal: non-verbal sound.
+非言語音
+#
+#####
+# fragment:
+#語断片
+#
+#####
+# unknown: unknown part of speech.
+#未知語
diff --git a/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/stopwords.txt b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/stopwords.txt
new file mode 100644
index 00000000000..78129406ea7
--- /dev/null
+++ b/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/stopwords.txt
@@ -0,0 +1,13 @@
+# short set of japanese stopwords
+いう
+する
+人物
+さま
+すること
+ため
+もの
+おいて
+なる
+できる
+おく
+ある
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/SegmenterTest.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/SegmenterTest.java
new file mode 100644
index 00000000000..e0c35a03d63
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/SegmenterTest.java
@@ -0,0 +1,231 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.util.List;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class SegmenterTest extends LuceneTestCase {
+
+ private static Segmenter segmenter;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ segmenter = new Segmenter();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ segmenter = null;
+ }
+
+ @Test
+ public void testSegmentation() {
+ // Skip tests for Michelle Kwan -- UniDic segments Kwan as ク ワン
+ // String input = "ミシェル・クワンが優勝しました。スペースステーションに行きます。うたがわしい。";
+ // String[] surfaceForms = {
+ // "ミシェル", "・", "クワン", "が", "優勝", "し", "まし", "た", "。",
+ // "スペース", "ステーション", "に", "行き", "ます", "。",
+ // "うたがわしい", "。"
+ // };
+ String input = "スペースステーションに行きます。うたがわしい。";
+ String[] surfaceForms = {
+ "スペース", "ステーション", "に", "行き", "ます", "。",
+ "うたがわしい", "。"
+ };
+ List<Token> tokens = segmenter.tokenize(input);
+ assertTrue(tokens.size() == surfaceForms.length);
+ for (int i = 0; i < tokens.size(); i++) {
+ assertEquals(surfaceForms[i], tokens.get(i).getSurfaceFormString());
+ }
+ }
+
+ @Test
+ public void testReadings() {
+ List<Token> tokens = segmenter.tokenize("寿司が食べたいです。");
+ assertEquals(6, tokens.size());
+ assertEquals("スシ", tokens.get(0).getReading());
+ assertEquals("ガ", tokens.get(1).getReading());
+ assertEquals("タベ", tokens.get(2).getReading());
+ assertEquals("タイ", tokens.get(3).getReading());
+ assertEquals("デス", tokens.get(4).getReading());
+ assertEquals("。", tokens.get(5).getReading());
+ }
+
+ @Test
+ public void testReadings2() {
+ List<Token> tokens = segmenter.tokenize("多くの学生が試験に落ちた。");
+ assertEquals(9, tokens.size());
+ assertEquals("オオク", tokens.get(0).getReading());
+ assertEquals("ノ", tokens.get(1).getReading());
+ assertEquals("ガクセイ", tokens.get(2).getReading());
+ assertEquals("ガ", tokens.get(3).getReading());
+ assertEquals("シケン", tokens.get(4).getReading());
+ assertEquals("ニ", tokens.get(5).getReading());
+ assertEquals("オチ", tokens.get(6).getReading());
+ assertEquals("タ", tokens.get(7).getReading());
+ assertEquals("。", tokens.get(8).getReading());
+ }
+
+ @Test
+ public void testPronunciations() {
+ List<Token> tokens = segmenter.tokenize("寿司が食べたいです。");
+ assertEquals(6, tokens.size());
+ assertEquals("スシ", tokens.get(0).getPronunciation());
+ assertEquals("ガ", tokens.get(1).getPronunciation());
+ assertEquals("タベ", tokens.get(2).getPronunciation());
+ assertEquals("タイ", tokens.get(3).getPronunciation());
+ assertEquals("デス", tokens.get(4).getPronunciation());
+ assertEquals("。", tokens.get(5).getPronunciation());
+ }
+
+ @Test
+ public void testPronunciations2() {
+ List<Token> tokens = segmenter.tokenize("多くの学生が試験に落ちた。");
+ assertEquals(9, tokens.size());
+ // pronunciation differs from reading here
+ assertEquals("オーク", tokens.get(0).getPronunciation());
+ assertEquals("ノ", tokens.get(1).getPronunciation());
+ assertEquals("ガクセイ", tokens.get(2).getPronunciation());
+ assertEquals("ガ", tokens.get(3).getPronunciation());
+ assertEquals("シケン", tokens.get(4).getPronunciation());
+ assertEquals("ニ", tokens.get(5).getPronunciation());
+ assertEquals("オチ", tokens.get(6).getPronunciation());
+ assertEquals("タ", tokens.get(7).getPronunciation());
+ assertEquals("。", tokens.get(8).getPronunciation());
+ }
+
+ @Test
+ public void testBasicForms() {
+ List<Token> tokens = segmenter.tokenize("それはまだ実験段階にあります。");
+ assertEquals(9, tokens.size());
+ assertNull(tokens.get(0).getBaseForm());
+ assertNull(tokens.get(1).getBaseForm());
+ assertNull(tokens.get(2).getBaseForm());
+ assertNull(tokens.get(3).getBaseForm());
+ assertNull(tokens.get(4).getBaseForm());
+ assertNull(tokens.get(5).getBaseForm());
+ assertEquals(tokens.get(6).getBaseForm(), "ある");
+ assertNull(tokens.get(7).getBaseForm());
+ assertNull(tokens.get(8).getBaseForm());
+ }
+
+ @Test
+ public void testInflectionTypes() {
+ List<Token> tokens = segmenter.tokenize("それはまだ実験段階にあります。");
+ assertEquals(9, tokens.size());
+ assertNull(tokens.get(0).getInflectionType());
+ assertNull(tokens.get(1).getInflectionType());
+ assertNull(tokens.get(2).getInflectionType());
+ assertNull(tokens.get(3).getInflectionType());
+ assertNull(tokens.get(4).getInflectionType());
+ assertNull(tokens.get(5).getInflectionType());
+ assertEquals("五段・ラ行", tokens.get(6).getInflectionType());
+ assertEquals("特殊・マス", tokens.get(7).getInflectionType());
+ assertNull(tokens.get(8).getInflectionType());
+ }
+
+ @Test
+ public void testInflectionForms() {
+ List<Token> tokens = segmenter.tokenize("それはまだ実験段階にあります。");
+ assertEquals(9, tokens.size());
+ assertNull(tokens.get(0).getInflectionForm());
+ assertNull(tokens.get(1).getInflectionForm());
+ assertNull(tokens.get(2).getInflectionForm());
+ assertNull(tokens.get(3).getInflectionForm());
+ assertNull(tokens.get(4).getInflectionForm());
+ assertNull(tokens.get(5).getInflectionForm());
+ assertEquals("連用形", tokens.get(6).getInflectionForm());
+ assertEquals("基本形", tokens.get(7).getInflectionForm());
+ assertNull(tokens.get(8).getInflectionForm());
+ }
+
+ @Test
+ public void testPartOfSpeech() {
+ List<Token> tokens = segmenter.tokenize("それはまだ実験段階にあります。");
+ assertEquals(9, tokens.size());
+ assertEquals("名詞-代名詞-一般", tokens.get(0).getPartOfSpeech());
+ assertEquals("助詞-係助詞", tokens.get(1).getPartOfSpeech());
+ assertEquals("副詞-助詞類接続", tokens.get(2).getPartOfSpeech());
+ assertEquals("名詞-サ変接続", tokens.get(3).getPartOfSpeech());
+ assertEquals("名詞-一般", tokens.get(4).getPartOfSpeech());
+ assertEquals("助詞-格助詞-一般", tokens.get(5).getPartOfSpeech());
+ assertEquals("動詞-自立", tokens.get(6).getPartOfSpeech());
+ assertEquals("助動詞", tokens.get(7).getPartOfSpeech());
+ assertEquals("記号-句点", tokens.get(8).getPartOfSpeech());
+ }
+
+ // TODO: the next 2 tests are no longer using the first/last word ids, maybe lookup the words and fix?
+ // do we have a possibility to actually lookup the first and last word from dictionary?
+ public void testYabottai() {
+ List<Token> tokens = segmenter.tokenize("やぼったい");
+ assertEquals(1, tokens.size());
+ assertEquals("やぼったい", tokens.get(0).getSurfaceFormString());
+ }
+
+ public void testTsukitosha() {
+ List<Token> tokens = segmenter.tokenize("突き通しゃ");
+ assertEquals(1, tokens.size());
+ assertEquals("突き通しゃ", tokens.get(0).getSurfaceFormString());
+ }
+
+ public void testBocchan() throws Exception {
+ doTestBocchan(1);
+ }
+
+ @Test @Nightly
+ public void testBocchanBig() throws Exception {
+ doTestBocchan(100);
+ }
+
+ private void doTestBocchan(int numIterations) throws Exception {
+ LineNumberReader reader = new LineNumberReader(new InputStreamReader(
+ this.getClass().getResourceAsStream("bocchan.utf-8")));
+
+ String line = reader.readLine();
+ reader.close();
+
+ if (VERBOSE) {
+ System.out.println("Test for Bocchan without pre-splitting sentences");
+ }
+ long totalStart = System.currentTimeMillis();
+ for (int i = 0; i < numIterations; i++){
+ segmenter.tokenize(line);
+ }
+ if (VERBOSE) {
+ System.out.println("Total time : " + (System.currentTimeMillis() - totalStart));
+ System.out.println("Test for Bocchan with pre-splitting sentences");
+ }
+ String[] sentences = line.split("、|。");
+ totalStart = System.currentTimeMillis();
+ for (int i = 0; i < numIterations; i++) {
+ for (String sentence: sentences) {
+ segmenter.tokenize(sentence);
+ }
+ }
+ if (VERBOSE) {
+ System.out.println("Total time : " + (System.currentTimeMillis() - totalStart));
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestExtendedMode.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestExtendedMode.java
new file mode 100644
index 00000000000..1212f00d608
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestExtendedMode.java
@@ -0,0 +1,63 @@
+package org.apache.lucene.analysis.kuromoji;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.BaseTokenStreamTestCase;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.kuromoji.Segmenter.Mode;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util._TestUtil;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class TestExtendedMode extends BaseTokenStreamTestCase {
+ private final Segmenter segmenter = new Segmenter(Mode.EXTENDED);
+ private final Analyzer analyzer = new Analyzer() {
+
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer tokenizer = new KuromojiTokenizer(segmenter, reader);
+ return new TokenStreamComponents(tokenizer, tokenizer);
+ }
+ };
+
+ /** simple test for supplementary characters */
+ public void testSurrogates() throws IOException {
+ assertAnalyzesTo(analyzer, "𩬅艱鍟䇹愯瀛",
+ new String[] { "𩬅", "艱", "鍟", "䇹", "愯", "瀛" });
+ }
+
+ /** random test ensuring we don't ever split supplementaries */
+ public void testSurrogates2() throws IOException {
+ int numIterations = atLeast(10000);
+ for (int i = 0; i < numIterations; i++) {
+ String s = _TestUtil.randomUnicodeString(random, 100);
+ TokenStream ts = analyzer.tokenStream("foo", new StringReader(s));
+ CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
+ ts.reset();
+ while (ts.incrementToken()) {
+ assertTrue(UnicodeUtil.validUTF16String(termAtt));
+ }
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiAnalyzer.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiAnalyzer.java
new file mode 100644
index 00000000000..3f0361d7d24
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiAnalyzer.java
@@ -0,0 +1,51 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.analysis.BaseTokenStreamTestCase;
+
+public class TestKuromojiAnalyzer extends BaseTokenStreamTestCase {
+ /** This test fails with NPE when the
+ * stopwords file is missing in classpath */
+ public void testResourcesAvailable() {
+ new KuromojiAnalyzer(TEST_VERSION_CURRENT);
+ }
+
+ /**
+ * An example sentence, test removal of particles, etc by POS,
+ * lemmatization with the basic form, and that position increments
+ * and offsets are correct.
+ */
+ public void testBasics() throws IOException {
+ assertAnalyzesTo(new KuromojiAnalyzer(TEST_VERSION_CURRENT), "多くの学生が試験に落ちた。",
+ new String[] { "多く", "学生", "試験", "落ちる" },
+ new int[] { 0, 3, 6, 9 },
+ new int[] { 2, 5, 8, 11 },
+ new int[] { 1, 2, 2, 2 }
+ );
+ }
+
+ /**
+ * blast random strings against the analyzer
+ */
+ public void testRandom() throws IOException {
+ checkRandomData(random, new KuromojiAnalyzer(TEST_VERSION_CURRENT), atLeast(10000));
+ }
+}
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiBaseFormFilter.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiBaseFormFilter.java
new file mode 100644
index 00000000000..4d38ccf188f
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiBaseFormFilter.java
@@ -0,0 +1,50 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.BaseTokenStreamTestCase;
+import org.apache.lucene.analysis.Tokenizer;
+
+public class TestKuromojiBaseFormFilter extends BaseTokenStreamTestCase {
+ private Analyzer analyzer = new Analyzer() {
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer tokenizer = new KuromojiTokenizer(reader);
+ return new TokenStreamComponents(tokenizer, new KuromojiBaseFormFilter(tokenizer));
+ }
+ };
+
+ public void testBasics() throws IOException {
+ assertAnalyzesTo(analyzer, "それはまだ実験段階にあります",
+ new String[] { "それ", "は", "まだ", "実験", "段階", "に", "ある", "ます" }
+ );
+ }
+
+ public void testEnglish() throws IOException {
+ assertAnalyzesTo(analyzer, "this atest",
+ new String[] { "this", "atest" });
+ }
+
+ public void testRandomStrings() throws IOException {
+ checkRandomData(random, analyzer, atLeast(10000));
+ }
+}
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiTokenizer.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiTokenizer.java
new file mode 100644
index 00000000000..14e7eb47065
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/TestKuromojiTokenizer.java
@@ -0,0 +1,150 @@
+package org.apache.lucene.analysis.kuromoji;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.BaseTokenStreamTestCase;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util._TestUtil;
+
+public class TestKuromojiTokenizer extends BaseTokenStreamTestCase {
+ private Analyzer analyzer = new Analyzer() {
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
+ Tokenizer tokenizer = new KuromojiTokenizer(reader);
+ return new TokenStreamComponents(tokenizer, tokenizer);
+ }
+ };
+
+ public void testDecomposition1() throws Exception {
+ assertAnalyzesTo(analyzer, "本来は、貧困層の女性や子供に医療保護を提供するために創設された制度である、" +
+ "アメリカ低所得者医療援助制度が、今日では、その予算の約3分の1を老人に費やしている。",
+ new String[] { "本来", "は", "貧困", "層", "の", "女性", "や", "子供", "に", "医療", "保護", "を",
+ "提供", "する", "ため", "に", "創設", "さ", "れ", "た", "制度", "で", "ある", "アメリカ",
+ "低", "所得", "者", "医療", "援助", "制度", "が", "今日", "で", "は", "その",
+ "予算", "の", "約", "3", "分の", "1", "を", "老人", "に", "費やし", "て", "いる" },
+ new int[] { 0, 2, 4, 6, 7, 8, 10, 11, 13, 14, 16, 18, 19, 21, 23, 25, 26, 28, 29, 30,
+ 31, 33, 34, 37, 41, 42, 44, 45, 47, 49, 51, 53, 55, 56, 58, 60,
+ 62, 63, 64, 65, 67, 68, 69, 71, 72, 75, 76 },
+ new int[] { 2, 3, 6, 7, 8, 10, 11, 13, 14, 16, 18, 19, 21, 23, 25, 26, 28, 29, 30, 31,
+ 33, 34, 36, 41, 42, 44, 45, 47, 49, 51, 52, 55, 56, 57, 60, 62,
+ 63, 64, 65, 67, 68, 69, 71, 72, 75, 76, 78 }
+ );
+ }
+
+ public void testDecomposition2() throws Exception {
+ assertAnalyzesTo(analyzer, "麻薬の密売は根こそぎ絶やさなければならない",
+ new String[] { "麻薬", "の", "密売", "は", "根こそぎ", "絶やさ", "なけれ", "ば", "なら", "ない" },
+ new int[] { 0, 2, 3, 5, 6, 10, 13, 16, 17, 19 },
+ new int[] { 2, 3, 5, 6, 10, 13, 16, 17, 19, 21 }
+ );
+ }
+
+ public void testDecomposition3() throws Exception {
+ assertAnalyzesTo(analyzer, "魔女狩大将マシュー・ホプキンス。",
+ new String[] { "魔女", "狩", "大将", "マシュー", "ホプキンス" },
+ new int[] { 0, 2, 3, 5, 10 },
+ new int[] { 2, 3, 5, 9, 15 }
+ );
+ }
+
+ public void testDecomposition4() throws Exception {
+ assertAnalyzesTo(analyzer, "これは本ではない",
+ new String[] { "これ", "は", "本", "で", "は", "ない" },
+ new int[] { 0, 2, 3, 4, 5, 6 },
+ new int[] { 2, 3, 4, 5, 6, 8 }
+ );
+ }
+
+ public void testDecomposition5() throws Exception {
+ assertAnalyzesTo(analyzer, "くよくよくよくよくよくよくよくよくよくよくよくよくよくよくよくよくよくよくよくよ",
+ new String[] { "くよくよ", "くよくよ", "くよくよ", "くよくよ", "くよくよ", "くよくよ", "くよくよ", "くよくよ", "くよくよ", "くよくよ" },
+ new int[] { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36},
+ new int[] { 4, 8, 12, 16, 20, 24, 28, 32, 36, 40 }
+ );
+ }
+
+ /** Tests that sentence offset is incorporated into the resulting offsets */
+ public void testTwoSentences() throws Exception {
+ assertAnalyzesTo(analyzer, "魔女狩大将マシュー・ホプキンス。 魔女狩大将マシュー・ホプキンス。",
+ new String[] { "魔女", "狩", "大将", "マシュー", "ホプキンス", "魔女", "狩", "大将", "マシュー", "ホプキンス" },
+ new int[] { 0, 2, 3, 5, 10, 17, 19, 20, 22, 27 },
+ new int[] { 2, 3, 5, 9, 15, 19, 20, 22, 26, 32 }
+ );
+ }
+
+ /** blast some random strings through the analyzer */
+ public void testRandomStrings() throws Exception {
+ checkRandomData(random, analyzer, 10000*RANDOM_MULTIPLIER);
+ }
+
+ public void testLargeDocReliability() throws Exception {
+ for (int i = 0; i < 100; i++) {
+ String s = _TestUtil.randomUnicodeString(random, 10000);
+ TokenStream ts = analyzer.tokenStream("foo", new StringReader(s));
+ ts.reset();
+ while (ts.incrementToken()) {
+ }
+ }
+ }
+
+ /** simple test for supplementary characters */
+ public void testSurrogates() throws IOException {
+ assertAnalyzesTo(analyzer, "𩬅艱鍟䇹愯瀛",
+ new String[] { "𩬅", "艱", "鍟", "䇹", "愯", "瀛" });
+ }
+
+ /** random test ensuring we don't ever split supplementaries */
+ public void testSurrogates2() throws IOException {
+ int numIterations = atLeast(10000);
+ for (int i = 0; i < numIterations; i++) {
+ String s = _TestUtil.randomUnicodeString(random, 100);
+ TokenStream ts = analyzer.tokenStream("foo", new StringReader(s));
+ CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
+ ts.reset();
+ while (ts.incrementToken()) {
+ assertTrue(UnicodeUtil.validUTF16String(termAtt));
+ }
+ }
+ }
+
+ // note: test is kinda silly since kuromoji emits punctuation tokens.
+ // but, when/if we filter these out it will be useful.
+ public void testEnd() throws Exception {
+ assertTokenStreamContents(analyzer.tokenStream("foo", new StringReader("これは本ではない")),
+ new String[] { "これ", "は", "本", "で", "は", "ない" },
+ new int[] { 0, 2, 3, 4, 5, 6 },
+ new int[] { 2, 3, 4, 5, 6, 8 },
+ new Integer(8)
+ );
+
+ assertTokenStreamContents(analyzer.tokenStream("foo", new StringReader("これは本ではない ")),
+ new String[] { "これ", "は", "本", "で", "は", "ない" },
+ new int[] { 0, 2, 3, 4, 5, 6, 8 },
+ new int[] { 2, 3, 4, 5, 6, 8, 9 },
+ new Integer(12)
+ );
+ }
+}
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/bocchan.utf-8 b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/bocchan.utf-8
new file mode 100644
index 00000000000..a4c7ea3a02e
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/bocchan.utf-8
@@ -0,0 +1 @@
+坊っちゃん夏目漱石-------------------------------------------------------【テキスト中に現れる記号について】《》:ルビ(例)坊《ぼ》っちゃん|:ルビの付く文字列の始まりを特定する記号(例)夕方|折戸《おりど》の蔭《かげ》に[#]:入力者注 主に外字の説明や、傍点の位置の指定(例)おくれんかな[#「おくれんかな」に傍点]-------------------------------------------------------     一 親譲《おやゆず》りの無鉄砲《むてっぽう》で小供の時から損ばかりしている。小学校に居る時分学校の二階から飛び降りて一週間ほど腰《こし》を抜《ぬ》かした事がある。なぜそんな無闇《むやみ》をしたと聞く人があるかも知れぬ。別段深い理由でもない。新築の二階から首を出していたら、同級生の一人が冗談《じょうだん》に、いくら威張《いば》っても、そこから飛び降りる事は出来まい。弱虫やーい。と囃《はや》したからである。小使《こづかい》に負ぶさって帰って来た時、おやじが大きな眼《め》をして二階ぐらいから飛び降りて腰を抜かす奴《やつ》があるかと云《い》ったから、この次は抜かさずに飛んで見せますと答えた。 親類のものから西洋製のナイフを貰《もら》って奇麗《きれい》な刃《は》を日に翳《かざ》して、友達《ともだち》に見せていたら、一人が光る事は光るが切れそうもないと云った。切れぬ事があるか、何でも切ってみせると受け合った。そんなら君の指を切ってみろと注文したから、何だ指ぐらいこの通りだと右の手の親指の甲《こう》をはすに切り込《こ》んだ。幸《さいわい》ナイフが小さいのと、親指の骨が堅《かた》かったので、今だに親指は手に付いている。しかし創痕《きずあと》は死ぬまで消えぬ。 庭を東へ二十歩に行き尽《つく》すと、南上がりにいささかばかりの菜園があって、真中《まんなか》に栗《くり》の木が一本立っている。これは命より大事な栗だ。実の熟する時分は起き抜けに背戸《せど》を出て落ちた奴を拾ってきて、学校で食う。菜園の西側が山城屋《やましろや》という質屋の庭続きで、この質屋に勘太郎《かんたろう》という十三四の倅《せがれ》が居た。勘太郎は無論弱虫である。弱虫の癖《くせ》に四つ目垣を乗りこえて、栗を盗《ぬす》みにくる。ある日の夕方|折戸《おりど》の蔭《かげ》に隠《かく》れて、とうとう勘太郎を捕《つら》まえてやった。その時勘太郎は逃《に》げ路《みち》を失って、一生懸命《いっしょうけんめい》に飛びかかってきた。向《むこ》うは二つばかり年上である。弱虫だが力は強い。鉢《はち》の開いた頭を、こっちの胸へ宛《あ》ててぐいぐい押《お》した拍子《ひょうし》に、勘太郎の頭がすべって、おれの袷《あわせ》の袖《そで》の中にはいった。邪魔《じゃま》になって手が使えぬから、無暗に手を振《ふ》ったら、袖の中にある勘太郎の頭が、右左へぐらぐら靡《なび》いた。しまいに苦しがって袖の中から、おれの二の腕《うで》へ食い付いた。痛かったから勘太郎を垣根へ押しつけておいて、足搦《あしがら》をかけて向うへ倒《たお》してやった。山城屋の地面は菜園より六尺がた低い。勘太郎は四つ目垣を半分|崩《くず》して、自分の領分へ真逆様《まっさかさま》に落ちて、ぐうと云った。勘太郎が落ちるときに、おれの袷の片袖がもげて、急に手が自由になった。その晩母が山城屋に詫《わ》びに行ったついでに袷の片袖も取り返して来た。 この外いたずらは大分やった。大工の兼公《かねこう》と肴屋《さかなや》の角《かく》をつれて、茂作《もさく》の人参畠《にんじんばたけ》をあらした事がある。人参の芽が出揃《でそろ》わぬ処《ところ》へ藁《わら》が一面に敷《し》いてあったから、その上で三人が半日|相撲《すもう》をとりつづけに取ったら、人参がみんな踏《ふ》みつぶされてしまった。古川《ふるかわ》の持っている田圃《たんぼ》の井戸《いど》を埋《う》めて尻《しり》を持ち込まれた事もある。太い孟宗《もうそう》の節を抜いて、深く埋めた中から水が湧《わ》き出て、そこいらの稲《いね》にみずがかかる仕掛《しかけ》であった。その時分はどんな仕掛か知らぬから、石や棒《ぼう》ちぎれをぎゅうぎゅう井戸の中へ挿《さ》し込んで、水が出なくなったのを見届けて、うちへ帰って飯を食っていたら、古川が真赤《まっか》になって怒鳴《どな》り込んで来た。たしか罰金《ばっきん》を出して済んだようである。 おやじはちっともおれを可愛《かわい》がってくれなかった。母は兄ばかり贔屓《ひいき》にしていた。この兄はやに色が白くって、芝居《しばい》の真似《まね》をして女形《おんながた》になるのが好きだった。おれを見る度にこいつはどうせ碌《ろく》なものにはならないと、おやじが云った。乱暴で乱暴で行く先が案じられると母が云った。なるほど碌なものにはならない。ご覧の通りの始末である。行く先が案じられたのも無理はない。ただ懲役《ちょうえき》に行かないで生きているばかりである。 母が病気で死ぬ二三日《にさんち》前台所で宙返りをしてへっついの角で肋骨《あばらぼね》を撲《う》って大いに痛かった。母が大層|怒《おこ》って、お前のようなものの顔は見たくないと云うから、親類へ泊《とま》りに行っていた。するととうとう死んだと云う報知《しらせ》が来た。そう早く死ぬとは思わなかった。そんな大病なら、もう少し大人《おとな》しくすればよかったと思って帰って来た。そうしたら例の兄がおれを親不孝だ、おれのために、おっかさんが早く死んだんだと云った。口惜《くや》しかったから、兄の横っ面を張って大変|叱《しか》られた。 母が死んでからは、おやじと兄と三人で暮《くら》していた。おやじは何にもせぬ男で、人の顔さえ見れば貴様は駄目《だめ》だ駄目だと口癖のように云っていた。何が駄目なんだか今に分らない。妙《みょう》なおやじがあったもんだ。兄は実業家になるとか云ってしきりに英語を勉強していた。元来女のような性分で、ずるいから、仲がよくなかった。十日に一遍《いっぺん》ぐらいの割で喧嘩《けんか》をしていた。ある時|将棋《しょうぎ》をさしたら卑怯《ひきょう》な待駒《まちごま》をして、人が困ると嬉《うれ》しそうに冷やかした。あんまり腹が立ったから、手に在った飛車を眉間《みけん》へ擲《たた》きつけてやった。眉間が割れて少々血が出た。兄がおやじに言付《いつ》けた。おやじがおれを勘当《かんどう》すると言い出した。 その時はもう仕方がないと観念して先方の云う通り勘当されるつもりでいたら、十年来召し使っている清《きよ》という下女が、泣きながらおやじに詫《あや》まって、ようやくおやじの怒《いか》りが解けた。それにもかかわらずあまりおやじを怖《こわ》いとは思わなかった。かえってこの清と云う下女に気の毒であった。この下女はもと由緒《ゆいしょ》のあるものだったそうだが、瓦解《がかい》のときに零落《れいらく》して、つい奉公《ほうこう》までするようになったのだと聞いている。だから婆《ばあ》さんである。この婆さんがどういう因縁《いんえん》か、おれを非常に可愛がってくれた。不思議なものである。母も死ぬ三日前に愛想《あいそ》をつかした――おやじも年中持て余している――町内では乱暴者の悪太郎と爪弾《つまはじ》きをする――このおれを無暗に珍重《ちんちょう》してくれた。おれは到底《とうてい》人に好かれる性《たち》でないとあきらめていたから、他人から木の端《はし》のように取り扱《あつか》われるのは何とも思わない、かえってこの清のようにちやほやしてくれるのを不審《ふしん》に考えた。清は時々台所で人の居ない時に「あなたは真《ま》っ直《すぐ》でよいご気性だ」と賞《ほ》める事が時々あった。しかしおれには清の云う意味が分からなかった。好《い》い気性なら清以外のものも、もう少し善くしてくれるだろうと思った。清がこんな事を云う度におれはお世辞は嫌《きら》いだと答えるのが常であった。すると婆さんはそれだから好いご気性ですと云っては、嬉しそうにおれの顔を眺《なが》めている。自分の力でおれを製造して誇《ほこ》ってるように見える。少々気味がわるかった。 母が死んでから清はいよいよおれを可愛がった。時々は小供心になぜあんなに可愛がるのかと不審に思った。つまらない、廃《よ》せばいいのにと思った。気の毒だと思った。それでも清は可愛がる。折々は自分の小遣《こづか》いで金鍔《きんつば》や紅梅焼《こうばいやき》を買ってくれる。寒い夜などはひそかに蕎麦粉《そばこ》を仕入れておいて、いつの間にか寝《ね》ている枕元《まくらもと》へ蕎麦湯を持って来てくれる。時には鍋焼饂飩《なべやきうどん》さえ買ってくれた。ただ食い物ばかりではない。靴足袋《くつたび》ももらった。鉛筆《えんぴつ》も貰った、帳面も貰った。これはずっと後の事であるが金を三円ばかり貸してくれた事さえある。何も貸せと云った訳ではない。向うで部屋へ持って来てお小遣いがなくてお困りでしょう、お使いなさいと云ってくれたんだ。おれは無論入らないと云ったが、是非使えと云うから、借りておいた。実は大変嬉しかった。その三円を蝦蟇口《がまぐち》へ入れて、懐《ふところ》へ入れたなり便所へ行ったら、すぽりと後架《こうか》の中へ落《おと》してしまった。仕方がないから、のそのそ出てきて実はこれこれだと清に話したところが、清は早速竹の棒を捜《さが》して来て、取って上げますと云った。しばらくすると井戸端《いどばた》でざあざあ音がするから、出てみたら竹の先へ蝦蟇口の紐《ひも》を引き懸《か》けたのを水で洗っていた。それから口をあけて壱円札《いちえんさつ》を改めたら茶色になって模様が消えかかっていた。清は火鉢で乾《かわ》かして、これでいいでしょうと出した。ちょっとかいでみて臭《くさ》いやと云ったら、それじゃお出しなさい、取り換《か》えて来て上げますからと、どこでどう胡魔化《ごまか》したか札の代りに銀貨を三円持って来た。この三円は何に使ったか忘れてしまった。今に返すよと云ったぎり、返さない。今となっては十倍にして返してやりたくても返せない。 清が物をくれる時には必ずおやじも兄も居ない時に限る。おれは何が嫌いだと云って人に隠れて自分だけ得をするほど嫌いな事はない。兄とは無論仲がよくないけれども、兄に隠して清から菓子《かし》や色鉛筆を貰いたくはない。なぜ、おれ一人にくれて、兄さんには遣《や》らないのかと清に聞く事がある。すると清は澄《すま》したものでお兄様《あにいさま》はお父様《とうさま》が買ってお上げなさるから構いませんと云う。これは不公平である。おやじは頑固《がんこ》だけれども、そんな依怙贔負《えこひいき》はせぬ男だ。しかし清の眼から見るとそう見えるのだろう。全く愛に溺《おぼ》れていたに違《ちが》いない。元は身分のあるものでも教育のない婆さんだから仕方がない。単にこればかりではない。贔負目は恐ろしいものだ。清はおれをもって将来立身出世して立派なものになると思い込んでいた。その癖勉強をする兄は色ばかり白くって、とても役には立たないと一人できめてしまった。こんな婆さんに逢《あ》っては叶《かな》わない。自分の好きなものは必ずえらい人物になって、嫌いなひとはきっと落ち振れるものと信じている。おれはその時から別段何になると云う了見《りょうけん》もなかった。しかし清がなるなると云うものだから、やっぱり何かに成れるんだろうと思っていた。今から考えると馬鹿馬鹿《ばかばか》しい。ある時などは清にどんなものになるだろうと聞いてみた事がある。ところが清にも別段の考えもなかったようだ。ただ手車《てぐるま》へ乗って、立派な玄関《げんかん》のある家をこしらえるに相違《そうい》ないと云った。 それから清はおれがうちでも持って独立したら、一所《いっしょ》になる気でいた。どうか置いて下さいと何遍も繰《く》り返して頼んだ。おれも何だかうちが持てるような気がして、うん置いてやると返事だけはしておいた。ところがこの女はなかなか想像の強い女で、あなたはどこがお好き、麹町《こうじまち》ですか麻布《あざぶ》ですか、お庭へぶらんこをおこしらえ遊ばせ、西洋間は一つでたくさんですなどと勝手な計画を独りで並《なら》べていた。その時は家なんか欲しくも何ともなかった。西洋館も日本建《にほんだて》も全く不用であったから、そんなものは欲しくないと、いつでも清に答えた。すると、あなたは欲がすくなくって、心が奇麗だと云ってまた賞めた。清は何と云っても賞めてくれる。 母が死んでから五六年の間はこの状態で暮していた。おやじには叱られる。兄とは喧嘩をする。清には菓子を貰う、時々賞められる。別に望みもない。これでたくさんだと思っていた。ほかの小供も一概《いちがい》にこんなものだろうと思っていた。ただ清が何かにつけて、あなたはお可哀想《かわいそう》だ、不仕合《ふしあわせ》だと無暗に云うものだから、それじゃ可哀想で不仕合せなんだろうと思った。その外に苦になる事は少しもなかった。ただおやじが小遣いをくれないには閉口した。 母が死んでから六年目の正月におやじも卒中で亡くなった。その年の四月におれはある私立の中学校を卒業する。六月に兄は商業学校を卒業した。兄は何とか会社の九州の支店に口があって行《ゆ》かなければならん。おれは東京でまだ学問をしなければならない。兄は家を売って財産を片付けて任地へ出立《しゅったつ》すると云い出した。おれはどうでもするがよかろうと返事をした。どうせ兄の厄介《やっかい》になる気はない。世話をしてくれるにしたところで、喧嘩をするから、向うでも何とか云い出すに極《きま》っている。なまじい保護を受ければこそ、こんな兄に頭を下げなければならない。牛乳配達をしても食ってられると覚悟《かくご》をした。兄はそれから道具屋を呼んで来て、先祖代々の瓦落多《がらくた》を二束三文《にそくさんもん》に売った。家屋敷《いえやしき》はある人の周旋《しゅうせん》である金満家に譲った。この方は大分金になったようだが、詳《くわ》しい事は一向知らぬ。おれは一ヶ月以前から、しばらく前途の方向のつくまで神田の小川町《おがわまち》へ下宿していた。清は十何年居たうちが人手に渡《わた》るのを大いに残念がったが、自分のものでないから、仕様がなかった。あなたがもう少し年をとっていらっしゃれば、ここがご相続が出来ますものをとしきりに口説いていた。もう少し年をとって相続が出来るものなら、今でも相続が出来るはずだ。婆さんは何《なんに》も知らないから年さえ取れば兄の家がもらえると信じている。 兄とおれはかように分れたが、困ったのは清の行く先である。兄は無論連れて行ける身分でなし、清も兄の尻にくっ付いて九州|下《くんだ》りまで出掛ける気は毛頭なし、と云ってこの時のおれは四畳半《よじょうはん》の安下宿に籠《こも》って、それすらもいざとなれば直ちに引き払《はら》わねばならぬ始末だ。どうする事も出来ん。清に聞いてみた。どこかへ奉公でもする気かねと云ったらあなたがおうちを持って、奥《おく》さまをお貰いになるまでは、仕方がないから、甥《おい》の厄介になりましょうとようやく決心した返事をした。この甥は裁判所の書記でまず今日には差支《さしつか》えなく暮していたから、今までも清に来るなら来いと二三度勧めたのだが、清はたとい下女奉公はしても年来住み馴《な》れた家《うち》の方がいいと云って応じなかった。しかし今の場合知らぬ屋敷へ奉公易《ほうこうが》えをして入らぬ気兼《きがね》を仕直すより、甥の厄介になる方がましだと思ったのだろう。それにしても早くうちを持ての、妻《さい》を貰えの、来て世話をするのと云う。親身《しんみ》の甥よりも他人のおれの方が好きなのだろう。 九州へ立つ二日前兄が下宿へ来て金を六百円出してこれを資本にして商買《しょうばい》をするなり、学資にして勉強をするなり、どうでも随意《ずいい》に使うがいい、その代りあとは構わないと云った。兄にしては感心なやり方だ、何の六百円ぐらい貰わんでも困りはせんと思ったが、例に似ぬ淡泊《たんばく》な処置が気に入ったから、礼を云って貰っておいた。兄はそれから五十円出してこれをついでに清に渡してくれと云ったから、異議なく引き受けた。二日立って新橋の停車場《ていしゃば》で分れたぎり兄にはその後一遍も逢わない。 おれは六百円の使用法について寝ながら考えた。商買をしたって面倒《めんど》くさくって旨《うま》く出来るものじゃなし、ことに六百円の金で商買らしい商買がやれる訳でもなかろう。よしやれるとしても、今のようじゃ人の前へ出て教育を受けたと威張れないからつまり損になるばかりだ。資本などはどうでもいいから、これを学資にして勉強してやろう。六百円を三に割って一年に二百円ずつ使えば三年間は勉強が出来る。三年間一生懸命にやれば何か出来る。それからどこの学校へはいろうと考えたが、学問は生来《しょうらい》どれもこれも好きでない。ことに語学とか文学とか云うものは真平《まっぴら》ご免《めん》だ。新体詩などと来ては二十行あるうちで一行も分らない。どうせ嫌いなものなら何をやっても同じ事だと思ったが、幸い物理学校の前を通り掛《かか》ったら生徒募集の広告が出ていたから、何も縁だと思って規則書をもらってすぐ入学の手続きをしてしまった。今考えるとこれも親譲りの無鉄砲から起《おこ》った失策だ。 三年間まあ人並《ひとなみ》に勉強はしたが別段たちのいい方でもないから、席順はいつでも下から勘定《かんじょう》する方が便利であった。しかし不思議なもので、三年立ったらとうとう卒業してしまった。自分でも可笑《おか》しいと思ったが苦情を云う訳もないから大人しく卒業しておいた。 卒業してから八日目に校長が呼びに来たから、何か用だろうと思って、出掛けて行ったら、四国辺のある中学校で数学の教師が入る。月給は四十円だが、行ってはどうだという相談である。おれは三年間学問はしたが実を云うと教師になる気も、田舎《いなか》へ行く考えも何もなかった。もっとも教師以外に何をしようと云うあてもなかったから、この相談を受けた時、行きましょうと即席《そくせき》に返事をした。これも親譲りの無鉄砲が祟《たた》ったのである。 引き受けた以上は赴任《ふにん》せねばならぬ。この三年間は四畳半に蟄居《ちっきょ》して小言はただの一度も聞いた事がない。喧嘩もせずに済んだ。おれの生涯のうちでは比較的呑気《ひかくてきのんき》な時節であった。しかしこうなると四畳半も引き払わなければならん。生れてから東京以外に踏み出したのは、同級生と一所に鎌倉《かまくら》へ遠足した時ばかりである。今度は鎌倉どころではない。大変な遠くへ行かねばならぬ。地図で見ると海浜で針の先ほど小さく見える。どうせ碌な所ではあるまい。どんな町で、どんな人が住んでるか分らん。分らんでも困らない。心配にはならぬ。ただ行くばかりである。もっとも少々面倒臭い。 家を畳《たた》んでからも清の所へは折々行った。清の甥というのは存外結構な人である。おれが行《ゆ》くたびに、居《お》りさえすれば、何くれと款待《もて》なしてくれた。清はおれを前へ置いて、いろいろおれの自慢《じまん》を甥に聞かせた。今に学校を卒業すると麹町辺へ屋敷を買って役所へ通うのだなどと吹聴《ふいちょう》した事もある。独りで極《き》めて一人《ひとり》で喋舌《しゃべ》るから、こっちは困《こ》まって顔を赤くした。それも一度や二度ではない。折々おれが小さい時寝小便をした事まで持ち出すには閉口した。甥は何と思って清の自慢を聞いていたか分らぬ。ただ清は昔風《むかしふう》の女だから、自分とおれの関係を封建《ほうけん》時代の主従《しゅじゅう》のように考えていた。自分の主人なら甥のためにも主人に相違ないと合点《がてん》したものらしい。甥こそいい面《つら》の皮だ。 いよいよ約束が極まって、もう立つと云う三日前に清を尋《たず》ねたら、北向きの三畳に風邪《かぜ》を引いて寝ていた。おれの来たのを見て起き直るが早いか、坊《ぼ》っちゃんいつ家《うち》をお持ちなさいますと聞いた。卒業さえすれば金が自然とポッケットの中に湧いて来ると思っている。そんなにえらい人をつらまえて、まだ坊っちゃんと呼ぶのはいよいよ馬鹿気ている。おれは単簡に当分うちは持たない。田舎へ行くんだと云ったら、非常に失望した容子《ようす》で、胡麻塩《ごましお》の鬢《びん》の乱れをしきりに撫《な》でた。あまり気の毒だから「行《ゆ》く事は行くがじき帰る。来年の夏休みにはきっと帰る」と慰《なぐさ》めてやった。それでも妙な顔をしているから「何を見やげに買って来てやろう、何が欲しい」と聞いてみたら「越後《えちご》の笹飴《ささあめ》が食べたい」と云った。越後の笹飴なんて聞いた事もない。第一方角が違う。「おれの行く田舎には笹飴はなさそうだ」と云って聞かしたら「そんなら、どっちの見当です」と聞き返した。「西の方だよ」と云うと「箱根《はこね》のさきですか手前ですか」と問う。随分持てあました。 出立の日には朝から来て、いろいろ世話をやいた。来る途中《とちゅう》小間物屋で買って来た歯磨《はみがき》と楊子《ようじ》と手拭《てぬぐい》をズックの革鞄《かばん》に入れてくれた。そんな物は入らないと云ってもなかなか承知しない。車を並べて停車場へ着いて、プラットフォームの上へ出た時、車へ乗り込んだおれの顔をじっと見て「もうお別れになるかも知れません。随分ご機嫌《きげん》よう」と小さな声で云った。目に涙《なみだ》が一杯《いっぱい》たまっている。おれは泣かなかった。しかしもう少しで泣くところであった。汽車がよっぽど動き出してから、もう大丈夫《だいしょうぶ》だろうと思って、窓から首を出して、振り向いたら、やっぱり立っていた。何だか大変小さく見えた。     二 ぶうと云《い》って汽船がとまると、艀《はしけ》が岸を離《はな》れて、漕《こ》ぎ寄せて来た。船頭は真《ま》っ裸《ぱだか》に赤ふんどしをしめている。野蛮《やばん》な所だ。もっともこの熱さでは着物はきられまい。日が強いので水がやに光る。見つめていても眼《め》がくらむ。事務員に聞いてみるとおれはここへ降りるのだそうだ。見るところでは大森《おおもり》ぐらいな漁村だ。人を馬鹿《ばか》にしていらあ、こんな所に我慢《がまん》が出来るものかと思ったが仕方がない。威勢《いせい》よく一番に飛び込んだ。続《つ》づいて五六人は乗ったろう。外に大きな箱《はこ》を四つばかり積み込んで赤ふんは岸へ漕ぎ戻《もど》して来た。陸《おか》へ着いた時も、いの一番に飛び上がって、いきなり、磯《いそ》に立っていた鼻たれ小僧《こぞう》をつらまえて中学校はどこだと聞いた。小僧はぼんやりして、知らんがの、と云った。気の利かぬ田舎《いなか》ものだ。猫《ねこ》の額ほどな町内の癖《くせ》に、中学校のありかも知らぬ奴《やつ》があるものか。ところへ妙《みょう》な筒《つつ》っぽうを着た男がきて、こっちへ来いと云うから、尾《つ》いて行ったら、港屋とか云う宿屋へ連れて来た。やな女が声を揃《そろ》えてお上がりなさいと云うので、上がるのがいやになった。門口へ立ったなり中学校を教えろと云ったら、中学校はこれから汽車で二里ばかり行かなくっちゃいけないと聞いて、なお上がるのがいやになった。おれは、筒っぽうを着た男から、おれの革鞄《かばん》を二つ引きたくって、のそのそあるき出した。宿屋のものは変な顔をしていた。 停車場はすぐ知れた。切符《きっぷ》も訳なく買った。乗り込んでみるとマッチ箱のような汽車だ。ごろごろと五分ばかり動いたと思ったら、もう降りなければならない。道理で切符が安いと思った。たった三銭である。それから車を傭《やと》って、中学校へ来たら、もう放課後で誰《だれ》も居ない。宿直はちょっと用達《ようたし》に出たと小使《こづかい》が教えた。随分《ずいぶん》気楽な宿直がいるものだ。校長でも尋《たず》ねようかと思ったが、草臥《くたび》れたから、車に乗って宿屋へ連れて行けと車夫に云い付けた。車夫は威勢よく山城屋《やましろや》と云ううちへ横付けにした。山城屋とは質屋の勘太郎《かんたろう》の屋号と同じだからちょっと面白く思った。 何だか二階の楷子段《はしごだん》の下の暗い部屋へ案内した。熱くって居られやしない。こんな部屋はいやだと云ったらあいにくみんな塞《ふさ》がっておりますからと云いながら革鞄を抛《ほう》り出したまま出て行った。仕方がないから部屋の中へはいって汗《あせ》をかいて我慢《がまん》していた。やがて湯に入れと云うから、ざぶりと飛び込んで、すぐ上がった。帰りがけに覗《のぞ》いてみると涼《すず》しそうな部屋がたくさん空いている。失敬な奴だ。嘘《うそ》をつきゃあがった。それから下女が膳《ぜん》を持って来た。部屋は熱《あ》つかったが、飯は下宿のよりも大分|旨《うま》かった。給仕をしながら下女がどちらからおいでになりましたと聞くから、東京から来たと答えた。すると東京はよい所でございましょうと云ったから当《あた》り前だと答えてやった。膳を下げた下女が台所へいった時分、大きな笑い声が聞《きこ》えた。くだらないから、すぐ寝《ね》たが、なかなか寝られない。熱いばかりではない。騒々《そうぞう》しい。下宿の五倍ぐらいやかましい。うとうとしたら清《きよ》の夢《ゆめ》を見た。清が越後《えちご》の笹飴《ささあめ》を笹ぐるみ、むしゃむしゃ食っている。笹は毒だからよしたらよかろうと云うと、いえこの笹がお薬でございますと云《い》って旨そうに食っている。おれがあきれ返って大きな口を開いてハハハハと笑ったら眼が覚めた。下女が雨戸を明けている。相変らず空の底が突《つ》き抜《ぬ》けたような天気だ。 道中《どうちゅう》をしたら茶代をやるものだと聞いていた。茶代をやらないと粗末《そまつ》に取り扱われると聞いていた。こんな、狭《せま》くて暗い部屋へ押《お》し込めるのも茶代をやらないせいだろう。見すぼらしい服装《なり》をして、ズックの革鞄と毛繻子《けじゅす》の蝙蝠傘《こうもり》を提げてるからだろう。田舎者の癖に人を見括《みくび》ったな。一番茶代をやって驚《おどろ》かしてやろう。おれはこれでも学資のあまりを三十円ほど懐《ふところ》に入れて東京を出て来たのだ。汽車と汽船の切符代と雑費を差し引いて、まだ十四円ほどある。みんなやったってこれからは月給を貰《もら》うんだから構わない。田舎者はしみったれだから五円もやれば驚《おど》ろいて眼を廻《まわ》すに極《きま》っている。どうするか見ろと済《すま》して顔を洗って、部屋へ帰って待ってると、夕べの下女が膳を持って来た。盆《ぼん》を持って給仕をしながら、やににやにや笑ってる。失敬な奴だ。顔のなかをお祭りでも通りゃしまいし。これでもこの下女の面《つら》よりよっぽど上等だ。飯を済ましてからにしようと思っていたが、癪《しゃく》に障《さわ》ったから、中途《ちゅうと》で五円|札《さつ》を一|枚《まい》出して、あとでこれを帳場へ持って行けと云ったら、下女は変な顔をしていた。それから飯を済ましてすぐ学校へ出懸《でか》けた。靴《くつ》は磨《みが》いてなかった。 学校は昨日《きのう》車で乗りつけたから、大概《たいがい》の見当は分っている。四つ角を二三度曲がったらすぐ門の前へ出た。門から玄関《げんかん》までは御影石《みかげいし》で敷《し》きつめてある。きのうこの敷石の上を車でがらがらと通った時は、無暗《むやみ》に仰山《ぎょうさん》な音がするので少し弱った。途中から小倉《こくら》の制服を着た生徒にたくさん逢《あ》ったが、みんなこの門をはいって行く。中にはおれより背が高くって強そうなのが居る。あんな奴を教えるのかと思ったら何だか気味が悪《わ》るくなった。名刺《めいし》を出したら校長室へ通した。校長は薄髯《うすひげ》のある、色の黒い、目の大きな狸《たぬき》のような男である。やにもったいぶっていた。まあ精出して勉強してくれと云って、恭《うやうや》しく大きな印の捺《おさ》った、辞令を渡《わた》した。この辞令は東京へ帰るとき丸めて海の中へ抛り込《こ》んでしまった。校長は今に職員に紹介《しょうかい》してやるから、一々その人にこの辞令を見せるんだと云って聞かした。余計な手数だ。そんな面倒《めんどう》な事をするよりこの辞令を三日間職員室へ張り付ける方がましだ。 教員が控所《ひかえじょ》へ揃《そろ》うには一時間目の喇叭《らっぱ》が鳴らなくてはならぬ。大分時間がある。校長は時計を出して見て、追々《おいおい》ゆるりと話すつもりだが、まず大体の事を呑《の》み込んでおいてもらおうと云って、それから教育の精神について長いお談義を聞かした。おれは無論いい加減に聞いていたが、途中からこれは飛んだ所へ来たと思った。校長の云うようにはとても出来ない。おれみたような無鉄砲《むてっぽう》なものをつらまえて、生徒の模範《もはん》になれの、一校の師表《しひょう》と仰《あお》がれなくてはいかんの、学問以外に個人の徳化を及《およ》ぼさなくては教育者になれないの、と無暗に法外な注文をする。そんなえらい人が月給四十円で遥々《はるばる》こんな田舎へくるもんか。人間は大概似たもんだ。腹が立てば喧嘩《けんか》の一つぐらいは誰でもするだろうと思ってたが、この様子じゃめったに口も聞けない、散歩も出来ない。そんなむずかしい役なら雇《やと》う前にこれこれだと話すがいい。おれは嘘《うそ》をつくのが嫌《きら》いだから、仕方がない、だまされて来たのだとあきらめて、思い切りよく、ここで断《こと》わって帰っちまおうと思った。宿屋へ五円やったから財布《さいふ》の中には九円なにがししかない。九円じゃ東京までは帰れない。茶代なんかやらなければよかった。惜《お》しい事をした。しかし九円だって、どうかならない事はない。旅費は足りなくっても嘘をつくよりましだと思って、到底《とうてい》あなたのおっしゃる通りにゃ、出来ません、この辞令は返しますと云ったら、校長は狸のような眼をぱちつかせておれの顔を見ていた。やがて、今のはただ希望である、あなたが希望通り出来ないのはよく知っているから心配しなくってもいいと云いながら笑った。そのくらいよく知ってるなら、始めから威嚇《おどさ》さなければいいのに。 そう、こうする内に喇叭が鳴った。教場の方が急にがやがやする。もう教員も控所へ揃いましたろうと云うから、校長に尾いて教員控所へはいった。広い細長い部屋の周囲に机を並《なら》べてみんな腰《こし》をかけている。おれがはいったのを見て、みんな申し合せたようにおれの顔を見た。見世物じゃあるまいし。それから申し付けられた通り一人一人《ひとりびとり》の前へ行って辞令を出して挨拶《あいさつ》をした。大概《たいがい》は椅子《いす》を離れて腰をかがめるばかりであったが、念の入ったのは差し出した辞令を受け取って一応拝見をしてそれを恭《うやうや》しく返却《へんきゃく》した。まるで宮芝居の真似《まね》だ。十五人目に体操《たいそう》の教師へと廻って来た時には、同じ事を何返もやるので少々じれったくなった。向《むこ》うは一度で済む。こっちは同じ所作《しょさ》を十五返繰り返している。少しはひとの了見《りょうけん》も察してみるがいい。 挨拶をしたうちに教頭のなにがしと云うのが居た。これは文学士だそうだ。文学士と云えば大学の卒業生だからえらい人なんだろう。妙《みょう》に女のような優しい声を出す人だった。もっとも驚いたのはこの暑いのにフランネルの襯衣《しゃつ》を着ている。いくらか薄《うす》い地には相違《そうい》なくっても暑いには極ってる。文学士だけにご苦労千万な服装《なり》をしたもんだ。しかもそれが赤シャツだから人を馬鹿《ばか》にしている。あとから聞いたらこの男は年が年中赤シャツを着るんだそうだ。妙な病気があった者だ。当人の説明では赤は身体《からだ》に薬になるから、衛生のためにわざわざ誂《あつ》らえるんだそうだが、入らざる心配だ。そんならついでに着物も袴《はかま》も赤にすればいい。それから英語の教師に古賀《こが》とか云う大変顔色の悪《わ》るい男が居た。大概顔の蒼《あお》い人は瘠《や》せてるもんだがこの男は蒼くふくれている。昔《むかし》小学校へ行く時分、浅井《あさい》の民《たみ》さんと云う子が同級生にあったが、この浅井のおやじがやはり、こんな色つやだった。浅井は百姓《ひゃくしょう》だから、百姓になるとあんな顔になるかと清に聞いてみたら、そうじゃありません、あの人はうらなりの唐茄子《とうなす》ばかり食べるから、蒼くふくれるんですと教えてくれた。それ以来蒼くふくれた人を見れば必ずうらなりの唐茄子を食った酬《むく》いだと思う。この英語の教師もうらなりばかり食ってるに違《ちが》いない。もっともうらなりとは何の事か今もって知らない。清に聞いてみた事はあるが、清は笑って答えなかった。大方清も知らないんだろう。それからおれと同じ数学の教師に堀田《ほった》というのが居た。これは逞《たくま》しい毬栗坊主《いがぐりぼうず》で、叡山《えいざん》の悪僧《あくそう》と云うべき面構《つらがまえ》である。人が叮寧《ていねい》に辞令を見せたら見向きもせず、やあ君が新任の人か、ちと遊びに来給《きたま》えアハハハと云った。何がアハハハだ。そんな礼儀《れいぎ》を心得ぬ奴の所へ誰が遊びに行くものか。おれはこの時からこの坊主に山嵐《やまあらし》という渾名《あだな》をつけてやった。漢学の先生はさすがに堅《かた》いものだ。昨日お着きで、さぞお疲れで、それでもう授業をお始めで、大分ご励精《れいせい》で、――とのべつに弁じたのは愛嬌《あいきょう》のあるお爺《じい》さんだ。画学の教師は全く芸人風だ。べらべらした透綾《すきや》の羽織を着て、扇子《せんす》をぱちつかせて、お国はどちらでげす、え? 東京? そりゃ嬉《うれ》しい、お仲間が出来て……私《わたし》もこれで江戸《えど》っ子ですと云った。こんなのが江戸っ子なら江戸には生れたくないもんだと心中に考えた。そのほか一人一人についてこんな事を書けばいくらでもある。しかし際限がないからやめる。 挨拶が一通り済んだら、校長が今日はもう引き取ってもいい、もっとも授業上の事は数学の主任と打ち合せをしておいて、明後日《あさって》から課業を始めてくれと云った。数学の主任は誰かと聞いてみたら例の山嵐であった。忌々《いまいま》しい、こいつの下に働くのかおやおやと失望した。山嵐は「おい君どこに宿《とま》ってるか、山城屋か、うん、今に行って相談する」と云い残して白墨《はくぼく》を持って教場へ出て行った。主任の癖に向うから来て相談するなんて不見識な男だ。しかし呼び付けるよりは感心だ。 それから学校の門を出て、すぐ宿へ帰ろうと思ったが、帰ったって仕方がないから、少し町を散歩してやろうと思って、無暗に足の向く方をあるき散らした。県庁も見た。古い前世紀の建築である。兵営も見た。麻布《あざぶ》の聯隊《れんたい》より立派でない。大通りも見た。神楽坂《かぐらざか》を半分に狭くしたぐらいな道幅《みちはば》で町並《まちなみ》はあれより落ちる。二十五万石の城下だって高の知れたものだ。こんな所に住んでご城下だなどと威張《いば》ってる人間は可哀想《かわいそう》なものだと考えながらくると、いつしか山城屋の前に出た。広いようでも狭いものだ。これで大抵《たいてい》は見尽《みつく》したのだろう。帰って飯でも食おうと門口をはいった。帳場に坐《すわ》っていたかみさんが、おれの顔を見ると急に飛び出してきてお帰り……と板の間へ頭をつけた。靴《くつ》を脱《ぬ》いで上がると、お座敷《ざしき》があきましたからと下女が二階へ案内をした。十五|畳《じょう》の表二階で大きな床《とこ》の間《ま》がついている。おれは生れてからまだこんな立派な座敷へはいった事はない。この後いつはいれるか分らないから、洋服を脱いで浴衣《ゆかた》一枚になって座敷の真中《まんなか》へ大の字に寝てみた。いい心持ちである。 昼飯を食ってから早速清へ手紙をかいてやった。おれは文章がまずい上に字を知らないから手紙を書くのが大嫌《だいきら》いだ。またやる所もない。しかし清は心配しているだろう。難船して死にやしないかなどと思っちゃ困るから、奮発《ふんぱつ》して長いのを書いてやった。その文句はこうである。「きのう着いた。つまらん所だ。十五畳の座敷に寝ている。宿屋へ茶代を五円やった。かみさんが頭を板の間へすりつけた。夕べは寝られなかった。清が笹飴を笹ごと食う夢を見た。来年の夏は帰る。今日学校へ行ってみんなにあだなをつけてやった。校長は狸、教頭は赤シャツ、英語の教師はうらなり、数学は山嵐、画学はのだいこ。今にいろいろな事を書いてやる。さようなら」 手紙をかいてしまったら、いい心持ちになって眠気《ねむけ》がさしたから、最前のように座敷の真中へのびのびと大の字に寝た。今度は夢も何も見ないでぐっすり寝た。この部屋かいと大きな声がするので目が覚めたら、山嵐がはいって来た。最前は失敬、君の受持ちは……と人が起き上がるや否や談判を開かれたので大いに狼狽《ろうばい》した。受持ちを聞いてみると別段むずかしい事もなさそうだから承知した。このくらいの事なら、明後日は愚《おろか》、明日《あした》から始めろと云ったって驚ろかない。授業上の打ち合せが済んだら、君はいつまでこんな宿屋に居るつもりでもあるまい、僕《ぼく》がいい下宿を周旋《しゅうせん》してやるから移りたまえ。外のものでは承知しないが僕が話せばすぐ出来る。早い方がいいから、今日見て、あす移って、あさってから学校へ行けば極りがいいと一人で呑み込んでいる。なるほど十五畳敷にいつまで居る訳にも行くまい。月給をみんな宿料《しゅくりょう》に払《はら》っても追っつかないかもしれぬ。五円の茶代を奮発《ふんぱつ》してすぐ移るのはちと残念だが、どうせ移る者なら、早く引き越《こ》して落ち付く方が便利だから、そこのところはよろしく山嵐に頼《たの》む事にした。すると山嵐はともかくもいっしょに来てみろと云うから、行った。町はずれの岡の中腹にある家で至極|閑静《かんせい》だ。主人は骨董《こっとう》を売買するいか銀と云う男で、女房《にょうぼう》は亭主《ていしゅ》よりも四つばかり年嵩《としかさ》の女だ。中学校に居た時ウィッチと云う言葉を習った事があるがこの女房はまさにウィッチに似ている。ウィッチだって人の女房だから構わない。とうとう明日から引き移る事にした。帰りに山嵐は通町《とおりちょう》で氷水を一|杯奢《ぱいおご》った。学校で逢った時はやに横風《おうふう》な失敬な奴だと思ったが、こんなにいろいろ世話をしてくれるところを見ると、わるい男でもなさそうだ。ただおれと同じようにせっかちで肝癪持《かんしゃくもち》らしい。あとで聞いたらこの男が一番生徒に人望があるのだそうだ。     三 いよいよ学校へ出た。初めて教場へはいって高い所へ乗った時は、何だか変だった。講釈をしながら、おれでも先生が勤まるのかと思った。生徒はやかましい。時々|図抜《ずぬ》けた大きな声で先生と云《い》う。先生には応《こた》えた。今まで物理学校で毎日先生先生と呼びつけていたが、先生と呼ぶのと、呼ばれるのは雲泥《うんでい》の差だ。何だか足の裏がむずむずする。おれは卑怯《ひきょう》な人間ではない。臆病《おくびょう》な男でもないが、惜《お》しい事に胆力《たんりょく》が欠けている。先生と大きな声をされると、腹の減った時に丸の内で午砲《どん》を聞いたような気がする。最初の一時間は何だかいい加減にやってしまった。しかし別段困った質問も掛《か》けられずに済んだ。控所《ひかえじょ》へ帰って来たら、山嵐がどうだいと聞いた。うんと単簡に返事をしたら山嵐は安心したらしかった。 二時間目に白墨《はくぼく》を持って控所を出た時には何だか敵地へ乗り込《こ》むような気がした。教場へ出ると今度の組は前より大きな奴《やつ》ばかりである。おれは江戸《えど》っ子で華奢《きゃしゃ》に小作りに出来ているから、どうも高い所へ上がっても押《お》しが利かない。喧嘩《けんか》なら相撲取《すもうとり》とでもやってみせるが、こんな大僧《おおぞう》を四十人も前へ並《なら》べて、ただ一|枚《まい》の舌をたたいて恐縮《きょうしゅく》させる手際はない。しかしこんな田舎者《いなかもの》に弱身を見せると癖《くせ》になると思ったから、なるべく大きな声をして、少々巻き舌で講釈してやった。最初のうちは、生徒も烟《けむ》に捲《ま》かれてぼんやりしていたから、それ見ろとますます得意になって、べらんめい調を用いてたら、一番前の列の真中《まんなか》に居た、一番強そうな奴が、いきなり起立して先生と云う。そら来たと思いながら、何だと聞いたら、「あまり早くて分からんけれ、もちっと、ゆるゆる遣《や》って、おくれんかな、もし」と云った。おくれんかな[#「おくれんかな」に傍点]、もし[#「もし」に傍点]は生温《なまぬ》るい言葉だ。早過ぎるなら、ゆっくり云ってやるが、おれは江戸っ子だから君等《きみら》の言葉は使えない、分《わか》らなければ、分るまで待ってるがいいと答えてやった。この調子で二時間目は思ったより、うまく行った。ただ帰りがけに生徒の一人がちょっとこの問題を解釈をしておくれんかな、もし、と出来そうもない幾何《きか》の問題を持って逼《せま》ったには冷汗《ひやあせ》を流した。仕方がないから何だか分らない、この次教えてやると急いで引き揚《あ》げたら、生徒がわあと囃《はや》した。その中に出来ん出来んと云う声が聞《きこ》える。箆棒《べらぼう》め、先生だって、出来ないのは当り前だ。出来ないのを出来ないと云うのに不思議があるもんか。そんなものが出来るくらいなら四十円でこんな田舎へくるもんかと控所へ帰って来た。今度はどうだとまた山嵐が聞いた。うんと云ったが、うんだけでは気が済まなかったから、この学校の生徒は分らずやだなと云ってやった。山嵐は妙《みょう》な顔をしていた。 三時間目も、四時間目も昼過ぎの一時間も大同小異であった。最初の日に出た級は、いずれも少々ずつ失敗した。教師ははたで見るほど楽じゃないと思った。授業はひと通り済んだが、まだ帰れない、三時までぽつ然《ねん》として待ってなくてはならん。三時になると、受持級の生徒が自分の教室を掃除《そうじ》して報知《しらせ》にくるから検分をするんだそうだ。それから、出席簿《しゅっせきぼ》を一応調べてようやくお暇《ひま》が出る。いくら月給で買われた身体《からだ》だって、あいた時間まで学校へ縛《しば》りつけて机と睨《にら》めっくらをさせるなんて法があるものか。しかしほかの連中はみんな大人《おとな》しくご規則通りやってるから新参のおればかり、だだを捏《こ》ねるのもよろしくないと思って我慢《がまん》していた。帰りがけに、君何でもかんでも三時|過《すぎ》まで学校にいさせるのは愚《おろか》だぜと山嵐に訴えたら、山嵐はそうさアハハハと笑ったが、あとから真面目《まじめ》になって、君あまり学校の不平を云うと、いかんぜ。云うなら僕《ぼく》だけに話せ、随分《ずいぶん》妙な人も居るからなと忠告がましい事を云った。四つ角で分れたから詳《くわ》しい事は聞くひまがなかった。 それからうちへ帰ってくると、宿の亭主《ていしゅ》がお茶を入れましょうと云ってやって来る。お茶を入れると云うからご馳走《ちそう》をするのかと思うと、おれの茶を遠慮《えんりょ》なく入れて自分が飲むのだ。この様子では留守中《るすちゅう》も勝手にお茶を入れましょうを一人《ひとり》で履行《りこう》しているかも知れない。亭主が云うには手前は書画骨董《しょがこっとう》がすきで、とうとうこんな商買を内々で始めるようになりました。あなたもお見受け申すところ大分ご風流でいらっしゃるらしい。ちと道楽にお始めなすってはいかがですと、飛んでもない勧誘《かんゆう》をやる。二年前ある人の使《つかい》に帝国《ていこく》ホテルへ行った時は錠前《じょうまえ》直しと間違《まちが》えられた事がある。ケットを被《かぶ》って、鎌倉《かまくら》の大仏を見物した時は車屋から親方と云われた。その外|今日《こんにち》まで見損《みそくな》われた事は随分あるが、まだおれをつらまえて大分ご風流でいらっしゃると云ったものはない。大抵《たいてい》はなりや様子でも分る。風流人なんていうものは、画《え》を見ても、頭巾《ずきん》を被《かぶ》るか短冊《たんざく》を持ってるものだ。このおれを風流人だなどと真面目に云うのはただの曲者《くせもの》じゃない。おれはそんな呑気《のんき》な隠居《いんきょ》のやるような事は嫌《きら》いだと云ったら、亭主はへへへへと笑いながら、いえ始めから好きなものは、どなたもございませんが、いったんこの道にはいるとなかなか出られませんと一人で茶を注いで妙な手付《てつき》をして飲んでいる。実はゆうべ茶を買ってくれと頼《たの》んでおいたのだが、こんな苦い濃《こ》い茶はいやだ。一|杯《ぱい》飲むと胃に答えるような気がする。今度からもっと苦くないのを買ってくれと云ったら、かしこまりましたとまた一杯しぼって飲んだ。人の茶だと思って無暗《むやみ》に飲む奴《やつ》だ。主人が引き下がってから、明日の下読《したよみ》をしてすぐ寝《ね》てしまった。 それから毎日毎日学校へ出ては規則通り働く、毎日毎日帰って来ると主人がお茶を入れましょうと出てくる。一週間ばかりしたら学校の様子もひと通りは飲み込めたし、宿の夫婦の人物も大概《たいがい》は分った。ほかの教師に聞いてみると辞令を受けて一週間から一ヶ月ぐらいの間は自分の評判がいいだろうか、悪《わ》るいだろうか非常に気に掛《か》かるそうであるが、おれは一向そんな感じはなかった。教場で折々しくじるとその時だけはやな心持ちだが三十分ばかり立つと奇麗《きれい》に消えてしまう。おれは何事によらず長く心配しようと思っても心配が出来ない男だ。教場のしくじりが生徒にどんな影響《えいきょう》を与《あた》えて、その影響が校長や教頭にどんな反応を呈《てい》するかまるで無頓着《むとんじゃく》であった。おれは前に云う通りあまり度胸の据《すわ》った男ではないのだが、思い切りはすこぶるいい人間である。この学校がいけなければすぐどっかへ行《ゆ》く覚悟《かくご》でいたから、狸《たぬき》も赤シャツも、ちっとも恐《おそろ》しくはなかった。まして教場の小僧《こぞう》共なんかには愛嬌《あいきょう》もお世辞も使う気になれなかった。学校はそれでいいのだが下宿の方はそうはいかなかった。亭主が茶を飲みに来るだけなら我慢もするが、いろいろな者を持ってくる。始めに持って来たのは何でも印材で、十《とお》ばかり並《なら》べておいて、みんなで三円なら安い物だお買いなさいと云う。田舎巡《いなかまわ》りのヘボ絵師じゃあるまいし、そんなものは入らないと云ったら、今度は華山《かざん》とか何とか云う男の花鳥の掛物《かけもの》をもって来た。自分で床《とこ》の間《ま》へかけて、いい出来じゃありませんかと云うから、そうかなと好加減《いいかげん》に挨拶《あいさつ》をすると、華山には二人《ふたり》ある、一人は何とか華山で、一人は何とか華山ですが、この幅《ふく》はその何とか華山の方だと、くだらない講釈をしたあとで、どうです、あなたなら十五円にしておきます。お買いなさいと催促《さいそく》をする。金がないと断わると、金なんか、いつでもようございますとなかなか頑固《がんこ》だ。金があつても買わないんだと、その時は追っ払《ぱら》っちまった。その次には鬼瓦《おにがわら》ぐらいな大硯《おおすずり》を担ぎ込んだ。これは端渓《たんけい》です、端渓ですと二|遍《へん》も三遍も端渓がるから、面白半分に端渓た何だいと聞いたら、すぐ講釈を始め出した。端渓には上層中層下層とあって、今時のものはみんな上層ですが、これはたしかに中層です、この眼《がん》をご覧なさい。眼が三つあるのは珍《めず》らしい。溌墨《はつぼく》の具合も至極よろしい、試してご覧なさいと、おれの前へ大きな硯を突《つ》きつける。いくらだと聞くと、持主が支那《しな》から持って帰って来て是非売りたいと云いますから、お安くして三十円にしておきましょうと云う。この男は馬鹿《ばか》に相違《そうい》ない。学校の方はどうかこうか無事に勤まりそうだが、こう骨董責《こっとうぜめ》に逢《あ》ってはとても長く続きそうにない。 そのうち学校もいやになった。  ある日の晩|大町《おおまち》と云う所を散歩していたら郵便局の隣《とな》りに蕎麦《そば》とかいて、下に東京と注を加えた看板があった。おれは蕎麦が大好きである。東京に居《お》った時でも蕎麦屋の前を通って薬味の香《にお》いをかぐと、どうしても暖簾《のれん》がくぐりたくなった。今日までは数学と骨董で蕎麦を忘れていたが、こうして看板を見ると素通りが出来なくなる。ついでだから一杯食って行こうと思って上がり込んだ。見ると看板ほどでもない。東京と断《こと》わる以上はもう少し奇麗にしそうなものだが、東京を知らないのか、金がないのか、滅法《めっぽう》きたない。畳《たたみ》は色が変ってお負けに砂でざらざらしている。壁《かべ》は煤《すす》で真黒《まっくろ》だ。天井《てんじょう》はランプの油烟《ゆえん》で燻《くす》ぼってるのみか、低くって、思わず首を縮めるくらいだ。ただ麗々と蕎麦の名前をかいて張り付けたねだん付けだけは全く新しい。何でも古いうちを買って二三日《にさんち》前から開業したに違《ちが》いなかろう。ねだん付の第一号に天麩羅《てんぷら》とある。おい天麩羅を持ってこいと大きな声を出した。するとこの時まで隅《すみ》の方に三人かたまって、何かつるつる、ちゅうちゅう食ってた連中《れんじゅう》が、ひとしくおれの方を見た。部屋《へや》が暗いので、ちょっと気がつかなかったが顔を合せると、みんな学校の生徒である。先方で挨拶《あいさつ》をしたから、おれも挨拶をした。その晩は久《ひさ》し振《ぶり》に蕎麦を食ったので、旨《うま》かったから天麩羅を四杯|平《たいら》げた。 翌日何の気もなく教場へはいると、黒板一杯ぐらいな大きな字で、天麩羅先生とかいてある。おれの顔を見てみんなわあと笑った。おれは馬鹿馬鹿しいから、天麩羅を食っちゃ可笑《おか》しいかと聞いた。すると生徒の一人《ひとり》が、しかし四杯は過ぎるぞな、もし、と云った。四杯食おうが五杯食おうがおれの銭でおれが食うのに文句があるもんかと、さっさと講義を済まして控所へ帰って来た。十分立って次の教場へ出ると一つ天麩羅四杯なり。但《ただ》し笑うべからず。と黒板にかいてある。さっきは別に腹も立たなかったが今度は癪《しゃく》に障《さわ》った。冗談《じょうだん》も度を過ごせばいたずらだ。焼餅《やきもち》の黒焦《くろこげ》のようなもので誰《だれ》も賞《ほ》め手はない。田舎者はこの呼吸が分からないからどこまで押《お》して行っても構わないと云う了見《りょうけん》だろう。一時間あるくと見物する町もないような狭《せま》い都に住んで、外に何にも芸がないから、天麩羅事件を日露《にちろ》戦争のように触《ふ》れちらかすんだろう。憐《あわ》れな奴等《やつら》だ。小供の時から、こんなに教育されるから、いやにひねっこびた、植木鉢《うえきばち》の楓《かえで》みたような小人《しょうじん》が出来るんだ。無邪気《むじゃき》ならいっしょに笑ってもいいが、こりゃなんだ。小供の癖《くせ》に乙《おつ》に毒気を持ってる。おれはだまって、天麩羅を消して、こんないたずらが面白いか、卑怯《ひきょう》な冗談だ。君等は卑怯と云う意味を知ってるか、と云ったら、自分がした事を笑われて怒《おこ》るのが卑怯じゃろうがな、もしと答えた奴がある。やな奴だ。わざわざ東京から、こんな奴を教えに来たのかと思ったら情なくなった。余計な減らず口を利かないで勉強しろと云って、授業を始めてしまった。それから次の教場へ出たら天麩羅を食うと減らず口が利きたくなるものなりと書いてある。どうも始末に終えない。あんまり腹が立ったから、そんな生意気な奴は教えないと云ってすたすた帰って来てやった。生徒は休みになって喜んだそうだ。こうなると学校より骨董の方がまだましだ。 天麩羅蕎麦もうちへ帰って、一晩寝たらそんなに肝癪《かんしゃく》に障らなくなった。学校へ出てみると、生徒も出ている。何だか訳が分らない。それから三日ばかりは無事であったが、四日目の晩に住田《すみた》と云う所へ行って団子《だんご》を食った。この住田と云う所は温泉のある町で城下から汽車だと十分ばかり、歩いて三十分で行かれる、料理屋も温泉宿も、公園もある上に遊廓《ゆうかく》がある。おれのはいった団子屋は遊廓の入口にあって、大変うまいという評判だから、温泉に行った帰りがけにちょっと食ってみた。今度は生徒にも逢わなかったから、誰《だれ》も知るまいと思って、翌日学校へ行って、一時間目の教場へはいると団子二|皿《さら》七銭と書いてある。実際おれは二皿食って七銭|払《はら》った。どうも厄介《やっかい》な奴等だ。二時間目にもきっと何かあると思うと遊廓の団子旨い旨いと書いてある。あきれ返った奴等だ。団子がそれで済んだと思ったら今度は赤手拭《あかてぬぐい》と云うのが評判になった。何の事だと思ったら、つまらない来歴だ。おれはここへ来てから、毎日住田の温泉へ行く事に極《き》めている。ほかの所は何を見ても東京の足元にも及《およ》ばないが温泉だけは立派なものだ。せっかく来た者だから毎日はいってやろうという気で、晩飯前に運動かたがた出掛《でかけ》る。ところが行くときは必ず西洋手拭の大きな奴をぶら下げて行く。この手拭が湯に染《そま》った上へ、赤い縞《しま》が流れ出したのでちょっと見ると紅色《べにいろ》に見える。おれはこの手拭を行きも帰りも、汽車に乗ってもあるいても、常にぶら下げている。それで生徒がおれの事を赤手拭赤手拭と云うんだそうだ。どうも狭い土地に住んでるとうるさいものだ。まだある。温泉は三階の新築で上等は浴衣《ゆかた》をかして、流しをつけて八銭で済む。その上に女が天目《てんもく》へ茶を載《の》せて出す。おれはいつでも上等へはいった。すると四十円の月給で毎日上等へはいるのは贅沢《ぜいたく》だと云い出した。余計なお世話だ。まだある。湯壺《ゆつぼ》は花崗石《みかげいし》を畳《たた》み上げて、十五|畳敷《じょうじき》ぐらいの広さに仕切ってある。大抵《たいてい》は十三四人|漬《つか》ってるがたまには誰も居ない事がある。深さは立って乳の辺まであるから、運動のために、湯の中を泳ぐのはなかなか愉快《ゆかい》だ。おれは人の居ないのを見済《みすま》しては十五畳の湯壺を泳ぎ巡《まわ》って喜んでいた。ところがある日三階から威勢《いせい》よく下りて今日も泳げるかなとざくろ口を覗《のぞ》いてみると、大きな札へ黒々と湯の中で泳ぐべからずとかいて貼《は》りつけてある。湯の中で泳ぐものは、あまりあるまいから、この貼札《はりふだ》はおれのために特別に新調したのかも知れない。おれはそれから泳ぐのは断念した。泳ぐのは断念したが、学校へ出てみると、例の通り黒板に湯の中で泳ぐべからずと書いてあるには驚《おど》ろいた。何だか生徒全体がおれ一人を探偵《たんてい》しているように思われた。くさくさした。生徒が何を云ったって、やろうと思った事をやめるようなおれではないが、何でこんな狭苦しい鼻の先がつかえるような所へ来たのかと思うと情なくなった。それでうちへ帰ると相変らず骨董責である。     四 学校には宿直があって、職員が代る代るこれをつとめる。但《ただ》し狸《たぬき》と赤シャツは例外である。何でこの両人が当然の義務を免《まぬ》かれるのかと聞いてみたら、奏任待遇《そうにんたいぐう》だからと云う。面白くもない。月給はたくさんとる、時間は少ない、それで宿直を逃《の》がれるなんて不公平があるものか。勝手な規則をこしらえて、それが当《あた》り前《まえ》だというような顔をしている。よくまああんなにずうずうしく出来るものだ。これについては大分不平であるが、山嵐《やまあらし》の説によると、いくら一人《ひとり》で不平を並《なら》べたって通るものじゃないそうだ。一人だって二人《ふたり》だって正しい事なら通りそうなものだ。山嵐は might is right という英語を引いて説諭《せつゆ》を加えたが、何だか要領を得ないから、聞き返してみたら強者の権利と云う意味だそうだ。強者の権利ぐらいなら昔《むかし》から知っている。今さら山嵐から講釈をきかなくってもいい。強者の権利と宿直とは別問題だ。狸や赤シャツが強者だなんて、誰《だれ》が承知するものか。議論は議論としてこの宿直がいよいよおれの番に廻《まわ》って来た。一体|疳性《かんしょう》だから夜具蒲団《やぐふとん》などは自分のものへ楽に寝ないと寝たような心持ちがしない。小供の時から、友達のうちへ泊《とま》った事はほとんどないくらいだ。友達のうちでさえ厭《いや》なら学校の宿直はなおさら厭だ。厭だけれども、これが四十円のうちへ籠《こも》っているなら仕方がない。我慢《がまん》して勤めてやろう。 教師も生徒も帰ってしまったあとで、一人ぽかんとしているのは随分《ずいぶん》間が抜《ぬ》けたものだ。宿直部屋は教場の裏手にある寄宿舎の西はずれの一室だ。ちょっとはいってみたが、西日をまともに受けて、苦しくって居たたまれない。田舎《いなか》だけあって秋がきても、気長に暑いもんだ。生徒の賄《まかない》を取りよせて晩飯を済ましたが、まずいには恐《おそ》れ入《い》った。よくあんなものを食って、あれだけに暴れられたもんだ。それで晩飯を急いで四時半に片付けてしまうんだから豪傑《ごうけつ》に違《ちが》いない。飯は食ったが、まだ日が暮《く》れないから寝《ね》る訳に行かない。ちょっと温泉に行きたくなった。宿直をして、外へ出るのはいい事だか、悪《わ》るい事だかしらないが、こうつくねんとして重禁錮《じゅうきんこ》同様な憂目《うきめ》に逢《あ》うのは我慢の出来るもんじゃない。始めて学校へ来た時当直の人はと聞いたら、ちょっと用達《ようたし》に出たと小使《こづかい》が答えたのを妙《みょう》だと思ったが、自分に番が廻《まわ》ってみると思い当る。出る方が正しいのだ。おれは小使にちょっと出てくると云ったら、何かご用ですかと聞くから、用じゃない、温泉へはいるんだと答えて、さっさと出掛《でか》けた。赤手拭《あかてぬぐい》は宿へ忘れて来たのが残念だが今日は先方で借りるとしよう。 それからかなりゆるりと、出たりはいったりして、ようやく日暮方《ひぐれがた》になったから、汽車へ乗って古町《こまち》の停車場《ていしゃば》まで来て下りた。学校まではこれから四丁だ。訳はないとあるき出すと、向うから狸が来た。狸はこれからこの汽車で温泉へ行こうと云う計画なんだろう。すたすた急ぎ足にやってきたが、擦《す》れ違《ちが》った時おれの顔を見たから、ちょっと挨拶《あいさつ》をした。すると狸はあなたは今日は宿直ではなかったですかねえ[#「なかったですかねえ」に傍点]と真面目《まじめ》くさって聞いた。なかったですかねえもないもんだ。二時間前おれに向って今夜は始めての宿直ですね。ご苦労さま。と礼を云ったじゃないか。校長なんかになるといやに曲りくねった言葉を使うもんだ。おれは腹が立ったから、ええ宿直です。宿直ですから、これから帰って泊る事はたしかに泊りますと云い捨てて済ましてあるき出した。竪町《たてまち》の四つ角までくると今度は山嵐《やまあらし》に出っ喰《く》わした。どうも狭《せま》い所だ。出てあるきさえすれば必ず誰かに逢う。「おい君は宿直じゃないか」と聞くから「うん、宿直だ」と答えたら、「宿直が無暗《むやみ》に出てあるくなんて、不都合《ふつごう》じゃないか」と云った。「ちっとも不都合なもんか、出てあるかない方が不都合だ」と威張《いば》ってみせた。「君のずぼらにも困るな、校長か教頭に出逢うと面倒《めんどう》だぜ」と山嵐に似合わない事を云うから「校長にはたった今逢った。暑い時には散歩でもしないと宿直も骨でしょうと校長が、おれの散歩をほめたよ」と云って、面倒|臭《くさ》いから、さっさと学校へ帰って来た。 それから日はすぐくれる。くれてから二時間ばかりは小使を宿直部屋へ呼んで話をしたが、それも飽《あ》きたから、寝られないまでも床《とこ》へはいろうと思って、寝巻に着換《きが》えて、蚊帳《かや》を捲《ま》くって、赤い毛布《けっと》を跳《は》ねのけて、とんと尻持《しりもち》を突《つ》いて、仰向《あおむ》けになった。おれが寝るときにとんと尻持をつくのは小供の時からの癖《くせ》だ。わるい癖だと云って小川町《おがわまち》の下宿に居た時分、二階下に居た法律学校の書生が苦情を持ち込《こ》んだ事がある。法律の書生なんてものは弱い癖に、やに口が達者なもので、愚《ぐ》な事を長たらしく述べ立てるから、寝る時にどんどん音がするのはおれの尻がわるいのじゃない。下宿の建築が粗末《そまつ》なんだ。掛《か》ケ合うなら下宿へ掛ケ合えと凹《へこ》ましてやった。この宿直部屋は二階じゃないから、いくら、どしんと倒《たお》れても構わない。なるべく勢《いきおい》よく倒れないと寝たような心持ちがしない。ああ愉快だと足をうんと延ばすと、何だか両足へ飛び付いた。ざらざらして蚤《のみ》のようでもないからこいつあと驚《おど》ろいて、足を二三度|毛布《けっと》の中で振《ふ》ってみた。するとざらざらと当ったものが、急に殖《ふ》え出して脛《すね》が五六カ所、股《もも》が二三カ所、尻の下でぐちゃりと踏《ふ》み潰《つぶ》したのが一つ、臍《へそ》の所まで飛び上がったのが一つ――いよいよ驚ろいた。早速《さっそく》起き上《あが》って、毛布《けっと》をぱっと後ろへ抛《ほう》ると、蒲団の中から、バッタが五六十飛び出した。正体の知れない時は多少気味が悪《わ》るかったが、バッタと相場が極《き》まってみたら急に腹が立った。バッタの癖に人を驚ろかしやがって、どうするか見ろと、いきなり括《くく》り枕《まくら》を取って、二三度|擲《たた》きつけたが、相手が小さ過ぎるから勢よく抛《な》げつける割に利目《ききめ》がない。仕方がないから、また布団の上へ坐《すわ》って、煤掃《すすはき》の時に蓙《ござ》を丸めて畳《たたみ》を叩《たた》くように、そこら近辺を無暗にたたいた。バッタが驚ろいた上に、枕の勢で飛び上がるものだから、おれの肩《かた》だの、頭だの鼻の先だのへくっ付いたり、ぶつかったりする。顔へ付いた奴《やつ》は枕で叩く訳に行かないから、手で攫《つか》んで、一生懸命に擲きつける。忌々《いまいま》しい事に、いくら力を出しても、ぶつかる先が蚊帳だから、ふわりと動くだけで少しも手答がない。バッタは擲きつけられたまま蚊帳へつらまっている。死にもどうもしない。ようやくの事に三十分ばかりでバッタは退治《たいじ》た。箒《ほうき》を持って来てバッタの死骸《しがい》を掃き出した。小使が来て何ですかと云うから、何ですかもあるもんか、バッタを床の中に飼《か》っとく奴がどこの国にある。間抜《まぬけ》め。と叱《しか》ったら、私は存じませんと弁解をした。存じませんで済むかと箒を椽側《えんがわ》へ抛《ほう》り出したら、小使は恐る恐る箒を担いで帰って行った。 おれは早速寄宿生を三人ばかり総代に呼び出した。すると六人出て来た。六人だろうが十人だろうが構うものか。寝巻のまま腕《うで》まくりをして談判を始めた。「なんでバッタなんか、おれの床の中へ入れた」「バッタた何ぞな」と真先《まっさき》の一人がいった。やに落ち付いていやがる。この学校じゃ校長ばかりじゃない、生徒まで曲りくねった言葉を使うんだろう。「バッタを知らないのか、知らなけりゃ見せてやろう」と云ったが、生憎《あいにく》掃き出してしまって一|匹《ぴき》も居ない。また小使を呼んで、「さっきのバッタを持ってこい」と云ったら、「もう掃溜《はきだめ》へ棄《す》ててしまいましたが、拾って参りましょうか」と聞いた。「うんすぐ拾って来い」と云うと小使は急いで馳《か》け出したが、やがて半紙の上へ十匹ばかり載《の》せて来て「どうもお気の毒ですが、生憎夜でこれだけしか見当りません。あしたになりましたらもっと拾って参ります」と云う。小使まで馬鹿《ばか》だ。おれはバッタの一つを生徒に見せて「バッタたこれだ、大きなずう体をして、バッタを知らないた、何の事だ」と云うと、一番左の方に居た顔の丸い奴が「そりゃ、イナゴぞな、もし」と生意気におれを遣《や》り込《こ》めた。「篦棒《べらぼう》め、イナゴもバッタも同じもんだ。第一先生を捕《つら》まえてなもし[#「なもし」に傍点]た何だ。菜飯《なめし》は田楽《でんがく》の時より外に食うもんじゃない」とあべこべに遣り込めてやったら「なもしと菜飯とは違うぞな、もし」と云った。いつまで行ってもなもし[#「なもし」に傍点]を使う奴だ。「イナゴでもバッタでも、何でおれの床の中へ入れたんだ。おれがいつ、バッタを入れてくれと頼《たの》んだ」「誰も入れやせんがな」「入れないものが、どうして床の中に居るんだ」「イナゴは温《ぬく》い所が好きじゃけれ、大方一人でおはいりたのじゃあろ」「馬鹿あ云え。バッタが一人でおはいりになるなんて――バッタにおはいりになられてたまるもんか。――さあなぜこんないたずらをしたか、云え」「云えてて、入れんものを説明しようがないがな」 けちな奴等《やつら》だ。自分で自分のした事が云えないくらいなら、てんでしないがいい。証拠《しょうこ》さえ挙がらなければ、しらを切るつもりで図太く構えていやがる。おれだって中学に居た時分は少しはいたずらもしたもんだ。しかしだれがしたと聞かれた時に、尻込みをするような卑怯《ひきょう》な事はただの一度もなかった。したものはしたので、しないものはしないに極《きま》ってる。おれなんぞは、いくら、いたずらをしたって潔白なものだ。嘘を吐《つ》いて罰《ばつ》を逃《に》げるくらいなら、始めからいたずらなんかやるものか。いたずらと罰はつきもんだ。罰があるからいたずらも心持ちよく出来る。いたずらだけで罰はご免蒙《めんこうむ》るなんて下劣《げれつ》な根性がどこの国に流行《はや》ると思ってるんだ。金は借りるが、返す事はご免だと云う連中はみんな、こんな奴等が卒業してやる仕事に相違《そうい》ない。全体中学校へ何しにはいってるんだ。学校へはいって、嘘を吐いて、胡魔化《ごまか》して、陰《かげ》でこせこせ生意気な悪いたずらをして、そうして大きな面で卒業すれば教育を受けたもんだと癇違《かんちが》いをしていやがる。話せない雑兵《ぞうひょう》だ。 おれはこんな腐《くさ》った了見《りょうけん》の奴等と談判するのは胸糞《むなくそ》が悪《わ》るいから、「そんなに云われなきゃ、聞かなくっていい。中学校へはいって、上品も下品も区別が出来ないのは気の毒なものだ」と云って六人を逐《お》っ放《ぱな》してやった。おれは言葉や様子こそあまり上品じゃないが、心はこいつらよりも遥《はる》かに上品なつもりだ。六人は悠々《ゆうゆう》と引き揚《あ》げた。上部《うわべ》だけは教師のおれよりよっぽどえらく見える。実は落ち付いているだけなお悪るい。おれには到底《とうてい》これほどの度胸はない。 それからまた床へはいって横になったら、さっきの騒動《そうどう》で蚊帳の中はぶんぶん唸《うな》っている。手燭《てしょく》をつけて一匹ずつ焼くなんて面倒な事は出来ないから、釣手《つりて》をはずして、長く畳《たた》んでおいて部屋の中で横竪《よこたて》十文字に振《ふる》ったら、環《かん》が飛んで手の甲《こう》をいやというほど撲《ぶ》った。三度目に床へはいった時は少々落ち付いたがなかなか寝られない。時計を見ると十時半だ。考えてみると厄介な所へ来たもんだ。一体中学の先生なんて、どこへ行っても、こんなものを相手にするなら気の毒なものだ。よく先生が品切れにならない。よっぽど辛防《しんぼう》強い朴念仁《ぼくねんじん》がなるんだろう。おれには到底やり切れない。それを思うと清《きよ》なんてのは見上げたものだ。教育もない身分もない婆《ばあ》さんだが、人間としてはすこぶる尊《たっ》とい。今まではあんなに世話になって別段|難有《ありがた》いとも思わなかったが、こうして、一人で遠国へ来てみると、始めてあの親切がわかる。越後《えちご》の笹飴《ささあめ》が食いたければ、わざわざ越後まで買いに行って食わしてやっても、食わせるだけの価値は充分《じゅうぶん》ある。清はおれの事を欲がなくって、真直《まっすぐ》な気性だと云って、ほめるが、ほめられるおれよりも、ほめる本人の方が立派な人間だ。何だか清に逢いたくなった。 清の事を考えながら、のつそつしていると、突然《とつぜん》おれの頭の上で、数で云ったら三四十人もあろうか、二階が落っこちるほどどん、どん、どんと拍子《ひょうし》を取って床板を踏みならす音がした。すると足音に比例した大きな鬨《とき》の声が起《おこ》った。おれは何事が持ち上がったのかと驚ろいて飛び起きた。飛び起きる途端《とたん》に、ははあさっきの意趣返《いしゅがえ》しに生徒があばれるのだなと気がついた。手前のわるい事は悪るかったと言ってしまわないうちは罪は消えないもんだ。わるい事は、手前達に覚《おぼえ》があるだろう。本来なら寝てから後悔《こうかい》してあしたの朝でもあやまりに来るのが本筋だ。たとい、あやまらないまでも恐れ入って、静粛《せいしゅく》に寝ているべきだ。それを何だこの騒《さわ》ぎは。寄宿舎を建てて豚《ぶた》でも飼っておきあしまいし。気狂《きちが》いじみた真似《まね》も大抵《たいてい》にするがいい。どうするか見ろと、寝巻のまま宿直部屋を飛び出して、楷子段《はしごだん》を三股半《みまたはん》に二階まで躍《おど》り上がった。すると不思議な事に、今まで頭の上で、たしかにどたばた暴れていたのが、急に静まり返って、人声どころか足音もしなくなった。これは妙だ。ランプはすでに消してあるから、暗くてどこに何が居るか判然と分《わか》らないが、人気《ひとけ》のあるとないとは様子でも知れる。長く東から西へ貫《つらぬ》いた廊下《ろうか》には鼠《ねずみ》一|匹《ぴき》も隠《かく》れていない。廊下のはずれから月がさして、遥か向うが際どく明るい。どうも変だ、おれは小供の時から、よく夢《ゆめ》を見る癖があって、夢中《むちゅう》に跳ね起きて、わからぬ寝言を云って、人に笑われた事がよくある。十六七の時ダイヤモンドを拾った夢を見た晩なぞは、むくりと立ち上がって、そばに居た兄に、今のダイヤモンドはどうしたと、非常な勢《いきおい》で尋《たず》ねたくらいだ。その時は三日ばかりうち中《じゅう》の笑い草になって大いに弱った。ことによると今のも夢かも知れない。しかしたしかにあばれたに違いないがと、廊下の真中《まんなか》で考え込んでいると、月のさしている向うのはずれで、一二三わあと、三四十人の声がかたまって響《ひび》いたかと思う間もなく、前のように拍子を取って、一同が床板《ゆかいた》を踏み鳴らした。それ見ろ夢じゃないやっぱり事実だ。静かにしろ、夜なかだぞ、とこっちも負けんくらいな声を出して、廊下を向うへ馳《か》けだした。おれの通る路《みち》は暗い、ただはずれに見える月あかりが目標《めじるし》だ。おれが馳け出して二間も来たかと思うと、廊下の真中で、堅《かた》い大きなものに向脛《むこうずね》をぶつけて、あ痛い[#「あ痛い」に傍点]が頭へひびく間に、身体はすとんと前へ抛《ほう》り出された。こん畜生《ちきしょう》と起き上がってみたが、馳けられない。気はせくが、足だけは云う事を利かない。じれったいから、一本足で飛んで来たら、もう足音も人声も静まり返って、森《しん》としている。いくら人間が卑怯だって、こんなに卑怯に出来るものじゃない。まるで豚だ。こうなれば隠れている奴を引きずり出して、あやまらせてやるまではひかないぞと、心を極《き》めて寝室《しんしつ》の一つを開けて中を検査しようと思ったが開かない。錠《じょう》をかけてあるのか、机か何か積んで立て懸《か》けてあるのか、押《お》しても、押しても決して開かない。今度は向う合せの北側の室《へや》を試みた。開かない事はやっぱり同然である。おれが戸を開けて中に居る奴を引っ捕《つ》らまえてやろうと、焦慮《いらっ》てると、また東のはずれで鬨の声と足拍子が始まった。この野郎《やろう》申し合せて、東西相応じておれを馬鹿にする気だな、とは思ったがさてどうしていいか分らない。正直に白状してしまうが、おれは勇気のある割合に智慧《ちえ》が足りない。こんな時にはどうしていいかさっぱりわからない。わからないけれども、決して負けるつもりはない。このままに済ましてはおれの顔にかかわる。江戸《えど》っ子は意気地《いくじ》がないと云われるのは残念だ。宿直をして鼻垂《はなった》れ小僧《こぞう》にからかわれて、手のつけようがなくって、仕方がないから泣き寝入りにしたと思われちゃ一生の名折れだ。これでも元は旗本《はたもと》だ。旗本の元は清和源氏《せいわげんじ》で、多田《ただ》の満仲《まんじゅう》の後裔《こうえい》だ。こんな土百姓《どびゃくしょう》とは生まれからして違うんだ。ただ智慧のないところが惜しいだけだ。どうしていいか分らないのが困るだけだ。困ったって負けるものか。正直だから、どうしていいか分らないんだ。世の中に正直が勝たないで、外に勝つものがあるか、考えてみろ。今夜中に勝てなければ、あした勝つ。あした勝てなければ、あさって勝つ。あさって勝てなければ、下宿から弁当を取り寄せて勝つまでここに居る。おれはこう決心をしたから、廊下の真中へあぐらをかいて夜のあけるのを待っていた。蚊がぶんぶん来たけれども何ともなかった。さっき、ぶつけた向脛を撫《な》でてみると、何だかぬらぬらする。血が出るんだろう。血なんか出たければ勝手に出るがいい。そのうち最前からの疲《つか》れが出て、ついうとうと寝てしまった。何だか騒がしいので、眼《め》が覚めた時はえっ糞《くそ》しまったと飛び上がった。おれの坐《すわ》ってた右側にある戸が半分あいて、生徒が二人、おれの前に立っている。おれは正気に返って、はっと思う途端に、おれの鼻の先にある生徒の足を引《ひ》っ攫《つか》んで、力任せにぐいと引いたら、そいつは、どたりと仰向《あおむけ》に倒れた。ざまを見ろ。残る一人がちょっと狼狽《ろうばい》したところを、飛びかかって、肩を抑《おさ》えて二三度こづき廻したら、あっけに取られて、眼をぱちぱちさせた。さあおれの部屋まで来いと引っ立てると、弱虫だと見えて、一も二もなく尾《つ》いて来た。夜《よ》はとうにあけている。 おれが宿直部屋へ連れてきた奴を詰問《きつもん》し始めると、豚は、打《ぶ》っても擲いても豚だから、ただ知らんがなで、どこまでも通す了見と見えて、けっして白状しない。そのうち一人来る、二人来る、だんだん二階から宿直部屋へ集まってくる。見るとみんな眠《ねむ》そうに瞼《まぶた》をはらしている。けちな奴等だ。一晩ぐらい寝ないで、そんな面をして男と云われるか。面でも洗って議論に来いと云ってやったが、誰も面を洗いに行かない。 おれは五十人あまりを相手に約一時間ばかり押問答《おしもんどう》をしていると、ひょっくり狸がやって来た。あとから聞いたら、小使が学校に騒動がありますって、わざわざ知らせに行ったのだそうだ。これしきの事に、校長を呼ぶなんて意気地がなさ過ぎる。それだから中学校の小使なんぞをしてるんだ。 校長はひと通りおれの説明を聞いた。生徒の言草《いいぐさ》もちょっと聞いた。追って処分するまでは、今まで通り学校へ出ろ。早く顔を洗って、朝飯を食わないと時間に間に合わないから、早くしろと云って寄宿生をみんな放免《ほうめん》した。手温《てぬ》るい事だ。おれなら即席《そくせき》に寄宿生をことごとく退校してしまう。こんな悠長《ゆうちょう》な事をするから生徒が宿直員を馬鹿にするんだ。その上おれに向って、あなたもさぞご心配でお疲れでしょう、今日はご授業に及《およ》ばんと云うから、おれはこう答えた。「いえ、ちっとも心配じゃありません。こんな事が毎晩あっても、命のある間は心配にゃなりません。授業はやります、一晩ぐらい寝なくって、授業が出来ないくらいなら、頂戴《ちょうだい》した月給を学校の方へ割戻《わりもど》します」校長は何と思ったものか、しばらくおれの顔を見つめていたが、しかし顔が大分はれていますよと注意した。なるほど何だか少々重たい気がする。その上べた一面|痒《かゆ》い。蚊がよっぽと刺《さ》したに相違ない。おれは顔中ぼりぼり掻《か》きながら、顔はいくら膨《は》れたって、口はたしかにきけますから、授業には差し支《つか》えませんと答えた。校長は笑いながら、大分元気ですねと賞《ほ》めた。実を云うと賞めたんじゃあるまい、ひやかしたんだろう。     五 君|釣《つ》りに行きませんかと赤シャツがおれに聞いた。赤シャツは気味の悪《わ》るいように優しい声を出す男である。まるで男だか女だか分《わか》りゃしない。男なら男らしい声を出すもんだ。ことに大学卒業生じゃないか。物理学校でさえおれくらいな声が出るのに、文学士がこれじゃ見っともない。 おれはそうですなあと少し進まない返事をしたら、君釣をした事がありますかと失敬な事を聞く。あんまりないが、子供の時、小梅《こうめ》の釣堀《つりぼり》で鮒《ふな》を三|匹《びき》釣った事がある。それから神楽坂《かぐらざか》の毘沙門《びしゃもん》の縁日《えんにち》で八寸ばかりの鯉《こい》を針で引っかけて、しめたと思ったら、ぽちゃりと落としてしまったがこれは今考えても惜《お》しいと云《い》ったら、赤シャツは顋《あご》を前の方へ突《つ》き出してホホホホと笑った。何もそう気取って笑わなくっても、よさそうな者だ。「それじゃ、まだ釣りの味は分らんですな。お望みならちと伝授しましょう」とすこぶる得意である。だれがご伝授をうけるものか。一体釣や猟《りょう》をする連中はみんな不人情な人間ばかりだ。不人情でなくって、殺生《せっしょう》をして喜ぶ訳がない。魚だって、鳥だって殺されるより生きてる方が楽に極《き》まってる。釣や猟をしなくっちゃ活計《かっけい》がたたないなら格別だが、何不足なく暮《くら》している上に、生き物を殺さなくっちゃ寝られないなんて贅沢《ぜいたく》な話だ。こう思ったが向《むこ》うは文学士だけに口が達者だから、議論じゃ叶《かな》わないと思って、だまってた。すると先生このおれを降参させたと疳違《かんちが》いして、早速伝授しましょう。おひまなら、今日どうです、いっしょに行っちゃ。吉川《よしかわ》君と二人《ふたり》ぎりじゃ、淋《さむ》しいから、来たまえとしきりに勧める。吉川君というのは画学の教師で例の野だいこの事だ。この野だは、どういう了見《りょうけん》だか、赤シャツのうちへ朝夕|出入《でいり》して、どこへでも随行《ずいこう》して行《ゆ》く。まるで同輩《どうはい》じゃない。主従《しゅうじゅう》みたようだ。赤シャツの行く所なら、野だは必ず行くに極《きま》っているんだから、今さら驚《おど》ろきもしないが、二人で行けば済むところを、なんで無愛想《ぶあいそ》のおれへ口を掛《か》けたんだろう。大方|高慢《こうまん》ちきな釣道楽で、自分の釣るところをおれに見せびらかすつもりかなんかで誘《さそ》ったに違いない。そんな事で見せびらかされるおれじゃない。鮪《まぐろ》の二匹や三匹釣ったって、びくともするもんか。おれだって人間だ、いくら下手《へた》だって糸さえ卸《おろ》しゃ、何かかかるだろう、ここでおれが行かないと、赤シャツの事だから、下手だから行かないんだ、嫌《きら》いだから行かないんじゃないと邪推《じゃすい》するに相違《そうい》ない。おれはこう考えたから、行きましょうと答えた。それから、学校をしまって、一応うちへ帰って、支度《したく》を整えて、停車場で赤シャツと野だを待ち合せて浜《はま》へ行った。船頭は一人《ひとり》で、船《ふね》は細長い東京辺では見た事もない恰好《かっこう》である。さっきから船中|見渡《みわた》すが釣竿《つりざお》が一本も見えない。釣竿なしで釣が出来るものか、どうする了見だろうと、野だに聞くと、沖釣《おきづり》には竿は用いません、糸だけでげすと顋を撫《な》でて黒人《くろうと》じみた事を云った。こう遣《や》り込《こ》められるくらいならだまっていればよかった。 船頭はゆっくりゆっくり漕《こ》いでいるが熟練は恐《おそろ》しいもので、見返《みか》えると、浜が小さく見えるくらいもう出ている。高柏寺《こうはくじ》の五重の塔《とう》が森の上へ抜《ぬ》け出して針のように尖《とん》がってる。向側《むこうがわ》を見ると青嶋《あおしま》が浮いている。これは人の住まない島だそうだ。よく見ると石と松《まつ》ばかりだ。なるほど石と松ばかりじゃ住めっこない。赤シャツは、しきりに眺望《ちょうぼう》していい景色だと云ってる。野だは絶景でげすと云ってる。絶景だか何だか知らないが、いい心持ちには相違ない。ひろびろとした海の上で、潮風に吹《ふ》かれるのは薬だと思った。いやに腹が減る。「あの松を見たまえ、幹が真直《まっすぐ》で、上が傘《かさ》のように開いてターナーの画にありそうだね」と赤シャツが野だに云うと、野だは「全くターナーですね。どうもあの曲り具合ったらありませんね。ターナーそっくりですよ」と心得顔である。ターナーとは何の事だか知らないが、聞かないでも困らない事だから黙《だま》っていた。舟は島を右に見てぐるりと廻《まわ》った。波は全くない。これで海だとは受け取りにくいほど平《たいら》だ。赤シャツのお陰《かげ》ではなはだ愉快《ゆかい》だ。出来る事なら、あの島の上へ上がってみたいと思ったから、あの岩のある所へは舟はつけられないんですかと聞いてみた。つけられん事もないですが、釣をするには、あまり岸じゃいけないですと赤シャツが異議を申し立てた。おれは黙ってた。すると野だがどうです教頭、これからあの島をターナー島と名づけようじゃありませんかと余計な発議《ほつぎ》をした。赤シャツはそいつは面白い、吾々《われわれ》はこれからそう云おうと賛成した。この吾々のうちにおれもはいってるなら迷惑《めいわく》だ。おれには青嶋でたくさんだ。あの岩の上に、どうです、ラフハエルのマドンナを置いちゃ。いい画が出来ますぜと野だが云うと、マドンナの話はよそうじゃないかホホホホと赤シャツが気味の悪るい笑い方をした。なに誰も居ないから大丈夫《だいじょうぶ》ですと、ちょっとおれの方を見たが、わざと顔をそむけてにやにやと笑った。おれは何だかやな心持ちがした。マドンナだろうが、小旦那《こだんな》だろうが、おれの関係した事でないから、勝手に立たせるがよかろうが、人に分らない事を言って分らないから聞いたって構やしませんてえような風をする。下品な仕草だ。これで当人は私《わたし》も江戸《えど》っ子でげすなどと云ってる。マドンナと云うのは何でも赤シャツの馴染《なじみ》の芸者の渾名《あだな》か何かに違いないと思った。なじみの芸者を無人島の松の木の下に立たして眺《なが》めていれば世話はない。それを野だが油絵にでもかいて展覧会へ出したらよかろう。 ここいらがいいだろうと船頭は船をとめて、錨《いかり》を卸した。幾尋《いくひろ》あるかねと赤シャツが聞くと、六尋《むひろ》ぐらいだと云う。六尋ぐらいじゃ鯛《たい》はむずかしいなと、赤シャツは糸を海へなげ込んだ。大将鯛を釣る気と見える、豪胆《ごうたん》なものだ。野だは、なに教頭のお手際じゃかかりますよ。それになぎですからとお世辞を云いながら、これも糸を繰《く》り出して投げ入れる。何だか先に錘《おもり》のような鉛《なまり》がぶら下がってるだけだ。浮《うき》がない。浮がなくって釣をするのは寒暖計なしで熱度をはかるようなものだ。おれには到底《とうてい》出来ないと見ていると、さあ君もやりたまえ糸はありますかと聞く。糸はあまるほどあるが、浮がありませんと云ったら、浮がなくっちゃ釣が出来ないのは素人《しろうと》ですよ。こうしてね、糸が水底《みずそこ》へついた時分に、船縁《ふなべり》の所で人指しゆびで呼吸をはかるんです、食うとすぐ手に答える。――そらきた、と先生急に糸をたぐり始めるから、何かかかったと思ったら何にもかからない、餌《え》がなくなってたばかりだ。いい気味《きび》だ。教頭、残念な事をしましたね、今のはたしかに大ものに違いなかったんですが、どうも教頭のお手際でさえ逃《に》げられちゃ、今日は油断ができませんよ。しかし逃げられても何ですね。浮と睨《にら》めくらをしている連中よりはましですね。ちょうど歯どめがなくっちゃ自転車へ乗れないのと同程度ですからねと野だは妙《みよう》な事ばかり喋舌《しゃべ》る。よっぽど撲《なぐ》りつけてやろうかと思った。おれだって人間だ、教頭ひとりで借り切った海じゃあるまいし。広い所だ。鰹《かつお》の一匹ぐらい義理にだって、かかってくれるだろうと、どぼんと錘と糸を抛《ほう》り込んでいい加減に指の先であやつっていた。 しばらくすると、何だかぴくぴくと糸にあたるものがある。おれは考えた。こいつは魚に相違ない。生きてるものでなくっちゃ、こうぴくつく訳がない。しめた、釣れたとぐいぐい手繰《たぐ》り寄せた。おや釣れましたかね、後世|恐《おそ》るべしだと野だがひやかすうち、糸はもう大概手繰り込んでただ五尺ばかりほどしか、水に浸《つ》いておらん。船縁から覗《のぞ》いてみたら、金魚のような縞《しま》のある魚が糸にくっついて、右左へ漾《ただよ》いながら、手に応じて浮き上がってくる。面白い。水際から上げるとき、ぽちゃりと跳《は》ねたから、おれの顔は潮水だらけになった。ようやくつらまえて、針をとろうとするがなかなか取れない。捕《つら》まえた手はぬるぬるする。大いに気味がわるい。面倒だから糸を振《ふ》って胴《どう》の間《ま》へ擲《たた》きつけたら、すぐ死んでしまった。赤シャツと野だは驚ろいて見ている。おれは海の中で手をざぶざぶと洗って、鼻の先へあてがってみた。まだ腥臭《なまぐさ》い。もう懲《こ》り懲《ご》りだ。何が釣れたって魚は握《にぎ》りたくない。魚も握られたくなかろう。そうそう糸を捲いてしまった。 一番槍《いちばんやり》はお手柄《てがら》だがゴルキじゃ、と野だがまた生意気を云うと、ゴルキと云うと露西亜《ロシア》の文学者みたような名だねと赤シャツが洒落《しゃれ》た。そうですね、まるで露西亜の文学者ですねと野だはすぐ賛成しやがる。ゴルキが露西亜の文学者で、丸木が芝《しば》の写真師で、米のなる木が命の親だろう。一体この赤シャツはわるい癖《くせ》だ。誰《だれ》を捕《つら》まえても片仮名の唐人《とうじん》の名を並べたがる。人にはそれぞれ専門があったものだ。おれのような数学の教師にゴルキだか車力《しゃりき》だか見当がつくものか、少しは遠慮《えんりょ》するがいい。云《い》うならフランクリンの自伝だとかプッシング、ツー、ゼ、フロントだとか、おれでも知ってる名を使うがいい。赤シャツは時々帝国文学とかいう真赤《まっか》な雑誌を学校へ持って来て難有《ありがた》そうに読んでいる。山嵐《やまあらし》に聞いてみたら、赤シャツの片仮名はみんなあの雑誌から出るんだそうだ。帝国文学も罪な雑誌だ。 それから赤シャツと野だは一生懸命《いっしょうけんめい》に釣っていたが、約一時間ばかりのうちに二人《ふたり》で十五六上げた。可笑《おか》しい事に釣れるのも、釣れるのも、みんなゴルキばかりだ。鯛なんて薬にしたくってもありゃしない。今日は露西亜文学の大当りだと赤シャツが野だに話している。あなたの手腕《しゅわん》でゴルキなんですから、私《わたし》なんぞがゴルキなのは仕方がありません。当り前ですなと野だが答えている。船頭に聞くとこの小魚は骨が多くって、まずくって、とても食えないんだそうだ。ただ肥料《こやし》には出来るそうだ。赤シャツと野だは一生懸命に肥料を釣っているんだ。気の毒の至りだ。おれは一|匹《ぴき》で懲《こ》りたから、胴の間へ仰向《あおむ》けになって、さっきから大空を眺めていた。釣をするよりこの方がよっぽど洒落《しゃれ》ている。 すると二人は小声で何か話し始めた。おれにはよく聞《きこ》えない、また聞きたくもない。おれは空を見ながら清《きよ》の事を考えている。金があって、清をつれて、こんな奇麗《きれい》な所へ遊びに来たらさぞ愉快だろう。いくら景色がよくっても野だなどといっしょじゃつまらない。清は皺苦茶《しわくちゃ》だらけの婆さんだが、どんな所へ連れて出たって恥《は》ずかしい心持ちはしない。野だのようなのは、馬車に乗ろうが、船に乗ろうが、凌雲閣《りょううんかく》へのろうが、到底寄り付けたものじゃない。おれが教頭で、赤シャツがおれだったら、やっぱりおれにへけつけお世辞を使って赤シャツを冷《ひや》かすに違いない。江戸っ子は軽薄《けいはく》だと云うがなるほどこんなものが田舎巡《いなかまわ》りをして、私《わたし》は江戸っ子でげすと繰り返していたら、軽薄は江戸っ子で、江戸っ子は軽薄の事だと田舎者が思うに極まってる。こんな事を考えていると、何だか二人がくすくす笑い出した。笑い声の間に何か云うが途切《とぎ》れ途切れでとんと要領を得ない。「え? どうだか……」「……全くです……知らないんですから……罪ですね」「まさか……」「バッタを……本当ですよ」 おれは外の言葉には耳を傾《かたむ》けなかったが、バッタと云う野だの語《ことば》を聴《き》いた時は、思わずきっとなった。野だは何のためかバッタと云う言葉だけことさら力を入れて、明瞭《めいりょう》におれの耳にはいるようにして、そのあとをわざとぼかしてしまった。おれは動かないでやはり聞いていた。「また例の堀田《ほった》が……」「そうかも知れない……」「天麩羅《てんぷら》……ハハハハハ」「……煽動《せんどう》して……」「団子《だんご》も?」 言葉はかように途切れ途切れであるけれども、バッタだの天麩羅だの、団子だのというところをもって推し測ってみると、何でもおれのことについて内所話《ないしょばな》しをしているに相違ない。話すならもっと大きな声で話すがいい、また内所話をするくらいなら、おれなんか誘わなければいい。いけ好かない連中だ。バッタだろうが雪踏《せった》だろうが、非はおれにある事じゃない。校長がひとまずあずけろと云ったから、狸《たぬき》の顔にめんじてただ今のところは控《ひか》えているんだ。野だの癖に入らぬ批評をしやがる。毛筆《けふで》でもしゃぶって引っ込んでるがいい。おれの事は、遅《おそ》かれ早かれ、おれ一人で片付けてみせるから、差支《さしつか》えはないが、また例の堀田が[#「また例の堀田が」に傍点]とか煽動して[#「煽動して」に傍点]とか云う文句が気にかかる。堀田がおれを煽動して騒動《そうどう》を大きくしたと云う意味なのか、あるいは堀田が生徒を煽動しておれをいじめたと云うのか方角がわからない。青空を見ていると、日の光がだんだん弱って来て、少しはひやりとする風が吹き出した。線香《せんこう》の烟《けむり》のような雲が、透《す》き徹《とお》る底の上を静かに伸《の》して行ったと思ったら、いつしか底の奥《おく》に流れ込んで、うすくもやを掛《か》けたようになった。 もう帰ろうかと赤シャツが思い出したように云うと、ええちょうど時分ですね。今夜はマドンナの君にお逢《あ》いですかと野だが云う。赤シャツは馬鹿《ばか》あ云っちゃいけない、間違いになると、船縁に身を倚《も》たした奴《やつ》を、少し起き直る。エヘヘヘヘ大丈夫ですよ。聞いたって……と野だが振り返った時、おれは皿《さら》のような眼《め》を野だの頭の上へまともに浴びせ掛けてやった。野だはまぼしそうに引っ繰り返って、や、こいつは降参だと首を縮めて、頭を掻《か》いた。何という猪口才《ちょこざい》だろう。 船は静かな海を岸へ漕《こ》ぎ戻《もど》る。君|釣《つり》はあまり好きでないと見えますねと赤シャツが聞くから、ええ寝《ね》ていて空を見る方がいいですと答えて、吸いかけた巻烟草《まきたばこ》を海の中へたたき込んだら、ジュと音がして艪《ろ》の足で掻き分けられた浪《なみ》の上を揺《ゆ》られながら漾《ただよ》っていった。「君が来たんで生徒も大いに喜んでいるから、奮発《ふんぱつ》してやってくれたまえ」と今度は釣にはまるで縁故《えんこ》もない事を云い出した。「あんまり喜んでもいないでしょう」「いえ、お世辞じゃない。全く喜んでいるんです、ね、吉川君」「喜んでるどころじゃない。大騒《おおさわ》ぎです」と野だはにやにやと笑った。こいつの云う事は一々|癪《しゃく》に障《さわ》るから妙だ。「しかし君注意しないと、険呑《けんのん》ですよ」と赤シャツが云うから「どうせ険呑です。こうなりゃ険呑は覚悟《かくご》です」と云ってやった。実際おれは免職《めんしょく》になるか、寄宿生をことごとくあやまらせるか、どっちか一つにする了見でいた。「そう云っちゃ、取りつきどころもないが――実は僕も教頭として君のためを思うから云うんだが、わるく取っちゃ困る」「教頭は全く君に好意を持ってるんですよ。僕も及《およ》ばずながら、同じ江戸っ子だから、なるべく長くご在校を願って、お互《たがい》に力になろうと思って、これでも蔭ながら尽力《じんりょく》しているんですよ」と野だが人間|並《なみ》の事を云った。野だのお世話になるくらいなら首を縊《くく》って死んじまわあ。「それでね、生徒は君の来たのを大変|歓迎《かんげい》しているんだが、そこにはいろいろな事情があってね。君も腹の立つ事もあるだろうが、ここが我慢《がまん》だと思って、辛防《しんぼう》してくれたまえ。決して君のためにならないような事はしないから」「いろいろの事情た、どんな事情です」「それが少し込み入ってるんだが、まあだんだん分りますよ。僕《ぼく》が話さないでも自然と分って来るです、ね吉川君」「ええなかなか込み入ってますからね。一朝一夕にゃ到底分りません。しかしだんだん分ります、僕が話さないでも自然と分って来るです」と野だは赤シャツと同じような事を云う。「そんな面倒《めんどう》な事情なら聞かなくてもいいんですが、あなたの方から話し出したから伺《うかが》うんです」「そりゃごもっともだ。こっちで口を切って、あとをつけないのは無責任ですね。それじゃこれだけの事を云っておきましょう。あなたは失礼ながら、まだ学校を卒業したてで、教師は始めての、経験である。ところが学校というものはなかなか情実のあるもので、そう書生流に淡泊《たんぱく》には行《ゆ》かないですからね」「淡泊に行かなければ、どんな風に行くんです」「さあ君はそう率直だから、まだ経験に乏《とぼ》しいと云うんですがね……」「どうせ経験には乏しいはずです。履歴書《りれきしょ》にもかいときましたが二十三年四ヶ月ですから」「さ、そこで思わぬ辺から乗ぜられる事があるんです」「正直にしていれば誰《だれ》が乗じたって怖《こわ》くはないです」「無論怖くはない、怖くはないが、乗ぜられる。現に君の前任者がやられたんだから、気を付けないといけないと云うんです」 野だが大人《おとな》しくなったなと気が付いて、ふり向いて見ると、いつしか艫《とも》の方で船頭と釣の話をしている。野だが居ないんでよっぽど話しよくなった。「僕の前任者が、誰《だ》れに乗ぜられたんです」「だれと指すと、その人の名誉に関係するから云えない。また判然と証拠《しょうこ》のない事だから云うとこっちの落度になる。とにかく、せっかく君が来たもんだから、ここで失敗しちゃ僕等《ぼくら》も君を呼んだ甲斐《かい》がない。どうか気を付けてくれたまえ」「気を付けろったって、これより気の付けようはありません。わるい事をしなけりゃ好《い》いんでしょう」 赤シャツはホホホホと笑った。別段おれは笑われるような事を云った覚えはない。今日《こんにち》ただ今に至るまでこれでいいと堅《かた》く信じている。考えてみると世間の大部分の人はわるくなる事を奨励《しょうれい》しているように思う。わるくならなければ社会に成功はしないものと信じているらしい。たまに正直な純粋《じゅんすい》な人を見ると、坊《ぼ》っちゃんだの小僧《こぞう》だのと難癖《なんくせ》をつけて軽蔑《けいべつ》する。それじゃ小学校や中学校で嘘《うそ》をつくな、正直にしろと倫理《りんり》の先生が教えない方がいい。いっそ思い切って学校で嘘をつく法とか、人を信じない術とか、人を乗せる策を教授する方が、世のためにも当人のためにもなるだろう。赤シャツがホホホホと笑ったのは、おれの単純なのを笑ったのだ。単純や真率が笑われる世の中じゃ仕様がない。清はこんな時に決して笑った事はない。大いに感心して聞いたもんだ。清の方が赤シャツよりよっぽど上等だ。「無論|悪《わ》るい事をしなければ好いんですが、自分だけ悪るい事をしなくっても、人の悪るいのが分らなくっちゃ、やっぱりひどい目に逢うでしょう。世の中には磊落《らいらく》なように見えても、淡泊なように見えても、親切に下宿の世話なんかしてくれても、めったに油断の出来ないのがありますから……。大分寒くなった。もう秋ですね、浜の方は靄《もや》でセピヤ色になった。いい景色だ。おい、吉川君どうだい、あの浜の景色は……」と大きな声を出して野だを呼んだ。なあるほどこりゃ奇絶《きぜつ》ですね。時間があると写生するんだが、惜《お》しいですね、このままにしておくのはと野だは大いにたたく。 港屋の二階に灯が一つついて、汽車の笛《ふえ》がヒューと鳴るとき、おれの乗っていた舟は磯《いそ》の砂へざぐりと、舳《へさき》をつき込んで動かなくなった。お早うお帰りと、かみさんが、浜に立って赤シャツに挨拶《あいさつ》する。おれは船端《ふなばた》から、やっと掛声《かけごえ》をして磯へ飛び下りた。     六 野だは大嫌《だいきら》いだ。こんな奴《やつ》は沢庵石《たくあんいし》をつけて海の底へ沈《しず》めちまう方が日本のためだ。赤シャツは声が気に食わない。あれは持前の声をわざと気取ってあんな優しいように見せてるんだろう。いくら気取ったって、あの面じゃ駄目《だめ》だ。惚《ほ》れるものがあったってマドンナぐらいなものだ。しかし教頭だけに野だよりむずかしい事を云《い》う。うちへ帰って、あいつの申し条を考えてみると一応もっとものようでもある。はっきりとした事は云わないから、見当がつきかねるが、何でも山嵐《やまあらし》がよくない奴だから用心しろと云うのらしい。それならそうとはっきり断言するがいい、男らしくもない。そうして、そんな悪《わ》るい教師なら、早く免職《めんしょく》さしたらよかろう。教頭なんて文学士の癖《くせ》に意気地《いくじ》のないもんだ。蔭口《かげぐち》をきくのでさえ、公然と名前が云えないくらいな男だから、弱虫に極《き》まってる。弱虫は親切なものだから、あの赤シャツも女のような親切ものなんだろう。親切は親切、声は声だから、声が気に入らないって、親切を無にしちゃ筋が違《ちが》う。それにしても世の中は不思議なものだ、虫の好かない奴が親切で、気のあった友達が悪漢《わるもの》だなんて、人を馬鹿《ばか》にしている。大方|田舎《いなか》だから万事東京のさかに行くんだろう。物騒《ぶっそう》な所だ。今に火事が氷って、石が豆腐《とうふ》になるかも知れない。しかし、あの山嵐が生徒を煽動するなんて、いたずらをしそうもないがな。一番人望のある教師だと云うから、やろうと思ったら大抵《たいてい》の事は出来るかも知れないが、――第一そんな廻《まわ》りくどい事をしないでも、じかにおれを捕《つら》まえて喧嘩《けんか》を吹き懸《か》けりゃ手数が省ける訳だ。おれが邪魔《じゃま》になるなら、実はこれこれだ、邪魔だから辞職してくれと云や、よさそうなもんだ。物は相談ずくでどうでもなる。向《むこ》うの云い条がもっともなら、明日にでも辞職してやる。ここばかり米が出来る訳でもあるまい。どこの果《はて》へ行ったって、のたれ死《じに》はしないつもりだ。山嵐もよっぽど話せない奴だな。 ここへ来た時第一番に氷水を奢《おご》ったのは山嵐だ。そんな裏表のある奴から、氷水でも奢ってもらっちゃ、おれの顔に関わる。おれはたった一|杯《ぱい》しか飲まなかったから一銭五|厘《りん》しか払《はら》わしちゃない。しかし一銭だろうが五厘だろうが、詐欺師《さぎし》の恩になっては、死ぬまで心持ちがよくない。あした学校へ行ったら、一銭五厘返しておこう。おれは清《きよ》から三円借りている。その三円は五年|経《た》った今日までまだ返さない。返せないんじゃない。返さないんだ。清は今に返すだろうなどと、かりそめにもおれの懐中《かいちゅう》をあてにしてはいない。おれも今に返そうなどと他人がましい義理立てはしないつもりだ。こっちがこんな心配をすればするほど清の心を疑ぐるようなもので、清の美しい心にけちを付けると同じ事になる。返さないのは清を踏《ふ》みつけるのじゃない、清をおれの片破《かたわ》れと思うからだ。清と山嵐とはもとより比べ物にならないが、たとい氷水だろうが、甘茶《あまちゃ》だろうが、他人から恵《めぐみ》を受けて、だまっているのは向うをひとかどの人間と見立てて、その人間に対する厚意の所作だ。割前を出せばそれだけの事で済むところを、心のうちで難有《ありがた》いと恩に着るのは銭金で買える返礼じゃない。無位無冠でも一人前の独立した人間だ。独立した人間が頭を下げるのは百万両より尊《たっ》といお礼と思わなければならない。 おれはこれでも山嵐に一銭五厘|奮発《ふんぱつ》させて、百万両より尊とい返礼をした気でいる。山嵐は難有《ありがた》いと思ってしかるべきだ。それに裏へ廻って卑劣《ひれつ》な振舞《ふるまい》をするとは怪《け》しからん野郎《やろう》だ。あした行って一銭五厘返してしまえば借りも貸しもない。そうしておいて喧嘩をしてやろう。 おれはここまで考えたら、眠《ねむ》くなったからぐうぐう寝《ね》てしまった。あくる日は思う仔細《しさい》があるから、例刻より早ヤ目に出校して山嵐を待ち受けた。ところがなかなか出て来ない。うらなりが出て来る。漢学の先生が出て来る。野だが出て来る。しまいには赤シャツまで出て来たが山嵐の机の上は白墨《はくぼく》が一本|竪《たて》に寝ているだけで閑静《かんせい》なものだ。おれは、控所《ひかえじょ》へはいるや否や返そうと思って、うちを出る時から、湯銭のように手の平へ入れて一銭五厘、学校まで握《にぎ》って来た。おれは膏《あぶら》っ手だから、開けてみると一銭五厘が汗《あせ》をかいている。汗をかいてる銭を返しちゃ、山嵐が何とか云うだろうと思ったから、机の上へ置いてふうふう吹いてまた握った。ところへ赤シャツが来て昨日は失敬、迷惑《めいわく》でしたろうと云ったから、迷惑じゃありません、お蔭で腹が減りましたと答えた。すると赤シャツは山嵐の机の上へ肱《ひじ》を突《つ》いて、あの盤台面《ばんだいづら》をおれの鼻の側面へ持って来たから、何をするかと思ったら、君昨日返りがけに船の中で話した事は、秘密にしてくれたまえ。まだ誰《だれ》にも話しやしますまいねと云った。女のような声を出すだけに心配性な男と見える。話さない事はたしかである。しかしこれから話そうと云う心持ちで、すでに一銭五厘手の平に用意しているくらいだから、ここで赤シャツから口留めをされちゃ、ちと困る。赤シャツも赤シャツだ。山嵐と名を指さないにしろ、あれほど推察の出来る謎《なぞ》をかけておきながら、今さらその謎を解いちゃ迷惑だとは教頭とも思えぬ無責任だ。元来ならおれが山嵐と戦争をはじめて鎬《しのぎ》を削《けず》ってる真中《まんなか》へ出て堂々とおれの肩《かた》を持つべきだ。それでこそ一校の教頭で、赤シャツを着ている主意も立つというもんだ。 おれは教頭に向《むか》って、まだ誰にも話さないが、これから山嵐と談判するつもりだと云ったら、赤シャツは大いに狼狽《ろうばい》して、君そんな無法な事をしちゃ困る。僕《ぼく》は堀田《ほった》君の事について、別段君に何も明言した覚えはないんだから――君がもしここで乱暴を働いてくれると、僕は非常に迷惑する。君は学校に騒動《そうどう》を起すつもりで来たんじゃなかろうと妙《みょう》に常識をはずれた質問をするから、当《あた》り前《まえ》です、月給をもらったり、騒動を起したりしちゃ、学校の方でも困るでしょうと云った。すると赤シャツはそれじゃ昨日の事は君の参考だけにとめて、口外してくれるなと汗をかいて依頼《いらい》に及《およ》ぶから、よろしい、僕も困るんだが、そんなにあなたが迷惑ならよしましょうと受け合った。君|大丈夫《だいじょうぶ》かいと赤シャツは念を押《お》した。どこまで女らしいんだか奥行《おくゆき》がわからない。文学士なんて、みんなあんな連中ならつまらんものだ。辻褄《つじつま》の合わない、論理に欠けた注文をして恬然《てんぜん》としている。しかもこのおれを疑ぐってる。憚《はばか》りながら男だ。受け合った事を裏へ廻って反古《ほご》にするようなさもしい了見《りょうけん》はもってるもんか。 ところへ両隣《りょうどな》りの机の所有主も出校したんで、赤シャツは早々自分の席へ帰って行った。赤シャツは歩《あ》るき方から気取ってる。部屋の中を往来するのでも、音を立てないように靴《くつ》の底をそっと落《おと》す。音を立てないであるくのが自慢《じまん》になるもんだとは、この時から始めて知った。泥棒《どろぼう》の稽古《けいこ》じゃあるまいし、当り前にするがいい。やがて始業の喇叭《らっぱ》がなった。山嵐はとうとう出て来ない。仕方がないから、一銭五厘を机の上へ置いて教場へ出掛《でか》けた。 授業の都合《つごう》で一時間目は少し後《おく》れて、控所へ帰ったら、ほかの教師はみんな机を控えて話をしている。山嵐もいつの間にか来ている。欠勤だと思ったら遅刻《ちこく》したんだ。おれの顔を見るや否や今日は君のお蔭で遅刻したんだ。罰金《ばっきん》を出したまえと云った。おれは机の上にあった一銭五厘を出して、これをやるから取っておけ。先達《せんだっ》て通町《とおりちょう》で飲んだ氷水の代だと山嵐の前へ置くと、何を云ってるんだと笑いかけたが、おれが存外|真面目《まじめ》でいるので、つまらない冗談《じょうだん》をするなと銭をおれの机の上に掃《は》き返した。おや山嵐の癖《くせ》にどこまでも奢る気だな。「冗談じゃない本当だ。おれは君に氷水を奢られる因縁《いんえん》がないから、出すんだ。取らない法があるか」「そんなに一銭五厘が気になるなら取ってもいいが、なぜ思い出したように、今時分返すんだ」「今時分でも、いつ時分でも、返すんだ。奢られるのが、いやだから返すんだ」 山嵐は冷然とおれの顔を見てふんと云った。赤シャツの依頼がなければ、ここで山嵐の卑劣《ひれつ》をあばいて大喧嘩をしてやるんだが、口外しないと受け合ったんだから動きがとれない。人がこんなに真赤《まっか》になってるのにふんという理窟《りくつ》があるものか。「氷水の代は受け取るから、下宿は出てくれ」「一銭五厘受け取ればそれでいい。下宿を出ようが出まいがおれの勝手だ」「ところが勝手でない、昨日、あすこの亭主《ていしゅ》が来て君に出てもらいたいと云うから、その訳を聞いたら亭主の云うのはもっともだ。それでももう一応たしかめるつもりで今朝《けさ》あすこへ寄って詳《くわ》しい話を聞いてきたんだ」 おれには山嵐の云う事が何の意味だか分らない。「亭主が君に何を話したんだか、おれが知ってるもんか。そう自分だけで極めたって仕様があるか。訳があるなら、訳を話すが順だ。てんから亭主の云う方がもっともだなんて失敬千万な事を云うな」「うん、そんなら云ってやろう。君は乱暴であの下宿で持て余《あ》まされているんだ。いくら下宿の女房だって、下女たあ違うぜ。足を出して拭《ふ》かせるなんて、威張《いば》り過ぎるさ」「おれが、いつ下宿の女房に足を拭かせた」「拭かせたかどうだか知らないが、とにかく向うじゃ、君に困ってるんだ。下宿料の十円や十五円は懸物《かけもの》を一|幅《ぷく》売りゃ、すぐ浮《う》いてくるって云ってたぜ」「利いた風な事をぬかす野郎《やろう》だ。そんなら、なぜ置いた」「なぜ置いたか、僕は知らん、置くことは置いたんだが、いやになったんだから、出ろと云うんだろう。君出てやれ」「当り前だ。居てくれと手を合せたって、居るものか。一体そんな云い懸《がか》りを云うような所へ周旋《しゅうせん》する君からしてが不埒《ふらち》だ」「おれが不埒か、君が大人《おとな》しくないんだか、どっちかだろう」 山嵐もおれに劣《おと》らぬ肝癪持《かんしゃくも》ちだから、負け嫌《ぎら》いな大きな声を出す。控所に居た連中は何事が始まったかと思って、みんな、おれと山嵐の方を見て、顋《あご》を長くしてぼんやりしている。おれは、別に恥《は》ずかしい事をした覚えはないんだから、立ち上がりながら、部屋中一通り見巡《みま》わしてやった。みんなが驚《おど》ろいてるなかに野だだけは面白そうに笑っていた。おれの大きな眼《め》が、貴様も喧嘩をするつもりかと云う権幕で、野だの干瓢《かんぴょう》づらを射貫《いぬ》いた時に、野だは突然《とつぜん》真面目な顔をして、大いにつつしんだ。少し怖《こ》わかったと見える。そのうち喇叭が鳴る。山嵐もおれも喧嘩を中止して教場へ出た。 午後は、先夜おれに対して無礼を働いた寄宿生の処分法についての会議だ。会議というものは生れて始めてだからとんと容子《ようす》が分らないが、職員が寄って、たかって自分勝手な説をたてて、それを校長が好い加減に纏《まと》めるのだろう。纏めるというのは黒白《こくびゃく》の決しかねる事柄《ことがら》について云うべき言葉だ。この場合のような、誰が見たって、不都合としか思われない事件に会議をするのは暇潰《ひまつぶ》しだ。誰が何と解釈したって異説の出ようはずがない。こんな明白なのは即座《そくざ》に校長が処分してしまえばいいに。随分《ずいぶん》決断のない事だ。校長ってものが、これならば、何の事はない、煮《に》え切《き》らない愚図《ぐず》の異名だ。 会議室は校長室の隣《とな》りにある細長い部屋で、平常は食堂の代理を勤める。黒い皮で張った椅子《いす》が二十|脚《きゃく》ばかり、長いテーブルの周囲に並《なら》んでちょっと神田の西洋料理屋ぐらいな格だ。そのテーブルの端《はじ》に校長が坐《すわ》って、校長の隣りに赤シャツが構える。あとは勝手次第に席に着くんだそうだが、体操《たいそう》の教師だけはいつも席末に謙遜《けんそん》するという話だ。おれは様子が分らないから、博物の教師と漢学の教師の間へはいり込《こ》んだ。向うを見ると山嵐と野だが並んでる。野だの顔はどう考えても劣等だ。喧嘩はしても山嵐の方が遥《はる》かに趣《おもむき》がある。おやじの葬式《そうしき》の時に小日向《こびなた》の養源寺《ようげんじ》の座敷《ざしき》にかかってた懸物はこの顔によく似ている。坊主《ぼうず》に聞いてみたら韋駄天《いだてん》と云う怪物だそうだ。今日は怒《おこ》ってるから、眼をぐるぐる廻しちゃ、時々おれの方を見る。そんな事で威嚇《おど》かされてたまるもんかと、おれも負けない気で、やっぱり眼をぐりつかせて、山嵐をにらめてやった。おれの眼は恰好《かっこう》はよくないが、大きい事においては大抵な人には負けない。あなたは眼が大きいから役者になるときっと似合いますと清がよく云ったくらいだ。 もう大抵お揃《そろ》いでしょうかと校長が云うと、書記の川村と云うのが一つ二つと頭数を勘定《かんじょう》してみる。一人足りない。一人不足ですがと考えていたが、これは足りないはずだ。唐茄子《とうなす》のうらなり君が来ていない。おれとうらなり君とはどう云う宿世《すくせ》の因縁かしらないが、この人の顔を見て以来どうしても忘れられない。控所へくれば、すぐ、うらなり君が眼に付く、途中《とちゅう》をあるいていても、うらなり先生の様子が心に浮《うか》ぶ。温泉へ行くと、うらなり君が時々|蒼《あお》い顔をして湯壺《ゆつぼ》のなかに膨《ふく》れている。挨拶《あいさつ》をするとへえと恐縮《きょうしゅく》して頭を下げるから気の毒になる。学校へ出てうらなり君ほど大人しい人は居ない。めったに笑った事もないが、余計な口をきいた事もない。おれは君子という言葉を書物の上で知ってるが、これは字引にあるばかりで、生きてるものではないと思ってたが、うらなり君に逢《あ》ってから始めて、やっぱり正体のある文字だと感心したくらいだ。 このくらい関係の深い人の事だから、会議室へはいるや否や、うらなり君の居ないのは、すぐ気がついた。実を云うと、この男の次へでも坐《す》わろうかと、ひそかに目標《めじるし》にして来たくらいだ。校長はもうやがて見えるでしょうと、自分の前にある紫《むらさき》の袱紗包《ふくさづつみ》をほどいて、蒟蒻版《こんにゃくばん》のような者を読んでいる。赤シャツは琥珀《こはく》のパイプを絹ハンケチで磨《みが》き始めた。この男はこれが道楽である。赤シャツ相当のところだろう。ほかの連中は隣り同志で何だか私語《ささや》き合っている。手持無沙汰《てもちぶさた》なのは鉛筆《えんぴつ》の尻《しり》に着いている、護謨《ゴム》の頭でテーブルの上へしきりに何か書いている。野だは時々山嵐に話しかけるが、山嵐は一向応じない。ただうん[#「うん」に傍点]とかああ[#「ああ」に傍点]と云うばかりで、時々|怖《こわ》い眼をして、おれの方を見る。おれも負けずに睨《にら》め返す。 ところへ待ちかねた、うらなり君が気の毒そうにはいって来て少々用事がありまして、遅刻|致《いた》しましたと慇懃《いんぎん》に狸《たぬき》に挨拶《あいさつ》をした。では会議を開きますと狸はまず書記の川村君に蒟蒻版を配布させる。見ると最初が処分の件、次が生徒|取締《とりしまり》の件、その他二三ヶ条である。狸は例の通りもったいぶって、教育の生霊《いきりょう》という見えでこんな意味の事を述べた。「学校の職員や生徒に過失のあるのは、みんな自分の寡徳《かとく》の致すところで、何か事件がある度に、自分はよくこれで校長が勤まるとひそかに慚愧《ざんき》の念に堪《た》えんが、不幸にして今回もまたかかる騒動を引き起したのは、深く諸君に向って謝罪しなければならん。しかしひとたび起った以上は仕方がない、どうにか処分をせんければならん、事実はすでに諸君のご承知の通りであるからして、善後策について腹蔵のない事を参考のためにお述べ下さい」 おれは校長の言葉を聞いて、なるほど校長だの狸だのと云うものは、えらい事を云うもんだと感心した。こう校長が何もかも責任を受けて、自分の咎《とが》だとか、不徳だとか云うくらいなら、生徒を処分するのは、やめにして、自分から先へ免職《めんしょく》になったら、よさそうなもんだ。そうすればこんな面倒《めんどう》な会議なんぞを開く必要もなくなる訳だ。第一常識から云《い》っても分ってる。おれが大人しく宿直をする。生徒が乱暴をする。わるいのは校長でもなけりゃ、おれでもない、生徒だけに極《きま》ってる。もし山嵐が煽動《せんどう》したとすれば、生徒と山嵐を退治《たいじ》ればそれでたくさんだ。人の尻《しり》を自分で背負《しょ》い込《こ》んで、おれの尻だ、おれの尻だと吹き散らかす奴が、どこの国にあるもんか、狸でなくっちゃ出来る芸当じゃない。彼《かれ》はこんな条理《じょうり》に適《かな》わない議論を吐《は》いて、得意気に一同を見廻した。ところが誰も口を開くものがない。博物の教師は第一教場の屋根に烏《からす》がとまってるのを眺《なが》めている。漢学の先生は蒟蒻版《こんにゃくばん》を畳《たた》んだり、延ばしたりしてる。山嵐はまだおれの顔をにらめている。会議と云うものが、こんな馬鹿気《ばかげ》たものなら、欠席して昼寝でもしている方がましだ。 おれは、じれったくなったから、一番大いに弁じてやろうと思って、半分尻をあげかけたら、赤シャツが何か云い出したから、やめにした。見るとパイプをしまって、縞《しま》のある絹ハンケチで顔をふきながら、何か云っている。あの手巾《はんけち》はきっとマドンナから巻き上げたに相違《そうい》ない。男は白い麻《あさ》を使うもんだ。「私も寄宿生の乱暴を聞いてはなはだ教頭として不行届《ふゆきとどき》であり、かつ平常の徳化が少年に及ばなかったのを深く慚《は》ずるのであります。でこう云う事は、何か陥欠《かんけつ》があると起るもので、事件その物を見ると何だか生徒だけがわるいようであるが、その真相を極めると責任はかえって学校にあるかも知れない。だから表面上にあらわれたところだけで厳重な制裁を加えるのは、かえって未来のためによくないかとも思われます。かつ少年血気のものであるから活気があふれて、善悪の考えはなく、半ば無意識にこんな悪戯《いたずら》をやる事はないとも限らん。でもとより処分法は校長のお考えにある事だから、私の容喙《ようかい》する限りではないが、どうかその辺をご斟酌《しんしゃく》になって、なるべく寛大なお取計《とりはからい》を願いたいと思います」 なるほど狸が狸なら、赤シャツも赤シャツだ。生徒があばれるのは、生徒がわるいんじゃない教師が悪るいんだと公言している。気狂《きちがい》が人の頭を撲《なぐ》り付けるのは、なぐられた人がわるいから、気狂がなぐるんだそうだ。難有《ありがた》い仕合せだ。活気にみちて困るなら運動場へ出て相撲《すもう》でも取るがいい、半ば無意識に床の中へバッタを入れられてたまるものか。この様子じゃ寝頸《ねくび》をかかれても、半ば無意識だって放免するつもりだろう。 おれはこう考えて何か云おうかなと考えてみたが、云うなら人を驚ろすかように滔々《とうとう》と述べたてなくっちゃつまらない、おれの癖として、腹が立ったときに口をきくと、二言か三言で必ず行き塞《つま》ってしまう。狸でも赤シャツでも人物から云うと、おれよりも下等だが、弁舌はなかなか達者だから、まずい事を喋舌《しゃべ》って揚足《あげあし》を取られちゃ面白くない。ちょっと腹案を作ってみようと、胸のなかで文章を作ってる。すると前に居た野だが突然起立したには驚ろいた。野だの癖に意見を述べるなんて生意気だ。野だは例のへらへら調で「実に今回のバッタ事件及び咄喊《とっかん》事件は吾々《われわれ》心ある職員をして、ひそかに吾《わが》校将来の前途《ぜんと》に危惧《きぐ》の念を抱《いだ》かしむるに足る珍事《ちんじ》でありまして、吾々職員たるものはこの際|奮《ふる》って自ら省りみて、全校の風紀を振粛《しんしゅく》しなければなりません。それでただ今校長及び教頭のお述べになったお説は、実に肯綮《こうけい》に中《あた》った剴切《がいせつ》なお考えで私は徹頭徹尾《てっとうてつび》賛成致します。どうかなるべく寛大《かんだい》のご処分を仰《あお》ぎたいと思います」と云った。野だの云う事は言語はあるが意味がない、漢語をのべつに陳列《ちんれつ》するぎりで訳が分らない。分ったのは徹頭徹尾賛成致しますと云う言葉だけだ。 おれは野だの云う意味は分らないけれども、何だか非常に腹が立ったから、腹案も出来ないうちに起《た》ち上がってしまった。「私は徹頭徹尾反対です……」と云ったがあとが急に出て来ない。「……そんな頓珍漢《とんちんかん》な、処分は大嫌《だいきら》いです」とつけたら、職員が一同笑い出した。「一体生徒が全然|悪《わ》るいです。どうしても詫《あや》まらせなくっちゃ、癖になります。退校さしても構いません。……何だ失敬な、新しく来た教師だと思って……」と云って着席した。すると右隣りに居る博物が「生徒がわるい事も、わるいが、あまり厳重な罰などをするとかえって反動を起していけないでしょう。やっぱり教頭のおっしゃる通り、寛な方に賛成します」と弱い事を云った。左隣の漢学は穏便説《おんびんせつ》に賛成と云った。歴史も教頭と同説だと云った。忌々《いまいま》しい、大抵のものは赤シャツ党だ。こんな連中が寄り合って学校を立てていりゃ世話はない。おれは生徒をあやまらせるか、辞職するか二つのうち一つに極めてるんだから、もし赤シャツが勝ちを制したら、早速うちへ帰って荷作りをする覚悟《かくご》でいた。どうせ、こんな手合《てあい》を弁口《べんこう》で屈伏《くっぷく》させる手際はなし、させたところでいつまでご交際を願うのは、こっちでご免だ。学校に居ないとすればどうなったって構うもんか。また何か云うと笑うに違いない。だれが云うもんかと澄《すま》していた。 すると今までだまって聞いていた山嵐が奮然として、起ち上がった。野郎また赤シャツ賛成の意を表するな、どうせ、貴様とは喧嘩だ、勝手にしろと見ていると山嵐は硝子《ガラス》窓を振《ふる》わせるような声で「私《わたくし》は教頭及びその他諸君のお説には全然不同意であります。というものはこの事件はどの点から見ても、五十名の寄宿生が新来の教師|某氏《ぼうし》を軽侮《けいぶ》してこれを翻弄《ほんろう》しようとした所為《しょい》とより外《ほか》には認められんのであります。教頭はその源因を教師の人物いかんにお求めになるようでありますが失礼ながらそれは失言かと思います。某氏が宿直にあたられたのは着後早々の事で、まだ生徒に接せられてから二十日に満たぬ頃《ころ》であります。この短かい二十日間において生徒は君の学問人物を評価し得る余地がないのであります。軽侮されべき至当な理由があって、軽侮を受けたのなら生徒の行為に斟酌《しんしゃく》を加える理由もありましょうが、何らの源因もないのに新来の先生を愚弄《ぐろう》するような軽薄な生徒を寛仮《かんか》しては学校の威信《いしん》に関わる事と思います。教育の精神は単に学問を授けるばかりではない、高尚《こうしょう》な、正直な、武士的な元気を鼓吹《こすい》すると同時に、野卑《やひ》な、軽躁《けいそう》な、暴慢《ぼうまん》な悪風を掃蕩《そうとう》するにあると思います。もし反動が恐《おそろ》しいの、騒動が大きくなるのと姑息《こそく》な事を云った日にはこの弊風《へいふう》はいつ矯正《きょうせい》出来るか知れません。かかる弊風を杜絶《とぜつ》するためにこそ吾々はこの学校に職を奉じているので、これを見逃《みの》がすくらいなら始めから教師にならん方がいいと思います。私は以上の理由で寄宿生一同を厳罰《げんばつ》に処する上に、当該《とうがい》教師の面前において公けに謝罪の意を表せしむるのを至当の所置と心得ます」と云いながら、どんと腰《こし》を卸《おろ》した。一同はだまって何にも言わない。赤シャツはまたパイプを拭《ふ》き始めた。おれは何だか非常に嬉《うれ》しかった。おれの云おうと思うところをおれの代りに山嵐がすっかり言ってくれたようなものだ。おれはこう云う単純な人間だから、今までの喧嘩はまるで忘れて、大いに難有《ありがた》いと云う顔をもって、腰を卸した山嵐の方を見たら、山嵐は一向知らん面《かお》をしている。 しばらくして山嵐はまた起立した。「ただ今ちょっと失念して言い落《おと》しましたから、申します。当夜の宿直員は宿直中外出して温泉に行かれたようであるが、あれはもっての外の事と考えます。いやしくも自分が一校の留守番を引き受けながら、咎《とが》める者のないのを幸《さいわい》に、場所もあろうに温泉などへ入湯にいくなどと云うのは大きな失体である。生徒は生徒として、この点については校長からとくに責任者にご注意あらん事を希望します」 妙な奴だ、ほめたと思ったら、あとからすぐ人の失策をあばいている。おれは何の気もなく、前の宿直が出あるいた事を知って、そんな習慣だと思って、つい温泉まで行ってしまったんだが、なるほどそう云われてみると、これはおれが悪るかった。攻撃《こうげき》されても仕方がない。そこでおれはまた起って「私は正に宿直中に温泉に行きました。これは全くわるい。あやまります」と云って着席したら、一同がまた笑い出した。おれが何か云いさえすれば笑う。つまらん奴等《やつら》だ。貴様等これほど自分のわるい事を公けにわるかったと断言出来るか、出来ないから笑うんだろう。 それから校長は、もう大抵ご意見もないようでありますから、よく考えた上で処分しましょうと云った。ついでだからその結果を云うと、寄宿生は一週間の禁足になった上に、おれの前へ出て謝罪をした。謝罪をしなければその時辞職して帰るところだったがなまじい、おれのいう通りになったのでとうとう大変な事になってしまった。それはあとから話すが、校長はこの時会議の引き続きだと号してこんな事を云った。生徒の風儀《ふうぎ》は、教師の感化で正していかなくてはならん、その一着手として、教師はなるべく飲食店などに出入《しゅつにゅう》しない事にしたい。もっとも送別会などの節は特別であるが、単独にあまり上等でない場所へ行くのはよしたい――たとえば蕎麦屋《そばや》だの、団子屋《だんごや》だの――と云いかけたらまた一同が笑った。野だが山嵐を見て天麩羅《てんぷら》と云って目くばせをしたが山嵐は取り合わなかった。いい気味《きび》だ。 おれは脳がわるいから、狸の云うことなんか、よく分らないが、蕎麦屋や団子屋へ行って、中学の教師が勤まらなくっちゃ、おれみたような食い心棒《しんぼう》にゃ到底《とうてい》出来っ子ないと思った。それなら、それでいいから、初手から蕎麦と団子の嫌いなものと注文して雇《やと》うがいい。だんまりで辞令を下げておいて、蕎麦を食うな、団子を食うなと罪なお布令《ふれ》を出すのは、おれのような外に道楽のないものにとっては大変な打撃だ。すると赤シャツがまた口を出した。「元来中学の教師なぞは社会の上流にくらいするものだからして、単に物質的の快楽ばかり求めるべきものでない。その方に耽《ふけ》るとつい品性にわるい影響《えいきょう》を及ぼすようになる。しかし人間だから、何か娯楽《ごらく》がないと、田舎《いなか》へ来て狭《せま》い土地では到底|暮《くら》せるものではない。それで釣《つり》に行くとか、文学書を読むとか、または新体詩や俳句を作るとか、何でも高尚《こうしょう》な精神的娯楽を求めなくってはいけない……」 だまって聞いてると勝手な熱を吹く。沖《おき》へ行って肥料《こやし》を釣ったり、ゴルキが露西亜《ロシア》の文学者だったり、馴染《なじみ》の芸者が松《まつ》の木の下に立ったり、古池へ蛙《かわず》が飛び込んだりするのが精神的娯楽なら、天麩羅を食って団子を呑《の》み込むのも精神的娯楽だ。そんな下さらない娯楽を授けるより赤シャツの洗濯《せんたく》でもするがいい。あんまり腹が立ったから「マドンナに逢《あ》うのも精神的娯楽ですか」と聞いてやった。すると今度は誰も笑わない。妙な顔をして互《たがい》に眼と眼を見合せている。赤シャツ自身は苦しそうに下を向いた。それ見ろ。利いたろう。ただ気の毒だったのはうらなり君で、おれが、こう云ったら蒼い顔をますます蒼くした。     七 おれは即夜《そくや》下宿を引き払《はら》った。宿へ帰って荷物をまとめていると、女房《にょうぼう》が何か不都合《ふつごう》でもございましたか、お腹の立つ事があるなら、云《い》っておくれたら改めますと云う。どうも驚《おど》ろく。世の中にはどうして、こんな要領を得ない者ばかり揃《そろ》ってるんだろう。出てもらいたいんだか、居てもらいたいんだか分《わか》りゃしない。まるで気狂《きちがい》だ。こんな者を相手に喧嘩《けんか》をしたって江戸《えど》っ子の名折れだから、車屋をつれて来てさっさと出てきた。 出た事は出たが、どこへ行くというあてもない。車屋が、どちらへ参りますと云うから、だまって尾《つ》いて来い、今にわかる、と云って、すたすたやって来た。面倒《めんどう》だから山城屋へ行こうかとも考えたが、また出なければならないから、つまり手数だ。こうして歩いてるうちには下宿とか、何とか看板のあるうちを目付け出すだろう。そうしたら、そこが天意に叶《かな》ったわが宿と云う事にしよう。とぐるぐる、閑静《かんせい》で住みよさそうな所をあるいているうち、とうとう鍛冶屋町《かじやちょう》へ出てしまった。ここは士族|屋敷《やしき》で下宿屋などのある町ではないから、もっと賑《にぎ》やかな方へ引き返そうかとも思ったが、ふといい事を考え付いた。おれが敬愛するうらなり君はこの町内に住んでいる。うらなり君は土地の人で先祖代々の屋敷を控《ひか》えているくらいだから、この辺の事情には通じているに相違《そうい》ない。あの人を尋《たず》ねて聞いたら、よさそうな下宿を教えてくれるかも知れない。幸《さいわい》一度|挨拶《あいさつ》に来て勝手は知ってるから、捜《さ》がしてあるく面倒はない。ここだろうと、いい加減に見当をつけて、ご免《めん》ご免と二返ばかり云うと、奥《おく》から五十ぐらいな年寄《としより》が古風な紙燭《しそく》をつけて、出て来た。おれは若い女も嫌《きら》いではないが、年寄を見ると何だかなつかしい心持ちがする。大方|清《きよ》がすきだから、その魂《たましい》が方々のお婆《ばあ》さんに乗り移るんだろう。これは大方うらなり君のおっ母《か》さんだろう。切り下げの品格のある婦人だが、よくうらなり君に似ている。まあお上がりと云うところを、ちょっとお目にかかりたいからと、主人を玄関《げんかん》まで呼び出して実はこれこれだが君どこか心当りはありませんかと尋ねてみた。うらなり先生それはさぞお困りでございましょう、としばらく考えていたが、この裏町に萩野《はぎの》と云って老人夫婦ぎりで暮《く》らしているものがある、いつぞや座敷《ざしき》を明けておいても無駄《むだ》だから、たしかな人があるなら貸してもいいから周旋《しゅうせん》してくれと頼《たの》んだ事がある。今でも貸すかどうか分らんが、まあいっしょに行って聞いてみましょうと、親切に連れて行ってくれた。 その夜から萩野の家の下宿人となった。驚《おどろ》いたのは、おれがいか銀の座敷を引き払うと、翌日《あくるひ》から入れ違《ちが》いに野だが平気な顔をして、おれの居た部屋を占領《せんりょう》した事だ。さすがのおれもこれにはあきれた。世の中はいかさま師ばかりで、お互《たがい》に乗せっこをしているのかも知れない。いやになった。 世間がこんなものなら、おれも負けない気で、世間並《せけんなみ》にしなくちゃ、遣《や》りきれない訳になる。巾着切《きんちゃくきり》の上前をはねなければ三度のご膳《ぜん》が戴《いただ》けないと、事が極《き》まればこうして、生きてるのも考え物だ。と云ってぴんぴんした達者なからだで、首を縊《くく》っちゃ先祖へ済まない上に、外聞が悪い。考えると物理学校などへはいって、数学なんて役にも立たない芸を覚えるよりも、六百円を資本《もとで》にして牛乳屋でも始めればよかった。そうすれば清もおれの傍《そば》を離《はな》れずに済むし、おれも遠くから婆さんの事を心配しずに暮《くら》される。いっしょに居るうちは、そうでもなかったが、こうして田舎《いなか》へ来てみると清はやっぱり善人だ。あんな気立《きだて》のいい女は日本中さがして歩いたってめったにはない。婆さん、おれの立つときに、少々|風邪《かぜ》を引いていたが今頃《いまごろ》はどうしてるか知らん。先だっての手紙を見たらさぞ喜んだろう。それにしても、もう返事がきそうなものだが――おれはこんな事ばかり考えて二三日暮していた。 気になるから、宿のお婆さんに、東京から手紙は来ませんかと時々|尋《たず》ねてみるが、聞くたんびに何にも参りませんと気の毒そうな顔をする。ここの夫婦はいか銀とは違って、もとが士族だけに双方《そうほう》共上品だ。爺《じい》さんが夜《よ》るになると、変な声を出して謡《うたい》をうたうには閉口するが、いか銀のようにお茶を入れましょうと無暗《むやみ》に出て来ないから大きに楽だ。お婆さんは時々部屋へ来ていろいろな話をする。どうして奥さんをお連れなさって、いっしょにお出《い》でなんだのぞなもしなどと質問をする。奥さんがあるように見えますかね。可哀想《かわいそう》にこれでもまだ二十四ですぜと云ったらそれでも、あなた二十四で奥さんがおありなさるのは当り前ぞなもしと冒頭《ぼうとう》を置いて、どこの誰《だれ》さんは二十でお嫁《よめ》をお貰《もら》いたの、どこの何とかさんは二十二で子供を二人《ふたり》お持ちたのと、何でも例を半ダースばかり挙げて反駁《はんばく》を試みたには恐《おそ》れ入った。それじゃ僕《ぼく》も二十四でお嫁をお貰いるけれ、世話をしておくれんかなと田舎言葉を真似《まね》て頼んでみたら、お婆さん正直に本当かなもしと聞いた。「本当の本当《ほんま》のって僕あ、嫁が貰いたくって仕方がないんだ」「そうじゃろうがな、もし。若いうちは誰もそんなものじゃけれ」この挨拶《あいさつ》には痛み入って返事が出来なかった。「しかし先生はもう、お嫁がおありなさるに極《きま》っとらい。私はちゃんと、もう、睨《ね》らんどるぞなもし」「へえ、活眼《かつがん》だね。どうして、睨らんどるんですか」「どうしててて。東京から便りはないか、便りはないかてて、毎日便りを待ち焦《こ》がれておいでるじゃないかなもし」「こいつあ驚《おどろ》いた。大変な活眼だ」「中《あた》りましたろうがな、もし」「そうですね。中ったかも知れませんよ」「しかし今時の女子《おなご》は、昔《むかし》と違《ちご》うて油断が出来んけれ、お気をお付けたがええぞなもし」「何ですかい、僕の奥さんが東京で間男でもこしらえていますかい」「いいえ、あなたの奥さんはたしかじゃけれど……」「それで、やっと安心した。それじゃ何を気を付けるんですい」「あなたのはたしか――あなたのはたしかじゃが――」「どこに不たしかなのが居ますかね」「ここ等《ら》にも大分|居《お》ります。先生、あの遠山のお嬢《じょう》さんをご存知かなもし」「いいえ、知りませんね」「まだご存知ないかなもし。ここらであなた一番の別嬪《べっぴん》さんじゃがなもし。あまり別嬪さんじゃけれ、学校の先生方はみんなマドンナマドンナと言うといでるぞなもし。まだお聞きんのかなもし」「うん、マドンナですか。僕あ芸者の名かと思った」「いいえ、あなた。マドンナと云うと唐人《とうじん》の言葉で、別嬪さんの事じゃろうがなもし」「そうかも知れないね。驚いた」「大方画学の先生がお付けた名ぞなもし」「野だがつけたんですかい」「いいえ、あの吉川《よしかわ》先生がお付けたのじゃがなもし」「そのマドンナが不たしかなんですかい」「そのマドンナさんが不たしかなマドンナさんでな、もし」「厄介《やっかい》だね。渾名《あだな》の付いてる女にゃ昔から碌《ろく》なものは居ませんからね。そうかも知れませんよ」「ほん当にそうじゃなもし。鬼神《きじん》のお松《まつ》じゃの、妲妃《だっき》のお百じゃのてて怖《こわ》い女が居《お》りましたなもし」「マドンナもその同類なんですかね」「そのマドンナさんがなもし、あなた。そらあの、あなたをここへ世話をしておくれた古賀先生なもし――あの方の所へお嫁《よめ》に行く約束《やくそく》が出来ていたのじゃがなもし――」「へえ、不思議なもんですね。あのうらなり君が、そんな艶福《えんぷく》のある男とは思わなかった。人は見懸《みか》けによらない者だな。ちっと気を付けよう」「ところが、去年あすこのお父さんが、お亡くなりて、――それまではお金もあるし、銀行の株も持ってお出《いで》るし、万事|都合《つごう》がよかったのじゃが――それからというものは、どういうものか急に暮し向きが思わしくなくなって――つまり古賀さんがあまりお人が好過《よす》ぎるけれ、お欺《だま》されたんぞなもし。それや、これやでお輿入《こしいれ》も延びているところへ、あの教頭さんがお出《い》でて、是非お嫁にほしいとお云いるのじゃがなもし」「あの赤シャツがですか。ひどい奴《やつ》だ。どうもあのシャツはただのシャツじゃないと思ってた。それから?」「人を頼んで懸合《かけお》うておみると、遠山さんでも古賀さんに義理があるから、すぐには返事は出来かねて――まあよう考えてみようぐらいの挨拶をおしたのじゃがなもし。すると赤シャツさんが、手蔓《てづる》を求めて遠山さんの方へ出入《でいり》をおしるようになって、とうとうあなた、お嬢さんを手馴付《てなづ》けておしまいたのじゃがなもし。赤シャツさんも赤シャツさんじゃが、お嬢さんもお嬢さんじゃてて、みんなが悪《わ》るく云いますのよ。いったん古賀さんへ嫁に行くてて承知をしときながら、今さら学士さんがお出《いで》たけれ、その方に替《か》えよてて、それじゃ今日様《こんにちさま》へ済むまいがなもし、あなた」「全く済まないね。今日様どころか明日様にも明後日様にも、いつまで行ったって済みっこありませんね」「それで古賀さんにお気の毒じゃてて、お友達の堀田《ほった》さんが教頭の所へ意見をしにお行きたら、赤シャツさんが、あしは約束のあるものを横取りするつもりはない。破約になれば貰うかも知れんが、今のところは遠山家とただ交際をしているばかりじゃ、遠山家と交際をするには別段古賀さんに済まん事もなかろうとお云いるけれ、堀田さんも仕方がなしにお戻《もど》りたそうな。赤シャツさんと堀田さんは、それ以来|折合《おりあい》がわるいという評判ぞなもし」「よくいろいろな事を知ってますね。どうして、そんな詳《くわ》しい事が分るんですか。感心しちまった」「狭《せま》いけれ何でも分りますぞなもし」 分り過ぎて困るくらいだ。この容子《ようす》じゃおれの天麩羅《てんぷら》や団子《だんご》の事も知ってるかも知れない。厄介《やっかい》な所だ。しかしお蔭様《かげさま》でマドンナの意味もわかるし、山嵐と赤シャツの関係もわかるし大いに後学になった。ただ困るのはどっちが悪る者だか判然しない。おれのような単純なものには白とか黒とか片づけてもらわないと、どっちへ味方をしていいか分らない。「赤シャツと山嵐たあ、どっちがいい人ですかね」「山嵐て何ぞなもし」「山嵐というのは堀田の事ですよ」「そりゃ強い事は堀田さんの方が強そうじゃけれど、しかし赤シャツさんは学士さんじゃけれ、働きはある方《かた》ぞな、もし。それから優しい事も赤シャツさんの方が優しいが、生徒の評判は堀田さんの方がええというぞなもし」「つまりどっちがいいんですかね」「つまり月給の多い方が豪《えら》いのじゃろうがなもし」 これじゃ聞いたって仕方がないから、やめにした。それから二三日して学校から帰るとお婆さんがにこにこして、へえお待遠さま。やっと参りました。と一本の手紙を持って来てゆっくりご覧と云って出て行った。取り上げてみると清からの便りだ。符箋《ふせん》が二三|枚《まい》ついてるから、よく調べると、山城屋から、いか銀の方へ廻《まわ》して、いか銀から、萩野《はぎの》へ廻って来たのである。その上山城屋では一週間ばかり逗留《とうりゅう》している。宿屋だけに手紙まで泊《とめ》るつもりなんだろう。開いてみると、非常に長いもんだ。坊《ぼ》っちゃんの手紙を頂いてから、すぐ返事をかこうと思ったが、あいにく風邪を引いて一週間ばかり寝《ね》ていたものだから、つい遅《おそ》くなって済まない。その上今時のお嬢さんのように読み書きが達者でないものだから、こんなまずい字でも、かくのによっぽど骨が折れる。甥《おい》に代筆を頼もうと思ったが、せっかくあげるのに自分でかかなくっちゃ、坊っちゃんに済まないと思って、わざわざ下《し》たがきを一返して、それから清書をした。清書をするには二日で済んだが、下た書きをするには四日かかった。読みにくいかも知れないが、これでも一生懸命《いっしょうけんめい》にかいたのだから、どうぞしまいまで読んでくれ。という冒頭《ぼうとう》で四尺ばかり何やらかやら認《したた》めてある。なるほど読みにくい。字がまずいばかりではない、大抵《たいてい》平仮名だから、どこで切れて、どこで始まるのだか句読《くとう》をつけるのによっぽど骨が折れる。おれは焦《せ》っ勝《か》ちな性分だから、こんな長くて、分りにくい手紙は、五円やるから読んでくれと頼まれても断わるのだが、この時ばかりは真面目《まじめ》になって、始《はじめ》から終《しまい》まで読み通した。読み通した事は事実だが、読む方に骨が折れて、意味がつながらないから、また頭から読み直してみた。部屋のなかは少し暗くなって、前の時より見にくく、なったから、とうとう椽鼻《えんばな》へ出て腰《こし》をかけながら鄭寧《ていねい》に拝見した。すると初秋《はつあき》の風が芭蕉《ばしょう》の葉を動かして、素肌《すはだ》に吹《ふ》きつけた帰りに、読みかけた手紙を庭の方へなびかしたから、しまいぎわには四尺あまりの半切れがさらりさらりと鳴って、手を放すと、向《むこ》うの生垣まで飛んで行きそうだ。おれはそんな事には構っていられない。坊っちゃんは竹を割ったような気性だが、ただ肝癪《かんしゃく》が強過ぎてそれが心配になる。――ほかの人に無暗《むやみ》に渾名《あだな》なんか、つけるのは人に恨《うら》まれるもとになるから、やたらに使っちゃいけない、もしつけたら、清だけに手紙で知らせろ。――田舎者は人がわるいそうだから、気をつけてひどい目に遭《あ》わないようにしろ。――気候だって東京より不順に極ってるから、寝冷《ねびえ》をして風邪を引いてはいけない。坊っちゃんの手紙はあまり短過ぎて、容子がよくわからないから、この次にはせめてこの手紙の半分ぐらいの長さのを書いてくれ。――宿屋へ茶代を五円やるのはいいが、あとで困りゃしないか、田舎へ行って頼《たよ》りになるはお金ばかりだから、なるべく倹約《けんやく》して、万一の時に差支《さしつか》えないようにしなくっちゃいけない。――お小遣《こづかい》がなくて困るかも知れないから、為替《かわせ》で十円あげる。――先《せん》だって坊っちゃんからもらった五十円を、坊っちゃんが、東京へ帰って、うちを持つ時の足しにと思って、郵便局へ預けておいたが、この十円を引いてもまだ四十円あるから大丈夫だ。――なるほど女と云うものは細かいものだ。 おれが椽鼻で清の手紙をひらつかせながら、考え込《こ》んでいると、しきりの襖《ふすま》をあけて、萩野のお婆さんが晩めしを持ってきた。まだ見てお出《い》でるのかなもし。えっぽど長いお手紙じゃなもし、と云ったから、ええ大事な手紙だから風に吹かしては見、吹かしては見るんだと、自分でも要領を得ない返事をして膳《ぜん》についた。見ると今夜も薩摩芋《さつまいも》の煮《に》つけだ。ここのうちは、いか銀よりも鄭寧《ていねい》で、親切で、しかも上品だが、惜《お》しい事に食い物がまずい。昨日も芋、一昨日《おととい》も芋で今夜も芋だ。おれは芋は大好きだと明言したには相違ないが、こう立てつづけに芋を食わされては命がつづかない。うらなり君を笑うどころか、おれ自身が遠からぬうちに、芋のうらなり先生になっちまう。清ならこんな時に、おれの好きな鮪《まぐろ》のさし身か、蒲鉾《かまぼこ》のつけ焼を食わせるんだが、貧乏《びんぼう》士族のけちん坊《ぼう》と来ちゃ仕方がない。どう考えても清といっしょでなくっちあ駄目《だめ》だ。もしあの学校に長くでも居る模様なら、東京から召《よ》び寄《よ》せてやろう。天麩羅|蕎麦《そば》を食っちゃならない、団子を食っちゃならない、それで下宿に居て芋ばかり食って黄色くなっていろなんて、教育者はつらいものだ。禅宗《ぜんしゅう》坊主だって、これよりは口に栄耀《えよう》をさせているだろう。――おれは一皿の芋を平げて、机の抽斗《ひきだし》から生卵を二つ出して、茶碗《ちゃわん》の縁《ふち》でたたき割って、ようやく凌《しの》いだ。生卵ででも営養をとらなくっちあ一週二十一時間の授業が出来るものか。 今日は清の手紙で湯に行く時間が遅くなった。しかし毎日行きつけたのを一日でも欠かすのは心持ちがわるい。汽車にでも乗って出懸《でか》けようと、例の赤手拭《あかてぬぐい》をぶら下げて停車場《ていしゃば》まで来ると二三分前に発車したばかりで、少々待たなければならぬ。ベンチへ腰を懸けて、敷島《しきしま》を吹かしていると、偶然《ぐうぜん》にもうらなり君がやって来た。おれはさっきの話を聞いてから、うらなり君がなおさら気の毒になった。平常《ふだん》から天地の間に居候《いそうろう》をしているように、小さく構えているのがいかにも憐《あわ》れに見えたが、今夜は憐れどころの騒《さわ》ぎではない。出来るならば月給を倍にして、遠山のお嬢さんと明日《あした》から結婚《けっこん》さして、一ヶ月ばかり東京へでも遊びにやってやりたい気がした矢先だから、やお湯ですか、さあ、こっちへお懸けなさいと威勢《いせい》よく席を譲《ゆず》ると、うらなり君は恐《おそ》れ入った体裁で、いえ構《かも》うておくれなさるな、と遠慮《えんりょ》だか何だかやっぱり立ってる。少し待たなくっちゃ出ません、草臥《くたび》れますからお懸けなさいとまた勧めてみた。実はどうかして、そばへ懸けてもらいたかったくらいに気の毒でたまらない。それではお邪魔《じゃま》を致《いた》しましょうとようやくおれの云う事を聞いてくれた。世の中には野だみたように生意気な、出ないで済む所へ必ず顔を出す奴もいる。山嵐のようにおれが居なくっちゃ日本《にっぽん》が困るだろうと云うような面を肩《かた》の上へ載《の》せてる奴もいる。そうかと思うと、赤シャツのようにコスメチックと色男の問屋をもって自ら任じているのもある。教育が生きてフロックコートを着ればおれになるんだと云わぬばかりの狸《たぬき》もいる。皆々《みなみな》それ相応に威張ってるんだが、このうらなり先生のように在れどもなきがごとく、人質に取られた人形のように大人《おとな》しくしているのは見た事がない。顔はふくれているが、こんな結構な男を捨てて赤シャツに靡《なび》くなんて、マドンナもよっぼど気の知れないおきゃんだ。赤シャツが何ダース寄ったって、これほど立派な旦那様《だんなさま》が出来るもんか。「あなたはどっか悪いんじゃありませんか。大分たいぎそうに見えますが……」「いえ、別段これという持病もないですが……」「そりゃ結構です。からだが悪いと人間も駄目ですね」「あなたは大分ご丈夫《じょうぶ》のようですな」「ええ瘠《や》せても病気はしません。病気なんてものあ大嫌いですから」 うらなり君は、おれの言葉を聞いてにやにやと笑った。 ところへ入口で若々しい女の笑声が聞《きこ》えたから、何心なく振《ふ》り返ってみるとえらい奴が来た。色の白い、ハイカラ頭の、背の高い美人と、四十五六の奥さんとが並《なら》んで切符《きっぷ》を売る窓の前に立っている。おれは美人の形容などが出来る男でないから何にも云えないが全く美人に相違ない。何だか水晶《すいしょう》の珠《たま》を香水《こうすい》で暖《あっ》ためて、掌《てのひら》へ握《にぎ》ってみたような心持ちがした。年寄の方が背は低い。しかし顔はよく似ているから親子だろう。おれは、や、来たなと思う途端《とたん》に、うらなり君の事は全然《すっかり》忘れて、若い女の方ばかり見ていた。すると、うらなり君が突然《とつぜん》おれの隣《となり》から、立ち上がって、そろそろ女の方へ歩き出したんで、少し驚いた。マドンナじゃないかと思った。三人は切符所の前で軽く挨拶している。遠いから何を云ってるのか分らない。 停車場の時計を見るともう五分で発車だ。早く汽車がくればいいがなと、話し相手が居なくなったので待ち遠しく思っていると、また一人あわてて場内へ馳《か》け込《こ》んで来たものがある。見れば赤シャツだ。何だかべらべら然たる着物へ縮緬《ちりめん》の帯をだらしなく巻き付けて、例の通り金鎖《きんぐさ》りをぶらつかしている。あの金鎖りは贋物《にせもの》である。赤シャツは誰《だれ》も知るまいと思って、見せびらかしているが、おれはちゃんと知ってる。赤シャツは馳け込んだなり、何かきょろきょろしていたが、切符|売下所《うりさげじょ》の前に話している三人へ慇懃《いんぎん》にお辞儀《じぎ》をして、何か二こと、三こと、云ったと思ったら、急にこっちへ向いて、例のごとく猫足《ねこあし》にあるいて来て、や君も湯ですか、僕は乗り後れやしないかと思って心配して急いで来たら、まだ三四分ある。あの時計はたしかかしらんと、自分の金側《きんがわ》を出して、二分ほどちがってると云いながら、おれの傍《そば》へ腰を卸《おろ》した。女の方はちっとも見返らないで杖《つえ》の上に顋《あご》をのせて、正面ばかり眺《なが》めている。年寄の婦人は時々赤シャツを見るが、若い方は横を向いたままである。いよいよマドンナに違いない。 やがて、ピューと汽笛《きてき》が鳴って、車がつく。待ち合せた連中はぞろぞろ吾《わ》れ勝《がち》に乗り込む。赤シャツはいの一号に上等へ飛び込んだ。上等へ乗ったって威張れるどころではない、住田《すみた》まで上等が五銭で下等が三銭だから、わずか二銭違いで上下の区別がつく。こういうおれでさえ上等を奮発《ふんぱつ》して白切符を握《にぎ》ってるんでもわかる。もっとも田舎者はけちだから、たった二銭の出入でもすこぶる苦になると見えて、大抵《たいてい》は下等へ乗る。赤シャツのあとからマドンナとマドンナのお袋が上等へはいり込んだ。うらなり君は活版で押《お》したように下等ばかりへ乗る男だ。先生、下等の車室の入口へ立って、何だか躊躇《ちゅうちょ》の体《てい》であったが、おれの顔を見るや否や思いきって、飛び込んでしまった。おれはこの時何となく気の毒でたまらなかったから、うらなり君のあとから、すぐ同じ車室へ乗り込んだ。上等の切符で下等へ乗るに不都合はなかろう。 温泉へ着いて、三階から、浴衣《ゆかた》のなりで湯壺《ゆつぼ》へ下りてみたら、またうらなり君に逢った。おれは会議や何かでいざと極まると、咽喉《のど》が塞《ふさ》がって饒舌《しゃべ》れない男だが、平常《ふだん》は随分《ずいぶん》弁ずる方だから、いろいろ湯壺のなかでうらなり君に話しかけてみた。何だか憐れぽくってたまらない。こんな時に一口でも先方の心を慰《なぐさ》めてやるのは、江戸《えど》っ子の義務だと思ってる。ところがあいにくうらなり君の方では、うまい具合にこっちの調子に乗ってくれない。何を云っても、え[#「え」に傍点]とかいえ[#「いえ」に傍点]とかぎりで、しかもそのえ[#「え」に傍点]といえ[#「いえ」に傍点]が大分|面倒《めんどう》らしいので、しまいにはとうとう切り上げて、こっちからご免蒙《めんこうむ》った。 湯の中では赤シャツに逢わなかった。もっとも風呂《ふろ》の数はたくさんあるのだから、同じ汽車で着いても、同じ湯壺で逢うとは極まっていない。別段不思議にも思わなかった。風呂を出てみるといい月だ。町内の両側に柳《やなぎ》が植《うわ》って、柳の枝《えだ》が丸《ま》るい影を往来の中へ落《おと》している。少し散歩でもしよう。北へ登って町のはずれへ出ると、左に大きな門があって、門の突き当りがお寺で、左右が妓楼《ぎろう》である。山門のなかに遊廓《ゆうかく》があるなんて、前代未聞の現象だ。ちょっとはいってみたいが、また狸から会議の時にやられるかも知れないから、やめて素通りにした。門の並びに黒い暖簾《のれん》をかけた、小さな格子窓《こうしまど》の平屋はおれが団子を食って、しくじった所だ。丸提灯《まるぢょうちん》に汁粉《しるこ》、お雑煮《ぞうに》とかいたのがぶらさがって、提灯の火が、軒端《のきば》に近い一本の柳の幹を照らしている。食いたいなと思ったが我慢して通り過ぎた。 食いたい団子の食えないのは情ない。しかし自分の許嫁《いいなずけ》が他人に心を移したのは、なお情ないだろう。うらなり君の事を思うと、団子は愚《おろ》か、三日ぐらい断食《だんじき》しても不平はこぼせない訳だ。本当に人間ほどあてにならないものはない。あの顔を見ると、どうしたって、そんな不人情な事をしそうには思えないんだが――うつくしい人が不人情で、冬瓜《とうがん》の水膨《みずぶく》れのような古賀さんが善良な君子なのだから、油断が出来ない。淡泊《たんぱく》だと思った山嵐は生徒を煽動《せんどう》したと云うし。生徒を煽動したのかと思うと、生徒の処分を校長に逼《せま》るし。厭味《いやみ》で練りかためたような赤シャツが存外親切で、おれに余所《よそ》ながら注意をしてくれるかと思うと、マドンナを胡魔化《ごまか》したり、胡魔化したのかと思うと、古賀の方が破談にならなければ結婚は望まないんだと云うし。いか銀が難癖《なんくせ》をつけて、おれを追い出すかと思うと、すぐ野だ公が入《い》れ替《かわ》ったり――どう考えてもあてにならない。こんな事を清にかいてやったら定めて驚く事だろう。箱根《はこね》の向うだから化物《ばけもの》が寄り合ってるんだと云うかも知れない。 おれは、性来《しょうらい》構わない性分だから、どんな事でも苦にしないで今日まで凌いで来たのだが、ここへ来てからまだ一ヶ月立つか、立たないうちに、急に世のなかを物騒《ぶっそう》に思い出した。別段際だった大事件にも出逢わないのに、もう五つ六つ年を取ったような気がする。早く切り上げて東京へ帰るのが一番よかろう。などとそれからそれへ考えて、いつか石橋を渡《わた》って野芹川《のぜりがわ》の堤《どて》へ出た。川と云うとえらそうだが実は一間ぐらいな、ちょろちょろした流れで、土手に沿うて十二丁ほど下ると相生村《あいおいむら》へ出る。村には観音様《かんのんさま》がある。 温泉《ゆ》の町を振り返ると、赤い灯が、月の光の中にかがやいている。太鼓《たいこ》が鳴るのは遊廓に相違ない。川の流れは浅いけれども早いから、神経質の水のようにやたらに光る。ぶらぶら土手の上をあるきながら、約三丁も来たと思ったら、向うに人影《ひとかげ》が見え出した。月に透《す》かしてみると影は二つある。温泉《ゆ》へ来て村へ帰る若い衆《しゅ》かも知れない。それにしては唄《うた》もうたわない。存外静かだ。 だんだん歩いて行くと、おれの方が早足だと見えて、二つの影法師が、次第に大きくなる。一人は女らしい。おれの足音を聞きつけて、十間ぐらいの距離《きょり》に逼った時、男がたちまち振り向いた。月は後《うしろ》からさしている。その時おれは男の様子を見て、はてなと思った。男と女はまた元の通りにあるき出した。おれは考えがあるから、急に全速力で追っ懸《か》けた。先方は何の気もつかずに最初の通り、ゆるゆる歩を移している。今は話し声も手に取るように聞える。土手の幅は六尺ぐらいだから、並んで行けば三人がようやくだ。おれは苦もなく後ろから追い付いて、男の袖《そで》を擦《す》り抜《ぬ》けざま、二足前へ出した踵《くびす》をぐるりと返して男の顔を覗《のぞ》き込《こ》んだ。月は正面からおれの五分|刈《がり》の頭から顋の辺《あた》りまで、会釈《えしゃく》もなく照《てら》す。男はあっと小声に云ったが、急に横を向いて、もう帰ろうと女を促《うな》がすが早いか、温泉《ゆ》の町の方へ引き返した。 赤シャツは図太くて胡魔化すつもりか、気が弱くて名乗り損《そく》なったのかしら。ところが狭くて困ってるのは、おればかりではなかった。     八 赤シャツに勧められて釣《つり》に行った帰りから、山嵐《やまあらし》を疑ぐり出した。無い事を種に下宿を出ろと云われた時は、いよいよ不埒《ふらち》な奴《やつ》だと思った。ところが会議の席では案に相違《そうい》して滔々《とうとう》と生徒|厳罰論《げんばつろん》を述べたから、おや変だなと首を捩《ひね》った。萩野《はぎの》の婆《ばあ》さんから、山嵐が、うらなり君のために赤シャツと談判をしたと聞いた時は、それは感心だと手を拍《う》った。この様子ではわる者は山嵐じゃあるまい、赤シャツの方が曲ってるんで、好加減《いいかげん》な邪推《じゃすい》を実《まこと》しやかに、しかも遠廻《とおまわ》しに、おれの頭の中へ浸《し》み込《こ》ましたのではあるまいかと迷ってる矢先へ、野芹川《のぜりがわ》の土手で、マドンナを連れて散歩なんかしている姿を見たから、それ以来赤シャツは曲者《くせもの》だと極《き》めてしまった。曲者だか何だかよくは分《わか》らないが、ともかくも善《い》い男じゃない。表と裏とは違《ちが》った男だ。人間は竹のように真直《まっすぐ》でなくっちゃ頼《たの》もしくない。真直なものは喧嘩《けんか》をしても心持ちがいい。赤シャツのようなやさしいのと、親切なのと、高尚《こうしょう》なのと、琥珀《こはく》のパイプとを自慢《じまん》そうに見せびらかすのは油断が出来ない、めったに喧嘩も出来ないと思った。喧嘩をしても、回向院《えこういん》の相撲《すもう》のような心持ちのいい喧嘩は出来ないと思った。そうなると一銭五厘の出入《でいり》で控所《ひかえじょ》全体を驚《おど》ろかした議論の相手の山嵐の方がはるかに人間らしい。会議の時に金壺眼《かなつぼまなこ》をぐりつかせて、おれを睨《にら》めた時は憎《にく》い奴だと思ったが、あとで考えると、それも赤シャツのねちねちした猫撫声《ねこなでごえ》よりはましだ。実はあの会議が済んだあとで、よっぽど仲直りをしようかと思って、一こと二こと話しかけてみたが、野郎《やろう》返事もしないで、まだ眼《め》を剥《むく》ってみせたから、こっちも腹が立ってそのままにしておいた。 それ以来山嵐はおれと口を利かない。机の上へ返した一銭五厘はいまだに机の上に乗っている。ほこりだらけになって乗っている。おれは無論手が出せない、山嵐は決して持って帰らない。この一銭五厘が二人の間の墻壁《しょうへき》になって、おれは話そうと思っても話せない、山嵐は頑《がん》として黙《だま》ってる。おれと山嵐には一銭五厘が祟《たた》った。しまいには学校へ出て一銭五厘を見るのが苦になった。 山嵐とおれが絶交の姿となったに引き易《か》えて、赤シャツとおれは依然《いぜん》として在来の関係を保って、交際をつづけている。野芹川で逢《あ》った翌日などは、学校へ出ると第一番におれの傍《そば》へ来て、君今度の下宿はいいですかのまたいっしょに露西亜《ロシア》文学を釣《つ》りに行こうじゃないかのといろいろな事を話しかけた。おれは少々|憎《にく》らしかったから、昨夜《ゆうべ》は二返逢いましたねと云《い》ったら、ええ停車場《ていしゃば》で――君はいつでもあの時分|出掛《でか》けるのですか、遅いじゃないかと云う。野芹川の土手でもお目に懸《かか》りましたねと喰《く》らわしてやったら、いいえ僕《ぼく》はあっちへは行かない、湯にはいって、すぐ帰ったと答えた。何もそんなに隠《かく》さないでもよかろう、現に逢ってるんだ。よく嘘《うそ》をつく男だ。これで中学の教頭が勤まるなら、おれなんか大学総長がつとまる。おれはこの時からいよいよ赤シャツを信用しなくなった。信用しない赤シャツとは口をきいて、感心している山嵐とは話をしない。世の中は随分妙《ずいぶんみょう》なものだ。 ある日の事赤シャツがちょっと君に話があるから、僕のうちまで来てくれと云うから、惜《お》しいと思ったが温泉行きを欠勤して四時|頃《ごろ》出掛けて行った。赤シャツは一人ものだが、教頭だけに下宿はとくの昔《むかし》に引き払《はら》って立派な玄関《げんかん》を構えている。家賃は九円五|拾銭《じっせん》だそうだ。田舎《いなか》へ来て九円五拾銭払えばこんな家へはいれるなら、おれも一つ奮発《ふんぱつ》して、東京から清を呼び寄せて喜ばしてやろうと思ったくらいな玄関だ。頼むと云ったら、赤シャツの弟が取次《とりつぎ》に出て来た。この弟は学校で、おれに代数と算術を教わる至って出来のわるい子だ。その癖渡《くせわた》りものだから、生れ付いての田舎者よりも人が悪《わ》るい。 赤シャツに逢って用事を聞いてみると、大将例の琥珀のパイプで、きな臭《くさ》い烟草《たばこ》をふかしながら、こんな事を云った。「君が来てくれてから、前任者の時代よりも成績《せいせき》がよくあがって、校長も大いにいい人を得たと喜んでいるので――どうか学校でも信頼《しんらい》しているのだから、そのつもりで勉強していただきたい」「へえ、そうですか、勉強って今より勉強は出来ませんが――」「今のくらいで充分《じゅうぶん》です。ただ先だってお話しした事ですね、あれを忘れずにいて下さればいいのです」「下宿の世話なんかするものあ剣呑《けんのん》だという事ですか」「そう露骨《ろこつ》に云うと、意味もない事になるが――まあ善いさ――精神は君にもよく通じている事と思うから。そこで君が今のように出精《しゅっせい》して下されば、学校の方でも、ちゃんと見ているんだから、もう少しして都合《つごう》さえつけば、待遇《たいぐう》の事も多少はどうにかなるだろうと思うんですがね」「へえ、俸給《ほうきゅう》ですか。俸給なんかどうでもいいんですが、上がれば上がった方がいいですね」「それで幸い今度転任者が一人出来るから――もっとも校長に相談してみないと無論受け合えない事だが――その俸給から少しは融通《ゆうずう》が出来るかも知れないから、それで都合をつけるように校長に話してみようと思うんですがね」「どうも難有《ありがと》う。だれが転任するんですか」「もう発表になるから話しても差し支《つか》えないでしょう。実は古賀君です」「古賀さんは、だってここの人じゃありませんか」「ここの地《じ》の人ですが、少し都合があって――半分は当人の希望です」「どこへ行《ゆ》くんです」「日向《ひゅうが》の延岡《のべおか》で――土地が土地だから一級俸|上《あが》って行く事になりました」「誰《だれ》か代りが来るんですか」「代りも大抵《たいてい》極まってるんです。その代りの具合で君の待遇上の都合もつくんです」「はあ、結構です。しかし無理に上がらないでも構いません」「とも角も僕は校長に話すつもりです。それで校長も同意見らしいが、追っては君にもっと働いて頂《いた》だかなくってはならんようになるかも知れないから、どうか今からそのつもりで覚悟《かくご》をしてやってもらいたいですね」「今より時間でも増すんですか」「いいえ、時間は今より減るかも知れませんが――」「時間が減って、もっと働くんですか、妙だな」「ちょっと聞くと妙だが、――判然とは今言いにくいが――まあつまり、君にもっと重大な責任を持ってもらうかも知れないという意味なんです」 おれには一向分らない。今より重大な責任と云えば、数学の主任だろうが、主任は山嵐だから、やっこさんなかなか辞職する気遣《きづか》いはない。それに、生徒の人望があるから転任や免職《めんしょく》は学校の得策であるまい。赤シャツの談話はいつでも要領を得ない。要領を得なくっても用事はこれで済んだ。それから少し雑談をしているうちに、うらなり君の送別会をやる事や、ついてはおれが酒を飲むかと云う問や、うらなり先生は君子で愛すべき人だと云う事や――赤シャツはいろいろ弁じた。しまいに話をかえて君俳句をやりますかと来たから、こいつは大変だと思って、俳句はやりません、さようならと、そこそこに帰って来た。発句《ほっく》は芭蕉《ばしょう》か髪結床《かみいどこ》の親方のやるもんだ。数学の先生が朝顔やに釣瓶《つるべ》をとられてたまるものか。 帰ってうんと考え込んだ。世間には随分気の知れない男が居る。家屋敷はもちろん、勤める学校に不足のない故郷がいやになったからと云って、知らぬ他国へ苦労を求めに出る。それも花の都の電車が通《かよ》ってる所なら、まだしもだが、日向の延岡とは何の事だ。おれは船つきのいいここへ来てさえ、一ヶ月立たないうちにもう帰りたくなった。延岡と云えば山の中も山の中も大変な山の中だ。赤シャツの云うところによると船から上がって、一日《いちんち》馬車へ乗って、宮崎へ行って、宮崎からまた一日《いちんち》車へ乗らなくっては着けないそうだ。名前を聞いてさえ、開けた所とは思えない。猿《さる》と人とが半々に住んでるような気がする。いかに聖人のうらなり君だって、好んで猿の相手になりたくもないだろうに、何という物数奇《ものずき》だ。 ところへあいかわらず婆《ばあ》さんが夕食《ゆうめし》を運んで出る。今日もまた芋《いも》ですかいと聞いてみたら、いえ今日はお豆腐《とうふ》ぞなもしと云った。どっちにしたって似たものだ。「お婆さん古賀さんは日向へ行くそうですね」「ほん当にお気の毒じゃな、もし」「お気の毒だって、好んで行くんなら仕方がないですね」「好んで行くて、誰がぞなもし」「誰がぞなもしって、当人がさ。古賀先生が物数奇に行くんじゃありませんか」「そりゃあなた、大違いの勘五郎《かんごろう》ぞなもし」「勘五郎かね。だって今赤シャツがそう云いましたぜ。それが勘五郎なら赤シャツは嘘つきの法螺右衛門《ほらえもん》だ」「教頭さんが、そうお云いるのはもっともじゃが、古賀さんのお往《い》きともないのももっともぞなもし」「そんなら両方もっともなんですね。お婆さんは公平でいい。一体どういう訳なんですい」「今朝古賀のお母さんが見えて、だんだん訳をお話したがなもし」「どんな訳をお話したんです」「あそこもお父さんがお亡くなりてから、あたし達が思うほど暮《くら》し向《むき》が豊かになうてお困りじゃけれ、お母さんが校長さんにお頼みて、もう四年も勤めているものじゃけれ、どうぞ毎月頂くものを、今少しふやしておくれんかてて、あなた」「なるほど」「校長さんが、ようまあ考えてみとこうとお云いたげな。それでお母さんも安心して、今に増給のご沙汰《さた》があろぞ、今月か来月かと首を長くして待っておいでたところへ、校長さんがちょっと来てくれと古賀さんにお云いるけれ、行ってみると、気の毒だが学校は金が足りんけれ、月給を上げる訳にゆかん。しかし延岡になら空いた口があって、そっちなら毎月五円余分にとれるから、お望み通りでよかろうと思うて、その手続きにしたから行くがええと云われたげな。――」「じゃ相談じゃない、命令じゃありませんか」「さよよ。古賀さんはよそへ行って月給が増すより、元のままでもええから、ここに居《お》りたい。屋敷もあるし、母もあるからとお頼みたけれども、もうそう極めたあとで、古賀さんの代りは出来ているけれ仕方がないと校長がお云いたげな」「へん人を馬鹿《ばか》にしてら、面白《おもしろ》くもない。じゃ古賀さんは行く気はないんですね。どうれで変だと思った。五円ぐらい上がったって、あんな山の中へ猿のお相手をしに行く唐変木《とうへんぼく》はまずないからね」「唐変木て、先生なんぞなもし」「何でもいいでさあ、――全く赤シャツの作略《さりゃく》だね。よくない仕打《しうち》だ。まるで欺撃《だましうち》ですね。それでおれの月給を上げるなんて、不都合《ふつごう》な事があるものか。上げてやるったって、誰が上がってやるものか」「先生は月給がお上りるのかなもし」「上げてやるって云うから、断《こと》わろうと思うんです」「何で、お断わりるのぞなもし」「何でもお断わりだ。お婆さん、あの赤シャツは馬鹿ですぜ。卑怯《ひきょう》でさあ」「卑怯でもあんた、月給を上げておくれたら、大人《おとな》しく頂いておく方が得ぞなもし。若いうちはよく腹の立つものじゃが、年をとってから考えると、も少しの我慢《がまん》じゃあったのに惜しい事をした。腹立てたためにこないな損をしたと悔《くや》むのが当り前じゃけれ、お婆の言う事をきいて、赤シャツさんが月給をあげてやろとお言いたら、難有《ありがと》うと受けておおきなさいや」「年寄《としより》の癖に余計な世話を焼かなくってもいい。おれの月給は上がろうと下がろうとおれの月給だ」 婆さんはだまって引き込んだ。爺《じい》さんは呑気《のんき》な声を出して謡《うたい》をうたってる。謡というものは読んでわかる所を、やにむずかしい節をつけて、わざと分らなくする術だろう。あんな者を毎晩|飽《あ》きずに唸《うな》る爺さんの気が知れない。おれは謡どころの騒《さわ》ぎじゃない。月給を上げてやろうと云うから、別段欲しくもなかったが、入らない金を余しておくのももったいないと思って、よろしいと承知したのだが、転任したくないものを無理に転任させてその男の月給の上前を跳《は》ねるなんて不人情な事が出来るものか。当人がもとの通りでいいと云うのに延岡|下《くんだ》りまで落ちさせるとは一体どう云う了見《りょうけん》だろう。太宰権帥《だざいごんのそつ》でさえ博多《はかた》近辺で落ちついたものだ。河合又五郎《かあいまたごろう》だって相良《さがら》でとまってるじゃないか。とにかく赤シャツの所へ行って断わって来なくっちあ気が済まない。 小倉《こくら》の袴《はかま》をつけてまた出掛けた。大きな玄関へ突《つ》っ立って頼むと云うと、また例の弟が取次に出て来た。おれの顔を見てまた来たかという眼付《めつき》をした。用があれば二度だって三度だって来る。よる夜なかだって叩《たた》き起《おこ》さないとは限らない。教頭の所へご機嫌伺《きげんうかが》いにくるようなおれと見損《みそくな》ってるか。これでも月給が入らないから返しに来《きた》んだ。すると弟が今来客中だと云うから、玄関でいいからちょっとお目にかかりたいと云ったら奥《おく》へ引き込んだ。足元を見ると、畳付《たたみつ》きの薄っぺらな、のめりの駒下駄《こまげた》がある。奥でもう万歳《ばんざい》ですよと云う声が聞《きこ》える。お客とは野だだなと気がついた。野だでなくては、あんな黄色い声を出して、こんな芸人じみた下駄を穿《は》くものはない。 しばらくすると、赤シャツがランプを持って玄関まで出て来て、まあ上がりたまえ、外の人じゃない吉川君だ、と云うから、いえここでたくさんです。ちょっと話せばいいんです、と云って、赤シャツの顔を見ると金時のようだ。野だ公と一杯《いっぱい》飲んでると見える。「さっき僕の月給を上げてやるというお話でしたが、少し考えが変ったから断わりに来たんです」 赤シャツはランプを前へ出して、奥の方からおれの顔を眺《なが》めたが、とっさの場合返事をしかねて茫然《ぼうぜん》としている。増給を断わる奴が世の中にたった一人飛び出して来たのを不審《ふしん》に思ったのか、断わるにしても、今帰ったばかりで、すぐ出直してこなくってもよさそうなものだと、呆《あき》れ返ったのか、または双方合併《そうほうがっぺい》したのか、妙な口をして突っ立ったままである。「あの時承知したのは、古賀君が自分の希望で転任するという話でしたからで……」「古賀君は全く自分の希望で半ば転任するんです」「そうじゃないんです、ここに居たいんです。元の月給でもいいから、郷里に居たいのです」「君は古賀君から、そう聞いたのですか」「そりゃ当人から、聞いたんじゃありません」「じゃ誰からお聞きです」「僕の下宿の婆さんが、古賀さんのおっ母《か》さんから聞いたのを今日僕に話したのです」「じゃ、下宿の婆さんがそう云ったのですね」「まあそうです」「それは失礼ながら少し違うでしょう。あなたのおっしゃる通りだと、下宿屋の婆さんの云う事は信ずるが、教頭の云う事は信じないと云うように聞えるが、そういう意味に解釈して差支《さしつか》えないでしょうか」 おれはちょっと困った。文学士なんてものはやっぱりえらいものだ。妙な所へこだわって、ねちねち押《お》し寄せてくる。おれはよく親父《おやじ》から貴様はそそっかしくて駄目《だめ》だ駄目だと云われたが、なるほど少々そそっかしいようだ。婆さんの話を聞いてはっと思って飛び出して来たが、実はうらなり君にもうらなりのおっ母さんにも逢って詳《くわ》しい事情は聞いてみなかったのだ。だからこう文学士流に斬《き》り付けられると、ちょっと受け留めにくい。 正面からは受け留めにくいが、おれはもう赤シャツに対して不信任を心の中《うち》で申し渡してしまった。下宿の婆さんもけちん坊《ぼう》の欲張り屋に相違ないが、嘘は吐《つ》かない女だ、赤シャツのように裏表はない。おれは仕方がないから、こう答えた。「あなたの云う事は本当かも知れないですが――とにかく増給はご免蒙《めんこうむ》ります」「それはますます可笑《おか》しい。今君がわざわざお出《いで》になったのは増俸を受けるには忍《しの》びない、理由を見出したからのように聞えたが、その理由が僕の説明で取り去られたにもかかわらず増俸を否まれるのは少し解しかねるようですね」「解しかねるかも知れませんがね。とにかく断わりますよ」「そんなに否《いや》なら強いてとまでは云いませんが、そう二三時間のうちに、特別の理由もないのに豹変《ひょうへん》しちゃ、将来君の信用にかかわる」「かかわっても構わないです」「そんな事はないはずです、人間に信用ほど大切なものはありませんよ。よしんば今一歩|譲《ゆず》って、下宿の主人が……」「主人じゃない、婆さんです」「どちらでもよろしい。下宿の婆さんが君に話した事を事実としたところで、君の増給は古賀君の所得を削《けず》って得たものではないでしょう。古賀君は延岡へ行かれる。その代りがくる。その代りが古賀君よりも多少低給で来てくれる。その剰余《じょうよ》を君に廻《ま》わすと云うのだから、君は誰にも気の毒がる必要はないはずです。古賀君は延岡でただ今よりも栄進される。新任者は最初からの約束《やくそく》で安くくる。それで君が上がられれば、これほど都合《つごう》のいい事はないと思うですがね。いやなら否《いや》でもいいが、もう一返うちでよく考えてみませんか」 おれの頭はあまりえらくないのだから、いつもなら、相手がこういう巧妙《こうみょう》な弁舌を揮《ふる》えば、おやそうかな、それじゃ、おれが間違ってたと恐《おそ》れ入って引きさがるのだけれども、今夜はそうは行かない。ここへ来た最初から赤シャツは何だか虫が好かなかった。途中《とちゅう》で親切な女みたような男だと思い返した事はあるが、それが親切でも何でもなさそうなので、反動の結果今じゃよっぽど厭《いや》になっている。だから先がどれほどうまく論理的に弁論を逞《たくまし》くしようとも、堂々たる教頭流におれを遣り込めようとも、そんな事は構わない。議論のいい人が善人とはきまらない。遣り込められる方が悪人とは限らない。表向きは赤シャツの方が重々もっともだが、表向きがいくら立派だって、腹の中まで惚《ほ》れさせる訳には行かない。金や威力《いりょく》や理屈《りくつ》で人間の心が買える者なら、高利貸でも巡査《じゅんさ》でも大学教授でも一番人に好かれなくてはならない。中学の教頭ぐらいな論法でおれの心がどう動くものか。人間は好き嫌いで働くものだ。論法で働くものじゃない。「あなたの云う事はもっともですが、僕は増給がいやになったんですから、まあ断わります。考えたって同じ事です。さようなら」と云いすてて門を出た。頭の上には天の川が一筋かかっている。     九 うらなり君の送別会のあるという日の朝、学校へ出たら、山嵐《やまあらし》が突然《とつぜん》、君先だってはいか銀が来て、君が乱暴して困るから、どうか出るように話してくれと頼《たの》んだから、真面目《まじめ》に受けて、君に出てやれと話したのだが、あとから聞いてみると、あいつは悪《わ》るい奴《やつ》で、よく偽筆《ぎひつ》へ贋落款《にせらっかん》などを押《お》して売りつけるそうだから、全く君の事も出鱈目《でたらめ》に違《ちが》いない。君に懸物《かけもの》や骨董《こっとう》を売りつけて、商売にしようと思ってたところが、君が取り合わないで儲《もう》けがないものだから、あんな作りごとをこしらえて胡魔化《ごまか》したのだ。僕はあの人物を知らなかったので君に大変失敬した勘弁《かんべん》したまえと長々しい謝罪をした。 おれは何とも云わずに、山嵐の机の上にあった、一銭五|厘《りん》をとって、おれの蝦蟇口《がまぐち》のなかへ入れた。山嵐は君それを引き込《こ》めるのかと不審《ふしん》そうに聞くから、うんおれは君に奢《おご》られるのが、いやだったから、是非返すつもりでいたが、その後だんだん考えてみると、やっぱり奢ってもらう方がいいようだから、引き込ますんだと説明した。山嵐は大きな声をしてアハハハと笑いながら、そんなら、なぜ早く取らなかったのだと聞いた。実は取ろう取ろうと思ってたが、何だか妙《みょう》だからそのままにしておいた。近来は学校へ来て一銭五厘を見るのが苦になるくらいいやだったと云ったら、君はよっぽど負け惜《お》しみの強い男だと云うから、君はよっぽど剛情張《ごうじょうっぱ》りだと答えてやった。それから二人の間にこんな問答が起《おこ》った。「君は一体どこの産だ」「おれは江戸《えど》っ子だ」「うん、江戸っ子か、道理で負け惜しみが強いと思った」「きみはどこだ」「僕は会津《あいづ》だ」「会津っぽか、強情な訳だ。今日の送別会へ行くのかい」「行くとも、君は?」「おれは無論行くんだ。古賀さんが立つ時は、浜《はま》まで見送りに行こうと思ってるくらいだ」「送別会は面白いぜ、出て見たまえ。今日は大いに飲むつもりだ」「勝手に飲むがいい。おれは肴《さかな》を食ったら、すぐ帰る。酒なんか飲む奴は馬鹿《ばか》だ」「君はすぐ喧嘩《けんか》を吹《ふ》き懸《か》ける男だ。なるほど江戸っ子の軽跳《けいちょう》な風を、よく、あらわしてる」「何でもいい、送別会へ行く前にちょっとおれのうちへお寄り、話《はな》しがあるから」 山嵐は約束《やくそく》通りおれの下宿へ寄った。おれはこの間から、うらなり君の顔を見る度に気の毒でたまらなかったが、いよいよ送別の今日となったら、何だか憐《あわ》れっぽくって、出来る事なら、おれが代りに行ってやりたい様な気がしだした。それで送別会の席上で、大いに演説でもしてその行を盛《さかん》にしてやりたいと思うのだが、おれのべらんめえ調子じゃ、到底《とうてい》物にならないから、大きな声を出す山嵐を雇《やと》って、一番赤シャツの荒肝《あらぎも》を挫《ひし》いでやろうと考え付いたから、わざわざ山嵐を呼んだのである。 おれはまず冒頭《ぼうとう》としてマドンナ事件から説き出したが、山嵐は無論マドンナ事件はおれより詳《くわ》しく知っている。おれが野芹川《のぜりがわ》の土手の話をして、あれは馬鹿野郎《ばかやろう》だと云ったら、山嵐は君はだれを捕《つら》まえても馬鹿|呼《よば》わりをする。今日学校で自分の事を馬鹿と云ったじゃないか。自分が馬鹿なら、赤シャツは馬鹿じゃない。自分は赤シャツの同類じゃないと主張した。それじゃ赤シャツは腑抜《ふぬ》けの呆助《ほうすけ》だと云ったら、そうかもしれないと山嵐は大いに賛成した。山嵐は強い事は強いが、こんな言葉になると、おれより遥《はる》かに字を知っていない。会津っぽなんてものはみんな、こんな、ものなんだろう。 それから増給事件と将来重く登用すると赤シャツが云った話をしたら山嵐はふふんと鼻から声を出して、それじゃ僕を免職《めんしょく》する考えだなと云った。免職するつもりだって、君は免職になる気かと聞いたら、誰《だれ》がなるものか、自分が免職になるなら、赤シャツもいっしょに免職させてやると大いに威張《いば》った。どうしていっしょに免職させる気かと押し返して尋《たず》ねたら、そこはまだ考えていないと答えた。山嵐は強そうだが、智慧《ちえ》はあまりなさそうだ。おれが増給を断《こと》わったと話したら、大将大きに喜んでさすが江戸っ子だ、えらいと賞《ほ》めてくれた。 うらなりが、そんなに厭《いや》がっているなら、なぜ留任の運動をしてやらなかったと聞いてみたら、うらなりから話を聞いた時は、既《すで》にきまってしまって、校長へ二度、赤シャツへ一度行って談判してみたが、どうする事も出来なかったと話した。それについても古賀があまり好人物過ぎるから困る。赤シャツから話があった時、断然断わるか、一応考えてみますと逃《に》げればいいのに、あの弁舌に胡魔化されて、即席《そくせき》に許諾《きょだく》したものだから、あとからお母《っか》さんが泣きついても、自分が談判に行っても役に立たなかったと非常に残念がった。 今度の事件は全く赤シャツが、うらなりを遠ざけて、マドンナを手に入れる策略なんだろうとおれが云ったら、無論そうに違いない。あいつは大人《おとな》しい顔をして、悪事を働いて、人が何か云うと、ちゃんと逃道《にげみち》を拵《こしら》えて待ってるんだから、よっぽど奸物《かんぶつ》だ。あんな奴にかかっては鉄拳制裁《てっけんせいさい》でなくっちゃ利かないと、瘤《こぶ》だらけの腕《うで》をまくってみせた。おれはついでだから、君の腕は強そうだな柔術《じゅうじゅつ》でもやるかと聞いてみた。すると大将二の腕へ力瘤を入れて、ちょっと攫《つか》んでみろと云うから、指の先で揉《も》んでみたら、何の事はない湯屋にある軽石の様なものだ。 おれはあまり感心したから、君そのくらいの腕なら、赤シャツの五人や六人は一度に張り飛ばされるだろうと聞いたら、無論さと云いながら、曲げた腕を伸《の》ばしたり、縮ましたりすると、力瘤がぐるりぐるりと皮のなかで廻転《かいてん》する。すこぶる愉快《ゆかい》だ。山嵐の証明する所によると、かんじん綯《よ》りを二本より合せて、この力瘤の出る所へ巻きつけて、うんと腕を曲げると、ぷつりと切れるそうだ。かんじんよりなら、おれにも出来そうだと云ったら、出来るものか、出来るならやってみろと来た。切れないと外聞がわるいから、おれは見合せた。 君どうだ、今夜の送別会に大いに飲んだあと、赤シャツと野だを撲《なぐ》ってやらないかと面白半分に勧めてみたら、山嵐はそうだなと考えていたが、今夜はまあよそうと云った。なぜと聞くと、今夜は古賀に気の毒だから――それにどうせ撲るくらいなら、あいつらの悪るい所を見届けて現場で撲らなくっちゃ、こっちの落度になるからと、分別のありそうな事を附加《つけた》した。山嵐でもおれよりは考えがあると見える。 じゃ演説をして古賀君を大いにほめてやれ、おれがすると江戸っ子のぺらぺらになって重みがなくていけない。そうして、きまった所へ出ると、急に溜飲《りゅういん》が起って咽喉《のど》の所へ、大きな丸《たま》が上がって来て言葉が出ないから、君に譲《ゆず》るからと云ったら、妙な病気だな、じゃ君は人中じゃ口は利けないんだね、困るだろう、と聞くから、何そんなに困りゃしないと答えておいた。 そうこうするうち時間が来たから、山嵐と一所に会場へ行く。会場は花晨亭《かしんてい》といって、当地《ここ》で第一等の料理屋だそうだが、おれは一度も足を入れた事がない。もとの家老とかの屋敷《やしき》を買い入れて、そのまま開業したという話だが、なるほど見懸《みかけ》からして厳《いか》めしい構えだ。家老の屋敷が料理屋になるのは、陣羽織《じんばおり》を縫《ぬ》い直して、胴着《どうぎ》にする様なものだ。 二人が着いた頃《ころ》には、人数《にんず》ももう大概揃《たいがいそろ》って、五十|畳《じょう》の広間に二つ三つ人間の塊《かたまり》が出来ている。五十畳だけに床《とこ》は素敵に大きい。おれが山城屋で占領《せんりょう》した十五畳敷の床とは比較にならない。尺を取ってみたら二間あった。右の方に、赤い模様のある瀬戸物の瓶《かめ》を据《す》えて、その中に松《まつ》の大きな枝《えだ》が挿《さ》してある。松の枝を挿して何にする気か知らないが、何ヶ月立っても散る気遣いがないから、銭が懸らなくって、よかろう。あの瀬戸物はどこで出来るんだと博物の教師に聞いたら、あれは瀬戸物じゃありません、伊万里《いまり》ですと云った。伊万里だって瀬戸物じゃないかと、云ったら、博物はえへへへへと笑っていた。あとで聞いてみたら、瀬戸で出来る焼物だから、瀬戸と云うのだそうだ。おれは江戸っ子だから、陶器《とうき》の事を瀬戸物というのかと思っていた。床の真中に大きな懸物があって、おれの顔くらいな大きさな字が二十八字かいてある。どうも下手《へた》なものだ。あんまり不味《まず》いから、漢学の先生に、なぜあんなまずいものを麗々《れいれい》と懸けておくんですと尋《たず》ねたところ、先生はあれは海屋《かいおく》といって有名な書家のかいた者だと教えてくれた。海屋だか何だか、おれは今だに下手だと思っている。 やがて書記の川村がどうかお着席をと云うから、柱があって靠《よ》りかかるのに都合のいい所へ坐《すわ》った。海屋の懸物の前に狸《たぬき》が羽織《はおり》、袴《はかま》で着席すると、左に赤シャツが同じく羽織袴で陣取《じんど》った。右の方は主人公だというのでうらなり先生、これも日本服で控《ひか》えている。おれは洋服だから、かしこまるのが窮屈《きゅうくつ》だったから、すぐ胡坐《あぐら》をかいた。隣《とな》りの体操《たいそう》教師は黒ずぼん[#「ずぼん」に傍点]で、ちゃんとかしこまっている。体操の教師だけにいやに修行が積んでいる。やがてお膳《ぜん》が出る。徳利《とくり》が並《なら》ぶ。幹事が立って、一言《いちごん》開会の辞を述べる。それから狸が立つ。赤シャツが起《た》つ。ことごとく送別の辞を述べたが、三人共申し合せたようにうらなり君の、良教師で好人物な事を吹聴《ふいちょう》して、今回去られるのはまことに残念である、学校としてのみならず、個人として大いに惜しむところであるが、ご一身上のご都合で、切に転任をご希望になったのだから致《いた》し方《かた》がないという意味を述べた。こんな嘘《うそ》をついて送別会を開いて、それでちっとも恥《はず》かしいとも思っていない。ことに赤シャツに至って三人のうちで一番うらなり君をほめた。この良友を失うのは実に自分にとって大なる不幸であるとまで云った。しかもそのいい方がいかにも、もっともらしくって、例のやさしい声を一層やさしくして、述べ立てるのだから、始めて聞いたものは、誰でもきっとだまされるに極《きま》ってる。マドンナも大方この手で引掛《ひっか》けたんだろう。赤シャツが送別の辞を述べ立てている最中、向側《むかいがわ》に坐っていた山嵐がおれの顔を見てちょっと稲光《いなびかり》をさした。おれは返電として、人指し指でべっかんこうをして見せた。 赤シャツが座に復するのを待ちかねて、山嵐がぬっと立ち上がったから、おれは嬉《うれ》しかったので、思わず手をぱちぱちと拍《う》った。すると狸を始め一同がことごとくおれの方を見たには少々困った。山嵐は何を云うかと思うとただ今校長始めことに教頭は古賀君の転任を非常に残念がられたが、私は少々反対で古賀君が一日《いちじつ》も早く当地を去られるのを希望しております。延岡は僻遠《へきえん》の地で、当地に比べたら物質上の不便はあるだろう。が、聞くところによれば風俗のすこぶる淳朴《じゅんぼく》な所で、職員生徒ことごとく上代樸直《じょうだいぼくちょく》の気風を帯びているそうである。心にもないお世辞を振《ふ》り蒔《ま》いたり、美しい顔をして君子を陥《おとしい》れたりするハイカラ野郎は一人もないと信ずるからして、君のごとき温良|篤厚《とっこう》の士は必ずその地方一般の歓迎《かんげい》を受けられるに相違《そうい》ない。吾輩《わがはい》は大いに古賀君のためにこの転任を祝するのである。終りに臨んで君が延岡に赴任《ふにん》されたら、その地の淑女《しゅくじょ》にして、君子の好逑《こうきゅう》となるべき資格あるものを択《えら》んで一日《いちじつ》も早く円満なる家庭をかたち作って、かの不貞無節なるお転婆《てんば》を事実の上において慚死《ざんし》せしめん事を希望します。えへんえへんと二つばかり大きな咳払《せきばら》いをして席に着いた。おれは今度も手を叩《たた》こうと思ったが、またみんながおれの面《かお》を見るといやだから、やめにしておいた。山嵐が坐ると今度はうらなり先生が起った。先生はご鄭寧《ていねい》に、自席から、座敷の端《はし》の末座まで行って、慇懃《いんぎん》に一同に挨拶《あいさつ》をした上、今般は一身上の都合で九州へ参る事になりましたについて、諸先生方が小生のためにこの盛大《せいだい》なる送別会をお開き下さったのは、まことに感銘《かんめい》の至りに堪《た》えぬ次第で――ことにただ今は校長、教頭その他諸君の送別の辞を頂戴《ちょうだい》して、大いに難有《ありがた》く服膺《ふくよう》する訳であります。私はこれから遠方へ参りますが、なにとぞ従前の通りお見捨てなくご愛顧《あいこ》のほどを願います。とへえつく張って席に戻《もど》った。うらなり君はどこまで人が好いんだか、ほとんど底が知れない。自分がこんなに馬鹿にされている校長や、教頭に恭《うやうや》しくお礼を云っている。それも義理|一遍《いっぺん》の挨拶ならだが、あの様子や、あの言葉つきや、あの顔つきから云うと、心《しん》から感謝しているらしい。こんな聖人に真面目にお礼を云われたら、気の毒になって、赤面しそうなものだが狸も赤シャツも真面目に謹聴《きんちょう》しているばかりだ。 挨拶が済んだら、あちらでもチュー、こちらでもチュー、という音がする。おれも真似をして汁《しる》を飲んでみたがまずいもんだ。口取《くちとり》に蒲鉾《かまぼこ》はついてるが、どす黒くて竹輪の出来損《できそこ》ないである。刺身《さしみ》も並んでるが、厚くって鮪《まぐろ》の切り身を生で食うと同じ事だ。それでも隣《とな》り近所の連中はむしゃむしゃ旨《うま》そうに食っている。大方江戸前の料理を食った事がないんだろう。 そのうち燗徳利《かんどくり》が頻繁《ひんぱん》に往来し始めたら、四方が急に賑《にぎ》やかになった。野だ公は恭しく校長の前へ出て盃《さかずき》を頂いてる。いやな奴だ。うらなり君は順々に献酬《けんしゅう》をして、一巡周《いちじゅんめぐ》るつもりとみえる。はなはだご苦労である。うらなり君がおれの前へ来て、一つ頂戴致しましょうと袴のひだを正して申し込まれたから、おれも窮屈にズボンのままかしこまって、一|盃《ぱい》差し上げた。せっかく参って、すぐお別れになるのは残念ですね。ご出立《しゅったつ》はいつです、是非浜までお見送りをしましょうと云ったら、うらなり君はいえご用|多《おお》のところ決してそれには及《およ》びませんと答えた。うらなり君が何と云ったって、おれは学校を休んで送る気でいる。 それから一時間ほどするうちに席上は大分乱れて来る。まあ一|杯《ぱい》、おや僕が飲めと云うのに……などと呂律《ろれつ》の巡《まわ》りかねるのも一人二人《ひとりふたり》出来て来た。少々|退屈《たいくつ》したから便所へ行って、昔風な庭を星明りにすかして眺《なが》めていると山嵐が来た。どうださっきの演説はうまかったろう。と大分得意である。大賛成だが一ヶ所気に入らないと抗議《こうぎ》を申し込んだら、どこが不賛成だと聞いた。「美しい顔をして人を陥れるようなハイカラ野郎は延岡に居《お》らないから……と君は云ったろう」「うん」「ハイカラ野郎だけでは不足だよ」「じゃ何と云うんだ」「ハイカラ野郎の、ペテン師の、イカサマ師の、猫被《ねこっかぶ》りの、香具師《やし》の、モモンガーの、岡っ引きの、わんわん鳴けば犬も同然な奴とでも云うがいい」「おれには、そう舌は廻らない。君は能弁だ。第一単語を大変たくさん知ってる。それで演舌《えんぜつ》が出来ないのは不思議だ」「なにこれは喧嘩《けんか》のときに使おうと思って、用心のために取っておく言葉さ。演舌となっちゃ、こうは出ない」「そうかな、しかしぺらぺら出るぜ。もう一遍やって見たまえ」「何遍でもやるさいいか。――ハイカラ野郎のペテン師の、イカサマ師の……」と云いかけていると、椽側《えんがわ》をどたばた云わして、二人ばかり、よろよろしながら馳《か》け出して来た。「両君そりゃひどい、――逃げるなんて、――僕が居るうちは決して逃《にが》さない、さあのみたまえ。――いかさま師?――面白い、いかさま面白い。――さあ飲みたまえ」とおれと山嵐をぐいぐい引っ張って行く。実はこの両人共便所に来たのだが、酔《よ》ってるもんだから、便所へはいるのを忘れて、おれ等を引っ張るのだろう。酔っ払いは目の中《あた》る所へ用事を拵えて、前の事はすぐ忘れてしまうんだろう。「さあ、諸君、いかさま師を引っ張って来た。さあ飲ましてくれたまえ。いかさま師をうんと云うほど、酔わしてくれたまえ。君逃げちゃいかん」と逃げもせぬ、おれを壁際《かべぎわ》へ圧《お》し付けた。諸方を見廻してみると、膳の上に満足な肴の乗っているのは一つもない。自分の分を奇麗《きれい》に食い尽《つく》して、五六間先へ遠征《えんせい》に出た奴もいる。校長はいつ帰ったか姿が見えない。 ところへお座敷はこちら? と芸者が三四人はいって来た。おれも少し驚《おど》ろいたが、壁際へ圧し付けられているんだから、じっとしてただ見ていた。すると今まで床柱《とこばしら》へもたれて例の琥珀《こはく》のパイプを自慢《じまん》そうに啣《くわ》えていた、赤シャツが急に起《た》って、座敷を出にかかった。向《むこ》うからはいって来た芸者の一人が、行き違いながら、笑って挨拶をした。その一人は一番若くて一番奇麗な奴だ。遠くで聞《きこ》えなかったが、おや今晩はぐらい云ったらしい。赤シャツは知らん顔をして出て行ったぎり、顔を出さなかった。大方校長のあとを追懸《おいか》けて帰ったんだろう。 芸者が来たら座敷中急に陽気になって、一同が鬨《とき》の声を揚《あ》げて歓迎《かんげい》したのかと思うくらい、騒々《そうぞう》しい。そうしてある奴はなんこを攫《つか》む。その声の大きな事、まるで居合抜《いあいぬき》の稽古《けいこ》のようだ。こっちでは拳《けん》を打ってる。よっ、はっ、と夢中《むちゅう》で両手を振るところは、ダーク一座の操人形《あやつりにんぎょう》よりよっぽど上手《じょうず》だ。向うの隅《すみ》ではおいお酌《しゃく》だ、と徳利を振ってみて、酒だ酒だと言い直している。どうもやかましくて騒々しくってたまらない。そのうちで手持無沙汰《てもちぶさた》に下を向いて考え込んでるのはうらなり君ばかりである。自分のために送別会を開いてくれたのは、自分の転任を惜《おし》んでくれるんじゃない。みんなが酒を呑《の》んで遊ぶためだ。自分独りが手持無沙汰で苦しむためだ。こんな送別会なら、開いてもらわない方がよっぽどましだ。 しばらくしたら、めいめい胴間声《どうまごえ》を出して何か唄《うた》い始めた。おれの前へ来た一人の芸者が、あんた、なんぞ、唄いなはれ、と三味線を抱《かか》えたから、おれは唄わない、貴様唄ってみろと云ったら、金《かね》や太鼓《たいこ》でねえ、迷子の迷子の三太郎と、どんどこ、どんのちゃんちきりん。叩いて廻って逢《あ》われるものならば、わたしなんぞも、金や太鼓でどんどこ、どんのちゃんちきりんと叩いて廻って逢いたい人がある、と二た息にうたって、おおしんどと云った。おおしんどなら、もっと楽なものをやればいいのに。 すると、いつの間にか傍《そば》へ来て坐った、野だが、鈴ちゃん逢いたい人に逢ったと思ったら、すぐお帰りで、お気の毒さまみたようでげすと相変らず噺《はな》し家みたような言葉使いをする。知りまへんと芸者はつんと済ました。野だは頓着《とんじゃく》なく、たまたま逢いは逢いながら……と、いやな声を出して義太夫《ぎだゆう》の真似《まね》をやる。おきなはれやと芸者は平手で野だの膝《ひざ》を叩いたら野だは恐悦《きょうえつ》して笑ってる。この芸者は赤シャツに挨拶をした奴だ。芸者に叩かれて笑うなんて、野だもおめでたい者だ。鈴ちゃん僕が紀伊《き》の国を踴《おど》るから、一つ弾《ひ》いて頂戴と云い出した。野だはこの上まだ踴る気でいる。 向うの方で漢学のお爺《じい》さんが歯のない口を歪《ゆが》めて、そりゃ聞えません伝兵衛《でんべい》さん、お前とわたしのその中は……とまでは無事に済《すま》したが、それから? と芸者に聞いている。爺さんなんて物覚えのわるいものだ。一人が博物を捕《つら》まえて近頃《ちかごろ》こないなのが、でけましたぜ、弾いてみまほうか。よう聞いて、いなはれや――花月巻《かげつまき》、白いリボンのハイカラ頭、乗るは自転車、弾くはヴァイオリン、半可《はんか》の英語でぺらぺらと、I am glad to see you と唄うと、博物はなるほど面白い、英語入りだねと感心している。 山嵐は馬鹿に大きな声を出して、芸者、芸者と呼んで、おれが剣舞《けんぶ》をやるから、三味線を弾けと号令を下した。芸者はあまり乱暴な声なので、あっけに取られて返事もしない。山嵐は委細構わず、ステッキを持って来て、踏破千山万岳烟《ふみやぶるせんざんばんがくのけむり》と真中《まんなか》へ出て独りで隠《かく》し芸を演じている。ところへ野だがすでに紀伊《き》の国を済まして、かっぽれを済まして、棚《たな》の達磨《だるま》さんを済して丸裸《まるはだか》の越中褌《えっちゅうふんどし》一つになって、棕梠箒《しゅろぼうき》を小脇に抱《か》い込んで、日清談判|破裂《はれつ》して……と座敷中練りあるき出した。まるで気違《きちが》いだ。 おれはさっきから苦しそうに袴も脱《ぬ》がず控えているうらなり君が気の毒でたまらなかったが、なんぼ自分の送別会だって、越中褌の裸踴《はだかおどり》まで羽織袴で我慢《がまん》してみている必要はあるまいと思ったから、そばへ行って、古賀さんもう帰りましょうと退去を勧めてみた。するとうらなり君は今日は私の送別会だから、私が先へ帰っては失礼です、どうぞご遠慮《えんりょ》なくと動く景色もない。なに構うもんですか、送別会なら、送別会らしくするがいいです、あの様をご覧なさい。気狂会《きちがいかい》です。さあ行きましょうと、進まないのを無理に勧めて、座敷を出かかるところへ、野だが箒を振り振り進行して来て、やご主人が先へ帰るとはひどい。日清談判だ。帰せないと箒を横にして行く手を塞《ふさ》いだ。おれはさっきから肝癪《かんしゃく》が起っているところだから、日清談判なら貴様はちゃんちゃんだろうと、いきなり拳骨《げんこつ》で、野だの頭をぽかりと喰《く》わしてやった。野だは二三秒の間毒気を抜かれた体《てい》で、ぼんやりしていたが、おやこれはひどい。お撲《ぶ》ちになったのは情ない。この吉川をご打擲《ちょうちゃく》とは恐れ入った。いよいよもって日清談判だ。とわからぬ事をならべているところへ、うしろから山嵐が何か騒動《そうどう》が始まったと見てとって、剣舞をやめて、飛んできたが、このていたらくを見て、いきなり頸筋《くびすじ》をうんと攫《つか》んで引き戻《もど》した。日清……いたい。いたい。どうもこれは乱暴だと振りもがくところを横に捩《ねじ》ったら、すとんと倒《たお》れた。あとはどうなったか知らない。途中《とちゅう》でうらなり君に別れて、うちへ帰ったら十一時過ぎだった。     十 祝勝会で学校はお休みだ。練兵場《れんぺいば》で式があるというので、狸《たぬき》は生徒を引率して参列しなくてはならない。おれも職員の一人《ひとり》としていっしょにくっついて行くんだ。町へ出ると日の丸だらけで、まぼしいくらいである。学校の生徒は八百人もあるのだから、体操の教師が隊伍《たいご》を整えて、一組一組の間を少しずつ明けて、それへ職員が一人か二人《ふたり》ずつ監督《かんとく》として割り込《こ》む仕掛《しか》けである。仕掛《しかけ》だけはすこぶる巧妙《こうみょう》なものだが、実際はすこぶる不手際である。生徒は小供《こども》の上に、生意気で、規律を破らなくっては生徒の体面にかかわると思ってる奴等《やつら》だから、職員が幾人《いくたり》ついて行ったって何の役に立つもんか。命令も下さないのに勝手な軍歌をうたったり、軍歌をやめるとワーと訳もないのに鬨《とき》の声を揚《あ》げたり、まるで浪人《ろうにん》が町内をねりあるいてるようなものだ。軍歌も鬨の声も揚げない時はがやがや何か喋舌《しゃべ》ってる。喋舌らないでも歩けそうなもんだが、日本人はみな口から先へ生れるのだから、いくら小言を云《い》ったって聞きっこない。喋舌るのもただ喋舌るのではない、教師のわる口を喋舌るんだから、下等だ。おれは宿直事件で生徒を謝罪さして、まあこれならよかろうと思っていた。ところが実際は大違《おおちが》いである。下宿の婆《ばあ》さんの言葉を借りて云えば、正に大違いの勘五郎《かんごろう》である。生徒があやまったのは心《しん》から後悔《こうかい》してあやまったのではない。ただ校長から、命令されて、形式的に頭を下げたのである。商人が頭ばかり下げて、狡《ずる》い事をやめないのと一般で生徒も謝罪だけはするが、いたずらは決してやめるものでない。よく考えてみると世の中はみんなこの生徒のようなものから成立しているかも知れない。人があやまったり詫《わ》びたりするのを、真面目《まじめ》に受けて勘弁するのは正直過ぎる馬鹿《ばか》と云うんだろう。あやまるのも仮りにあやまるので、勘弁するのも仮りに勘弁するのだと思ってれば差《さ》し支《つか》えない。もし本当にあやまらせる気なら、本当に後悔するまで叩《たた》きつけなくてはいけない。 おれが組と組の間にはいって行くと、天麩羅《てんぷら》だの、団子《だんご》だの、と云う声が絶えずする。しかも大勢だから、誰《だれ》が云うのだか分らない。よし分ってもおれの事を天麩羅と云ったんじゃありません、団子と申したのじゃありません、それは先生が神経衰弱《しんけいすいじゃく》だから、ひがんで、そう聞くんだぐらい云うに極《き》まってる。こんな卑劣《ひれつ》な根性は封建時代から、養成したこの土地の習慣なんだから、いくら云って聞かしたって、教えてやったって、到底《とうてい》直りっこない。こんな土地に一年も居ると、潔白なおれも、この真似《まね》をしなければならなく、なるかも知れない。向《むこ》うでうまく言い抜《ぬ》けられるような手段で、おれの顔を汚《よご》すのを抛《ほう》っておく、樗蒲一《ちょぼいち》はない。向こうが人ならおれも人だ。生徒だって、子供だって、ずう体はおれより大きいや。だから刑罰《けいばつ》として何か返報をしてやらなくっては義理がわるい。ところがこっちから返報をする時分に尋常《じんじょう》の手段で行くと、向うから逆捩《さかねじ》を食わして来る。貴様がわるいからだと云うと、初手から逃《に》げ路《みち》が作ってある事だから滔々《とうとう》と弁じ立てる。弁じ立てておいて、自分の方を表向きだけ立派にしてそれからこっちの非を攻撃《こうげき》する。もともと返報にした事だから、こちらの弁護は向うの非が挙がらない上は弁護にならない。つまりは向うから手を出しておいて、世間体はこっちが仕掛けた喧嘩《けんか》のように、見傚《みな》されてしまう。大変な不利益だ。それなら向うのやるなり、愚迂多良童子《ぐうたらどうじ》を極め込んでいれば、向うはますます増長するばかり、大きく云えば世の中のためにならない。そこで仕方がないから、こっちも向うの筆法を用いて捕《つら》まえられないで、手の付けようのない返報をしなくてはならなくなる。そうなっては江戸《えど》っ子も駄目《だめ》だ。駄目だが一年もこうやられる以上は、おれも人間だから駄目でも何でもそうならなくっちゃ始末がつかない。どうしても早く東京へ帰って清《きよ》といっしょになるに限る。こんな田舎《いなか》に居るのは堕落《だらく》しに来ているようなものだ。新聞配達をしたって、ここまで堕落するよりはましだ。 こう考えて、いやいや、附《つ》いてくると、何だか先鋒《せんぽう》が急にがやがや騒《さわ》ぎ出した。同時に列はぴたりと留まる。変だから、列を右へはずして、向うを見ると、大手町《おおてまち》を突《つ》き当って薬師町《やくしまち》へ曲がる角の所で、行き詰《づま》ったぎり、押《お》し返したり、押し返されたりして揉《も》み合っている。前方から静かに静かにと声を涸《か》らして来た体操教師に何ですと聞くと、曲り角で中学校と師範《しはん》学校が衝突《しょうとつ》したんだと云う。 中学と師範とはどこの県下でも犬と猿《さる》のように仲がわるいそうだ。なぜだかわからないが、まるで気風が合わない。何かあると喧嘩をする。大方|狭《せま》い田舎で退屈《たいくつ》だから、暇潰《ひまつぶ》しにやる仕事なんだろう。おれは喧嘩は好きな方だから、衝突と聞いて、面白半分に馳《か》け出して行った。すると前の方にいる連中は、しきりに何だ地方税の癖《くせ》に、引き込めと、怒鳴《どな》ってる。後ろからは押せ押せと大きな声を出す。おれは邪魔《じゃま》になる生徒の間をくぐり抜けて、曲がり角へもう少しで出ようとした時に、前へ! と云う高く鋭《するど》い号令が聞《きこ》えたと思ったら師範学校の方は粛粛《しゅくしゅく》として行進を始めた。先を争った衝突は、折合がついたには相違《そうい》ないが、つまり中学校が一歩を譲《ゆず》ったのである。資格から云うと師範学校の方が上だそうだ。 祝勝の式はすこぶる簡単なものであった。旅団長が祝詞を読む、知事が祝詞を読む、参列者が万歳《ばんざい》を唱える。それでおしまいだ。余興は午後にあると云う話だから、ひとまず下宿へ帰って、こないだじゅうから、気に掛《かか》っていた、清への返事をかきかけた。今度はもっと詳《くわ》しく書いてくれとの注文だから、なるべく念入《ねんいり》に認《したた》めなくっちゃならない。しかしいざとなって、半切《はんきれ》を取り上げると、書く事はたくさんあるが、何から書き出していいか、わからない。あれにしようか、あれは面倒臭《めんどうくさ》い。これにしようか、これはつまらない。何か、すらすらと出て、骨が折れなくって、そうして清が面白がるようなものはないかしらん、と考えてみると、そんな注文通りの事件は一つもなさそうだ。おれは墨《すみ》を磨《す》って、筆をしめして、巻紙を睨《にら》めて、――巻紙を睨めて、筆をしめして、墨を磨って――同じ所作を同じように何返も繰《く》り返したあと、おれには、とても手紙は書けるものではないと、諦《あきら》めて硯《すずり》の蓋《ふた》をしてしまった。手紙なんぞをかくのは面倒臭い。やっぱり東京まで出掛けて行って、逢《あ》って話をするのが簡便だ。清の心配は察しないでもないが、清の注文通りの手紙を書くのは三七日の断食《だんじき》よりも苦しい。 おれは筆と巻紙を抛《ほう》り出して、ごろりと転がって肱枕《ひじまくら》をして庭《にわ》の方を眺《なが》めてみたが、やっぱり清の事が気にかかる。その時おれはこう思った。こうして遠くへ来てまで、清の身の上を案じていてやりさえすれば、おれの真心《まこと》は清に通じるに違いない。通じさえすれば手紙なんぞやる必要はない。やらなければ無事で暮《くら》してると思ってるだろう。たよりは死んだ時か病気の時か、何か事の起った時にやりさえすればいい訳だ。 庭は十坪《とつぼ》ほどの平庭で、これという植木もない。ただ一本の蜜柑《みかん》があって、塀《へい》のそとから、目標《めじるし》になるほど高い。おれはうちへ帰ると、いつでもこの蜜柑を眺める。東京を出た事のないものには蜜柑の生《な》っているところはすこぶる珍《めずら》しいものだ。あの青い実がだんだん熟してきて、黄色になるんだろうが、定めて奇麗《きれい》だろう。今でももう半分色の変ったのがある。婆《ばあ》さんに聞いてみると、すこぶる水気の多い、旨《うま》い蜜柑だそうだ。今に熟《うれ》たら、たんと召《め》し上がれと云ったから、毎日少しずつ食ってやろう。もう三週間もしたら、充分《じゅうぶん》食えるだろう。まさか三週間以内にここを去る事もなかろう。 おれが蜜柑の事を考えているところへ、偶然山嵐《ぐうぜんやまあらし》が話しにやって来た。今日は祝勝会だから、君といっしょにご馳走《ちそう》を食おうと思って牛肉を買って来たと、竹の皮の包《つつみ》を袂《たもと》から引きずり出して、座敷《ざしき》の真中《まんなか》へ抛り出した。おれは下宿で芋責《いもぜめ》豆腐責になってる上、蕎麦《そば》屋行き、団子《だんご》屋行きを禁じられてる際だから、そいつは結構だと、すぐ婆さんから鍋《なべ》と砂糖をかり込んで、煮方《にかた》に取りかかった。 山嵐は無暗《むやみ》に牛肉を頬張《ほおば》りながら、君あの赤シャツが芸者に馴染《なじみ》のある事を知ってるかと聞くから、知ってるとも、この間うらなりの送別会の時に来た一人がそうだろうと云ったら、そうだ僕《ぼく》はこの頃《ごろ》ようやく勘づいたのに、君はなかなか敏捷《びんしょう》だと大いにほめた。「あいつは、ふた言目には品性だの、精神的|娯楽《ごらく》だのと云う癖《くせ》に、裏へ廻《まわ》って、芸者と関係なんかつけとる、怪《け》しからん奴《やつ》だ。それもほかの人が遊ぶのを寛容《かんよう》するならいいが、君が蕎麦屋へ行ったり、団子屋へはいるのさえ取締上《とりしまりじょう》害になると云って、校長の口を通して注意を加えたじゃないか」「うん、あの野郎の考えじゃ芸者買は精神的娯楽で、天麩羅や、団子は物理的娯楽なんだろう。精神的娯楽なら、もっと大べらにやるがいい。何だあの様《ざま》は。馴染の芸者がはいってくると、入れ代りに席をはずして、逃げるなんて、どこまでも人を胡魔化《ごまか》す気だから気に食わない。そうして人が攻撃《こうげき》すると、僕は知らないとか、露西亜《ロシア》文学だとか、俳句が新体詩の兄弟分だとか云って、人を烟《けむ》に捲《ま》くつもりなんだ。あんな弱虫は男じゃないよ。全く御殿女中《ごてんじょちゅう》の生れ変りか何かだぜ。ことによると、あいつのおやじは湯島のかげま[#「かげま」に傍点]かもしれない」「湯島のかげま[#「かげま」に傍点]た何だ」「何でも男らしくないもんだろう。――君そこのところはまだ煮えていないぜ。そんなのを食うと絛虫《さなだむし》が湧《わ》くぜ」「そうか、大抵大丈夫《たいていだいじょうぶ》だろう。それで赤シャツは人に隠《かく》れて、温泉《ゆ》の町の角屋《かどや》へ行って、芸者と会見するそうだ」「角屋って、あの宿屋か」「宿屋兼料理屋さ。だからあいつを一番へこますためには、あいつが芸者をつれて、あすこへはいり込むところを見届けておいて面詰《めんきつ》するんだね」「見届けるって、夜番《よばん》でもするのかい」「うん、角屋の前に枡屋《ますや》という宿屋があるだろう。あの表二階をかりて、障子《しょうじ》へ穴をあけて、見ているのさ」「見ているときに来るかい」「来るだろう。どうせひと晩じゃいけない。二週間ばかりやるつもりでなくっちゃ」「随分《ずいぶん》疲れるぜ。僕あ、おやじの死ぬとき一週間ばかり徹夜《てつや》して看病した事があるが、あとでぼんやりして、大いに弱った事がある」「少しぐらい身体が疲れたって構わんさ。あんな奸物《かんぶつ》をあのままにしておくと、日本のためにならないから、僕が天に代って誅戮《ちゅうりく》を加えるんだ」「愉快《ゆかい》だ。そう事が極まれば、おれも加勢してやる。それで今夜から夜番をやるのかい」「まだ枡屋に懸合《かけあ》ってないから、今夜は駄目だ」「それじゃ、いつから始めるつもりだい」「近々のうちやるさ。いずれ君に報知をするから、そうしたら、加勢してくれたまえ」「よろしい、いつでも加勢する。僕《ぼく》は計略《はかりごと》は下手《へた》だが、喧嘩とくるとこれでなかなかすばしこいぜ」 おれと山嵐がしきりに赤シャツ退治の計略《はかりごと》を相談していると、宿の婆さんが出て来て、学校の生徒さんが一人、堀田《ほった》先生にお目にかかりたいててお出《い》でたぞなもし。今お宅へ参じたのじゃが、お留守《るす》じゃけれ、大方ここじゃろうてて捜《さが》し当ててお出でたのじゃがなもしと、閾《しきい》の所へ膝《ひざ》を突《つ》いて山嵐の返事を待ってる。山嵐はそうですかと玄関《げんかん》まで出て行ったが、やがて帰って来て、君、生徒が祝勝会の余興を見に行かないかって誘《さそ》いに来たんだ。今日は高知《こうち》から、何とか踴《おど》りをしに、わざわざここまで多人数《たにんず》乗り込んで来ているのだから、是非見物しろ、めったに見られない踴《おどり》だというんだ、君もいっしょに行ってみたまえと山嵐は大いに乗り気で、おれに同行を勧める。おれは踴なら東京でたくさん見ている。毎年|八幡様《はちまんさま》のお祭りには屋台が町内へ廻ってくるんだから汐酌《しおく》みでも何でもちゃんと心得ている。土佐っぽの馬鹿踴なんか、見たくもないと思ったけれども、せっかく山嵐が勧めるもんだから、つい行く気になって門へ出た。山嵐を誘いに来たものは誰かと思ったら赤シャツの弟だ。妙《みょう》な奴《やつ》が来たもんだ。 会場へはいると、回向院《えこういん》の相撲《すもう》か本門寺《ほんもんじ》の御会式《おえしき》のように幾旒《いくながれ》となく長い旗を所々に植え付けた上に、世界万国の国旗をことごとく借りて来たくらい、縄《なわ》から縄、綱《つな》から綱へ渡《わた》しかけて、大きな空が、いつになく賑《にぎ》やかに見える。東の隅《すみ》に一夜作りの舞台《ぶたい》を設けて、ここでいわゆる高知の何とか踴りをやるんだそうだ。舞台を右へ半町ばかりくると葭簀《よしず》の囲いをして、活花《いけばな》が陳列《ちんれつ》してある。みんなが感心して眺めているが、一向くだらないものだ。あんなに草や竹を曲げて嬉《うれ》しがるなら、背虫の色男や、跛《びっこ》の亭主《ていしゅ》を持って自慢《じまん》するがよかろう。 舞台とは反対の方面で、しきりに花火を揚げる。花火の中から風船が出た。帝国万歳《ていこくばんざい》とかいてある。天主の松の上をふわふわ飛んで営所のなかへ落ちた。次はぽんと音がして、黒い団子が、しょっと秋の空を射抜《いぬ》くように揚《あ》がると、それがおれの頭の上で、ぽかりと割れて、青い烟《けむり》が傘《かさ》の骨のように開いて、だらだらと空中に流れ込んだ。風船がまた上がった。今度は陸海軍万歳と赤地に白く染め抜いた奴が風に揺られて、温泉《ゆ》の町から、相生村《あいおいむら》の方へ飛んでいった。大方観音様の境内《けいだい》へでも落ちたろう。 式の時はさほどでもなかったが、今度は大変な人出だ。田舎にもこんなに人間が住んでるかと驚《おど》ろいたぐらいうじゃうじゃしている。利口《りこう》な顔はあまり見当らないが、数から云うとたしかに馬鹿に出来ない。そのうち評判の高知の何とか踴が始まった。踴というから藤間か何ぞのやる踴りかと早合点していたが、これは大間違いであった。 いかめしい後鉢巻《うしろはちまき》をして、立《た》っ付《つ》け袴《ばかま》を穿《は》いた男が十人ばかりずつ、舞台の上に三列に並《なら》んで、その三十人がことごとく抜き身を携《さ》げているには魂消《たまげ》た。前列と後列の間はわずか一尺五寸ぐらいだろう、左右の間隔《かんかく》はそれより短いとも長くはない。たった一人列を離《はな》れて舞台の端《はし》に立ってるのがあるばかりだ。この仲間|外《はず》れの男は袴だけはつけているが、後鉢巻は倹約して、抜身の代りに、胸へ太鼓《たいこ》を懸《か》けている。太鼓は太神楽《だいかぐら》の太鼓と同じ物だ。この男がやがて、いやあ、はああと呑気《のんき》な声を出して、妙な謡《うた》をうたいながら、太鼓をぼこぼん、ぼこぼんと叩《たた》く。歌の調子は前代未聞の不思議なものだ。三河万歳《みかわまんざい》と普陀洛《ふだらく》やの合併《がっぺい》したものと思えば大した間違いにはならない。 歌はすこぶる悠長《ゆうちょう》なもので、夏分の水飴《みずあめ》のように、だらしがないが、句切りをとるためにぼこぼんを入れるから、のべつのようでも拍子《ひょうし》は取れる。この拍子に応じて三十人の抜き身がぴかぴかと光るのだが、これはまたすこぶる迅速《じんそく》なお手際で、拝見していても冷々《ひやひや》する。隣《とな》りも後ろも一尺五寸以内に生きた人間が居て、その人間がまた切れる抜き身を自分と同じように振《ふ》り舞《ま》わすのだから、よほど調子が揃《そろ》わなければ、同志撃《どうしうち》を始めて怪我《けが》をする事になる。それも動かないで刀だけ前後とか上下とかに振るのなら、まだ危険《あぶなく》もないが、三十人が一度に足踏《あしぶ》みをして横を向く時がある。ぐるりと廻る事がある。膝を曲げる事がある。隣りのものが一秒でも早過ぎるか、遅《おそ》過ぎれば、自分の鼻は落ちるかも知れない。隣りの頭はそがれるかも知れない。抜き身の動くのは自由自在だが、その動く範囲《はんい》は一尺五寸角の柱のうちにかぎられた上に、前後左右のものと同方向に同速度にひらめかなければならない。こいつは驚いた、なかなかもって汐酌《しおくみ》や関《せき》の戸《と》の及《およ》ぶところでない。聞いてみると、これははなはだ熟練の入るもので容易な事では、こういう風に調子が合わないそうだ。ことにむずかしいのは、かの万歳節のぼこぼん先生だそうだ。三十人の足の運びも、手の働きも、腰《こし》の曲げ方も、ことごとくこのぼこぼん君の拍子一つで極まるのだそうだ。傍《はた》で見ていると、この大将が一番呑気そうに、いやあ、はああと気楽にうたってるが、その実ははなはだ責任が重くって非常に骨が折れるとは不思議なものだ。 おれと山嵐が感心のあまりこの踴を余念なく見物していると、半町ばかり、向うの方で急にわっと云う鬨の声がして、今まで穏《おだ》やかに諸所を縦覧していた連中が、にわかに波を打って、右左りに揺《うご》き始める。喧嘩だ喧嘩だと云う声がすると思うと、人の袖《そで》を潜《くぐ》り抜《ぬ》けて来た赤シャツの弟が、先生また喧嘩です、中学の方で、今朝《けさ》の意趣返《いしゅがえ》しをするんで、また師範《しはん》の奴と決戦を始めたところです、早く来て下さいと云いながらまた人の波のなかへ潜《もぐ》り込《こ》んでどっかへ行ってしまった。 山嵐は世話の焼ける小僧だまた始めたのか、いい加減にすればいいのにと逃げる人を避《よ》けながら一散に馳《か》け出した。見ている訳にも行かないから取り鎮《しず》めるつもりだろう。おれは無論の事逃げる気はない。山嵐の踵《かかと》を踏んであとからすぐ現場へ馳けつけた。喧嘩は今が真最中《まっさいちゅう》である。師範の方は五六十人もあろうか、中学はたしかに三割方多い。師範は制服をつけているが、中学は式後|大抵《たいてい》は日本服に着換《きが》えているから、敵味方はすぐわかる。しかし入り乱れて組んづ、解《ほご》れつ戦ってるから、どこから、どう手を付けて引き分けていいか分らない。山嵐は困ったなと云う風で、しばらくこの乱雑な有様を眺めていたが、こうなっちゃ仕方がない。巡査《じゅんさ》がくると面倒だ。飛び込んで分けようと、おれの方を見て云うから、おれは返事もしないで、いきなり、一番喧嘩の烈《はげ》しそうな所へ躍《おど》り込《こ》んだ。止《よ》せ止せ。そんな乱暴をすると学校の体面に関わる。よさないかと、出るだけの声を出して敵と味方の分界線らしい所を突《つ》き貫《ぬ》けようとしたが、なかなかそう旨《うま》くは行かない。一二間はいったら、出る事も引く事も出来なくなった。目の前に比較的《ひかくてき》大きな師範生が、十五六の中学生と組み合っている。止せと云ったら、止さないかと師範生の肩《かた》を持って、無理に引き分けようとする途端《とたん》にだれか知らないが、下からおれの足をすくった。おれは不意を打たれて握《にぎ》った、肩を放して、横に倒《たお》れた。堅《かた》い靴《くつ》でおれの背中の上へ乗った奴がある。両手と膝を突いて下から、跳《は》ね起きたら、乗った奴は右の方へころがり落ちた。起き上がって見ると、三間ばかり向うに山嵐の大きな身体が生徒の間に挟《はさ》まりながら、止せ止せ、喧嘩は止せ止せと揉み返されてるのが見えた。おい到底駄目だと云ってみたが聞えないのか返事もしない。 ひゅうと風を切って飛んで来た石が、いきなりおれの頬骨《ほおぼね》へ中《あた》ったなと思ったら、後ろからも、背中を棒《ぼう》でどやした奴がある。教師の癖《くせ》に出ている、打《ぶ》て打てと云う声がする。教師は二人だ。大きい奴と、小さい奴だ。石を抛《な》げろ。と云う声もする。おれは、なに生意気な事をぬかすな、田舎者の癖にと、いきなり、傍《そば》に居た師範生の頭を張りつけてやった。石がまたひゅうと来る。今度はおれの五|分刈《ぶがり》の頭を掠《かす》めて後ろの方へ飛んで行った。山嵐はどうなったか見えない。こうなっちゃ仕方がない。始めは喧嘩をとめにはいったんだが、どやされたり、石をなげられたりして、恐《おそ》れ入って引き下がるうんでれがんがあるものか。おれを誰だと思うんだ。身長《なり》は小さくっても喧嘩の本場で修行を積んだ兄さんだと無茶苦茶に張り飛ばしたり、張り飛ばされたりしていると、やがて巡査だ巡査だ逃げろ逃げろと云う声がした。今まで葛練《くずね》りの中で泳いでるように身動きも出来なかったのが、急に楽になったと思ったら、敵も味方も一度に引上げてしまった。田舎者でも退却《たいきゃく》は巧妙だ。クロパトキンより旨いくらいである。 山嵐はどうしたかと見ると、紋付《もんつき》の一重羽織《ひとえばおり》をずたずたにして、向うの方で鼻を拭《ふ》いている。鼻柱をなぐられて大分出血したんだそうだ。鼻がふくれ上がって真赤《まっか》になってすこぶる見苦しい。おれは飛白《かすり》の袷《あわせ》を着ていたから泥《どろ》だらけになったけれども、山嵐の羽織ほどな損害はない。しかし頬《ほっ》ぺたがぴりぴりしてたまらない。山嵐は大分血が出ているぜと教えてくれた。 巡査は十五六名来たのだが、生徒は反対の方面から退却したので、捕《つら》まったのは、おれと山嵐だけである。おれらは姓名《せいめい》を告げて、一部始終を話したら、ともかくも警察まで来いと云うから、警察へ行って、署長の前で事の顛末《てんまつ》を述べて下宿へ帰った。     十一 あくる日|眼《め》が覚めてみると、身体中《からだじゅう》痛くてたまらない。久しく喧嘩《けんか》をしつけなかったから、こんなに答えるんだろう。これじゃあんまり自慢《じまん》もできないと床《とこ》の中で考えていると、婆《ばあ》さんが四国新聞を持ってきて枕元《まくらもと》へ置いてくれた。実は新聞を見るのも退儀《たいぎ》なんだが、男がこれしきの事に閉口《へこ》たれて仕様があるものかと無理に腹這《はらば》いになって、寝《ね》ながら、二頁を開けてみると驚《おど》ろいた。昨日の喧嘩がちゃんと出ている。喧嘩の出ているのは驚ろかないのだが、中学の教師|堀田某《ほったぼう》と、近頃《ちかごろ》東京から赴任《ふにん》した生意気なる某とが、順良なる生徒を使嗾《しそう》してこの騒動《そうどう》を喚起《かんき》せるのみならず、両人は現場にあって生徒を指揮したる上、みだりに師範生に向《むか》って暴行をほしいままにしたりと書いて、次にこんな意見が附記《ふき》してある。本県の中学は昔時《せきじ》より善良温順の気風をもって全国の羨望《せんぼう》するところなりしが、軽薄《けいはく》なる二|豎子《じゅし》のために吾校《わがこう》の特権を毀損《きそん》せられて、この不面目を全市に受けたる以上は、吾人《ごじん》は奮然《ふんぜん》として起《た》ってその責任を問わざるを得ず。吾人は信ず、吾人が手を下す前に、当局者は相当の処分をこの無頼漢《ぶらいかん》の上に加えて、彼等《かれら》をして再び教育界に足を入るる余地なからしむる事を。そうして一字ごとにみんな黒点を加えて、お灸《きゅう》を据《す》えたつもりでいる。おれは床の中で、糞《くそ》でも喰《く》らえと云《い》いながら、むっくり飛び起きた。不思議な事に今まで身体の関節《ふしぶし》が非常に痛かったのが、飛び起きると同時に忘れたように軽くなった。 おれは新聞を丸めて庭へ抛《な》げつけたが、それでもまだ気に入らなかったから、わざわざ後架《こうか》へ持って行って棄《す》てて来た。新聞なんて無暗《むやみ》な嘘《うそ》を吐《つ》くもんだ。世の中に何が一番|法螺《ほら》を吹《ふ》くと云って、新聞ほどの法螺吹きはあるまい。おれの云ってしかるべき事をみんな向《むこ》うで並《なら》べていやがる。それに近頃東京から赴任した生意気な某とは何だ。天下に某と云う名前の人があるか。考えてみろ。これでもれっきとした姓《せい》もあり名もあるんだ。系図が見たけりゃ、多田満仲《ただのまんじゅう》以来の先祖を一人《ひとり》残らず拝ましてやらあ。――顔を洗ったら、頬《ほっ》ぺたが急に痛くなった。婆さんに鏡をかせと云ったら、けさの新聞をお見たかなもしと聞く。読んで後架へ棄てて来た。欲しけりゃ拾って来いと云ったら、驚《おどろ》いて引き下がった。鏡で顔を見ると昨日《きのう》と同じように傷がついている。これでも大事な顔だ、顔へ傷まで付けられた上へ生意気なる某などと、某呼ばわりをされればたくさんだ。 今日の新聞に辟易《へきえき》して学校を休んだなどと云われちゃ一生の名折れだから、飯を食っていの一号に出頭した。出てくる奴《やつ》も、出てくる奴もおれの顔を見て笑っている。何がおかしいんだ。貴様達にこしらえてもらった顔じゃあるまいし。そのうち、野だが出て来て、いや昨日はお手柄《てがら》で、――名誉《めいよ》のご負傷でげすか、と送別会の時に撲《なぐ》った返報と心得たのか、いやに冷《ひや》かしたから、余計な事を言わずに絵筆でも舐《な》めていろと云ってやった。するとこりゃ恐入《おそれい》りやした。しかしさぞお痛い事でげしょうと云うから、痛かろうが、痛くなかろうがおれの面だ。貴様の世話になるもんかと怒鳴《どな》りつけてやったら、向《むこ》う側の自席へ着いて、やっぱりおれの顔を見て、隣《とな》りの歴史の教師と何か内所話をして笑っている。 それから山嵐が出頭した。山嵐の鼻に至っては、紫色《むらさきいろ》に膨張《ぼうちょう》して、掘《ほ》ったら中から膿《うみ》が出そうに見える。自惚《うぬぼれ》のせいか、おれの顔よりよっぽど手ひどく遣《や》られている。おれと山嵐は机を並べて、隣り同志の近しい仲で、お負けにその机が部屋の戸口から真正面にあるんだから運がわるい。妙な顔が二つ塊《かた》まっている。ほかの奴は退屈《たいくつ》にさえなるときっとこっちばかり見る。飛んだ事でと口で云うが、心のうちではこの馬鹿《ばか》がと思ってるに相違《そうい》ない。それでなければああいう風に私語合《ささやきあ》ってはくすくす笑う訳がない。教場へ出ると生徒は拍手をもって迎《むか》えた。先生|万歳《ばんざい》と云うものが二三人あった。景気がいいんだか、馬鹿にされてるんだか分からない。おれと山嵐がこんなに注意の焼点《しょうてん》となってるなかに、赤シャツばかりは平常の通り傍《そば》へ来て、どうも飛んだ災難でした。僕は君等に対してお気の毒でなりません。新聞の記事は校長とも相談して、正誤を申し込《こ》む手続きにしておいたから、心配しなくてもいい。僕の弟が堀田君を誘《さそ》いに行ったから、こんな事が起《おこ》ったので、僕は実に申し訳がない。それでこの件についてはあくまで尽力《じんりょく》するつもりだから、どうかあしからず、などと半分謝罪的な言葉を並べている。校長は三時間目に校長室から出てきて、困った事を新聞がかき出しましたね。むずかしくならなければいいがと多少心配そうに見えた。おれには心配なんかない、先で免職《めんしょく》をするなら、免職される前に辞表を出してしまうだけだ。しかし自分がわるくないのにこっちから身を引くのは法螺吹きの新聞屋をますます増長させる訳だから、新聞屋を正誤させて、おれが意地にも務めるのが順当だと考えた。帰りがけに新聞屋に談判に行こうと思ったが、学校から取消《とりけし》の手続きはしたと云うから、やめた。 おれと山嵐は校長と教頭に時間の合間を見計《みはから》って、嘘のないところを一応説明した。校長と教頭はそうだろう、新聞屋が学校に恨《うら》みを抱《いだ》いて、あんな記事をことさらに掲《かか》げたんだろうと論断した。赤シャツはおれ等の行為《こうい》を弁解しながら控所《ひかえじょ》を一人ごとに廻《まわ》ってあるいていた。ことに自分の弟が山嵐を誘い出したのを自分の過失であるかのごとく吹聴《ふいちょう》していた。みんなは全く新聞屋がわるい、怪《け》しからん、両君は実に災難だと云った。 帰りがけに山嵐は、君赤シャツは臭《くさ》いぜ、用心しないとやられるぜと注意した。どうせ臭いんだ、今日から臭くなったんじゃなかろうと云うと、君まだ気が付かないか、きのうわざわざ、僕等を誘い出して喧嘩のなかへ、捲《ま》き込《こ》んだのは策だぜと教えてくれた。なるほどそこまでは気がつかなかった。山嵐は粗暴《そぼう》なようだが、おれより智慧《ちえ》のある男だと感心した。「ああやって喧嘩をさせておいて、すぐあとから新聞屋へ手を廻してあんな記事をかかせたんだ。実に奸物《かんぶつ》だ」「新聞までも赤シャツか。そいつは驚いた。しかし新聞が赤シャツの云う事をそう容易《たやす》く聴《き》くかね」「聴かなくって。新聞屋に友達が居りゃ訳はないさ」「友達が居るのかい」「居なくても訳ないさ。嘘をついて、事実これこれだと話しゃ、すぐ書くさ」「ひどいもんだな。本当に赤シャツの策なら、僕等はこの事件で免職になるかも知れないね」「わるくすると、遣《や》られるかも知れない」「そんなら、おれは明日《あした》辞表を出してすぐ東京へ帰っちまわあ。こんな下等な所に頼《たの》んだって居るのはいやだ」「君が辞表を出したって、赤シャツは困らない」「それもそうだな。どうしたら困るだろう」「あんな奸物の遣る事は、何でも証拠《しょうこ》の挙がらないように、挙がらないようにと工夫するんだから、反駁《はんばく》するのはむずかしいね」「厄介《やっかい》だな。それじゃ濡衣《ぬれぎぬ》を着るんだね。面白《おもしろ》くもない。天道是耶非《てんどうぜかひ》かだ」「まあ、もう二三日様子を見ようじゃないか。それでいよいよとなったら、温泉《ゆ》の町で取って抑《おさ》えるより仕方がないだろう」「喧嘩事件は、喧嘩事件としてか」「そうさ。こっちはこっちで向うの急所を抑えるのさ」「それもよかろう。おれは策略は下手《へた》なんだから、万事よろしく頼む。いざとなれば何でもする」 俺と山嵐はこれで分《わか》れた。赤シャツが果《はた》たして山嵐の推察通りをやったのなら、実にひどい奴だ。到底《とうてい》智慧比べで勝てる奴ではない。どうしても腕力《わんりょく》でなくっちゃ駄目《だめ》だ。なるほど世界に戦争は絶えない訳だ。個人でも、とどの詰《つま》りは腕力だ。 あくる日、新聞のくるのを待ちかねて、披《ひら》いてみると、正誤どころか取り消しも見えない。学校へ行って狸《たぬき》に催促《さいそく》すると、あしたぐらい出すでしょうと云う。明日になって六号活字で小さく取消が出た。しかし新聞屋の方で正誤は無論しておらない。また校長に談判すると、あれより手続きのしようはないのだと云う答だ。校長なんて狸のような顔をして、いやにフロック張っているが存外無勢力なものだ。虚偽《きょぎ》の記事を掲げた田舎新聞一つ詫《あや》まらせる事が出来ない。あんまり腹が立ったから、それじゃ私が一人で行って主筆に談判すると云ったら、それはいかん、君が談判すればまた悪口を書かれるばかりだ。つまり新聞屋にかかれた事は、うそにせよ、本当にせよ、つまりどうする事も出来ないものだ。あきらめるより外に仕方がないと、坊主の説教じみた説諭《せつゆ》を加えた。新聞がそんな者なら、一日も早く打《ぶ》っ潰《つぶ》してしまった方が、われわれの利益だろう。新聞にかかれるのと、泥鼈《すっぽん》に食いつかれるとが似たり寄ったりだとは今日《こんにち》ただ今狸の説明によって始めて承知|仕《つかまつ》った。 それから三日ばかりして、ある日の午後、山嵐が憤然《ふんぜん》とやって来て、いよいよ時機が来た、おれは例の計画を断行するつもりだと云うから、そうかそれじゃおれもやろうと、即座《そくざ》に一味徒党に加盟した。ところが山嵐が、君はよす方がよかろうと首を傾《かたむ》けた。なぜと聞くと君は校長に呼ばれて辞表を出せと云われたかと尋《たず》ねるから、いや云われない。君は? と聴き返すと、今日校長室で、まことに気の毒だけれども、事情やむをえんから処決《しょけつ》してくれと云われたとの事だ。「そんな裁判はないぜ。狸は大方|腹鼓《はらつづみ》を叩《たた》き過ぎて、胃の位置が顛倒《てんどう》したんだ。君とおれは、いっしょに、祝勝会へ出てさ、いっしょに高知のぴかぴか踴《おど》りを見てさ、いっしょに喧嘩をとめにはいったんじゃないか。辞表を出せというなら公平に両方へ出せと云うがいい。なんで田舎《いなか》の学校はそう理窟《りくつ》が分らないんだろう。焦慮《じれった》いな」「それが赤シャツの指金《さしがね》だよ。おれと赤シャツとは今までの行懸《ゆきがか》り上|到底《とうてい》両立しない人間だが、君の方は今の通り置いても害にならないと思ってるんだ」「おれだって赤シャツと両立するものか。害にならないと思うなんて生意気だ」「君はあまり単純過ぎるから、置いたって、どうでも胡魔化《ごまか》されると考えてるのさ」「なお悪いや。誰《だれ》が両立してやるものか」「それに先だって古賀が去ってから、まだ後任が事故のために到着《とうちゃく》しないだろう。その上に君と僕を同時に追い出しちゃ、生徒の時間に明きが出来て、授業にさし支《つか》えるからな」「それじゃおれを間《あい》のくさびに一席|伺《うかが》わせる気なんだな。こん畜生《ちくしょう》、だれがその手に乗るものか」 翌日《あくるひ》おれは学校へ出て校長室へ入って談判を始めた。「何で私に辞表を出せと云わないんですか」「へえ?」と狸はあっけに取られている。「堀田には出せ、私には出さないで好《い》いと云う法がありますか」「それは学校の方の都合《つごう》で……」「その都合が間違《まちが》ってまさあ。私が出さなくって済むなら堀田だって、出す必要はないでしょう」「その辺は説明が出来かねますが――堀田君は去られてもやむをえんのですが、あなたは辞表をお出しになる必要を認めませんから」 なるほど狸だ、要領を得ない事ばかり並べて、しかも落ち付き払《はら》ってる。おれは仕様がないから「それじゃ私も辞表を出しましょう。堀田君一人辞職させて、私が安閑《あんかん》として、留まっていられると思っていらっしゃるかも知れないが、私にはそんな不人情な事は出来ません」「それは困る。堀田も去りあなたも去ったら、学校の数学の授業がまるで出来なくなってしまうから……」「出来なくなっても私の知った事じゃありません」「君そう我儘《わがまま》を云うものじゃない、少しは学校の事情も察してくれなくっちゃ困る。それに、来てから一月立つか立たないのに辞職したと云うと、君の将来の履歴《りれき》に関係するから、その辺も少しは考えたらいいでしょう」「履歴なんか構うもんですか、履歴より義理が大切です」「そりゃごもっとも――君の云うところは一々ごもっともだが、わたしの云う方も少しは察して下さい。君が是非辞職すると云うなら辞職されてもいいから、代りのあるまでどうかやってもらいたい。とにかく、うちでもう一返考え直してみて下さい」 考え直すって、直しようのない明々白々たる理由だが、狸が蒼《あお》くなったり、赤くなったりして、可愛想《かわいそう》になったからひとまず考え直す事として引き下がった。赤シャツには口もきかなかった。どうせ遣っつけるなら塊《かた》めて、うんと遣っつける方がいい。 山嵐に狸と談判した模様を話したら、大方そんな事だろうと思った。辞表の事はいざとなるまでそのままにしておいても差支《さしつか》えあるまいとの話だったから、山嵐の云う通りにした。どうも山嵐の方がおれよりも利巧《りこう》らしいから万事山嵐の忠告に従う事にした。 山嵐はいよいよ辞表を出して、職員一同に告別の挨拶《あいさつ》をして浜《はま》の港屋まで下《さが》ったが、人に知れないように引き返して、温泉《ゆ》の町の枡屋《ますや》の表二階へ潜《ひそ》んで、障子《しょうじ》へ穴をあけて覗《のぞ》き出した。これを知ってるものはおればかりだろう。赤シャツが忍《しの》んで来ればどうせ夜だ。しかも宵《よい》の口は生徒やその他の目があるから、少なくとも九時過ぎに極《きま》ってる。最初の二晩はおれも十一時|頃《ごろ》まで張番《はりばん》をしたが、赤シャツの影《かげ》も見えない。三日目には九時から十時半まで覗いたがやはり駄目だ。駄目を踏《ふ》んで夜なかに下宿へ帰るほど馬鹿気た事はない。四五日《しごんち》すると、うちの婆さんが少々心配を始めて、奥《おく》さんのおありるのに、夜遊びはおやめたがええぞなもしと忠告した。そんな夜遊びとは夜遊びが違う。こっちのは天に代って誅戮《ちゅうりく》を加える夜遊びだ。とはいうものの一週間も通って、少しも験《げん》が見えないと、いやになるもんだ。おれは性急《せっかち》な性分だから、熱心になると徹夜《てつや》でもして仕事をするが、その代り何によらず長持ちのした試しがない。いかに天誅党でも飽《あ》きる事に変りはない。六日目には少々いやになって、七日目にはもう休もうかと思った。そこへ行くと山嵐は頑固《がんこ》なものだ。宵《よい》から十二時|過《すぎ》までは眼を障子へつけて、角屋の丸ぼやの瓦斯燈《がすとう》の下を睨《にら》めっきりである。おれが行くと今日は何人客があって、泊《とま》りが何人、女が何人といろいろな統計を示すのには驚ろいた。どうも来ないようじゃないかと云うと、うん、たしかに来るはずだがと時々|腕組《うでぐみ》をして溜息《ためいき》をつく。可愛想に、もし赤シャツがここへ一度来てくれなければ、山嵐は、生涯《しょうがい》天誅を加える事は出来ないのである。 八日目には七時頃から下宿を出て、まずゆるりと湯に入って、それから町で鶏卵《けいらん》を八つ買った。これは下宿の婆さんの芋責《いもぜめ》に応ずる策である。その玉子を四つずつ左右の袂《たもと》へ入れて、例の赤手拭《あかてぬぐい》を肩《かた》へ乗せて、懐手《ふところで》をしながら、枡屋《ますや》の楷子段《はしごだん》を登って山嵐の座敷《ざしき》の障子をあけると、おい有望有望と韋駄天《いだてん》のような顔は急に活気を呈《てい》した。昨夜《ゆうべ》までは少し塞《ふさ》ぎの気味で、はたで見ているおれさえ、陰気臭《いんきくさ》いと思ったくらいだが、この顔色を見たら、おれも急にうれしくなって、何も聞かない先から、愉快《ゆかい》愉快と云った。「今夜七時半頃あの小鈴《こすず》と云う芸者が角屋へはいった」「赤シャツといっしょか」「いいや」「それじゃ駄目だ」「芸者は二人づれだが、――どうも有望らしい」「どうして」「どうしてって、ああ云う狡《ずる》い奴だから、芸者を先へよこして、後から忍んでくるかも知れない」「そうかも知れない。もう九時だろう」「今九時十二分ばかりだ」と帯の間からニッケル製の時計を出して見ながら云ったが「おい洋燈《らんぷ》を消せ、障子へ二つ坊主頭が写ってはおかしい。狐《きつね》はすぐ疑ぐるから」 おれは一貫張《いっかんばり》の机の上にあった置き洋燈《らんぷ》をふっと吹きけした。星明りで障子だけは少々あかるい。月はまだ出ていない。おれと山嵐は一生懸命《いっしょうけんめい》に障子へ面《かお》をつけて、息を凝《こ》らしている。チーンと九時半の柱時計が鳴った。「おい来るだろうかな。今夜来なければ僕はもう厭《いや》だぜ」「おれは銭のつづく限りやるんだ」「銭っていくらあるんだい」「今日までで八日分五円六十銭払った。いつ飛び出しても都合《つごう》のいいように毎晩|勘定《かんじょう》するんだ」「それは手廻しがいい。宿屋で驚いてるだろう」「宿屋はいいが、気が放せないから困る」「その代り昼寝《ひるね》をするだろう」「昼寝はするが、外出が出来ないんで窮屈《きゅうくつ》でたまらない」「天誅も骨が折れるな。これで天網恢々疎《てんもうかいかいそ》にして洩《も》らしちまったり、何かしちゃ、つまらないぜ」「なに今夜はきっとくるよ。――おい見ろ見ろ」と小声になったから、おれは思わずどきりとした。黒い帽子《ぼうし》を戴《いただ》いた男が、角屋の瓦斯燈を下から見上げたまま暗い方へ通り過ぎた。違っている。おやおやと思った。そのうち帳場の時計が遠慮《えんりょ》なく十時を打った。今夜もとうとう駄目らしい。 世間は大分静かになった。遊廓《ゆうかく》で鳴らす太鼓《たいこ》が手に取るように聞《きこ》える。月が温泉《ゆ》の山の後《うしろ》からのっと顔を出した。往来はあかるい。すると、下《しも》の方から人声が聞えだした。窓から首を出す訳には行かないから、姿を突《つ》き留める事は出来ないが、だんだん近づいて来る模様だ。からんからんと駒下駄《こまげた》を引き擦《ず》る音がする。眼を斜《なな》めにするとやっと二人の影法師《かげぼうし》が見えるくらいに近づいた。「もう大丈夫《だいじょうぶ》ですね。邪魔《じゃま》ものは追っ払ったから」正《まさ》しく野だの声である。「強がるばかりで策がないから、仕様がない」これは赤シャツだ。「あの男もべらんめえに似ていますね。あのべらんめえと来たら、勇み肌《はだ》の坊《ぼ》っちゃんだから愛嬌《あいきょう》がありますよ」「増給がいやだの辞表を出したいのって、ありゃどうしても神経に異状があるに相違ない」おれは窓をあけて、二階から飛び下りて、思う様|打《ぶ》ちのめしてやろうと思ったが、やっとの事で辛防《しんぼう》した。二人はハハハハと笑いながら、瓦斯燈の下を潜《くぐ》って、角屋の中へはいった。「おい」「おい」「来たぜ」「とうとう来た」「これでようやく安心した」「野だの畜生、おれの事を勇み肌の坊っちゃんだと抜《ぬ》かしやがった」「邪魔物と云うのは、おれの事だぜ。失敬千万な」 おれと山嵐は二人の帰路を要撃《ようげき》しなければならない。しかし二人はいつ出てくるか見当がつかない。山嵐は下へ行って今夜ことによると夜中に用事があって出るかも知れないから、出られるようにしておいてくれと頼《たの》んで来た。今思うと、よく宿のものが承知したものだ。大抵《たいてい》なら泥棒《どろぼう》と間違えられるところだ。 赤シャツの来るのを待ち受けたのはつらかったが、出て来るのをじっとして待ってるのはなおつらい。寝る訳には行かないし、始終障子の隙《すき》から睨めているのもつらいし、どうも、こうも心が落ちつかなくって、これほど難儀《なんぎ》な思いをした事はいまだにない。いっその事角屋へ踏み込んで現場を取って抑《おさ》えようと発議《ほつぎ》したが、山嵐は一言にして、おれの申し出を斥《しりぞ》けた。自分共が今時分飛び込んだって、乱暴者だと云って途中《とちゅう》で遮《さえぎ》られる。訳を話して面会を求めれば居ないと逃《に》げるか別室へ案内をする。不用意のところへ踏み込めると仮定したところで何十とある座敷のどこに居るか分るものではない、退屈でも出るのを待つより外に策はないと云うから、ようやくの事でとうとう朝の五時まで我慢《がまん》した。 角屋から出る二人の影を見るや否や、おれと山嵐はすぐあとを尾《つ》けた。一番汽車はまだないから、二人とも城下まであるかなければならない。温泉《ゆ》の町をはずれると一丁ばかりの杉並木《すぎなみき》があって左右は田圃《たんぼ》になる。それを通りこすとここかしこに藁葺《わらぶき》があって、畠《はたけ》の中を一筋に城下まで通る土手へ出る。町さえはずれれば、どこで追いついても構わないが、なるべくなら、人家のない、杉並木で捕《つら》まえてやろうと、見えがくれについて来た。町を外《はず》れると急に馳《か》け足《あし》の姿勢で、はやてのように後ろから、追いついた。何が来たかと驚ろいて振《ふ》り向く奴を待てと云って肩に手をかけた。野だは狼狽《ろうばい》の気味で逃げ出そうという景色《けしき》だったから、おれが前へ廻って行手を塞《ふさ》いでしまった。「教頭の職を持ってるものが何で角屋へ行って泊《とま》った」と山嵐はすぐ詰《なじ》りかけた。「教頭は角屋へ泊って悪《わ》るいという規則がありますか」と赤シャツは依然《いぜん》として鄭寧《ていねい》な言葉を使ってる。顔の色は少々蒼い。「取締上《とりしまりじょう》不都合だから、蕎麦屋《そばや》や団子屋《だんごや》へさえはいってはいかんと、云うくらい謹直《きんちょく》な人が、なぜ芸者といっしょに宿屋へとまり込んだ」野だは隙を見ては逃げ出そうとするからおれはすぐ前に立ち塞がって「べらんめえの坊っちゃんた何だ」と怒鳴り付けたら、「いえ君の事を云ったんじゃないんです、全くないんです」と鉄面皮に言訳がましい事をぬかした。おれはこの時気がついてみたら、両手で自分の袂を握《にぎ》ってる。追っかける時に袂の中の卵がぶらぶらして困るから、両手で握りながら来たのである。おれはいきなり袂へ手を入れて、玉子を二つ取り出して、やっと云いながら、野だの面へ擲《たた》きつけた。玉子がぐちゃりと割れて鼻の先から黄味がだらだら流れだした。野だはよっぽど仰天《ぎょうてん》した者と見えて、わっと言いながら、尻持《しりもち》をついて、助けてくれと云った。おれは食うために玉子は買ったが、打《ぶ》つけるために袂へ入れてる訳ではない。ただ肝癪《かんしゃく》のあまりに、ついぶつけるともなしに打つけてしまったのだ。しかし野だが尻持を突いたところを見て始めて、おれの成功した事に気がついたから、こん畜生《ちくしょう》、こん畜生と云いながら残る六つを無茶苦茶に擲《たた》きつけたら、野だは顔中黄色になった。 おれが玉子をたたきつけているうち、山嵐と赤シャツはまだ談判最中である。「芸者をつれて僕が宿屋へ泊ったと云う証拠《しょうこ》がありますか」「宵に貴様のなじみの芸者が角屋へはいったのを見て云う事だ。胡魔化せるものか」「胡魔化す必要はない。僕は吉川君と二人で泊ったのである。芸者が宵にはいろうが、はいるまいが、僕の知った事ではない」「だまれ」と山嵐は拳骨《げんこつ》を食わした。赤シャツはよろよろしたが「これは乱暴だ、狼藉《ろうぜき》である。理非を弁じないで腕力に訴えるのは無法だ」「無法でたくさんだ」とまたぽかりと撲《な》ぐる。「貴様のような奸物はなぐらなくっちゃ、答えないんだ」とぽかぽかなぐる。おれも同時に野だを散々に擲き据えた。しまいには二人とも杉の根方にうずくまって動けないのか、眼がちらちらするのか逃げようともしない。「もうたくさんか、たくさんでなけりゃ、まだ撲《なぐ》ってやる」とぽかんぽかんと両人《ふたり》でなぐったら「もうたくさんだ」と云った。野だに「貴様もたくさんか」と聞いたら「無論たくさんだ」と答えた。「貴様等は奸物だから、こうやって天誅を加えるんだ。これに懲《こ》りて以来つつしむがいい。いくら言葉|巧《たく》みに弁解が立っても正義は許さんぞ」と山嵐が云ったら両人共《ふたりとも》だまっていた。ことによると口をきくのが退儀《たいぎ》なのかも知れない。「おれは逃げも隠《かく》れもせん。今夜五時までは浜の港屋に居る。用があるなら巡査《じゅんさ》なりなんなり、よこせ」と山嵐が云うから、おれも「おれも逃げも隠れもしないぞ。堀田と同じ所に待ってるから警察へ訴《うった》えたければ、勝手に訴えろ」と云って、二人してすたすたあるき出した。 おれが下宿へ帰ったのは七時少し前である。部屋へはいるとすぐ荷作りを始めたら、婆さんが驚いて、どうおしるのぞなもしと聞いた。お婆さん、東京へ行って奥さんを連れてくるんだと答えて勘定を済まして、すぐ汽車へ乗って浜へ来て港屋へ着くと、山嵐は二階で寝ていた。おれは早速辞表を書こうと思ったが、何と書いていいか分らないから、私儀《わたくしぎ》都合|有之《これあり》辞職の上東京へ帰り申候《もうしそろ》につき左様御承知被下度候《さようごしょうちくだされたくそろ》以上とかいて校長|宛《あて》にして郵便で出した。 汽船は夜六時の出帆《しゅっぱん》である。山嵐もおれも疲れて、ぐうぐう寝込んで眼が覚めたら、午後二時であった。下女に巡査は来ないかと聞いたら参りませんと答えた。「赤シャツも野だも訴えなかったなあ」と二人は大きに笑った。 その夜おれと山嵐はこの不浄《ふじょう》な地を離《はな》れた。船が岸を去れば去るほどいい心持ちがした。神戸から東京までは直行で新橋へ着いた時は、ようやく娑婆《しゃば》へ出たような気がした。山嵐とはすぐ分れたぎり今日まで逢う機会がない。 清《きよ》の事を話すのを忘れていた。――おれが東京へ着いて下宿へも行かず、革鞄《かばん》を提げたまま、清や帰ったよと飛び込んだら、あら坊っちゃん、よくまあ、早く帰って来て下さったと涙《なみだ》をぽたぽたと落した。おれもあまり嬉《うれ》しかったから、もう田舎《いなか》へは行かない、東京で清とうちを持つんだと云った。 その後ある人の周旋《しゅうせん》で街鉄《がいてつ》の技手になった。月給は二十五円で、家賃は六円だ。清は玄関《げんかん》付きの家でなくっても至極満足の様子であったが気の毒な事に今年の二月|肺炎《はいえん》に罹《かか》って死んでしまった。死ぬ前日おれを呼んで坊っちゃん後生だから清が死んだら、坊っちゃんのお寺へ埋《う》めて下さい。お墓のなかで坊っちゃんの来るのを楽しみに待っておりますと云った。だから清の墓は小日向《こびなた》の養源寺にある。[#地から1字上げ](明治三十九年四月)底本:「ちくま日本文学全集 夏目漱石」筑摩書房   1992(平成4)年1月20日第1刷発行底本の親本:「夏目漱石全集2」ちくま文庫、筑摩書房   1987(昭和62)年10月27日第1刷発行※底本の注にれば、本作品の原稿には、「そのうち学校もいやになった。」の後に、漱石自身による2字あけの指定があるという。このファイルでは、その情報にもとづいて、当該の箇所を2字あけとした。※底本は、物を数える際や地名などに用いる「ヶ」(区点番号5-86)を、大振りにつくっています。入力:真先芳秋校正:柳沢成雄1999年9月13日公開2004年2月27日修正青空文庫作成ファイル:このファイルは、インターネットの図書館、青空文庫(http://www.aozora.gr.jp/)で作られました。入力、校正、制作にあたったのは、ボランティアの皆さんです。
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/dict/TestTokenInfoDictionary.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/dict/TestTokenInfoDictionary.java
new file mode 100644
index 00000000000..c6b3c63c087
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/dict/TestTokenInfoDictionary.java
@@ -0,0 +1,107 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.util.ToStringUtil;
+import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.IntsRefFSTEnum;
+import org.apache.lucene.util.fst.IntsRefFSTEnum.InputOutput;
+
+public class TestTokenInfoDictionary extends LuceneTestCase {
+
+ /** enumerates the entire FST/lookup data and just does basic sanity checks */
+ public void testEnumerateAll() throws Exception {
+ // just for debugging
+ int numTerms = 0;
+ int numWords = 0;
+ int lastWordId = -1;
+ int lastSourceId = -1;
+ TokenInfoDictionary tid = TokenInfoDictionary.getInstance();
+ ConnectionCosts matrix = ConnectionCosts.getInstance();
+ FST<Long> fst = tid.getFST().getInternalFST();
+ IntsRefFSTEnum<Long> fstEnum = new IntsRefFSTEnum<Long>(fst);
+ InputOutput<Long> mapping;
+ IntsRef scratch = new IntsRef();
+ while ((mapping = fstEnum.next()) != null) {
+ numTerms++;
+ IntsRef input = mapping.input;
+ char chars[] = new char[input.length];
+ for (int i = 0; i < chars.length; i++) {
+ chars[i] = (char)input.ints[input.offset+i];
+ }
+ assertTrue(UnicodeUtil.validUTF16String(new String(chars)));
+
+ Long output = mapping.output;
+ int sourceId = output.intValue();
+ // we walk in order, terms, sourceIds, and wordIds should always be increasing
+ assertTrue(sourceId > lastSourceId);
+ lastSourceId = sourceId;
+ tid.lookupWordIds(sourceId, scratch);
+ for (int i = 0; i < scratch.length; i++) {
+ numWords++;
+ int wordId = scratch.ints[scratch.offset+i];
+ assertTrue(wordId > lastWordId);
+ lastWordId = wordId;
+
+ String baseForm = tid.getBaseForm(wordId);
+ assertTrue(baseForm == null || UnicodeUtil.validUTF16String(baseForm));
+
+ String inflectionForm = tid.getInflectionForm(wordId);
+ assertTrue(inflectionForm == null || UnicodeUtil.validUTF16String(inflectionForm));
+ if (inflectionForm != null) {
+ // check that its actually an ipadic inflection form
+ assertNotNull(ToStringUtil.getInflectedFormTranslation(inflectionForm));
+ }
+
+ String inflectionType = tid.getInflectionType(wordId);
+ assertTrue(inflectionType == null || UnicodeUtil.validUTF16String(inflectionType));
+ if (inflectionType != null) {
+ // check that its actually an ipadic inflection type
+ assertNotNull(ToStringUtil.getInflectionTypeTranslation(inflectionType));
+ }
+
+ int leftId = tid.getLeftId(wordId);
+ int rightId = tid.getRightId(wordId);
+
+ matrix.get(rightId, leftId);
+
+ tid.getWordCost(wordId);
+
+ String pos = tid.getPartOfSpeech(wordId);
+ assertNotNull(pos);
+ assertTrue(UnicodeUtil.validUTF16String(pos));
+ // check that its actually an ipadic pos tag
+ assertNotNull(ToStringUtil.getPOSTranslation(pos));
+
+ String pronunciation = tid.getPronunciation(wordId);
+ assertNotNull(pronunciation);
+ assertTrue(UnicodeUtil.validUTF16String(pronunciation));
+
+ String reading = tid.getReading(wordId);
+ assertNotNull(reading);
+ assertTrue(UnicodeUtil.validUTF16String(reading));
+ }
+ }
+ if (VERBOSE) {
+ System.out.println("checked " + numTerms + " terms, " + numWords + " words.");
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/dict/UserDictionaryTest.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/dict/UserDictionaryTest.java
new file mode 100644
index 00000000000..c076fa296e1
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/dict/UserDictionaryTest.java
@@ -0,0 +1,98 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.IOException;
+
+import org.apache.lucene.analysis.kuromoji.SegmenterTest;
+import org.apache.lucene.analysis.kuromoji.dict.UserDictionary;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
+
+public class UserDictionaryTest extends LuceneTestCase {
+
+ private UserDictionary readDict() throws IOException {
+ InputStream is = SegmenterTest.class.getResourceAsStream("userdict.txt");
+ if (is == null)
+ throw new FileNotFoundException("Cannot find userdict.txt in test classpath!");
+ try {
+ Reader reader = new InputStreamReader(is, IOUtils.CHARSET_UTF_8);
+ return new UserDictionary(reader);
+ } finally {
+ is.close();
+ }
+ }
+
+ @Test
+ public void testLookup() throws IOException {
+ UserDictionary dictionary = readDict();
+ String s = "関西国際空港に行った";
+ int[][] dictionaryEntryResult = dictionary.lookup(s.toCharArray(), 0, s.length());
+ // Length should be three 関西, 国際, 空港
+ assertEquals(3, dictionaryEntryResult.length);
+
+ // Test positions
+ assertEquals(0, dictionaryEntryResult[0][1]); // index of 関西
+ assertEquals(2, dictionaryEntryResult[1][1]); // index of 国際
+ assertEquals(4, dictionaryEntryResult[2][1]); // index of 空港
+
+ // Test lengths
+ assertEquals(2, dictionaryEntryResult[0][2]); // length of 関西
+ assertEquals(2, dictionaryEntryResult[1][2]); // length of 国際
+ assertEquals(2, dictionaryEntryResult[2][2]); // length of 空港
+
+ s = "関西国際空港と関西国際空港に行った";
+ int[][] dictionaryEntryResult2 = dictionary.lookup(s.toCharArray(), 0, s.length());
+ // Length should be six
+ assertEquals(6, dictionaryEntryResult2.length);
+ }
+
+ @Test
+ public void testReadings() throws IOException {
+ UserDictionary dictionary = readDict();
+ int[][] result = dictionary.lookup("日本経済新聞".toCharArray(), 0, 6);
+ assertEquals(3, result.length);
+ int wordIdNihon = result[0][0]; // wordId of 日本 in 日本経済新聞
+ assertEquals("ニホン", dictionary.getReading(wordIdNihon));
+
+ result = dictionary.lookup("朝青龍".toCharArray(), 0, 3);
+ assertEquals(1, result.length);
+ int wordIdAsashoryu = result[0][0]; // wordId for 朝青龍
+ assertEquals("アサショウリュウ", dictionary.getReading(wordIdAsashoryu));
+ }
+
+ @Test
+ public void testPartOfSpeech() throws IOException {
+ UserDictionary dictionary = readDict();
+ int[][] result = dictionary.lookup("日本経済新聞".toCharArray(), 0, 6);
+ assertEquals(3, result.length);
+ int wordIdKeizai = result[1][0]; // wordId of 経済 in 日本経済新聞
+ assertEquals("カスタム名詞", dictionary.getPartOfSpeech(wordIdKeizai));
+ }
+
+ @Test
+ public void testRead() throws IOException {
+ UserDictionary dictionary = readDict();
+ assertNotNull(dictionary);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/userdict.txt b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/userdict.txt
new file mode 100644
index 00000000000..cf4a920826f
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/userdict.txt
@@ -0,0 +1,6 @@
+# Custom segmentation for long entries
+日本経済新聞,日本 経済 新聞,ニホン ケイザイ シンブン,カスタム名詞
+関西国際空港,関西 国際 空港,カンサイ コクサイ クウコウ,テスト名詞
+
+# Custom reading for sumo wrestler
+朝青龍,朝青龍,アサショウリュウ,カスタム人名
diff --git a/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/util/TestToStringUtil.java b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/util/TestToStringUtil.java
new file mode 100644
index 00000000000..92a6396f1fa
--- /dev/null
+++ b/modules/analysis/kuromoji/src/test/org/apache/lucene/analysis/kuromoji/util/TestToStringUtil.java
@@ -0,0 +1,34 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestToStringUtil extends LuceneTestCase {
+ public void testPOS() {
+ assertEquals("noun-suffix-verbal", ToStringUtil.getPOSTranslation("名詞-接尾-サ変接続"));
+ }
+
+ public void testHepburn() {
+ assertEquals("majan", ToStringUtil.getRomanization("マージャン"));
+ assertEquals("uroncha", ToStringUtil.getRomanization("ウーロンチャ"));
+ assertEquals("chahan", ToStringUtil.getRomanization("チャーハン"));
+ assertEquals("chashu", ToStringUtil.getRomanization("チャーシュー"));
+ assertEquals("shumai", ToStringUtil.getRomanization("シューマイ"));
+ }
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/BinaryDictionaryWriter.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/BinaryDictionaryWriter.java
new file mode 100644
index 00000000000..98884e24f3b
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/BinaryDictionaryWriter.java
@@ -0,0 +1,371 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.store.OutputStreamDataOutput;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.CodecUtil;
+
+import org.apache.lucene.analysis.kuromoji.dict.BinaryDictionary;
+
+public abstract class BinaryDictionaryWriter {
+ protected final Class<? extends BinaryDictionary> implClazz;
+ protected ByteBuffer buffer;
+ private int targetMapEndOffset = 0, lastWordId = -1, lastSourceId = -1;
+ private int[] targetMap = new int[8192];
+ private int[] targetMapOffsets = new int[8192];
+ private final List<String> posDict = new ArrayList<String>();
+ private final Map<String,Integer> posDictLookup = new HashMap<String,Integer>();
+
+ private final List<String> inflDict = new ArrayList<String>();
+ private final Map<String,Integer> inflDictLookup = new HashMap<String,Integer>();
+
+ public BinaryDictionaryWriter(Class<? extends BinaryDictionary> implClazz, int size) {
+ this.implClazz = implClazz;
+ buffer = ByteBuffer.allocate(size);
+ }
+
+ /**
+ * put the entry in map
+ * @return current position of buffer, which will be wordId of next entry
+ */
+ public int put(String[] entry) {
+ short leftId = Short.parseShort(entry[1]);
+ short rightId = Short.parseShort(entry[2]);
+ short wordCost = Short.parseShort(entry[3]);
+
+ StringBuilder sb = new StringBuilder();
+
+ // build up the POS string
+ for (int i = 4; i < 8; i++) {
+ String part = entry[i];
+ assert part.length() > 0;
+ if (!"*".equals(part)) {
+ if (sb.length() > 0) {
+ sb.append('-');
+ }
+ sb.append(part);
+ }
+ }
+ String pos = sb.toString();
+ Integer posIndex = posDictLookup.get(pos);
+ if (posIndex == null) {
+ posIndex = posDict.size();
+ posDict.add(pos);
+ posDictLookup.put(pos, posIndex);
+ assert posDict.size() == posDictLookup.size();
+ }
+
+ sb.setLength(0);
+ sb.append(CSVUtil.quoteEscape(entry[8]));
+ sb.append(',');
+ sb.append(CSVUtil.quoteEscape(entry[9]));
+ String inflData = sb.toString();
+
+ Integer inflIndex = Integer.MAX_VALUE;
+ int hasInflData;
+ if ("*,*".equals(inflData)) {
+ hasInflData = 0; // no inflection data
+ } else {
+ hasInflData = 1;
+ inflIndex = inflDictLookup.get(inflData);
+ if (inflIndex == null) {
+ inflIndex = inflDict.size();
+ inflDict.add(inflData);
+ inflDictLookup.put(inflData, inflIndex);
+ assert inflDict.size() == inflDictLookup.size();
+ }
+ }
+
+ String baseForm = entry[10];
+ String reading = entry[11];
+ String pronunciation = entry[12];
+
+ // extend buffer if necessary
+ int left = buffer.remaining();
+ // worst case: three short, 4 bytes, one vint and features (all as utf-16)
+ int worstCase = 6 + 4 + 2 + 2*(baseForm.length() + reading.length() + pronunciation.length());
+ if (worstCase > left) {
+ ByteBuffer newBuffer = ByteBuffer.allocate(ArrayUtil.oversize(buffer.limit() + worstCase - left, 1));
+ buffer.flip();
+ newBuffer.put(buffer);
+ buffer = newBuffer;
+ }
+
+ buffer.putShort(leftId);
+ buffer.putShort(rightId);
+ buffer.putShort(wordCost);
+ assert posIndex.intValue() < 128;
+ buffer.put((byte) (posIndex.intValue() << 1 | hasInflData));
+
+ int pronunciationIsReading = pronunciation.equals(reading) ? 1 : 0;
+
+ if ("*".equals(baseForm) || baseForm.equals(entry[0])) {
+ buffer.put((byte)pronunciationIsReading); // base form is the same as surface form
+ } else {
+ assert baseForm.length() < 128;
+ buffer.put((byte)(baseForm.length() << 1 | pronunciationIsReading));
+ for (int i = 0; i < baseForm.length(); i++) {
+ buffer.putChar(baseForm.charAt(i));
+ }
+ }
+
+ if (isKatakana(reading)) {
+ buffer.put((byte) (reading.length() << 1 | 1));
+ writeKatakana(reading);
+ } else {
+ buffer.put((byte) (reading.length() << 1));
+ for (int i = 0; i < reading.length(); i++) {
+ buffer.putChar(reading.charAt(i));
+ }
+ }
+
+ if (pronunciationIsReading == 0) {
+ if (isKatakana(pronunciation)) {
+ buffer.put((byte) (pronunciation.length() << 1 | 1));
+ writeKatakana(pronunciation);
+ } else {
+ buffer.put((byte) (pronunciation.length() << 1));
+ for (int i = 0; i < pronunciation.length(); i++) {
+ buffer.putChar(pronunciation.charAt(i));
+ }
+ }
+ }
+
+ if (hasInflData > 0) {
+ int key = inflIndex.intValue();
+ assert key < 32768; // note there are really like 300 of these...
+ if (key < 128) {
+ buffer.put((byte) key);
+ } else {
+ buffer.put((byte) ((key & 0x7f) | 0x80));
+ buffer.put((byte) (key >>> 7));
+ }
+ }
+
+ return buffer.position();
+ }
+
+ private boolean isKatakana(String s) {
+ for (int i = 0; i < s.length(); i++) {
+ char ch = s.charAt(i);
+ if (ch < 0x30A0 || ch > 0x30FF) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void writeKatakana(String s) {
+ for (int i = 0; i < s.length(); i++) {
+ buffer.put((byte) (s.charAt(i) - 0x30A0));
+ }
+ }
+
+ public void addMapping(int sourceId, int wordId) {
+ assert wordId > lastWordId : "words out of order: " + wordId + " vs lastID: " + lastWordId;
+
+ if (sourceId > lastSourceId) {
+ assert sourceId > lastSourceId : "source ids out of order: lastSourceId=" + lastSourceId + " vs sourceId=" + sourceId;
+ targetMapOffsets = ArrayUtil.grow(targetMapOffsets, sourceId + 1);
+ for (int i = lastSourceId + 1; i <= sourceId; i++) {
+ targetMapOffsets[i] = targetMapEndOffset;
+ }
+ } else {
+ assert sourceId == lastSourceId;
+ }
+
+ targetMap = ArrayUtil.grow(targetMap, targetMapEndOffset + 1);
+ targetMap[targetMapEndOffset] = wordId;
+ targetMapEndOffset++;
+
+ lastSourceId = sourceId;
+ lastWordId = wordId;
+ }
+
+ protected final String getBaseFileName(String baseDir) throws IOException {
+ return baseDir + File.separator + implClazz.getName().replace('.', File.separatorChar);
+ }
+
+ /**
+ * Write dictionary in file
+ * Dictionary format is:
+ * [Size of dictionary(int)], [entry:{left id(short)}{right id(short)}{word cost(short)}{length of pos info(short)}{pos info(char)}], [entry...], [entry...].....
+ * @throws IOException
+ */
+ public void write(String baseDir) throws IOException {
+ final String baseName = getBaseFileName(baseDir);
+ writeDictionary(baseName + BinaryDictionary.DICT_FILENAME_SUFFIX);
+ writeTargetMap(baseName + BinaryDictionary.TARGETMAP_FILENAME_SUFFIX);
+ writePosDict(baseName + BinaryDictionary.POSDICT_FILENAME_SUFFIX);
+ writeInflDict(baseName + BinaryDictionary.INFLDICT_FILENAME_SUFFIX);
+ }
+
+ // TODO: maybe this int[] should instead be the output to the FST...
+ protected void writeTargetMap(String filename) throws IOException {
+ new File(filename).getParentFile().mkdirs();
+ OutputStream os = new FileOutputStream(filename);
+ try {
+ os = new BufferedOutputStream(os);
+ final DataOutput out = new OutputStreamDataOutput(os);
+ CodecUtil.writeHeader(out, BinaryDictionary.TARGETMAP_HEADER, BinaryDictionary.VERSION);
+
+ final int numSourceIds = lastSourceId + 1;
+ out.writeVInt(targetMapEndOffset); // <-- size of main array
+ out.writeVInt(numSourceIds + 1); // <-- size of offset array (+ 1 more entry)
+ int prev = 0, sourceId = 0;
+ for (int ofs = 0; ofs < targetMapEndOffset; ofs++) {
+ final int val = targetMap[ofs], delta = val - prev;
+ assert delta >= 0;
+ if (ofs == targetMapOffsets[sourceId]) {
+ out.writeVInt((delta << 1) | 0x01);
+ sourceId++;
+ } else {
+ out.writeVInt((delta << 1));
+ }
+ prev += delta;
+ }
+ assert sourceId == numSourceIds : "sourceId:"+sourceId+" != numSourceIds:"+numSourceIds;
+ } finally {
+ os.close();
+ }
+ }
+
+ protected void writePosDict(String filename) throws IOException {
+ new File(filename).getParentFile().mkdirs();
+ OutputStream os = new FileOutputStream(filename);
+ try {
+ os = new BufferedOutputStream(os);
+ final DataOutput out = new OutputStreamDataOutput(os);
+ CodecUtil.writeHeader(out, BinaryDictionary.POSDICT_HEADER, BinaryDictionary.VERSION);
+ out.writeVInt(posDict.size());
+ for (String s : posDict) {
+ out.writeString(s);
+ }
+ } finally {
+ os.close();
+ }
+ }
+
+ protected void writeInflDict(String filename) throws IOException {
+ new File(filename).getParentFile().mkdirs();
+ OutputStream os = new FileOutputStream(filename);
+ try {
+ os = new BufferedOutputStream(os);
+ final DataOutput out = new OutputStreamDataOutput(os);
+ CodecUtil.writeHeader(out, BinaryDictionary.INFLDICT_HEADER, BinaryDictionary.VERSION);
+ out.writeVInt(inflDict.size());
+ for (String s : inflDict) {
+ String data[] = CSVUtil.parse(s);
+ assert data.length == 2 : "malformed inflection: " + s;
+ out.writeString(data[0]);
+ out.writeString(data[1]);
+ }
+ } finally {
+ os.close();
+ }
+ }
+
+ protected void writeDictionary(String filename) throws IOException {
+ new File(filename).getParentFile().mkdirs();
+ final FileOutputStream os = new FileOutputStream(filename);
+ try {
+ final DataOutput out = new OutputStreamDataOutput(os);
+ CodecUtil.writeHeader(out, BinaryDictionary.DICT_HEADER, BinaryDictionary.VERSION);
+ out.writeVInt(buffer.position());
+ final WritableByteChannel channel = Channels.newChannel(os);
+ // Write Buffer
+ buffer.flip(); // set position to 0, set limit to current position
+ channel.write(buffer);
+ assert buffer.remaining() == 0L;
+ } finally {
+ os.close();
+ }
+ }
+
+ // TODO: the below is messy, but makes the dictionary smaller.
+ // we track frequencies of inflections so the highest-freq ones have smaller indexes.
+
+ /** optional: notes inflection seen in the data up front */
+ public void noteInflection(String entry[]) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(CSVUtil.quoteEscape(entry[8]));
+ sb.append(',');
+ sb.append(CSVUtil.quoteEscape(entry[9]));
+ String s = sb.toString();
+ if ("*,*".equals(s)) {
+ return; // no inflection data
+ }
+ Integer freq = notedInflections.get(s);
+ if (freq == null) {
+ freq = 0;
+ }
+ notedInflections.put(s, freq+1);
+ }
+
+ /** prepopulates inflection mapping by frequency */
+ public void finalizeInflections() {
+ InflectionAndFreq freqs[] = new InflectionAndFreq[notedInflections.size()];
+ int upto = 0;
+ for (Map.Entry<String,Integer> e : notedInflections.entrySet()) {
+ freqs[upto++] = new InflectionAndFreq(e.getKey(), e.getValue());
+ }
+ Arrays.sort(freqs, Collections.reverseOrder());
+ for (int i = 0; i < upto; i++) {
+ inflDict.add(freqs[i].inflection);
+ inflDictLookup.put(freqs[i].inflection, i);
+ }
+ }
+
+ static class InflectionAndFreq implements Comparable<InflectionAndFreq> {
+ String inflection;
+ int freq;
+
+ InflectionAndFreq(String s, int i) {
+ this.inflection = s;
+ this.freq = i;
+ }
+
+ public int compareTo(InflectionAndFreq other) {
+ int cmp = freq - other.freq;
+ if (cmp == 0) {
+ return inflection.compareTo(other.inflection);
+ } else {
+ return cmp;
+ }
+ }
+ }
+
+ private HashMap<String,Integer> notedInflections = new HashMap<String,Integer>();
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/CharacterDefinitionWriter.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/CharacterDefinitionWriter.java
new file mode 100644
index 00000000000..0cec85ea4c2
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/CharacterDefinitionWriter.java
@@ -0,0 +1,95 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
+
+import org.apache.lucene.analysis.kuromoji.dict.CharacterDefinition;
+
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.store.OutputStreamDataOutput;
+import org.apache.lucene.util.CodecUtil;
+
+public final class CharacterDefinitionWriter {
+
+ private final byte[] characterCategoryMap = new byte[0x10000];
+
+ private final boolean[] invokeMap = new boolean[CharacterDefinition.CLASS_COUNT];
+ private final boolean[] groupMap = new boolean[CharacterDefinition.CLASS_COUNT];
+
+ /**
+ * Constructor for building. TODO: remove write access
+ */
+ public CharacterDefinitionWriter() {
+ Arrays.fill(characterCategoryMap, CharacterDefinition.DEFAULT);
+ }
+
+ /**
+ * Put mapping from unicode code point to character class.
+ *
+ * @param codePoint
+ * code point
+ * @param characterClassName character class name
+ */
+ public void putCharacterCategory(int codePoint, String characterClassName) {
+ characterClassName = characterClassName.split(" ")[0]; // use first
+ // category
+ // class
+
+ // Override Nakaguro
+ if (codePoint == 0x30FB) {
+ characterClassName = "SYMBOL";
+ }
+ characterCategoryMap[codePoint] = CharacterDefinition.lookupCharacterClass(characterClassName);
+ }
+
+ public void putInvokeDefinition(String characterClassName, int invoke, int group, int length) {
+ final byte characterClass = CharacterDefinition.lookupCharacterClass(characterClassName);
+ invokeMap[characterClass] = invoke == 1;
+ groupMap[characterClass] = group == 1;
+ // TODO: length def ignored
+ }
+
+ public void write(String baseDir) throws IOException {
+ String filename = baseDir + File.separator +
+ CharacterDefinition.class.getName().replace('.', File.separatorChar) + CharacterDefinition.FILENAME_SUFFIX;
+ new File(filename).getParentFile().mkdirs();
+ OutputStream os = new FileOutputStream(filename);
+ try {
+ os = new BufferedOutputStream(os);
+ final DataOutput out = new OutputStreamDataOutput(os);
+ CodecUtil.writeHeader(out, CharacterDefinition.HEADER, CharacterDefinition.VERSION);
+ out.writeBytes(characterCategoryMap, 0, characterCategoryMap.length);
+ for (int i = 0; i < CharacterDefinition.CLASS_COUNT; i++) {
+ final byte b = (byte) (
+ (invokeMap[i] ? 0x01 : 0x00) |
+ (groupMap[i] ? 0x02 : 0x00)
+ );
+ out.writeByte(b);
+ }
+ } finally {
+ os.close();
+ }
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/ConnectionCostsBuilder.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/ConnectionCostsBuilder.java
new file mode 100644
index 00000000000..d8de2967447
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/ConnectionCostsBuilder.java
@@ -0,0 +1,67 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+
+public class ConnectionCostsBuilder {
+
+ private ConnectionCostsBuilder() {
+ }
+
+ public static ConnectionCostsWriter build(String filename) throws IOException {
+ FileInputStream inputStream = new FileInputStream(filename);
+ Charset cs = Charset.forName("US-ASCII");
+ CharsetDecoder decoder = cs.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPORT)
+ .onUnmappableCharacter(CodingErrorAction.REPORT);
+ InputStreamReader streamReader = new InputStreamReader(inputStream, decoder);
+ LineNumberReader lineReader = new LineNumberReader(streamReader);
+
+ String line = lineReader.readLine();
+ String[] dimensions = line.split("\\s+");
+
+ assert dimensions.length == 2;
+
+ int forwardSize = Integer.parseInt(dimensions[0]);
+ int backwardSize = Integer.parseInt(dimensions[1]);
+
+ assert forwardSize > 0 && backwardSize > 0;
+
+ ConnectionCostsWriter costs = new ConnectionCostsWriter(forwardSize, backwardSize);
+
+ while ((line = lineReader.readLine()) != null) {
+ String[] fields = line.split("\\s+");
+
+ assert fields.length == 3;
+
+ int forwardId = Integer.parseInt(fields[0]);
+ int backwardId = Integer.parseInt(fields[1]);
+ int cost = Integer.parseInt(fields[2]);
+
+ costs.add(forwardId, backwardId, cost);
+ }
+ return costs;
+ }
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/ConnectionCostsWriter.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/ConnectionCostsWriter.java
new file mode 100644
index 00000000000..71866eae842
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/ConnectionCostsWriter.java
@@ -0,0 +1,76 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.lucene.analysis.kuromoji.dict.ConnectionCosts;
+
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.store.OutputStreamDataOutput;
+import org.apache.lucene.util.CodecUtil;
+
+public final class ConnectionCostsWriter {
+
+ private final short[][] costs; // array is backward IDs first since get is called using the same backward ID consecutively. maybe doesn't matter.
+ private final int forwardSize;
+ private final int backwardSize;
+ /**
+ * Constructor for building. TODO: remove write access
+ */
+ public ConnectionCostsWriter(int forwardSize, int backwardSize) {
+ this.forwardSize = forwardSize;
+ this.backwardSize = backwardSize;
+ this.costs = new short[backwardSize][forwardSize];
+ }
+
+ public void add(int forwardId, int backwardId, int cost) {
+ this.costs[backwardId][forwardId] = (short)cost;
+ }
+
+ public void write(String baseDir) throws IOException {
+ String filename = baseDir + File.separator +
+ ConnectionCosts.class.getName().replace('.', File.separatorChar) + ConnectionCosts.FILENAME_SUFFIX;
+ new File(filename).getParentFile().mkdirs();
+ OutputStream os = new FileOutputStream(filename);
+ try {
+ os = new BufferedOutputStream(os);
+ final DataOutput out = new OutputStreamDataOutput(os);
+ CodecUtil.writeHeader(out, ConnectionCosts.HEADER, ConnectionCosts.VERSION);
+ out.writeVInt(forwardSize);
+ out.writeVInt(backwardSize);
+ int last = 0;
+ assert costs.length == backwardSize;
+ for (short[] a : costs) {
+ assert a.length == forwardSize;
+ for (int i = 0; i < a.length; i++) {
+ int delta = (int)a[i] - last;
+ out.writeVInt((delta >> 31) ^ (delta << 1));
+ last = a[i];
+ }
+ }
+ } finally {
+ os.close();
+ }
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/DictionaryBuilder.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/DictionaryBuilder.java
new file mode 100644
index 00000000000..91b52b0b203
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/DictionaryBuilder.java
@@ -0,0 +1,85 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+public class DictionaryBuilder {
+
+ public enum DictionaryFormat { IPADIC, UNIDIC };
+
+ private DictionaryBuilder() {
+ }
+
+ public static void build(DictionaryFormat format,
+ String inputDirname,
+ String outputDirname,
+ String encoding,
+ boolean normalizeEntry) throws IOException {
+ System.out.println("building tokeninfo dict...");
+ TokenInfoDictionaryBuilder tokenInfoBuilder = new TokenInfoDictionaryBuilder(format, encoding, normalizeEntry);
+ TokenInfoDictionaryWriter tokenInfoDictionary = tokenInfoBuilder.build(inputDirname);
+ tokenInfoDictionary.write(outputDirname);
+ tokenInfoDictionary = null;
+ tokenInfoBuilder = null;
+ System.out.println("done");
+
+ System.out.print("building unknown word dict...");
+ UnknownDictionaryBuilder unkBuilder = new UnknownDictionaryBuilder(encoding);
+ UnknownDictionaryWriter unkDictionary = unkBuilder.build(inputDirname);
+ unkDictionary.write(outputDirname);
+ unkDictionary = null;
+ unkBuilder = null;
+ System.out.println("done");
+
+ System.out.print("building connection costs...");
+ ConnectionCostsWriter connectionCosts
+ = ConnectionCostsBuilder.build(inputDirname + File.separator + "matrix.def");
+ connectionCosts.write(outputDirname);
+ System.out.println("done");
+ }
+
+ public static void main(String[] args) throws IOException, ClassNotFoundException {
+ DictionaryFormat format;
+ if (args[0].equalsIgnoreCase("ipadic")) {
+ format = DictionaryFormat.IPADIC;
+ } else if (args[0].equalsIgnoreCase("unidic")) {
+ format = DictionaryFormat.UNIDIC;
+ } else {
+ System.err.println("Illegal format " + args[0] + " using unidic instead");
+ format = DictionaryFormat.IPADIC;
+ }
+
+ String inputDirname = args[1];
+ String outputDirname = args[2];
+ String inputEncoding = args[3];
+ boolean normalizeEntries = Boolean.parseBoolean(args[4]);
+
+ System.out.println("dictionary builder");
+ System.out.println("");
+ System.out.println("dictionary format: " + format);
+ System.out.println("input directory: " + inputDirname);
+ System.out.println("output directory: " + outputDirname);
+ System.out.println("input encoding: " + inputEncoding);
+ System.out.println("normalize entries: " + normalizeEntries);
+ System.out.println("");
+ DictionaryBuilder.build(format, inputDirname, outputDirname, inputEncoding, normalizeEntries);
+ }
+
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/TokenInfoDictionaryBuilder.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/TokenInfoDictionaryBuilder.java
new file mode 100644
index 00000000000..52c44f506bb
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/TokenInfoDictionaryBuilder.java
@@ -0,0 +1,230 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.lucene.analysis.kuromoji.util.DictionaryBuilder.DictionaryFormat;
+import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.fst.Builder;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.PositiveIntOutputs;
+
+import com.ibm.icu.text.Normalizer2;
+
+/**
+ */
+public class TokenInfoDictionaryBuilder {
+
+ /** Internal word id - incrementally assigned as entries are read and added. This will be byte offset of dictionary file */
+ private int offset = 0;
+
+ private String encoding = "euc-jp";
+
+ private boolean normalizeEntries = false;
+ private Normalizer2 normalizer;
+
+ private DictionaryFormat format = DictionaryFormat.IPADIC;
+
+ public TokenInfoDictionaryBuilder(DictionaryFormat format, String encoding, boolean normalizeEntries) {
+ this.format = format;
+ this.encoding = encoding;
+ this.normalizeEntries = normalizeEntries;
+ this.normalizer = normalizeEntries ? Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.COMPOSE) : null;
+ }
+
+ public TokenInfoDictionaryWriter build(String dirname) throws IOException {
+ FilenameFilter filter = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".csv");
+ }
+ };
+ ArrayList<File> csvFiles = new ArrayList<File>();
+ for (File file : new File(dirname).listFiles(filter)) {
+ csvFiles.add(file);
+ }
+ Collections.sort(csvFiles);
+ return buildDictionary(csvFiles);
+ }
+
+ public TokenInfoDictionaryWriter buildDictionary(List<File> csvFiles) throws IOException {
+ TokenInfoDictionaryWriter dictionary = new TokenInfoDictionaryWriter(10 * 1024 * 1024);
+
+ // all lines in the file
+ System.out.println(" parse...");
+ List<String[]> lines = new ArrayList<String[]>(400000);
+ for (File file : csvFiles){
+ FileInputStream inputStream = new FileInputStream(file);
+ Charset cs = Charset.forName(encoding);
+ CharsetDecoder decoder = cs.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPORT)
+ .onUnmappableCharacter(CodingErrorAction.REPORT);
+ InputStreamReader streamReader = new InputStreamReader(inputStream, decoder);
+ BufferedReader reader = new BufferedReader(streamReader);
+
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ String[] entry = CSVUtil.parse(line);
+
+ if(entry.length < 13) {
+ System.out.println("Entry in CSV is not valid: " + line);
+ continue;
+ }
+
+ String[] formatted = formatEntry(entry);
+ dictionary.noteInflection(formatted);
+ lines.add(formatted);
+
+ // NFKC normalize dictionary entry
+ if (normalizeEntries) {
+ if (normalizer.isNormalized(entry[0])){
+ continue;
+ }
+ String[] normalizedEntry = new String[entry.length];
+ for (int i = 0; i < entry.length; i++) {
+ normalizedEntry[i] = normalizer.normalize(entry[i]);
+ }
+
+ formatted = formatEntry(normalizedEntry);
+ dictionary.noteInflection(formatted);
+ lines.add(formatted);
+ }
+ }
+ }
+
+ dictionary.finalizeInflections();
+
+ System.out.println(" sort...");
+
+ // sort by term: we sorted the files already and use a stable sort.
+ Collections.sort(lines, new Comparator<String[]>() {
+ public int compare(String[] left, String[] right) {
+ return left[0].compareTo(right[0]);
+ }
+ });
+
+ System.out.println(" encode...");
+
+ PositiveIntOutputs fstOutput = PositiveIntOutputs.getSingleton(true);
+ Builder<Long> fstBuilder = new Builder<Long>(FST.INPUT_TYPE.BYTE2, fstOutput);
+ IntsRef scratch = new IntsRef();
+ long ord = -1; // first ord will be 0
+ String lastValue = null;
+
+ // build tokeninfo dictionary
+ for (String[] entry : lines) {
+ int next = dictionary.put(entry);
+
+ if(next == offset){
+ System.out.println("Failed to process line: " + Arrays.toString(entry));
+ continue;
+ }
+
+ String token = entry[0];
+ if (!token.equals(lastValue)) {
+ // new word to add to fst
+ ord++;
+ lastValue = token;
+ scratch.grow(token.length());
+ scratch.length = token.length();
+ for (int i = 0; i < token.length(); i++) {
+ scratch.ints[i] = (int) token.charAt(i);
+ }
+ fstBuilder.add(scratch, fstOutput.get(ord));
+ }
+ dictionary.addMapping((int)ord, offset);
+ offset = next;
+ }
+
+ FST<Long> fst = fstBuilder.finish();
+ System.out.print(" " + fst.getNodeCount() + " nodes, " + fst.getArcCount() + " arcs, " + fst.sizeInBytes() + " bytes... ");
+ dictionary.setFST(fst);
+ System.out.println(" done");
+
+ return dictionary;
+ }
+
+ /*
+ * IPADIC features
+ *
+ * 0 - surface
+ * 1 - left cost
+ * 2 - right cost
+ * 3 - word cost
+ * 4-9 - pos
+ * 10 - base form
+ * 11 - reading
+ * 12 - pronounciation
+ *
+ * UniDic features
+ *
+ * 0 - surface
+ * 1 - left cost
+ * 2 - right cost
+ * 3 - word cost
+ * 4-9 - pos
+ * 10 - base form reading
+ * 11 - base form
+ * 12 - surface form
+ * 13 - surface reading
+ */
+
+ public String[] formatEntry(String[] features) {
+ if (this.format == DictionaryFormat.IPADIC) {
+ return features;
+ } else {
+ String[] features2 = new String[13];
+ features2[0] = features[0];
+ features2[1] = features[1];
+ features2[2] = features[2];
+ features2[3] = features[3];
+ features2[4] = features[4];
+ features2[5] = features[5];
+ features2[6] = features[6];
+ features2[7] = features[7];
+ features2[8] = features[8];
+ features2[9] = features[9];
+ features2[10] = features[11];
+
+ // If the surface reading is non-existent, use surface form for reading and pronunciation.
+ // This happens with punctuation in UniDic and there are possibly other cases as well
+ if (features[13].length() == 0) {
+ features2[11] = features[0];
+ features2[12] = features[0];
+ } else {
+ features2[11] = features[13];
+ features2[12] = features[13];
+ }
+ return features2;
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/TokenInfoDictionaryWriter.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/TokenInfoDictionaryWriter.java
new file mode 100644
index 00000000000..9fdad0b2565
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/TokenInfoDictionaryWriter.java
@@ -0,0 +1,48 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.lucene.analysis.kuromoji.dict.TokenInfoDictionary;
+import org.apache.lucene.util.fst.FST;
+
+public class TokenInfoDictionaryWriter extends BinaryDictionaryWriter {
+ private FST<Long> fst;
+
+ public TokenInfoDictionaryWriter(int size) {
+ super(TokenInfoDictionary.class, size);
+ }
+
+ public void setFST(FST<Long> fst) {
+ this.fst = fst;
+ }
+
+ @Override
+ public void write(String baseDir) throws IOException {
+ super.write(baseDir);
+ writeFST(getBaseFileName(baseDir) + TokenInfoDictionary.FST_FILENAME_SUFFIX);
+ }
+
+ protected void writeFST(String filename) throws IOException {
+ File f = new File(filename);
+ f.getParentFile().mkdirs();
+ fst.save(f);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/UnknownDictionaryBuilder.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/UnknownDictionaryBuilder.java
new file mode 100644
index 00000000000..c6e31147938
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/UnknownDictionaryBuilder.java
@@ -0,0 +1,137 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.lucene.analysis.kuromoji.dict.CharacterDefinition;
+
+public class UnknownDictionaryBuilder {
+ private static final String NGRAM_DICTIONARY_ENTRY = "NGRAM,5,5,-32768,-,*,*,*,*,*,*,*,*";
+
+ private String encoding = "euc-jp";
+
+ public UnknownDictionaryBuilder(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public UnknownDictionaryWriter build(String dirname) throws IOException {
+ UnknownDictionaryWriter unkDictionary = readDictionaryFile(dirname + File.separator + "unk.def"); //Should be only one file
+ readCharacterDefinition(dirname + File.separator + "char.def", unkDictionary);
+ return unkDictionary;
+ }
+
+ public UnknownDictionaryWriter readDictionaryFile(String filename)
+ throws IOException {
+ return readDictionaryFile(filename, encoding);
+ }
+
+ public UnknownDictionaryWriter readDictionaryFile(String filename, String encoding)
+ throws IOException {
+ UnknownDictionaryWriter dictionary = new UnknownDictionaryWriter(5 * 1024 * 1024);
+
+ FileInputStream inputStream = new FileInputStream(filename);
+ Charset cs = Charset.forName(encoding);
+ CharsetDecoder decoder = cs.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPORT)
+ .onUnmappableCharacter(CodingErrorAction.REPORT);
+ InputStreamReader streamReader = new InputStreamReader(inputStream, decoder);
+ LineNumberReader lineReader = new LineNumberReader(streamReader);
+
+ dictionary.put(CSVUtil.parse(NGRAM_DICTIONARY_ENTRY));
+
+ List<String[]> lines = new ArrayList<String[]>();
+ String line = null;
+ while ((line = lineReader.readLine()) != null) {
+ // note: unk.def only has 10 fields, it simplifies the writer to just append empty reading and pronunciation,
+ // even though the unknown dictionary returns hardcoded null here.
+ final String[] parsed = CSVUtil.parse(line + ",*,*"); // Probably we don't need to validate entry
+ lines.add(parsed);
+ dictionary.noteInflection(parsed); // for completeness; I think unk.def has no inflections...
+ }
+ dictionary.finalizeInflections(); // should also be no-op
+
+ Collections.sort(lines, new Comparator<String[]>() {
+ public int compare(String[] left, String[] right) {
+ int leftId = CharacterDefinition.lookupCharacterClass(left[0]);
+ int rightId = CharacterDefinition.lookupCharacterClass(right[0]);
+ return leftId - rightId;
+ }
+ });
+
+ for (String[] entry : lines) {
+ dictionary.put(entry);
+ }
+
+ return dictionary;
+ }
+
+ public void readCharacterDefinition(String filename, UnknownDictionaryWriter dictionary) throws IOException {
+ FileInputStream inputStream = new FileInputStream(filename);
+ InputStreamReader streamReader = new InputStreamReader(inputStream, encoding);
+ LineNumberReader lineReader = new LineNumberReader(streamReader);
+
+ String line = null;
+
+ while ((line = lineReader.readLine()) != null) {
+ line = line.replaceAll("^\\s", "");
+ line = line.replaceAll("\\s*#.*", "");
+ line = line.replaceAll("\\s+", " ");
+
+ // Skip empty line or comment line
+ if(line.length() == 0) {
+ continue;
+ }
+
+ if(line.startsWith("0x")) { // Category mapping
+ String[] values = line.split(" ", 2); // Split only first space
+
+ if(!values[0].contains("..")) {
+ int cp = Integer.decode(values[0]).intValue();
+ dictionary.putCharacterCategory(cp, values[1]);
+ } else {
+ String[] codePoints = values[0].split("\\.\\.");
+ int cpFrom = Integer.decode(codePoints[0]).intValue();
+ int cpTo = Integer.decode(codePoints[1]).intValue();
+
+ for(int i = cpFrom; i <= cpTo; i++){
+ dictionary.putCharacterCategory(i, values[1]);
+ }
+ }
+ } else { // Invoke definition
+ String[] values = line.split(" "); // Consecutive space is merged above
+ String characterClassName = values[0];
+ int invoke = Integer.parseInt(values[1]);
+ int group = Integer.parseInt(values[2]);
+ int length = Integer.parseInt(values[3]);
+ dictionary.putInvokeDefinition(characterClassName, invoke, group, length);
+ }
+ }
+ }
+}
diff --git a/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/UnknownDictionaryWriter.java b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/UnknownDictionaryWriter.java
new file mode 100644
index 00000000000..a63b35c8991
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/kuromoji/util/UnknownDictionaryWriter.java
@@ -0,0 +1,50 @@
+package org.apache.lucene.analysis.kuromoji.util;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.lucene.analysis.kuromoji.dict.CharacterDefinition;
+import org.apache.lucene.analysis.kuromoji.dict.BinaryDictionary;
+import org.apache.lucene.analysis.kuromoji.dict.UnknownDictionary;
+
+public class UnknownDictionaryWriter extends BinaryDictionaryWriter {
+ private final CharacterDefinitionWriter characterDefinition = new CharacterDefinitionWriter();
+
+ public UnknownDictionaryWriter(int size) {
+ super(UnknownDictionary.class, size);
+ }
+
+ @Override
+ public int put(String[] entry) {
+ // Get wordId of current entry
+ int wordId = buffer.position();
+
+ // Put entry
+ int result = super.put(entry);
+
+ // Put entry in targetMap
+ int characterId = CharacterDefinition.lookupCharacterClass(entry[0]);
+ addMapping(characterId, wordId);
+ return result;
+ }
+
+ /**
+ * Put mapping from unicode code point to character class.
+ *
+ * @param codePoint code point
+ * @param characterClassName character class name
+ */
+ public void putCharacterCategory(int codePoint, String characterClassName) {
+ characterDefinition.putCharacterCategory(codePoint, characterClassName);
+ }
+
+ public void putInvokeDefinition(String characterClassName, int invoke, int group, int length) {
+ characterDefinition.putInvokeDefinition(characterClassName, invoke, group, length);
+ }
+
+ @Override
+ public void write(String baseDir) throws IOException {
+ super.write(baseDir);
+ characterDefinition.write(baseDir);
+ }
+}
diff --git a/modules/analysis/kuromoji/src/tools/test/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionaryTest.java b/modules/analysis/kuromoji/src/tools/test/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionaryTest.java
new file mode 100644
index 00000000000..66b820fcdff
--- /dev/null
+++ b/modules/analysis/kuromoji/src/tools/test/org/apache/lucene/analysis/kuromoji/dict/UnknownDictionaryTest.java
@@ -0,0 +1,75 @@
+package org.apache.lucene.analysis.kuromoji.dict;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.kuromoji.util.CSVUtil;
+import org.apache.lucene.analysis.kuromoji.util.UnknownDictionaryWriter;
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
+
+public class UnknownDictionaryTest extends LuceneTestCase {
+ public static final String FILENAME = "unk-tokeninfo-dict.obj";
+
+ @Test
+ public void testPutCharacterCategory() {
+ UnknownDictionaryWriter unkDic = new UnknownDictionaryWriter(10 * 1024 * 1024);
+
+ try{
+ unkDic.putCharacterCategory(0, "DUMMY_NAME");
+ fail();
+ } catch(Exception e) {
+
+ }
+
+ try{
+ unkDic.putCharacterCategory(-1, "KATAKANA");
+ fail();
+ } catch(Exception e) {
+
+ }
+
+ unkDic.putCharacterCategory(0, "DEFAULT");
+ unkDic.putCharacterCategory(1, "GREEK");
+ unkDic.putCharacterCategory(2, "HIRAGANA");
+ unkDic.putCharacterCategory(3, "KATAKANA");
+ unkDic.putCharacterCategory(4, "KANJI");
+ }
+
+ @Test
+ public void testPut() {
+ UnknownDictionaryWriter unkDic = new UnknownDictionaryWriter(10 * 1024 * 1024);
+ try{
+ unkDic.put(CSVUtil.parse("KANJI,1285,11426,名詞,一般,*,*,*,*,*,*,*"));
+ fail();
+ } catch(Exception e){
+
+ }
+
+ String entry1 = "ALPHA,1285,1285,13398,名詞,一般,*,*,*,*,*,*,*";
+ String entry2 = "HIRAGANA,1285,1285,13069,名詞,一般,*,*,*,*,*,*,*";
+ String entry3 = "KANJI,1285,1285,11426,名詞,一般,*,*,*,*,*,*,*";
+
+ unkDic.putCharacterCategory(0, "ALPHA");
+ unkDic.putCharacterCategory(1, "HIRAGANA");
+ unkDic.putCharacterCategory(2, "KANJI");
+
+ unkDic.put(CSVUtil.parse(entry1));
+ unkDic.put(CSVUtil.parse(entry2));
+ unkDic.put(CSVUtil.parse(entry3));
+ }
+}
diff --git a/solr/contrib/analysis-extras/CHANGES.txt b/solr/contrib/analysis-extras/CHANGES.txt
index b1d043a8e39..cd575dc66b5 100644
--- a/solr/contrib/analysis-extras/CHANGES.txt
+++ b/solr/contrib/analysis-extras/CHANGES.txt
@@ -17,6 +17,9 @@ $Id$
the Solr 3.x ICUCollationKeyFilterFactory, and also supports
Locale-sensitive range queries. (rmuir)
+* LUCENE-3305: Added Kuromoji morphological analyzer for Japanese.
+ (Christian Moen, Masaru Hasegawa via Robert Muir)
+
================== 3.6.0 ==================
* SOLR-2919: Added parametric tailoring options to ICUCollationKeyFilterFactory.
diff --git a/solr/contrib/analysis-extras/README.txt b/solr/contrib/analysis-extras/README.txt
index 2c60e0e7917..a5bbf1bf07c 100644
--- a/solr/contrib/analysis-extras/README.txt
+++ b/solr/contrib/analysis-extras/README.txt
@@ -2,15 +2,16 @@ The analysis-extras plugin provides additional analyzers that rely
upon large dependencies/dictionaries.
It includes integration with ICU for multilingual support, and
-analyzers for Chinese and Polish.
+analyzers for Chinese, Japanese, and Polish.
Relies upon the following lucene components (in lucene-libs/):
* lucene-analyzers-icu-X.Y.jar
+ * lucene-analyzers-kuromoji-X.Y.jar
* lucene-analyzers-smartcn-X.Y.jar
* lucene-analyzers-stempel-X.Y.jar
And the ICU library (in lib/):
* icu4j-X.Y.jar
-
\ No newline at end of file
+
diff --git a/solr/contrib/analysis-extras/build.xml b/solr/contrib/analysis-extras/build.xml
index c6d2fdcf859..b0d6d4e5f7c 100644
--- a/solr/contrib/analysis-extras/build.xml
+++ b/solr/contrib/analysis-extras/build.xml
@@ -27,21 +27,23 @@
<path id="classpath">
<pathelement path="${analyzers-icu.jar}"/>
+ <pathelement path="${analyzers-kuromoji.jar}"/>
<pathelement path="${analyzers-smartcn.jar}"/>
<pathelement path="${analyzers-stempel.jar}"/>
<path refid="solr.base.classpath"/>
</path>
<target name="module-jars-to-solr"
- depends="jar-analyzers-icu, jar-analyzers-smartcn, jar-analyzers-stempel">
+ depends="jar-analyzers-icu, jar-analyzers-kuromoji, jar-analyzers-smartcn, jar-analyzers-stempel">
<mkdir dir="${build.dir}/lucene-libs"/>
<copy todir="${build.dir}/lucene-libs" preservelastmodified="true" flatten="true" failonerror="true" overwrite="true">
<fileset file="${analyzers-icu.jar}"/>
+ <fileset file="${analyzers-kuromoji.jar}"/>
<fileset file="${analyzers-smartcn.jar}"/>
<fileset file="${analyzers-stempel.jar}"/>
</copy>
</target>
- <target name="compile-core" depends="jar-analyzers-icu, jar-analyzers-smartcn, jar-analyzers-stempel, solr-contrib-build.compile-core"/>
+ <target name="compile-core" depends="jar-analyzers-icu, jar-analyzers-kuromoji, jar-analyzers-smartcn, jar-analyzers-stempel, solr-contrib-build.compile-core"/>
<target name="dist" depends="module-jars-to-solr, common-solr.dist"/>
</project>
diff --git a/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiBaseFormFilterFactory.java b/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiBaseFormFilterFactory.java
new file mode 100644
index 00000000000..b87dcec4ecc
--- /dev/null
+++ b/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiBaseFormFilterFactory.java
@@ -0,0 +1,40 @@
+package org.apache.solr.analysis;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.kuromoji.KuromojiBaseFormFilter;
+
+/**
+ * Factory for {@link KuromojiBaseFormFilter}.
+ * <pre class="prettyprint">
+ * &lt;fieldType name="text_ja" class="solr.TextField"&gt;
+ * &lt;analyzer&gt;
+ * &lt;tokenizer class="solr.KuromojiTokenizerFactory"/&gt;
+ * &lt;filter class="solr.KuromojiBaseFormFilterFactory"/&gt;
+ * &lt;/analyzer&gt;
+ * &lt;/fieldType&gt;
+ * </pre>
+ */
+public class KuromojiBaseFormFilterFactory extends BaseTokenFilterFactory {
+
+ @Override
+ public TokenStream create(TokenStream input) {
+ return new KuromojiBaseFormFilter(input);
+ }
+}
diff --git a/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiPartOfSpeechStopFilterFactory.java b/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiPartOfSpeechStopFilterFactory.java
new file mode 100644
index 00000000000..9ac566e5a9b
--- /dev/null
+++ b/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiPartOfSpeechStopFilterFactory.java
@@ -0,0 +1,65 @@
+package org.apache.solr.analysis;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.kuromoji.KuromojiPartOfSpeechStopFilter;
+import org.apache.lucene.analysis.util.CharArraySet;
+import org.apache.solr.common.ResourceLoader;
+import org.apache.solr.util.plugin.ResourceLoaderAware;
+
+/**
+ * Factory for {@link KuromojiPartOfSpeechStopFilter}.
+ * <pre class="prettyprint">
+ * &lt;fieldType name="text_ja" class="solr.TextField"&gt;
+ * &lt;analyzer&gt;
+ * &lt;tokenizer class="solr.KuromojiTokenizerFactory"/&gt;
+ * &lt;filter class="solr.KuromojiPartOfSpeechStopFilterFactory"
+ * tags="stopTags.txt"
+ * enablePositionIncrements="true"/&gt;
+ * &lt;/analyzer&gt;
+ * &lt;/fieldType&gt;
+ * </pre>
+ */
+public class KuromojiPartOfSpeechStopFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
+ private boolean enablePositionIncrements;
+ private Set<String> stopTags;
+
+ public void inform(ResourceLoader loader) {
+ String stopTagFiles = args.get("tags");
+ enablePositionIncrements = getBoolean("enablePositionIncrements", false);
+ try {
+ CharArraySet cas = getWordSet(loader, stopTagFiles, false);
+ stopTags = new HashSet<String>();
+ for (Object element : cas) {
+ char chars[] = (char[]) element;
+ stopTags.add(new String(chars));
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public TokenStream create(TokenStream stream) {
+ return new KuromojiPartOfSpeechStopFilter(enablePositionIncrements, stream, stopTags);
+ }
+}
diff --git a/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiTokenizerFactory.java b/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiTokenizerFactory.java
new file mode 100644
index 00000000000..6441dcc37b6
--- /dev/null
+++ b/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/KuromojiTokenizerFactory.java
@@ -0,0 +1,92 @@
+package org.apache.solr.analysis;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+import java.util.Locale;
+
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.kuromoji.KuromojiTokenizer;
+import org.apache.lucene.analysis.kuromoji.Segmenter;
+import org.apache.lucene.analysis.kuromoji.Segmenter.Mode;
+import org.apache.lucene.analysis.kuromoji.dict.UserDictionary;
+import org.apache.lucene.util.IOUtils;
+import org.apache.solr.analysis.BaseTokenizerFactory;
+import org.apache.solr.common.ResourceLoader;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.util.plugin.ResourceLoaderAware;
+
+/**
+ * Factory for {@link KuromojiTokenizer}.
+ * <pre class="prettyprint">
+ * &lt;fieldType name="text_ja" class="solr.TextField"&gt;
+ * &lt;analyzer&gt;
+ * &lt;tokenizer class="solr.KuromojiTokenizerFactory"
+ * mode=NORMAL
+ * user-dictionary=user.txt
+ * user-dictionary-encoding=UTF-8
+ * /&gt;
+ * &lt;filter class="solr.KuromojiBaseFormFilterFactory"/&gt;
+ * &lt;/analyzer&gt;
+ * &lt;/fieldType&gt;
+ * </pre>
+ */
+public class KuromojiTokenizerFactory extends BaseTokenizerFactory implements ResourceLoaderAware {
+ private static final String MODE = "mode";
+
+ private static final String USER_DICT_PATH = "user-dictionary";
+
+ private static final String USER_DICT_ENCODING = "user-dictionary-encoding";
+
+ private Segmenter segmenter;
+
+ @Override
+ public void inform(ResourceLoader loader) {
+ Mode mode = args.get(MODE) != null ? Mode.valueOf(args.get(MODE).toUpperCase(Locale.ENGLISH)) : Mode.NORMAL;
+ String userDictionaryPath = args.get(USER_DICT_PATH);
+ try {
+ if (userDictionaryPath != null) {
+ InputStream stream = loader.openResource(userDictionaryPath);
+ String encoding = args.get(USER_DICT_ENCODING);
+ if (encoding == null) {
+ encoding = IOUtils.UTF_8;
+ }
+ // note: we could allow for other encodings here as an argument
+ CharsetDecoder decoder = Charset.forName(encoding).newDecoder()
+ .onMalformedInput(CodingErrorAction.REPORT)
+ .onUnmappableCharacter(CodingErrorAction.REPORT);
+ Reader reader = new InputStreamReader(stream, decoder);
+ this.segmenter = new Segmenter(new UserDictionary(reader), mode);
+ } else {
+ this.segmenter = new Segmenter(mode);
+ }
+ } catch (Exception e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+ }
+ }
+
+ @Override
+ public Tokenizer create(Reader input) {
+ return new KuromojiTokenizer(segmenter, input);
+ }
+}
\ No newline at end of file
diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/StringMockSolrResourceLoader.java b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/StringMockSolrResourceLoader.java
new file mode 100644
index 00000000000..85ce1247047
--- /dev/null
+++ b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/StringMockSolrResourceLoader.java
@@ -0,0 +1,46 @@
+package org.apache.solr.analysis;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.solr.common.ResourceLoader;
+
+class StringMockSolrResourceLoader implements ResourceLoader {
+ String text;
+
+ StringMockSolrResourceLoader(String text) {
+ this.text = text;
+ }
+
+ public List<String> getLines(String resource) throws IOException {
+ return Arrays.asList(text.split("\n"));
+ }
+
+ public Object newInstance(String cname, String... subpackages) {
+ return null;
+ }
+
+ public InputStream openResource(String resource) throws IOException {
+ return new ByteArrayInputStream(text.getBytes("UTF-8"));
+ }
+}
diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestICUCollationKeyFilterFactory.java b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestICUCollationKeyFilterFactory.java
index 8ed490585fe..e5fd999b754 100644
--- a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestICUCollationKeyFilterFactory.java
+++ b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestICUCollationKeyFilterFactory.java
@@ -17,18 +17,14 @@ package org.apache.solr.analysis;
* limitations under the License.
*/
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.StringReader;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.core.KeywordTokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
-import org.apache.solr.common.ResourceLoader;
import com.ibm.icu.text.Collator;
import com.ibm.icu.text.RuleBasedCollator;
@@ -263,26 +259,6 @@ public class TestICUCollationKeyFilterFactory extends BaseTokenTestCase {
assertCollatesToSame(tsUmlaut, tsOE);
}
- private class StringMockSolrResourceLoader implements ResourceLoader {
- String text;
-
- StringMockSolrResourceLoader(String text) {
- this.text = text;
- }
-
- public List<String> getLines(String resource) throws IOException {
- return null;
- }
-
- public Object newInstance(String cname, String... subpackages) {
- return null;
- }
-
- public InputStream openResource(String resource) throws IOException {
- return new ByteArrayInputStream(text.getBytes("UTF-8"));
- }
- }
-
private void assertCollatesToSame(TokenStream stream1, TokenStream stream2) throws IOException {
assertCollation(stream1, stream2, 0);
}
diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiBaseFormFilterFactory.java b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiBaseFormFilterFactory.java
new file mode 100644
index 00000000000..db176a55300
--- /dev/null
+++ b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiBaseFormFilterFactory.java
@@ -0,0 +1,41 @@
+package org.apache.solr.analysis;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.solr.core.SolrResourceLoader;
+
+/**
+ * Simple tests for {@link KuromojiBaseFormFilterFactory}
+ */
+public class TestKuromojiBaseFormFilterFactory extends BaseTokenTestCase {
+ public void testBasics() throws IOException {
+ KuromojiTokenizerFactory tokenizerFactory = new KuromojiTokenizerFactory();
+ tokenizerFactory.init(DEFAULT_VERSION_PARAM);
+ tokenizerFactory.inform(new SolrResourceLoader(null, null));
+ TokenStream ts = tokenizerFactory.create(new StringReader("それはまだ実験段階にあります"));
+ KuromojiBaseFormFilterFactory factory = new KuromojiBaseFormFilterFactory();
+ ts = factory.create(ts);
+ assertTokenStreamContents(ts,
+ new String[] { "それ", "は", "まだ", "実験", "段階", "に", "ある", "ます" }
+ );
+ }
+}
diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiPartOfSpeechStopFilterFactory.java b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiPartOfSpeechStopFilterFactory.java
new file mode 100644
index 00000000000..ebaec1281a0
--- /dev/null
+++ b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiPartOfSpeechStopFilterFactory.java
@@ -0,0 +1,52 @@
+package org.apache.solr.analysis;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.solr.core.SolrResourceLoader;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Simple tests for {@link KuromojiPartOfSpeechStopFilter}
+ */
+public class TestKuromojiPartOfSpeechStopFilterFactory extends BaseTokenTestCase {
+ public void testBasics() throws IOException {
+ String tags =
+ "# verb-main:\n" +
+ "動詞-自立\n";
+
+ KuromojiTokenizerFactory tokenizerFactory = new KuromojiTokenizerFactory();
+ tokenizerFactory.init(DEFAULT_VERSION_PARAM);
+ tokenizerFactory.inform(new SolrResourceLoader(null, null));
+ TokenStream ts = tokenizerFactory.create(new StringReader("私は制限スピードを超える。"));
+ KuromojiPartOfSpeechStopFilterFactory factory = new KuromojiPartOfSpeechStopFilterFactory();
+ Map<String,String> args = new HashMap<String,String>();
+ args.put("luceneMatchVersion", TEST_VERSION_CURRENT.toString());
+ args.put("tags", "stoptags.txt");
+ factory.init(args);
+ factory.inform(new StringMockSolrResourceLoader(tags));
+ ts = factory.create(ts);
+ assertTokenStreamContents(ts,
+ new String[] { "私", "は", "制限", "スピード", "を" }
+ );
+ }
+}
diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiTokenizerFactory.java b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiTokenizerFactory.java
new file mode 100644
index 00000000000..a3c4c3e59df
--- /dev/null
+++ b/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestKuromojiTokenizerFactory.java
@@ -0,0 +1,61 @@
+package org.apache.solr.analysis;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.solr.core.SolrResourceLoader;
+
+/**
+ * Simple tests for {@link KuromojiTokenizerFactory}
+ */
+public class TestKuromojiTokenizerFactory extends BaseTokenTestCase {
+ public void testSimple() throws IOException {
+ KuromojiTokenizerFactory factory = new KuromojiTokenizerFactory();
+ factory.init(DEFAULT_VERSION_PARAM);
+ factory.inform(new SolrResourceLoader(null, null));
+ TokenStream ts = factory.create(new StringReader("これは本ではない"));
+ assertTokenStreamContents(ts,
+ new String[] { "これ", "は", "本", "で", "は", "ない" },
+ new int[] { 0, 2, 3, 4, 5, 6 },
+ new int[] { 2, 3, 4, 5, 6, 8 }
+ );
+ }
+
+ public void testUserDict() throws IOException {
+ String userDict =
+ "# Custom segmentation for long entries\n" +
+ "日本経済新聞,日本 経済 新聞,ニホン ケイザイ シンブン,カスタム名詞\n" +
+ "関西国際空港,関西 国際 空港,カンサイ コクサイ クウコウ,テスト名詞\n" +
+ "# Custom reading for sumo wrestler\n" +
+ "朝青龍,朝青龍,アサショウリュウ,カスタム人名\n";
+ KuromojiTokenizerFactory factory = new KuromojiTokenizerFactory();
+ Map<String,String> args = new HashMap<String,String>();
+ args.put("user-dictionary", "userdict.txt");
+ factory.init(args);
+ factory.inform(new StringMockSolrResourceLoader(userDict));
+ TokenStream ts = factory.create(new StringReader("関西国際空港に行った"));
+ assertTokenStreamContents(ts,
+ new String[] { "関西", "国際", "空港", "に", "行っ", "た" }
+ );
+ }
+}