You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/10/28 02:52:59 UTC
svn commit: r1536234 - in
/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src: data/
java/org/apache/lucene/analysis/ko/dic/
java/org/apache/lucene/analysis/ko/morph/
resources/org/apache/lucene/analysis/ko/dic/
tools/java/org/apache/lucene/ana...
Author: rmuir
Date: Mon Oct 28 01:52:58 2013
New Revision: 1536234
URL: http://svn.apache.org/r1536234
Log:
LUCENE-4956: more compound cleanups
Removed:
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/data/prefix.dic
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/data/suffix.dic
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/resources/org/apache/lucene/analysis/ko/dic/prefix.dic
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/resources/org/apache/lucene/analysis/ko/dic/suffix.dic
Modified:
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryResources.java
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryUtil.java
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/CompoundNounAnalyzer.java
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/WordSpaceAnalyzer.java
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/tools/java/org/apache/lucene/analysis/ko/dic/DictionaryBuilder.java
Modified: lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryResources.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryResources.java?rev=1536234&r1=1536233&r2=1536234&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryResources.java (original)
+++ lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryResources.java Mon Oct 28 01:52:58 2013
@@ -31,13 +31,7 @@ import org.apache.lucene.util.IOUtils;
public class DictionaryResources {
public static final String FILE_JOSA = "josa.dic";
-
- public static final String FILE_EOMI = "eomi.dic";
-
- public static final String FILE_PREFIX = "prefix.dic";
-
- public static final String FILE_SUFFIX = "suffix.dic";
-
+ public static final String FILE_EOMI = "eomi.dic";
public static final String FILE_UNCOMPOUNDS = "uncompounds.dic";
public static final String FILE_SYLLABLE_DAT = "syllable.dat";
Modified: lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryUtil.java?rev=1536234&r1=1536233&r2=1536234&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryUtil.java (original)
+++ lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/dic/DictionaryUtil.java Mon Oct 28 01:52:58 2013
@@ -22,7 +22,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import org.apache.lucene.codecs.CodecUtil;
@@ -37,13 +36,7 @@ public class DictionaryUtil {
private static final HangulDictionary dictionary;
private static final Set<String> josas = new HashSet<String>();
-
- private static final Set<String> eomis = new HashSet<String>();
-
- private static final Set<String> prefixs = new HashSet<String>();
-
- private static final Set<String> suffixs = new HashSet<String>();
-
+ private static final Set<String> eomis = new HashSet<String>();
private static final Set<String> uncompounds = new HashSet<String>();
static {
@@ -61,8 +54,6 @@ public class DictionaryUtil {
readFileToSet(josas,DictionaryResources.FILE_JOSA);
readFileToSet(eomis,DictionaryResources.FILE_EOMI);
- readFileToSet(prefixs,DictionaryResources.FILE_PREFIX);
- readFileToSet(suffixs,DictionaryResources.FILE_SUFFIX);
InputStream stream = DictionaryResources.class.getResourceAsStream(DictionaryResources.FILE_WORDS_DAT);
if (stream == null)
@@ -88,6 +79,16 @@ public class DictionaryUtil {
return dictionary.lookup(key) != null;
}
+ /** true if word exists matching specified features */
+ private static boolean hasWord(CharSequence key, int on, int off) {
+ Byte clazz = dictionary.lookup(key);
+ if (clazz == null) {
+ return false;
+ }
+ char flags = dictionary.getFlags(clazz);
+ return (flags & on) != 0 && (flags & off) == 0;
+ }
+
/** true if something with this prefix exists */
public static boolean hasWordPrefix(CharSequence prefix) {
return dictionary.hasPrefix(prefix);
@@ -116,12 +117,22 @@ public class DictionaryUtil {
return null;
}
}
+
+ /** true if there exists noun, compound noun, or adverb */
+ public static boolean hasWordExceptVerb(String key) {
+ return hasWord(key, WordEntry.NOUN | WordEntry.BUSA, 0);
+ }
/** Looks up noun, compound noun, or adverb */
public static WordEntry getWordExceptVerb(String key) {
return getWord(key, WordEntry.NOUN | WordEntry.BUSA, 0);
}
+ /** true if there exists noun (but not compound noun) */
+ public static boolean hasNoun(String key) {
+ return hasWord(key, WordEntry.NOUN, WordEntry.COMPOUND);
+ }
+
/** Looks up a noun (but not compound noun) */
public static WordEntry getNoun(String key) {
return getWord(key, WordEntry.NOUN, WordEntry.COMPOUND);
@@ -132,6 +143,11 @@ public class DictionaryUtil {
return getWord(key, WordEntry.COMPOUND, 0);
}
+ /** true if there exists noun including compound noun */
+ public static boolean hasAllNoun(String key) {
+ return hasWord(key, WordEntry.NOUN, 0);
+ }
+
/** return all noun including compound noun */
public static WordEntry getAllNoun(String key) {
return getWord(key, WordEntry.NOUN, 0);
@@ -170,14 +186,6 @@ public class DictionaryUtil {
return eomis.contains(str);
}
- public static boolean existPrefix(String str) {
- return prefixs.contains(str);
- }
-
- public static boolean existSuffix(String str) {
- return suffixs.contains(str);
- }
-
private static void readFileToSet(final Set<String> set, String dic) throws IOException {
DictionaryResources.readLines(dic, new LineProcessor() {
@Override
Modified: lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/CompoundNounAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/CompoundNounAnalyzer.java?rev=1536234&r1=1536233&r2=1536234&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/CompoundNounAnalyzer.java (original)
+++ lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/CompoundNounAnalyzer.java Mon Oct 28 01:52:58 2013
@@ -185,7 +185,7 @@ public class CompoundNounAnalyzer {
private CompoundEntry[] analyzeLongText(String input, boolean isFirst) {
int len = input.length();
- boolean hasSuffix = isFirst && DictionaryUtil.existSuffix(input.substring(len-1));
+ boolean hasSuffix = isFirst && existSuffix(input.charAt(len-1));
int pos = calculatePos(input, hasSuffix);
if (pos < 1) {
return null; // fail to search a valid word segment
@@ -259,18 +259,20 @@ public class CompoundNounAnalyzer {
*/
private int maxWord(String text, boolean hasSuffix, String prvText) {
+ // nocommit: this should really be an FST walk...
for(int i=text.length();i>1;i--) {
String seg = text.substring(0,i);
- WordEntry entry = DictionaryUtil.getAllNoun(seg);
- if(entry==null) continue;
+ if (!DictionaryUtil.hasAllNoun(seg)) {
+ continue;
+ }
if (i == text.length()-1 && hasSuffix) {
// if previous text exist in the dictionary.
boolean existPrv = false;
if(prvText.length()>=2)
- existPrv = (DictionaryUtil.getNoun(prvText.substring(prvText.length()-2))!=null);
+ existPrv = (DictionaryUtil.hasNoun(prvText.substring(prvText.length()-2)));
if(!existPrv&&prvText.length()>=3)
- existPrv = (DictionaryUtil.getNoun(prvText.substring(prvText.length()-3))!=null);
+ existPrv = (DictionaryUtil.hasNoun(prvText.substring(prvText.length()-3)));
return existPrv ? i : i+1;
} else {
return i;
@@ -310,11 +312,9 @@ public class CompoundNounAnalyzer {
private CompoundEntry analyzeSingle(String input) {
if (input.length() == 1) {
return new CompoundEntry(input, true);
+ } else {
+ return new CompoundEntry(input, DictionaryUtil.hasWordExceptVerb(input));
}
-
- WordEntry entry = DictionaryUtil.getWordExceptVerb(input);
-
- return new CompoundEntry(input, entry != null);
}
private static boolean isAlphaNumeric(String text) {
@@ -332,10 +332,12 @@ public class CompoundNounAnalyzer {
private boolean validCompound(String before, String after, boolean isFirst, int pos) {
- if(pos==1&&before.length()==1&&
- (!isFirst||!(DictionaryUtil.existPrefix(before) || isAlphaNumeric(before)))) return false;
+ if (pos == 1 && before.length() == 1 &&
+ (!isFirst || !(existPrefix(before.charAt(0)) || isAlphaNumeric(before)))) {
+ return false;
+ }
- if(after.length()==1&&!isFirst&&!DictionaryUtil.existSuffix(after)) return false;
+ if (after.length() == 1 && !isFirst && !existSuffix(after.charAt(0))) return false;
if(pos!=1&&before.length()==1) {
if (DictionaryUtil.isUncompound(before, after)) {
@@ -351,4 +353,32 @@ public class CompoundNounAnalyzer {
return true;
}
+
+ private static boolean existPrefix(char ch) {
+ switch (ch) {
+ case 'ìµ': case 'ê³ ': case 'ë¨': case 'ì¬': case 'ë¹':
+ case 'ì ': case '무': case 'êµ°': case 'ê°': case '기':
+ return true;
+ default: return false;
+ }
+ }
+
+ private static boolean existSuffix(char ch) {
+ switch (ch) {
+ case 'ê°': case 'ê°': case 'ê°': case 'ê°': case 'ê³': case '길': case 'ê³ ': case 'ê³µ':
+ case 'ê´': case 'êµ': case 'ê¶': case 'ê¸': case 'ê¸': case '기': case 'ë´': case 'ë':
+ case 'ë¨': case 'ë': case 'ë
': case 'ë': case 'ë¡': case 'ë¡ ': case 'ë ¥': case 'ë ¹':
+ case 'ë£': case 'ë¥': case 'ë¥ ': case 'ë§': case 'ë§': case 'ë§µ': case '문': case '물':
+ case 'ë©´': case 'ë°¤': case 'ë°©': case 'ë²': case 'ë¶': case 'ë¶': case 'ë³': case 'ë¹':
+ case 'ì¬': case 'ì': case 'ì': case 'ì¸': case 'ì ': case 'ì±': case 'ì': case 'ì':
+ case 'ì¬': case 'ì¤': case 'ì¼': case 'ì': case 'ì': case 'ì': case 'ì´': case 'ì¡':
+ case 'ì¼': case 'ì¨': case 'ì': case 'ì©': case 'ì': case 'ì¸': case 'ì¼': case 'ì':
+ case 'ì': case 'ì¥': case '족': case 'ì ': case 'ì¦': case '주': case 'ì¤': case 'ì§':
+ case 'ì§': case 'ì§': case 'ì ': case 'ì ': case 'ì ': case 'ì£': case 'ì»´': case 'í':
+ case 'í': case 'í': case 'í': case 'í': case 'ì°¨': case 'ì°½': case 'ì±
': case 'ì²':
+ case 'ì² ': case 'ì²´': case '층': case 'í': case 'í': case 'í': case 'í': case 'í':
+ return true;
+ default: return false;
+ }
+ }
}
Modified: lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/WordSpaceAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/WordSpaceAnalyzer.java?rev=1536234&r1=1536233&r2=1536234&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/WordSpaceAnalyzer.java (original)
+++ lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/morph/WordSpaceAnalyzer.java Mon Oct 28 01:52:58 2013
@@ -319,7 +319,7 @@ public class WordSpaceAnalyzer {
candidates.clear();
break;
}else if(pvword!=null&&VerbUtil.verbSuffix(candidates.get(0).getStem())
- &&DictionaryUtil.getNoun(pvword)!=null){ // ëª
ì¬ + ì©ì¸í ì ë¯¸ì¬ + ì´ë¯¸ ì²ë¦¬
+ && DictionaryUtil.hasNoun(pvword)) { // ëª
ì¬ + ì©ì¸í ì ë¯¸ì¬ + ì´ë¯¸ ì²ë¦¬
candidates.clear();
anlysisWithEomiDetail(snipt.substring(0,eend), candidates);
pvword=null;
@@ -464,7 +464,7 @@ public class WordSpaceAnalyzer {
output.removeLast();
return -1;
}else if(nEnd<input.length() && hasJOSA1
- && DictionaryUtil.getNoun(o.getSource())!=null) {
+ && DictionaryUtil.hasNoun(o.getSource())) {
return -1;
}else if(nEnd<input.length() && o.getScore()==AnalysisOutput.SCORE_ANALYSIS
&& DictionaryUtil.hasWordPrefix(ejend+input.charAt(nEnd))) { // 루ì¬íã´ ê¸ííìë¶ì기 ë°©ì§
Modified: lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/tools/java/org/apache/lucene/analysis/ko/dic/DictionaryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/tools/java/org/apache/lucene/analysis/ko/dic/DictionaryBuilder.java?rev=1536234&r1=1536233&r2=1536234&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/tools/java/org/apache/lucene/analysis/ko/dic/DictionaryBuilder.java (original)
+++ lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/tools/java/org/apache/lucene/analysis/ko/dic/DictionaryBuilder.java Mon Oct 28 01:52:58 2013
@@ -51,8 +51,6 @@ public class DictionaryBuilder {
String FILES_AS_IS[] = {
DictionaryResources.FILE_EOMI,
DictionaryResources.FILE_JOSA,
- DictionaryResources.FILE_PREFIX,
- DictionaryResources.FILE_SUFFIX,
DictionaryResources.FILE_UNCOMPOUNDS
};