You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2013/01/03 17:56:36 UTC
svn commit: r1428467 [1/4] - in /stanbol/trunk/commons/solr/extras: paoding/
paoding/src/ paoding/src/main/ paoding/src/main/java/
paoding/src/main/java/net/ paoding/src/main/java/net/paoding/
paoding/src/main/java/net/paoding/analysis/ paoding/src/mai...
Author: rwesten
Date: Thu Jan 3 16:56:34 2013
New Revision: 1428467
URL: http://svn.apache.org/viewvc?rev=1428467&view=rev
Log:
STANBOL-875: Adds the stanbol paoding fork including some changes required to run it as OSGI bundle
Added:
stanbol/trunk/commons/solr/extras/paoding/ (with props)
stanbol/trunk/commons/solr/extras/paoding/README.md
stanbol/trunk/commons/solr/extras/paoding/pom.xml
stanbol/trunk/commons/solr/extras/paoding/src/
stanbol/trunk/commons/solr/extras/paoding/src/main/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/Constants.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzer.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzerBean.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingTokenizer.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/TokenCollector.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/Estimate.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/TryPaodingAnalyzer.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/CompiledFileDictionaries.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MaxWordLengthTokenCollector.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MostWordsModeDictionariesCompiler.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MostWordsTokenCollector.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/SortingDictionariesCompiler.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/BinaryDictionary.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/Dictionary.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/DictionaryDelegate.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/HashBinaryDictionary.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/Hit.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/Word.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/detection/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/detection/Detector.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/detection/Difference.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/detection/DifferenceListener.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/detection/ExtensionFileFilter.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/detection/Node.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/detection/Snapshot.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/filewords/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/filewords/FileWordsReader.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/filewords/ReadListener.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/filewords/SimpleReadListener.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/dictionary/support/filewords/SimpleReadListener2.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/exception/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/exception/PaodingAnalysisException.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/Beef.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/CJKKnife.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/CharSet.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/Collector.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/CollectorStdoutImpl.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/CombinatoricsKnife.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/Dictionaries.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/DictionariesCompiler.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/DictionariesWare.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/FakeKnife.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/FileDictionaries.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/FileDictionariesDifferenceListener.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/Knife.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/KnifeBox.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/LetterKnife.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/NumberKnife.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/Paoding.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/PaodingMaker.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/knife/SmartKnifeBox.java
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/apache/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/apache/stanbol/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/apache/stanbol/commons/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/apache/stanbol/commons/solr/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/apache/stanbol/commons/solr/extras/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/apache/stanbol/commons/solr/extras/paoding/
stanbol/trunk/commons/solr/extras/paoding/src/main/java/org/apache/stanbol/commons/solr/extras/paoding/Activator.java
stanbol/trunk/commons/solr/extras/paoding/src/main/resources/
stanbol/trunk/commons/solr/extras/paoding/src/main/resources/paoding-analysis.properties
stanbol/trunk/commons/solr/extras/paoding/src/main/resources/paoding-dict.zip (with props)
Modified:
stanbol/trunk/commons/solr/extras/smartcn/ (props changed)
stanbol/trunk/commons/solr/extras/stempel/ (props changed)
Propchange: stanbol/trunk/commons/solr/extras/paoding/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan 3 16:56:34 2013
@@ -0,0 +1,7 @@
+.settings
+
+.classpath
+
+target
+
+.project
Added: stanbol/trunk/commons/solr/extras/paoding/README.md
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/README.md?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/README.md (added)
+++ stanbol/trunk/commons/solr/extras/paoding/README.md Thu Jan 3 16:56:34 2013
@@ -0,0 +1,59 @@
+<!--
+ 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.
+-->
+
+
+Apache Stanbol Commons Solr extension for paoding-analysis
+=========================================================
+
+This module provides the [paoding-analysis](http://code.google.com/p/paoding/) analyzer for Chinese as bundle extending the default Apache Stanbol Commons Solr core module.
+
+paoding-analysis version
+----------------------
+
+This modules includes an fork from revision 154 of the the [paoding-analysis](http://code.google.com/p/paoding/) projects [svn repository](http://paoding.googlecode.com/svn/trunk/).
+
+The last commit to this projects repository was in [Nov 15, 2010](https://code.google.com/p/paoding/source/detail?r=154). The project is under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
+
+Changes to the original paoding source
+--------
+
+This provides an overview on all changes made to the paoding source code (anything in the <code>net.paoding.*</code> packages)
+
+* The Logging framework was changed to SLF4J as this is the one preferable used by Stanbol
+* Resources are now loaded via both the ContextClassloader and (if not present) the Classloader used to load the padding classes. Originally the Classloader of the paoding classes was only considered if the ContextClassloader was <code>null</code>
+* Environment properties can now also be loaded from Java system properties (e.g. parsed via the -D argument to the JVM). System properties are only considered if no Environment property is defined.
+
+
+Dictionary
+----------
+
+The dictionary is included in the module in an ZIP archive. The <code>org.apache.stanbol.commons.solr.extras.paoding.Activator</code> class can be used to initialize the dictionary. When using this module in OSGI this will be done automatically by the Bundle Activator. Outside of OSGI (e.g. for unit test) this needs to be done manually by calling:
+
+ :::java
+ File paodingDict; //the directory for the dict
+ if(!paodingDict.isDirectory()){
+ Activator.initPaodingDictionary(paodingDict,
+ getClass().getClassLoader().getResourceAsStream(
+ Activator.DICT_ARCHIVE));
+ }
+ Activator.initPaodingDictHomeProperty(paodingDict);
+
+All initialization methods supported by paoding are still supported. In addition the dictionary location can now also be parsed as Java system property (e.g. by adding '-DPAODING_DIC_HOME={path}' when starting the JVM).
+
+This module also includes an default '<code>paoding-analysis.properties</code>' file that sets the default dictionary path to '.' (the working directory). Users can use their own dictionary file if they place it in the classpath in front of this module.
+
+
Added: stanbol/trunk/commons/solr/extras/paoding/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/pom.xml?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/pom.xml (added)
+++ stanbol/trunk/commons/solr/extras/paoding/pom.xml Thu Jan 3 16:56:34 2013
@@ -0,0 +1,123 @@
+<?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>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>stanbol-parent</artifactId>
+ <version>2-SNAPSHOT</version>
+ <relativePath>../../../../parent</relativePath>
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.solr.extras.paoding</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Stanbol Commons Solr Extension for Paoding Analysis</name>
+ <description>This provides an Solr Analyzer for Chinese including dictionary as
+ OSGI bundle. This includes a forced version of the Paoding code base.</description>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/stanbol/trunk/ext/
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/stanbol/trunk/ext/
+ </developerConnection>
+ <url>http://stanbol.apache.org</url>
+ </scm>
+
+ <build>
+ <!-- make it an OSGi bundle -->
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <!--
+ The Bundle Activator copies the dictionary to the persistent
+ location of the bundle and sets up the paoding analyzers to use
+ this directory.
+ -->
+ <Bundle-Activator>
+ org.apache.stanbol.commons.solr.extras.paoding.Activator
+ </Bundle-Activator>
+ <Embed-Dependency>paoding-analysis</Embed-Dependency>
+ <Import-Package>*</Import-Package>
+ <!--
+ For now export all paoding packages.This might however change
+ -->
+ <Export-Package>
+ org.apache.stanbol.commons.solr.extras.paoding;version=${project.version}
+ net.paoding.analysis;version=2.0.4,
+ net.paoding.analysis.analyzer;version=2.0.4,
+ net.paoding.analysis.knife;version=2.0.4,
+ net.paoding.analysis.analyzer.*;version=2.0.4,
+ net.paoding.analysis.dictionar.*version=2.0.4
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ <version>3.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-analyzers</artifactId>
+ <version>3.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/Constants.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/Constants.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/Constants.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/Constants.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,118 @@
+package net.paoding.analysis;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ *
+ * @author Zhiliang Wang [qieqie.wang@gmail.com]
+ *
+ * @since 2.0.0
+ */
+public class Constants {
+
+ /**
+ * "è¯å
¸ç®å½å®è£
ç®å½"é
ç½®çä¼å
级å«
+ * <p>
+ * "system-env"以åå
¶ä»é"this"çé
ç½®ï¼è¡¨ç¤ºä¼å
ä»ç¯å¢åéPAODING_DIC_HOMEç弿¾è¯å
¸ç®å½å®è£
ç¯å¢
+ * "this"表示ä¼å
仿¬é
ç½®æä»¶çpaoding.dic.homeé
置项æ¾<br>
+ * åªæå¨é«ä¼å
级没æé
ç½®ï¼æä¼æ¾ä½ä¼å
级çé
ç½®ã é»è®¤ç¯å¢åéçä¼å
级å«é«äºpaoding-analysis.properties屿§æä»¶é
ç½®ã
+ */
+ public static final String DIC_HOME_CONFIG_FIRST = "paoding.dic.home.config-first";
+ public static final String DIC_HOME_CONFIG_FIRST_DEFAULT = "system-env";
+
+ /**
+ * è¯å
¸å®è£
ç®å½ç¯å¢åéå
+ */
+ public static final String ENV_PAODING_DIC_HOME = "PAODING_DIC_HOME";
+
+ // -------------------------------------------------------------
+ /**
+ * è¯å
¸å®è£
ç®å½
+ * <p>
+ * é»è®¤å¼ä¸ºnullï¼ä»¥å¨ç¯å¢åéåé
ç½®æä»¶é½æ²¡æé
ç½®paoding.dic.homeçæ
åµä¸ï¼è®©PaodingMakerå°è¯ä»å½åå·¥ä½ç®å½ä¸ã类路å¾ä¸æ¢ç´¢æ¯å¦åå¨dicç®å½
+ */
+ public static final String DIC_HOME = "paoding.dic.home";
+ public static final String DIC_HOME_DEFAULT = null;
+
+ // -------------------------------------------------------------
+ //
+ public static final String DIC_CHARSET = "paoding.dic.charset";
+ public static final String DIC_CHARSET_DEFAULT = "UTF-8";
+
+ // dictionary word length limit
+ public static final String DIC_MAXWORDLEN = "paoding.dic.maxWordLen";
+ public static final String DIC_MAXWORDLEN_DEFAULT = "0";
+
+ // -------------------------------------------------------------
+ // dictionaries which are skip
+ public static final String DIC_SKIP_PREFIX = "paoding.dic.skip.prefix";
+ public static final String DIC_SKIP_PREFIX_DEFAULT = "x-";
+
+ // -------------------------------------------------------------
+ // chinese/cjk charactors that will not token
+ public static final String DIC_NOISE_CHARACTOR = "paoding.dic.noise-charactor";
+ public static final String DIC_NOISE_CHARACTOR_DEFAULT = "x-noise-charactor";
+
+ // -------------------------------------------------------------
+ // chinese/cjk words that will not token
+ public static final String DIC_NOISE_WORD = "paoding.dic.noise-word";
+ public static final String DIC_NOISE_WORD_DEFAULT = "x-noise-word";
+
+ // -------------------------------------------------------------
+ // unit words, like "ge", "zhi", ...
+ public static final String DIC_UNIT = "paoding.dic.unit";
+ public static final String DIC_UNIT_DEFAULT = "x-unit";
+
+ // -------------------------------------------------------------
+ // like "Wang", "Zhang", ...
+ public static final String DIC_CONFUCIAN_FAMILY_NAME = "paoding.dic.confucian-family-name";
+ public static final String DIC_CONFUCIAN_FAMILY_NAME_DEFAULT = "x-confucian-family-name";
+
+ // -------------------------------------------------------------
+ // like
+ public static final String DIC_FOR_COMBINATORICS = "paoding.dic.for-combinatorics";
+ public static final String DIC_FOR_COMBINATORICS_DEFAULT = "x-for-combinatorics";
+
+ // -------------------------------------------------------------
+ // like
+ public static final String DIC_DETECTOR_INTERVAL = "paoding.dic.detector.interval";
+ public static final String DIC_DETECTOR_INTERVAL_DEFAULT = "60";
+
+ // -------------------------------------------------------------
+ // like "default", "max", ...
+ public static final String ANALYZER_MODE = "paoding.analyzer.mode";
+ public static final String ANALYZER_MOE_DEFAULT = "most-words";
+
+ // -------------------------------------------------------------
+ //
+ public static final String ANALYZER_DICTIONARIES_COMPILER = "paoding.analyzer.dictionaries.compiler";
+ public static final String ANALYZER_DICTIONARIES_COMPILER_DEFAULT = null;
+
+ // -------------------------------------------------------------
+ private static final Map/* <String, String> */map = new HashMap();
+
+ static {
+ map.put(DIC_HOME_CONFIG_FIRST, DIC_HOME_CONFIG_FIRST_DEFAULT);
+ map.put(DIC_HOME, DIC_HOME_DEFAULT);
+ map.put(DIC_CHARSET, DIC_CHARSET_DEFAULT);
+ map.put(DIC_MAXWORDLEN, DIC_MAXWORDLEN_DEFAULT);
+ map.put(DIC_SKIP_PREFIX, DIC_SKIP_PREFIX_DEFAULT);
+ map.put(DIC_NOISE_CHARACTOR, DIC_NOISE_CHARACTOR_DEFAULT);
+ map.put(DIC_NOISE_WORD, DIC_NOISE_WORD_DEFAULT);
+ map.put(DIC_UNIT, DIC_UNIT_DEFAULT);
+ map.put(DIC_CONFUCIAN_FAMILY_NAME, DIC_CONFUCIAN_FAMILY_NAME_DEFAULT);
+ map.put(DIC_FOR_COMBINATORICS, DIC_FOR_COMBINATORICS_DEFAULT);
+ map.put(DIC_DETECTOR_INTERVAL, DIC_DETECTOR_INTERVAL_DEFAULT);
+ map.put(ANALYZER_MODE, ANALYZER_MOE_DEFAULT);
+ map.put(ANALYZER_DICTIONARIES_COMPILER, ANALYZER_DICTIONARIES_COMPILER_DEFAULT);
+ }
+
+ //
+ public static final String KNIFE_CLASS = "paoding.knife.class.";
+
+ public static String getProperty(Properties p, String name) {
+ return p.getProperty(name, (String) map.get(name));
+ }
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzer.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzer.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzer.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,153 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package net.paoding.analysis.analyzer;
+
+import java.util.Properties;
+
+import net.paoding.analysis.Constants;
+import net.paoding.analysis.analyzer.estimate.TryPaodingAnalyzer;
+import net.paoding.analysis.knife.Knife;
+import net.paoding.analysis.knife.Paoding;
+import net.paoding.analysis.knife.PaodingMaker;
+
+/**
+ * PaodingAnalyzeræ¯åºäºâåºä¸è§£çâæ¡æ¶çLuceneè¯è¯åæå¨ï¼æ¯âåºä¸è§£çâæ¡æ¶å¯¹Luceneçéé
å¨ã
+ * <p>
+ *
+ * PaodingAnalyzeræ¯çº¿ç¨å®å
¨çï¼å¹¶åæ
åµä¸ä½¿ç¨åä¸ä¸ªPaodingAnalyzerå®ä¾æ¯å¯è¡çã<br>
+ * PaodingAnalyzeræ¯å¯å¤ç¨çï¼æ¨è夿¬¡åä¸ä¸ªPaodingAnalyzerå®ä¾ã
+ * <p>
+ *
+ * PaodingAnalyzerèªå¨è¯»å类路å¾ä¸çpaoding-analysis.properties屿§æä»¶ï¼è£
é
PaodingAnalyzer
+ * <p>
+ *
+ * @author Zhiliang Wang [qieqie.wang@gmail.com]
+ *
+ * @see PaodingAnalyzerBean
+ *
+ * @since 1.0
+ *
+ */
+public class PaodingAnalyzer extends PaodingAnalyzerBean {
+
+ /**
+ * æ ¹æ®ç±»è·¯å¾ä¸çpaoding-analysis.propertiesæå»ºä¸ä¸ªPaodingAnalyzer对象
+ * <p>
+ * å¨ä¸ä¸ªJVMä¸ï¼å¯å¤æ¬¡å建ï¼èå¹¶ä¸ä¼å¤æ¬¡è¯»å屿§æä»¶ï¼ä¸ä¼éå¤è¯»ååå
¸ã
+ */
+ public PaodingAnalyzer() {
+ this(PaodingMaker.DEFAULT_PROPERTIES_PATH);
+ }
+
+ /**
+ * @param propertiesPath null表示使ç¨ç±»è·¯å¾ä¸çpaoding-analysis.properties
+ */
+ public PaodingAnalyzer(String propertiesPath) {
+ init(propertiesPath);
+ }
+
+ protected void init(String propertiesPath) {
+ // æ ¹æ®PaodingMaker说æï¼
+ // 1ã夿¬¡è°ç¨getProperties()ï¼è¿åç齿¯åä¸ä¸ªpropertieså®ä¾(åªè¦å±æ§æä»¶æ²¡åçè¿ä¿®æ¹)
+ // 2ãç¸åçpropertieså®ä¾ï¼PaodingMakerä¹å°è¿ååä¸ä¸ªPaodingå®ä¾
+ // æ ¹æ®ä»¥ä¸1ã2ç¹è¯´æï¼å¨æ¤è½å¤ä¿è¯å¤æ¬¡å建PaodingAnalyzerå¹¶ä¸ä¼å¤æ¬¡è£
è½½å±æ§æä»¶åè¯å
¸
+ if (propertiesPath == null) {
+ propertiesPath = PaodingMaker.DEFAULT_PROPERTIES_PATH;
+ }
+ Properties properties = PaodingMaker.getProperties(propertiesPath);
+ String mode = Constants
+ .getProperty(properties, Constants.ANALYZER_MODE);
+ Paoding paoding = PaodingMaker.make(properties);
+ setKnife(paoding);
+ setMode(mode);
+ }
+
+ /**
+ * æ¬æ¹æ³ä¸ºPaodingAnalyzeréå¸¦çæµè¯è¯ä¼°æ¹æ³ã <br>
+ * æ§è¡ä¹å¯ä»¥æ¥çåè¯ææã以ä¸ä»»éä¸ç§æ¹å¼è¿è¡:
+ * <p>
+ *
+ * java net...PaodingAnalyzer<br>
+ * java net...PaodingAnalyzer --help<br>
+ * java net...PaodingAnalyzer ä¸å人æ°å
񆆫<br>
+ * java net...PaodingAnalyzer -m max ä¸å人æ°å
񆆫<br>
+ * java net...PaodingAnalyzer -f c:/text.txt<br>
+ * java net...PaodingAnalyzer -f c:/text.txt -c utf-8<br>
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ if (System.getProperty("paoding.try.app") == null) {
+ System.setProperty("paoding.try.app", "PaodingAnalyzer");
+ System.setProperty("paoding.try.cmd", "java PaodingAnalyzer");
+ }
+ TryPaodingAnalyzer.main(args);
+ }
+
+ // --------------------------------------------------
+
+ /**
+ * @param knife
+ * @param default_mode
+ * @deprecated
+ */
+ public PaodingAnalyzer(Knife knife, int mode) {
+ super(knife, mode);
+ }
+
+ /**
+ * çä»·äºmaxMode()
+ *
+ * @param knife
+ * @return
+ * @deprecated
+ */
+ public static PaodingAnalyzer queryMode(Knife knife) {
+ return maxMode(knife);
+ }
+
+ /**
+ *
+ * @param knife
+ * @return
+ * @deprecated
+ */
+ public static PaodingAnalyzer defaultMode(Knife knife) {
+ return new PaodingAnalyzer(knife, MOST_WORDS_MODE);
+ }
+
+ /**
+ *
+ * @param knife
+ * @return
+ * @deprecated
+ */
+ public static PaodingAnalyzer maxMode(Knife knife) {
+ return new PaodingAnalyzer(knife, MAX_WORD_LENGTH_MODE);
+ }
+
+ /**
+ * çä»·äºdefaultMode()
+ *
+ * @param knife
+ * @return
+ * @deprecated
+ *
+ */
+ public static PaodingAnalyzer writerMode(Knife knife) {
+ return defaultMode(knife);
+ }
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzerBean.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzerBean.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzerBean.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingAnalyzerBean.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,174 @@
+package net.paoding.analysis.analyzer;
+
+import java.io.Reader;
+
+import net.paoding.analysis.analyzer.impl.MaxWordLengthTokenCollector;
+import net.paoding.analysis.analyzer.impl.MostWordsTokenCollector;
+import net.paoding.analysis.knife.Knife;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+
+public class PaodingAnalyzerBean extends Analyzer {
+
+ // -------------------------------------------------
+
+ /**
+ * æå¤åå
+ */
+ public static final int MOST_WORDS_MODE = 1;
+
+ /**
+ * ææå¤§åå
+ */
+ public static final int MAX_WORD_LENGTH_MODE = 2;
+
+ // -------------------------------------------------
+ /**
+ * ç¨äºåPaodingTokenizeræä¾ï¼åè§£ææ¬å符
+ *
+ * @see PaodingTokenizer#next()
+ *
+ */
+ private Knife knife;
+
+ /**
+ * @see #MOST_WORDS_MODE
+ * @see #MAX_WORD_LENGTH_MODE
+ */
+ private int mode = MOST_WORDS_MODE;
+
+ /**
+ *
+ */
+ private Class modeClass;
+
+ // -------------------------------------------------
+
+ public PaodingAnalyzerBean() {
+ }
+
+ /**
+ * @see #setKnife(Knife)
+ * @param knife
+ */
+ public PaodingAnalyzerBean(Knife knife) {
+ this.knife = knife;
+ }
+
+ /**
+ * @see #setKnife(Knife)
+ * @see #setMode(int)
+ * @param knife
+ * @param mode
+ */
+ public PaodingAnalyzerBean(Knife knife, int mode) {
+ this.knife = knife;
+ this.mode = mode;
+ }
+
+ /**
+ * @see #setKnife(Knife)
+ * @see #setMode(int)
+ * @param knife
+ * @param mode
+ */
+ public PaodingAnalyzerBean(Knife knife, String mode) {
+ this.knife = knife;
+ this.setMode(mode);
+ }
+
+ // -------------------------------------------------
+
+ public Knife getKnife() {
+ return knife;
+ }
+
+ public void setKnife(Knife knife) {
+ this.knife = knife;
+ }
+
+ public int getMode() {
+ return mode;
+ }
+
+ /**
+ * 设置åæå¨æ¨¡å¼.
+ * <p>
+ *
+ * @param mode
+ */
+ public void setMode(int mode) {
+ if (mode != MOST_WORDS_MODE && mode != MAX_WORD_LENGTH_MODE) {
+ throw new IllegalArgumentException("wrong mode:" + mode);
+ }
+ this.mode = mode;
+ this.modeClass = null;
+ }
+
+ /**
+ * 设置åæå¨æ¨¡å¼ç±»ã
+ *
+ * @param modeClass
+ * TokenCollectorçå®ç°ç±»ã
+ */
+ public void setModeClass(Class modeClass) {
+ this.modeClass = modeClass;
+ }
+
+ public void setModeClass(String modeClass) {
+ try {
+ this.modeClass = Class.forName(modeClass);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("not found mode class:" + e.getMessage());
+ }
+ }
+
+ public void setMode(String mode) {
+ if (mode.startsWith("class:")) {
+ setModeClass(mode.substring("class:".length()));
+ } else {
+ if ("most-words".equalsIgnoreCase(mode)
+ || "default".equalsIgnoreCase(mode)
+ || ("" + MOST_WORDS_MODE).equals(mode)) {
+ setMode(MOST_WORDS_MODE);
+ } else if ("max-word-length".equalsIgnoreCase(mode)
+ || ("" + MAX_WORD_LENGTH_MODE).equals(mode)) {
+ setMode(MAX_WORD_LENGTH_MODE);
+ }
+ else {
+ throw new IllegalArgumentException("ä¸åæ³çåæå¨Modeåæ°è®¾ç½®:" + mode);
+ }
+ }
+ }
+
+ // -------------------------------------------------
+
+ public TokenStream tokenStream(String fieldName, Reader reader) {
+ if (knife == null) {
+ throw new NullPointerException("knife should be set before token");
+ }
+ // PaodingTokenizeræ¯TokenStreamå®ç°ï¼ä½¿ç¨knifeè§£æreaderæµå
¥çææ¬
+ return new PaodingTokenizer(reader, knife, createTokenCollector());
+ }
+
+ protected TokenCollector createTokenCollector() {
+ if (modeClass != null) {
+ try {
+ return (TokenCollector) modeClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException("wrong mode class:" + e.getMessage());
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("wrong mode class:" + e.getMessage());
+ }
+ }
+ switch (mode) {
+ case MOST_WORDS_MODE:
+ return new MostWordsTokenCollector();
+ case MAX_WORD_LENGTH_MODE:
+ return new MaxWordLengthTokenCollector();
+ default:
+ throw new Error("never happened");
+ }
+ }
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingTokenizer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingTokenizer.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingTokenizer.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/PaodingTokenizer.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,217 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package net.paoding.analysis.analyzer;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Iterator;
+
+import net.paoding.analysis.analyzer.impl.MostWordsTokenCollector;
+import net.paoding.analysis.knife.Beef;
+import net.paoding.analysis.knife.Collector;
+import net.paoding.analysis.knife.Knife;
+import net.paoding.analysis.knife.Paoding;
+
+import org.apache.lucene.analysis.Token;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
+import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
+
+/**
+ * PaodingTokenizeræ¯åºäºâåºä¸è§£çâæ¡æ¶çTokenStreamå®ç°ï¼ä¸ºPaodingAnalyzer使ç¨ã
+ * <p>
+ *
+ * @author Zhiliang Wang [qieqie.wang@gmail.com]
+ *
+ * @see Beef
+ * @see Knife
+ * @see Paoding
+ * @see Tokenizer
+ * @see PaodingAnalyzer
+ *
+ * @see Collector
+ * @see TokenCollector
+ * @see MAxTokenCollector
+ * @see MostWordsTokenCollector
+ *
+ * @since 1.0
+ */
+public final class PaodingTokenizer extends Tokenizer implements Collector {
+
+ // -------------------------------------------------
+
+ /**
+ * ä»input读å
¥çæ»å符æ°
+ */
+ private int inputLength;
+
+ /**
+ *
+ */
+ private static final int bufferLength = 128;
+
+ /**
+ * æ¥æ¶æ¥èª{@link #input}çææ¬å符
+ *
+ * @see #next()
+ */
+ private final char[] buffer = new char[bufferLength];
+
+ /**
+ * {@link buffer}[0]å¨{@link #input}ä¸çåç§»
+ *
+ * @see #collect(String, int, int)
+ * @see #next()
+ */
+ private int offset;
+
+ /**
+ *
+ */
+ private final Beef beef = new Beef(buffer, 0, 0);
+
+ /**
+ *
+ */
+ private int dissected;
+
+ /**
+ * ç¨äºåè§£beefä¸çææ¬å符ï¼ç±PaodingAnalyzeræä¾
+ *
+ * @see #next()
+ */
+ private Knife knife;
+
+ /**
+ *
+ */
+ private TokenCollector tokenCollector;
+
+ /**
+ * tokensè¿ä»£å¨ï¼ç¨äºnext()æ¹æ³é¡ºåºè¯»åtokensä¸çToken对象
+ *
+ * @see #tokens
+ * @see #next()
+ */
+ private Iterator<Token> tokenIteractor;
+
+ private TermAttribute termAtt;
+ private OffsetAttribute offsetAtt;
+ private TypeAttribute typeAtt;
+
+ // -------------------------------------------------
+
+ /**
+ *
+ * @param input
+ * @param knife
+ * @param tokenCollector
+ */
+ public PaodingTokenizer(Reader input, Knife knife,
+ TokenCollector tokenCollector) {
+ this.input = input;
+ this.knife = knife;
+ this.tokenCollector = tokenCollector;
+ init();
+ }
+
+ private void init() {
+ termAtt = addAttribute(TermAttribute.class);
+ offsetAtt = addAttribute(OffsetAttribute.class);
+ typeAtt = addAttribute(TypeAttribute.class);
+ }
+
+ // -------------------------------------------------
+
+ public TokenCollector getTokenCollector() {
+ return tokenCollector;
+ }
+
+ public void setTokenCollector(TokenCollector tokenCollector) {
+ this.tokenCollector = tokenCollector;
+ }
+
+ // -------------------------------------------------
+
+ public void collect(String word, int offset, int end) {
+ tokenCollector.collect(word, this.offset + offset, this.offset + end);
+ }
+
+ // -------------------------------------------------
+ public int getInputLength() {
+ return inputLength;
+ }
+
+ @Override
+ public boolean incrementToken() throws IOException {
+ // å·²ç»ç©·å°½tokensIteractorçToken对象ï¼åç»§ç»è¯·æ±readeræµå
¥æ°æ®
+ while (tokenIteractor == null || !tokenIteractor.hasNext()) {
+ // System.out.println(dissected);
+ int read = 0;
+ int remainning = -1;// éæ°ä»reader读å
¥å符åï¼bufferä¸è¿å©ä¸çå符æ°ï¼è´æ°è¡¨ç¤ºå½åæä¸éè¦ä»readerä¸è¯»å
¥å符
+ if (dissected >= beef.length()) {
+ remainning = 0;
+ } else if (dissected < 0) {
+ remainning = bufferLength + dissected;
+ }
+ if (remainning >= 0) {
+ if (remainning > 0) {
+ System.arraycopy(buffer, -dissected, buffer, 0, remainning);
+ }
+ read = input
+ .read(buffer, remainning, bufferLength - remainning);
+ inputLength += read;
+ int charCount = remainning + read;
+ if (charCount < 0) {
+ // readerå·²å°½ï¼ææ¥å£next()è¦æ±è¿ånull.
+ return false;
+ }
+ if (charCount < bufferLength) {
+ buffer[charCount++] = 0;
+ }
+ // æé âçâï¼å¹¶ä½¿ç¨knifeâè§£âä¹
+ beef.set(0, charCount);
+ offset += Math.abs(dissected);
+ // offset -= remainning;
+ dissected = 0;
+ }
+ dissected = knife.dissect((Collector) this, beef, dissected);
+ // offset += read;// !!!
+ tokenIteractor = tokenCollector.iterator();
+ }
+ // è¿åtokensIteractorä¸ä¸ä¸ªToken对象
+ Token token = tokenIteractor.next();
+ termAtt.setTermBuffer(token.term());
+ offsetAtt.setOffset(correctOffset(token.startOffset()),
+ correctOffset(token.endOffset()));
+ typeAtt.setType("paoding");
+ return true;
+ }
+
+ @Override
+ public void reset() throws IOException {
+ super.reset();
+ offset = 0;
+ inputLength = 0;
+ }
+
+ @Override
+ public void reset(Reader input) throws IOException {
+ super.reset(input);
+ reset();
+ }
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/TokenCollector.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/TokenCollector.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/TokenCollector.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/TokenCollector.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package net.paoding.analysis.analyzer;
+
+import java.util.Iterator;
+
+import org.apache.lucene.analysis.Token;
+
+import net.paoding.analysis.knife.Collector;
+
+/**
+ *
+ * @author Zhiliang Wang [qieqie.wang@gmail.com]
+ *
+ * @since 1.1
+ */
+public interface TokenCollector extends Collector {
+
+ /**
+ *
+ * @return
+ */
+ public Iterator<Token> iterator();
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/Estimate.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/Estimate.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/Estimate.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/Estimate.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,207 @@
+package net.paoding.analysis.analyzer.estimate;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.LinkedList;
+
+import net.paoding.analysis.analyzer.PaodingTokenizer;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
+
+public class Estimate {
+ private Analyzer analyzer;
+ private String print;
+ private PrintGate printGate;
+
+ public Estimate() {
+ this.setPrint("50");// é»è®¤åªæå°å50è¡åè¯ææ
+ }
+
+ public Estimate(Analyzer analyzer) {
+ setAnalyzer(analyzer);
+ this.setPrint("50");// é»è®¤åªæå°å50è¡åè¯ææ
+ }
+
+ public void setAnalyzer(Analyzer analyzer) {
+ this.analyzer = analyzer;
+ }
+
+ public Analyzer getAnalyzer() {
+ return analyzer;
+ }
+
+ public void setPrint(String print) {
+ if (print == null || print.length() == 0
+ || print.equalsIgnoreCase("null")
+ || print.equalsIgnoreCase("no")) {
+ printGate = null;
+ this.print = null;
+ } else {
+ printGate = new LinePrintGate();
+ printGate.setPrint(print, 10);
+ this.print = print;
+ }
+ }
+
+ public String getPrint() {
+ return print;
+ }
+
+ public void test(String input) {
+ this.test(System.out, input);
+ }
+
+ public void test(PrintStream out, String input) {
+ Reader reader = new StringReaderEx(input);
+ this.test(out, reader);
+ }
+
+ public void test(PrintStream out, Reader reader) {
+ try {
+ long begin = System.currentTimeMillis();
+
+ LinkedList<CToken> list = new LinkedList<CToken>();
+ int wordsCount = 0;
+
+ //collect token
+ TokenStream ts = analyzer.tokenStream("", reader);
+ ts.reset();
+ TermAttribute termAtt = (TermAttribute) ts
+ .addAttribute(TermAttribute.class);
+ while (ts.incrementToken()) {
+ if (printGate != null && printGate.filter(wordsCount)) {
+ list.add(new CToken(termAtt.term(), wordsCount));
+ }
+ wordsCount++;
+ }
+
+ long end = System.currentTimeMillis();
+ int c = 0;
+ if (list.size() > 0) {
+ for (CToken ctoken : list) {
+ c = ctoken.i;
+ if (c % 10 == 0) {
+ if (c != 0) {
+ out.println();
+ }
+ out.print((c / 10 + 1) + ":\t");
+ }
+ out.print(ctoken.t + "/");
+ }
+ }
+ if (wordsCount == 0) {
+ System.out.println("\tAll are noise characters or words");
+ } else {
+ if (c % 10 != 1) {
+ System.out.println();
+ }
+ String inputLength = "<æªç¥>";
+ if (reader instanceof StringReaderEx) {
+ inputLength = "" + ((StringReaderEx) reader).inputLength;
+ } else if (ts instanceof PaodingTokenizer) {
+ inputLength = "" + ((PaodingTokenizer) ts).getInputLength();
+ }
+ System.out.println();
+ System.out.println("\tåè¯å¨" + analyzer.getClass().getName());
+ System.out.println("\tå
容é¿åº¦ " + inputLength + "åç¬¦ï¼ å "
+ + wordsCount + "个è¯");
+ System.out.println("\tåè¯èæ¶ " + (end - begin) + "ms ");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ // -------------------------------------------
+
+ static class CToken {
+ String t;
+ int i;
+
+ CToken(String t, int i) {
+ this.t = t;
+ this.i = i;
+ }
+ }
+
+ static interface PrintGate {
+ public void setPrint(String print, int unitSize);
+
+ boolean filter(int count);
+ }
+
+ static class PrintGateToken implements PrintGate {
+ private int begin;
+ private int end;
+
+ public void setBegin(int begin) {
+ this.begin = begin;
+ }
+
+ public void setEnd(int end) {
+ this.end = end;
+ }
+
+ public void setPrint(String print, int unitSize) {
+ int i = print.indexOf('-');
+ if (i > 0) {
+ int bv = Integer.parseInt(print.substring(0, i));
+ int ev = Integer.parseInt(print.substring(i + 1));
+ setBegin(unitSize * (Math.abs(bv) - 1));// 第5è¡ï¼æ¯ä»ç¬¬40å¼å§ç
+ setEnd(unitSize * Math.abs(ev));// å°ç¬¬10è¡ï¼æ¯æªæ¢äº100(ä¸å
å«è¯¥è¾¹ç)
+ } else {
+ setBegin(0);
+ int v = Integer.parseInt(print);
+ setEnd(unitSize * (Math.abs(v)));
+ }
+ }
+
+ public boolean filter(int count) {
+ return count >= begin && count < end;
+ }
+ }
+
+ static class LinePrintGate implements PrintGate {
+
+ private PrintGate[] list;
+
+ public void setPrint(String print, int unitSize) {
+ String[] prints = print.split(",");
+ list = new PrintGate[prints.length];
+ for (int i = 0; i < prints.length; i++) {
+ PrintGateToken pg = new PrintGateToken();
+ pg.setPrint(prints[i], unitSize);
+ list[i] = pg;
+ }
+ }
+
+ public boolean filter(int count) {
+ for (int i = 0; i < list.length; i++) {
+ if (list[i].filter(count)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ }
+
+ static class StringReaderEx extends StringReader {
+ private int inputLength;
+
+ public StringReaderEx(String s) {
+ super(s);
+ inputLength = s.length();
+ }
+ }
+
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/TryPaodingAnalyzer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/TryPaodingAnalyzer.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/TryPaodingAnalyzer.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/estimate/TryPaodingAnalyzer.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,299 @@
+package net.paoding.analysis.analyzer.estimate;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+import net.paoding.analysis.analyzer.PaodingAnalyzer;
+import net.paoding.analysis.knife.PaodingMaker;
+
+import org.apache.lucene.analysis.Analyzer;
+
+public class TryPaodingAnalyzer {
+ private static final String ARGS_TIP = ":";
+ static String input = null;
+ static String file = null;
+ static Reader reader = null;
+ static String charset = null;
+ static String mode = null;
+ static String analyzerName = null;
+ static String print = null;
+ static String properties = PaodingMaker.DEFAULT_PROPERTIES_PATH;
+
+ public static void main(String[] args) {
+ try {
+ resetArgs();
+
+ int inInput = 0;
+ for (int i = 0; i < args.length; i++) {
+ if (args[i] == null || (args[i] = args[i].trim()).length() == 0) {
+ continue;
+ }
+ if (args[i].equals("--file") || args[i].equals("-f")) {
+ file = args[++i];
+ } else if (args[i].equals("--charset") || args[i].equals("-c")) {
+ charset = args[++i];
+ } else if (args[i].equals("--mode") || args[i].equals("-m")) {
+ mode = args[++i];
+ } else if (args[i].equals("--properties") || args[i].equals("-p")) {
+ properties = args[++i];
+ } else if (args[i].equals("--analyzer") || args[i].equals("-a")) {
+ analyzerName = args[++i];
+ } else if (args[i].equals("--print") || args[i].equals("-P")) {
+ print = args[++i];
+ } else if (args[i].equals("--input") || args[i].equals("-i")) {
+ inInput++;
+ } else if (args[i].equals("--help") || args[i].equals("-h")
+ || args[i].equals("?")) {
+ printHelp();
+ return;
+ } else {
+ // éé项çåæ°æ°ç»è§ä¸ºinput
+ if (!args[i].startsWith("-")
+ && (i == 0 || args[i - 1].equals("-i") || args[i - 1].equals("--input") || !args[i - 1].startsWith("-"))) {
+ if (input == null) {
+ input = args[i];// !!没æ++i
+ } else {
+ input = input + ' ' + args[i];// !!没æ++i
+ }
+ inInput++;
+ }
+ }
+ }
+ if (file != null) {
+ input = null;
+ reader = getReader(file, charset);
+ }
+ //
+ analysing();
+ } catch (Exception e1) {
+ resetArgs();
+ e1.printStackTrace();
+ }
+ }
+
+
+
+ private static void resetArgs() {
+ input = null;
+ file = null;
+ reader = null;
+ charset = null;
+ mode = null;
+ print = null;
+ analyzerName = null;
+ properties = PaodingMaker.DEFAULT_PROPERTIES_PATH;
+ }
+
+
+
+ private static void analysing() throws Exception {
+ Analyzer analyzer;
+ if (analyzerName == null || analyzerName.length() == 0 || analyzerName.equalsIgnoreCase("paoding")) {
+ //properties==nullçåäºnew new PaodingAnalyzer();
+ analyzer = new PaodingAnalyzer(properties);
+ if (mode != null) {
+ ((PaodingAnalyzer) analyzer).setMode(mode);
+ }
+ }
+ else {
+ Class clz;
+ if (analyzerName.equalsIgnoreCase("standard")) {
+ analyzerName = "org.apache.lucene.analysis.standard.StandardAnalyzer";
+ }
+ else if (analyzerName.equalsIgnoreCase("cjk")) {
+ analyzerName = "org.apache.lucene.analysis.cjk.CJKAnalyzer";
+ }
+ else if (analyzerName.equalsIgnoreCase("cn") || analyzerName.equalsIgnoreCase("chinese")) {
+ analyzerName = "org.apache.lucene.analysis.cn.ChineseAnalyzer";
+ }
+ else if (analyzerName.equalsIgnoreCase("st") || analyzerName.equalsIgnoreCase("standard")) {
+ analyzerName = "org.apache.lucene.analysis.standard.StandardAnalyzer";
+ }
+ clz = Class.forName(analyzerName);
+ analyzer = (Analyzer) clz.newInstance();
+ }
+ boolean readInputFromConsle = false;
+ Estimate estimate = new Estimate(analyzer);
+ if (print != null) {
+ estimate.setPrint(print);
+ }
+ while (true) {
+ if (reader == null) {
+ if (input == null || input.length() == 0 || readInputFromConsle) {
+ input = getInputFromConsole();
+ readInputFromConsle = true;
+ }
+ if (input == null || input.length() == 0) {
+ System.out.println("Warn: none charactors you input!!");
+ continue;
+ }
+ else if (input.startsWith(ARGS_TIP)) {
+ String argsStr = input.substring(ARGS_TIP.length());
+ main(argsStr.split(" "));
+ continue;
+ }
+ }
+ if (reader != null) {
+ estimate.test(System.out, reader);
+ reader = null;
+ }
+ else {
+ estimate.test(System.out, input);
+ input = null;
+ }
+ System.out.println("--------------------------------------------------");
+ if (false == readInputFromConsle) {
+ return;
+ }
+ }
+ }
+
+ private static String getInputFromConsole() throws IOException {
+ printTitleIfNotPrinted("");
+ String input = null;
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ System.in));
+ String line;
+ do {
+ System.out.print("paoding> ");
+ line = reader.readLine();
+ if (line == null || line.length() == 0) {
+ continue;
+ }
+ if (line.equals(ARGS_TIP + "clear") || line.equals(ARGS_TIP + "c")) {
+ input = null;
+ System.out.println("paoding> Cleared");
+ return getInputFromConsole();
+ }
+ else if (line.equals(ARGS_TIP + "exit") || line.equals(ARGS_TIP + "quit") || line.equals(ARGS_TIP + "e") || line.equals(ARGS_TIP + "q") ) {
+ System.out.println("Bye!");
+ System.exit(0);
+ }
+ else if (input == null && line.startsWith(ARGS_TIP)) {
+ input = line;
+ break;
+ }
+ else {
+ if (line.endsWith(";")) {
+ if (line.length() > ";".length()) {
+ input = line.substring(0, line.length() - ";".length());
+ }
+ break;
+ }
+ else {
+ if (input == null) {
+ input = line;
+ } else {
+ input = input + "\n" + line;
+ }
+ }
+ }
+ } while (true);
+ return input == null ? null : input.trim();
+ }
+
+ private static void printHelp() {
+ String app = System.getProperty("paoding.try.app",
+ "TryPaodingAnalyzer");
+ String cmd = System.getProperty("paoding.try.cmd", "java "
+ + TryPaodingAnalyzer.class.getName());
+ System.out.println(app + "çç¨æ³:");
+ System.out.println("\t" + cmd + " [OPTIONS] [text_content]");
+ System.out.println("\nOPTIONS:");
+ System.out.println("\t--file, -f:\n\t\tæç« 以æä»¶çå½¢å¼è¾å
¥ï¼å¨åç¼å ä¸\"classpath:\"表示ä»ç±»è·¯å¾ä¸å¯»æ¾è¯¥æä»¶ã");
+ System.out.println("\t--charset, -c:\n\t\tæç« çå符éç¼ç ï¼æ¯å¦gbk,utf-8çãå¦ææ²¡æè®¾ç½®è¯¥é项ï¼å使ç¨Javaç¯å¢é»è®¤çå符éç¼ç ã");
+ System.out.println("\t--properties, -p:\n\t\tä¸è¯»åé»è®¤ç类路å¾ä¸çåºä¸åè¯å±æ§æä»¶ï¼èä½¿ç¨æå®çæä»¶ï¼å¨åç¼å ä¸\"classpath:\"表示ä»ç±»è·¯å¾ä¸å¯»æ¾è¯¥æä»¶ã");
+ System.out.println("\t--mode, -m:\n\t\t强å¶ä½¿ç¨ç»å®çmodeçåè¯å¨ï¼å¯ä»¥è®¾å®ä¸ºdefault,most-words,max-word-lengthææå®ç±»åçå
¶ä»mode(æå®ç±»åçï¼éè¦å åç¼\"class:\")ã");
+ System.out.println("\t--input, -i:\n\t\tè¦è¢«åè¯çæç« å
容ï¼å½æ²¡æéè¿-fæ--fileæå®æç« è¾å
¥æä»¶æ¶å¯éæ©è¿ä¸ªé项æå®è¦è¢«åè¯çå
容ã");
+ System.out.println("\t--analyzer, -a:\n\t\tæµè¯å
¶ä»åè¯å¨ï¼éè¿--analyzeræ-aæå®å
¶å®æ´ç±»åãç¹å«å°ï¼paodingãcjkãchineseãståå«å¯¹åºPaodingAnalyzerãCJKAnalyzerãChineseAnalyzerãStandardAnalyzer");
+ System.out.println("\t--print, -P:\n\t\t æ¯å¦æå°åè¯ç»æãé»è®¤æå°å50è¡ãè§åï¼noè¡¨ç¤ºä¸æå°ï¼50çä»·äº1-50è¡ï¼1-50表示æå°1è³50è¡;å¯ä»¥ä»¥éå·ç»å使ç¨ï¼å¦20,40-50表示æå°1-20以å40-50è¡");
+ System.out.println("\n示ä¾:");
+ System.out.println("\t" + cmd);
+ System.out.println("\t" + cmd + " ?");
+ System.out.println("\t" + cmd + " ä¸å人æ°å
񆆫");
+ System.out.println("\t" + cmd + " -m max ä¸å人æ°å
񆆫");
+ System.out.println("\t" + cmd + " -f e:/content.txt -c utf8");
+ System.out.println("\t" + cmd + " -f e:/content.txt -c utf8 -m max-word-length");
+ System.out.println("\t" + cmd + " -f e:/content.txt -c utf8 -a cjk");
+ System.out.println("\nè¥æ¯æ§å¶å°è¿å
¥\"paoding>\"å:");
+ titlePrinted = false;
+ printTitleIfNotPrinted("\t");
+ }
+
+
+ private static boolean titlePrinted = false;
+ private static boolean welcomePrinted = false;
+ private static void printTitleIfNotPrinted(String prefix) {
+ if (!titlePrinted) {
+ System.out.println();
+ if (!welcomePrinted) {
+ System.out.println("Welcome to Paoding Analyser(2.0.4-alpha2)");
+ System.out.println();
+ welcomePrinted = true;
+ }
+ System.out.println(prefix + "ç´æ¥è¾å
¥æç²è´´è¦è¢«åè¯çå
容ï¼ä»¥åå·;ç»æï¼å车åå¼å§åè¯ã");
+ System.out.println(prefix + "å¦èµ·ä¸è¡è¾å
¥:clearæ:cï¼ä½¿æ¤æ¬¡è¾å
¥æ æï¼ç¨ä»¥éæ°è¾å
¥ã");
+ System.out.println(prefix + "è¦ä½¿ç¨å½ä»¤è¡åæ°è¯»å
¥æä»¶å
容æå
¶ä»åæ°è¯·ä»¥åå·:å¼å§ï¼ç¶åè¾å
¥åæ°é项ã");
+ System.out.println(prefix + "éåºï¼è¯·è¾å
¥:quitæ:qã:exitã:e");
+ System.out.println(prefix + "éè¦å¸®å©ï¼è¯·è¾å
¥:?");
+ System.out.println(prefix + "注æï¼æå®å¯¹æä»¶åè¯ä¹åè¦äºè§£è¯¥æä»¶çç¼ç ï¼å¦æç³»ç»ç¼ç åæä»¶ç¼ç ä¸ä¸è´ï¼è¦éè¿-cæå®æä»¶çç¼ç ã");
+ System.out.println();
+ titlePrinted = true;
+ }
+ }
+
+
+ static String getContent(String path, String encoding) throws IOException {
+ return (String) read(path, encoding, true);
+ }
+
+ static Reader getReader(String path, String encoding) throws IOException {
+ return (Reader) read(path, encoding, false);
+ }
+
+ static Object read(String path, String encoding, boolean return_string) throws IOException {
+ InputStream in;
+ if (path.startsWith("classpath:")) {
+ path = path.substring("classpath:".length());
+ URL url = Estimate.class.getClassLoader().getResource(path);
+ if (url == null) {
+ throw new IllegalArgumentException("Not found " + path
+ + " in classpath.");
+ }
+ System.out.println("read content from:" + url.getFile());
+ in = url.openStream();
+ } else {
+ File f = new File(path);
+ if (!f.exists()) {
+ throw new IllegalArgumentException("Not found " + path
+ + " in system.");
+ }
+ System.out.println("read content from:" + f.getAbsolutePath());
+ in = new FileInputStream(f);
+ }
+ Reader re;
+ if (encoding != null) {
+ re = new InputStreamReader(in, encoding);
+ } else {
+ re = new InputStreamReader(in);
+ }
+ if (!return_string) {
+ return re;
+ }
+ char[] chs = new char[1024];
+ int count;
+ // 为å
¼å®¹ä½çæ¬çJDKï¼ä½¿ç¨StringBufferè䏿¯StringBuilder
+ StringBuffer content = new StringBuffer();
+ while ((count = re.read(chs)) != -1) {
+ content.append(chs, 0, count);
+ }
+ re.close();
+ return content.toString();
+ }
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/CompiledFileDictionaries.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/CompiledFileDictionaries.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/CompiledFileDictionaries.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/CompiledFileDictionaries.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,336 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package net.paoding.analysis.analyzer.impl;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import net.paoding.analysis.dictionary.BinaryDictionary;
+import net.paoding.analysis.dictionary.Dictionary;
+import net.paoding.analysis.dictionary.HashBinaryDictionary;
+import net.paoding.analysis.dictionary.Word;
+import net.paoding.analysis.dictionary.support.detection.Detector;
+import net.paoding.analysis.dictionary.support.detection.DifferenceListener;
+import net.paoding.analysis.dictionary.support.filewords.FileWordsReader;
+import net.paoding.analysis.exception.PaodingAnalysisException;
+import net.paoding.analysis.knife.CJKKnife;
+import net.paoding.analysis.knife.Dictionaries;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 䏿åå
¸ç¼åæ ¹æ®å°,为{@link CJKKnife}æç¨ã<br>
+ * 仿¬å¯¹è±¡å¯ä»¥è·å䏿éè¦çç¸å
³åå
¸ãå
æ¬è¯æ±è¡¨ãå§æ°è¡¨ã计éåä½è¡¨ã忽ç¥çè¯æååçã
+ * <p>
+ *
+ * @author Zhiliang Wang [qieqie.wang@gmail.com]
+ *
+ * @see CJKKnife
+ *
+ * @since 1.0
+ */
+public class CompiledFileDictionaries implements Dictionaries {
+
+ // -------------------------------------------------
+
+ protected Logger log = LoggerFactory.getLogger(CompiledFileDictionaries.class);
+
+ // -------------------------------------------------
+
+ /**
+ * è¯æ±è¡¨åå
¸
+ */
+ protected Dictionary vocabularyDictionary;
+
+ /**
+ * lantin+cjkçè¯å
¸
+ */
+ protected Dictionary combinatoricsDictionary;
+
+ /**
+ * å§æ°åå
¸
+ *
+ */
+ protected Dictionary confucianFamilyNamesDictionary;
+
+ /**
+ * 忽ç¥çåå
+ */
+ protected Dictionary noiseCharactorsDictionary;
+
+ /**
+ * 忽ç¥çè¯è¯
+ *
+ */
+ protected Dictionary noiseWordsDictionary;
+
+ /**
+ * 计éåä½
+ */
+ protected Dictionary unitsDictionary;
+
+ // -------------------------------------------------
+
+ protected String dicHome;
+ protected String noiseCharactor;
+ protected String noiseWord;
+ protected String unit;
+ protected String confucianFamilyName;
+ protected String combinatorics;
+ protected String charsetName;
+ protected int maxWordLen;
+
+ // ----------------------
+
+ public CompiledFileDictionaries() {
+ }
+
+ public CompiledFileDictionaries(String dicHome, String noiseCharactor,
+ String noiseWord, String unit, String confucianFamilyName,
+ String combinatorics, String charsetName, int maxWordLen) {
+ this.dicHome = dicHome;
+ this.noiseCharactor = noiseCharactor;
+ this.noiseWord = noiseWord;
+ this.unit = unit;
+ this.confucianFamilyName = confucianFamilyName;
+ this.combinatorics = combinatorics;
+ this.charsetName = charsetName;
+ this.maxWordLen = maxWordLen;
+ }
+
+ public String getDicHome() {
+ return dicHome;
+ }
+
+ public void setDicHome(String dicHome) {
+ this.dicHome = dicHome;
+ }
+
+ public String getNoiseCharactor() {
+ return noiseCharactor;
+ }
+
+ public void setNoiseCharactor(String noiseCharactor) {
+ this.noiseCharactor = noiseCharactor;
+ }
+
+ public String getNoiseWord() {
+ return noiseWord;
+ }
+
+ public void setNoiseWord(String noiseWord) {
+ this.noiseWord = noiseWord;
+ }
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public void setUnit(String unit) {
+ this.unit = unit;
+ }
+
+ public String getConfucianFamilyName() {
+ return confucianFamilyName;
+ }
+
+ public void setConfucianFamilyName(String confucianFamilyName) {
+ this.confucianFamilyName = confucianFamilyName;
+ }
+
+ public String getCharsetName() {
+ return charsetName;
+ }
+
+ public void setCharsetName(String charsetName) {
+ this.charsetName = charsetName;
+ }
+
+ public int getMaxWordLen() {
+ return maxWordLen;
+ }
+
+ public void setMaxWordLen(int maxWordLen) {
+ this.maxWordLen = maxWordLen;
+ }
+
+ public void setLantinFllowedByCjk(String lantinFllowedByCjk) {
+ this.combinatorics = lantinFllowedByCjk;
+ }
+
+ public String getLantinFllowedByCjk() {
+ return combinatorics;
+ }
+
+ // -------------------------------------------------
+
+ /**
+ * è¯æ±è¡¨åå
¸
+ *
+ * @return
+ */
+ public synchronized Dictionary getVocabularyDictionary() {
+ if (vocabularyDictionary == null) {
+ // å¤§æ¦æ5639个åæè¯è¯ï¼æ
å0x2fff=x^13>8000>8000*0.75=6000>5639
+ vocabularyDictionary = new HashBinaryDictionary(
+ getVocabularyWords(), 0x2fff, 0.75f);
+ }
+ return vocabularyDictionary;
+ }
+
+ /**
+ * å§æ°åå
¸
+ *
+ * @return
+ */
+ public synchronized Dictionary getConfucianFamilyNamesDictionary() {
+ if (confucianFamilyNamesDictionary == null) {
+ confucianFamilyNamesDictionary = new BinaryDictionary(
+ getConfucianFamilyNames());
+ }
+ return confucianFamilyNamesDictionary;
+ }
+
+ /**
+ * 忽ç¥çè¯è¯
+ *
+ * @return
+ */
+ public synchronized Dictionary getNoiseCharactorsDictionary() {
+ if (noiseCharactorsDictionary == null) {
+ noiseCharactorsDictionary = new HashBinaryDictionary(
+ getNoiseCharactors(), 256, 0.75f);
+ }
+ return noiseCharactorsDictionary;
+ }
+
+ /**
+ * 忽ç¥çåå
+ *
+ * @return
+ */
+ public synchronized Dictionary getNoiseWordsDictionary() {
+ if (noiseWordsDictionary == null) {
+ noiseWordsDictionary = new BinaryDictionary(getNoiseWords());
+ }
+ return noiseWordsDictionary;
+ }
+
+ /**
+ * 计éåä½
+ *
+ * @return
+ */
+ public synchronized Dictionary getUnitsDictionary() {
+ if (unitsDictionary == null) {
+ unitsDictionary = new HashBinaryDictionary(getUnits(), 1024, 0.75f);
+ }
+ return unitsDictionary;
+ }
+
+ public synchronized Dictionary getCombinatoricsDictionary() {
+ if (combinatoricsDictionary == null) {
+ combinatoricsDictionary = new BinaryDictionary(
+ getCombinatoricsWords());
+ }
+ return combinatoricsDictionary;
+ }
+
+ private Detector detector;
+
+ public synchronized void startDetecting(int interval, DifferenceListener l) {
+ if (detector != null || interval < 0) {
+ return;
+ }
+ Detector detector = new Detector();
+ detector.setHome(dicHome);
+ detector.setFilter(null);
+ detector.setFilter(new FileFilter() {
+ public boolean accept(File pathname) {
+ return pathname.getPath().endsWith(".dic.compiled")
+ || pathname.getPath().endsWith(".metadata");
+ }
+ });
+ detector.setLastSnapshot(detector.flash());
+ detector.setListener(l);
+ detector.setInterval(interval);
+ detector.start(true);
+ this.detector = detector;
+ }
+
+ public synchronized void stopDetecting() {
+ if (detector == null) {
+ return;
+ }
+ detector.setStop();
+ detector = null;
+ }
+
+ // ---------------------------------------------------------------
+ // 以ä¸ä¸ºè¾
婿§çæ¹å¼-ç±»ç§ææpackageç§æ
+
+ protected Word[] getDictionaryWords(String dicNameRelativeDicHome) {
+ File f = new File(this.dicHome, "/" + dicNameRelativeDicHome
+ + ".dic.compiled");
+ if (!f.exists()) {
+ return new Word[0];
+ }
+ try {
+ Map map = FileWordsReader.readWords(f.getAbsolutePath(),
+ charsetName, maxWordLen, LinkedList.class, ".dic.compiled");
+ List wordsList = (List) map.values().iterator().next();
+ return (Word[]) wordsList.toArray(new Word[wordsList.size()]);
+ } catch (IOException e) {
+ throw toRuntimeException(e);
+ }
+ }
+
+
+ protected Word[] getVocabularyWords() {
+ return getDictionaryWords("vocabulary");
+ }
+
+ protected Word[] getConfucianFamilyNames() {
+ return getDictionaryWords(confucianFamilyName);
+ }
+
+ protected Word[] getNoiseWords() {
+ return getDictionaryWords(noiseWord);
+ }
+
+ protected Word[] getNoiseCharactors() {
+ return getDictionaryWords(noiseCharactor);
+ }
+
+ protected Word[] getUnits() {
+ return getDictionaryWords(unit);
+ }
+
+ protected Word[] getCombinatoricsWords() {
+ return getDictionaryWords(combinatorics);
+ }
+
+ // --------------------------------------
+
+ protected RuntimeException toRuntimeException(IOException e) {
+ return new PaodingAnalysisException(e);
+ }
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MaxWordLengthTokenCollector.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MaxWordLengthTokenCollector.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MaxWordLengthTokenCollector.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MaxWordLengthTokenCollector.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,92 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package net.paoding.analysis.analyzer.impl;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+
+import net.paoding.analysis.analyzer.TokenCollector;
+
+import org.apache.lucene.analysis.Token;
+
+
+/**
+ *
+ * @author Zhiliang Wang [qieqie.wang@gmail.com]
+ *
+ * @since 1.1
+ */
+public class MaxWordLengthTokenCollector implements TokenCollector {
+
+ /**
+ * åå¨å½å被knifeåè§£èæçToken对象
+ *
+ */
+ private LinkedList/* <Token> */ tokens = new LinkedList/* <Token> */();
+
+ private Token candidate;
+
+ private Token last;
+
+ public Iterator/* <Token> */ iterator() {
+ if (candidate != null) {
+ this.tokens.add(candidate);
+ candidate = null;
+ }
+ Iterator/* <Token> */ iter = this.tokens.iterator();
+ this.tokens = new LinkedList/* <Token> */();
+ return iter;
+ }
+
+ public void collect(String word, int offset, int end) {
+ Token c = candidate != null ? candidate : last;
+ if (c == null) {
+ candidate = new Token(word, offset, end);
+ } else if (offset == c.startOffset()) {
+ if (end > c.endOffset()) {
+ candidate = new Token(word, offset, end);
+ }
+ } else if (offset > c.startOffset()) {
+ if (candidate != null) {
+ select(candidate);
+ }
+ if (end > c.endOffset()) {
+ candidate = new Token(word, offset, end);
+ } else {
+ candidate = null;
+ }
+ } else if (end >= c.endOffset()) {
+ if (last != null && last.startOffset() >= offset
+ && last.endOffset() <= end) {
+ for (Iterator/* <Token> */ iter = tokens.iterator(); iter.hasNext();) {
+ last = (Token) iter.next();
+ if (last.startOffset() >= offset && last.endOffset() <= end) {
+ iter.remove();
+ }
+ }
+ }
+ last = null;
+ candidate = new Token(word, offset, end);
+ }
+ }
+
+ protected void select(Token t) {
+ this.tokens.add(t);
+ this.last = t;
+ }
+
+}
Added: stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MostWordsModeDictionariesCompiler.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MostWordsModeDictionariesCompiler.java?rev=1428467&view=auto
==============================================================================
--- stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MostWordsModeDictionariesCompiler.java (added)
+++ stanbol/trunk/commons/solr/extras/paoding/src/main/java/net/paoding/analysis/analyzer/impl/MostWordsModeDictionariesCompiler.java Thu Jan 3 16:56:34 2013
@@ -0,0 +1,230 @@
+package net.paoding.analysis.analyzer.impl;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.BitSet;
+import java.util.Properties;
+
+import net.paoding.analysis.Constants;
+import net.paoding.analysis.dictionary.Dictionary;
+import net.paoding.analysis.dictionary.Hit;
+import net.paoding.analysis.dictionary.Word;
+import net.paoding.analysis.dictionary.support.detection.Snapshot;
+import net.paoding.analysis.knife.Beef;
+import net.paoding.analysis.knife.Collector;
+import net.paoding.analysis.knife.Dictionaries;
+import net.paoding.analysis.knife.DictionariesCompiler;
+import net.paoding.analysis.knife.Knife;
+
+public class MostWordsModeDictionariesCompiler implements DictionariesCompiler {
+ public static final String VERSION = "2";
+
+ public boolean shouldCompile(Properties p) throws Exception {
+ String dicHome = p.getProperty("paoding.dic.home.absolute.path");
+ File dicHomeFile = new File(dicHome);
+ File compliedMetadataFile = new File(dicHomeFile, ".compiled/most-words-mode/.metadata");
+ if (compliedMetadataFile.exists() && compliedMetadataFile.isFile()) {
+ // get checksum for all compiled dictionaries
+ String checksum = Snapshot.flash(
+ new File(dicHomeFile, ".compiled/most-words-mode"),
+ new FileFilter() {
+ public boolean accept(File pathname) {
+ return pathname.getPath().endsWith(".dic.compiled");
+ }
+ }).getCheckSum();
+
+ Properties compiledProperties = new Properties();
+ InputStream compiledPropertiesInput = new FileInputStream(compliedMetadataFile);
+ compiledProperties.load(compiledPropertiesInput);
+ compiledPropertiesInput.close();
+ String compiledCheckSum = compiledProperties.getProperty("paoding.analysis.compiler.checksum");
+ String clazz = compiledProperties.getProperty("paoding.analysis.compiler.class");
+ String version = compiledProperties.getProperty("paoding.analysis.compiler.version");
+ if (checksum.equals(compiledCheckSum) && this.getClass().getName().equalsIgnoreCase(clazz)
+ && VERSION.equalsIgnoreCase(version)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public void compile(Dictionaries dictionaries, Knife knife, Properties p) throws Exception {
+ String dicHome = p.getProperty("paoding.dic.home.absolute.path");
+ String noiseCharactor = getProperty(p, Constants.DIC_NOISE_CHARACTOR);
+ String noiseWord = getProperty(p, Constants.DIC_NOISE_WORD);
+ String unit = getProperty(p, Constants.DIC_UNIT);
+ String confucianFamilyName = getProperty(p, Constants.DIC_CONFUCIAN_FAMILY_NAME);
+ String combinatorics = getProperty(p, Constants.DIC_FOR_COMBINATORICS);
+ String charsetName = getProperty(p, Constants.DIC_CHARSET);
+
+ File dicHomeFile = new File(dicHome);
+ File compiledDicHomeFile = new File(dicHomeFile, ".compiled/most-words-mode");
+ compiledDicHomeFile.mkdirs();
+ //
+ Dictionary vocabularyDictionary = dictionaries.getVocabularyDictionary();
+ File vocabularyFile = new File(compiledDicHomeFile, "vocabulary.dic.compiled");
+ compileVocabulary(vocabularyDictionary, knife, vocabularyFile, charsetName);
+
+ //
+ Dictionary noiseCharactorsDictionary = dictionaries.getNoiseCharactorsDictionary();
+ File noiseCharactorsDictionaryFile = new File(compiledDicHomeFile, noiseCharactor + ".dic.compiled");
+ sortCompile(noiseCharactorsDictionary, noiseCharactorsDictionaryFile, charsetName);
+ //
+ Dictionary noiseWordsDictionary = dictionaries.getNoiseWordsDictionary();
+ File noiseWordsDictionaryFile = new File(compiledDicHomeFile, noiseWord + ".dic.compiled");
+ sortCompile(noiseWordsDictionary, noiseWordsDictionaryFile, charsetName);
+ //
+ Dictionary unitsDictionary = dictionaries.getUnitsDictionary();
+ File unitsDictionaryFile = new File(compiledDicHomeFile, unit + ".dic.compiled");
+ sortCompile(unitsDictionary, unitsDictionaryFile, charsetName);
+ //
+ Dictionary confucianFamilyDictionary = dictionaries.getConfucianFamilyNamesDictionary();
+ File confucianFamilyDictionaryFile = new File(compiledDicHomeFile, confucianFamilyName + ".dic.compiled");
+ sortCompile(confucianFamilyDictionary, confucianFamilyDictionaryFile, charsetName);
+ //
+ Dictionary combinatoricsDictionary = dictionaries.getCombinatoricsDictionary();
+ File combinatoricsDictionaryFile = new File(compiledDicHomeFile, combinatorics + ".dic.compiled");
+ sortCompile(combinatoricsDictionary, combinatoricsDictionaryFile, charsetName);
+
+ //
+ File compliedMetadataFile = new File(dicHomeFile, ".compiled/most-words-mode/.metadata");
+ if (compliedMetadataFile.exists()) {
+ //compliedMetadataFile.setWritable(true);
+ compliedMetadataFile.delete();
+ }
+ else {
+ compliedMetadataFile.getParentFile().mkdirs();
+ }
+ OutputStream compiledPropertiesOutput = new FileOutputStream(compliedMetadataFile);
+ Properties compiledProperties = new Properties();
+ String lastModifiedsKey = "paoding.analysis.properties.lastModifieds";
+ String filesKey = "paoding.analysis.properties.files";
+ compiledProperties.setProperty(lastModifiedsKey, p.getProperty(lastModifiedsKey));
+ compiledProperties.setProperty(filesKey, p.getProperty(filesKey));
+ compiledProperties.setProperty("paoding.analysis.compiler.checksum",
+ Snapshot.flash(
+ new File(dicHomeFile, ".compiled/most-words-mode"),
+ new FileFilter() {
+ public boolean accept(File pathname) {
+ return pathname.getPath().endsWith(
+ ".dic.compiled");
+ }
+ }).getCheckSum());
+ compiledProperties.setProperty("paoding.analysis.compiler.class", this.getClass().getName());
+ compiledProperties.setProperty("paoding.analysis.compiler.version", VERSION);
+ compiledProperties.store(compiledPropertiesOutput, "dont edit it! this file was auto generated by paoding.");
+ compiledPropertiesOutput.close();
+ compliedMetadataFile.setReadOnly();
+ }
+
+
+ public Dictionaries readCompliedDictionaries(Properties p) {
+ String dicHomeAbsolutePath = p.getProperty("paoding.dic.home.absolute.path");
+ String noiseCharactor = getProperty(p, Constants.DIC_NOISE_CHARACTOR);
+ String noiseWord = getProperty(p, Constants.DIC_NOISE_WORD);
+ String unit = getProperty(p, Constants.DIC_UNIT);
+ String confucianFamilyName = getProperty(p, Constants.DIC_CONFUCIAN_FAMILY_NAME);
+ String combinatorics = getProperty(p, Constants.DIC_FOR_COMBINATORICS);
+ String charsetName = getProperty(p, Constants.DIC_CHARSET);
+ int maxWordLen = Integer.valueOf(getProperty(p, Constants.DIC_MAXWORDLEN));
+ return new CompiledFileDictionaries(
+ dicHomeAbsolutePath + "/.compiled/most-words-mode",
+ noiseCharactor, noiseWord, unit,
+ confucianFamilyName, combinatorics, charsetName,maxWordLen);
+ }
+
+ private static String getProperty(Properties p, String name) {
+ return Constants.getProperty(p, name);
+ }
+
+
+ private void sortCompile(final Dictionary dictionary,
+ File dicFile, String charsetName) throws FileNotFoundException,
+ IOException, UnsupportedEncodingException {
+ int wordsSize = dictionary.size();
+ if (dicFile.exists()) {
+ //dicFile.setWritable(true);
+ dicFile.delete();
+ }
+ BufferedOutputStream out = new BufferedOutputStream(
+ new FileOutputStream(dicFile), 1024 * 16);
+
+ for (int i = 0; i < wordsSize; i++) {
+ Word word = dictionary.get(i);
+ out.write(word.getText().getBytes(charsetName));
+ if (word.getModifiers() != Word.DEFAUL) {
+ out.write("[m=".getBytes());
+ out.write(String.valueOf(word.getModifiers()).getBytes());
+ out.write(']');
+ }
+ out.write('\r');
+ out.write('\n');
+ }
+ out.flush();
+ out.close();
+ dicFile.setReadOnly();
+ }
+
+ private void compileVocabulary(final Dictionary vocabularyDictionary, Knife knife,
+ File vocabularyFile, String charsetName) throws FileNotFoundException,
+ IOException, UnsupportedEncodingException {
+ int vocabularySize = vocabularyDictionary.size();
+ Word[] vocabularyWords = new Word[vocabularySize];
+ char[] chs = new char[128];
+ for (int i = 0; i < vocabularySize; i ++) {
+ final Word curWord = vocabularyDictionary.get(i);
+ curWord.getText().getChars(0, curWord.length(), chs, 0);
+ chs[curWord.length()] = (char) -1;
+ Beef beef = new Beef(chs, 0, curWord.length() + 1);
+ final BitSet bs = new BitSet(curWord.length());
+ knife.dissect(new Collector(){
+ public void collect(String word, int offset, int end) {
+ Hit hit = vocabularyDictionary.search(word, 0, word.length());
+ if (hit.isHit() && hit.getWord().length() != curWord.length()) {
+ for (int j = offset; j < end; j++) {
+ bs.set(j, true);
+ }
+ }
+ }
+
+ }, beef, 0);
+
+ for (int j = 0; j < curWord.length();j++) {
+ if (!bs.get(j)) {
+ vocabularyWords[i] = curWord;
+ break;
+ }
+ }
+ }
+ if (vocabularyFile.exists()) {
+ //vocabularyFile.setWritable(true);
+ vocabularyFile.delete();
+ }
+ BufferedOutputStream out = new BufferedOutputStream(
+ new FileOutputStream(vocabularyFile), 1024 * 16);
+
+ for (int i = 0; i < vocabularySize; i++) {
+ if (vocabularyWords[i] != null) {
+ out.write(vocabularyWords[i].getText().getBytes(charsetName));
+ if (vocabularyWords[i].getModifiers() != Word.DEFAUL) {
+ out.write("[m=".getBytes());
+ out.write(String.valueOf(vocabularyWords[i].getModifiers()).getBytes());
+ out.write(']');
+ }
+ out.write('\r');
+ out.write('\n');
+ }
+ }
+ out.flush();
+ out.close();
+ vocabularyFile.setReadOnly();
+ }
+}