imbajin commented on code in PR #1989:
URL: 
https://github.com/apache/incubator-hugegraph/pull/1989#discussion_r1005309547


##########
hugegraph-core/src/main/java/com/baidu/hugegraph/analyzer/JcsegAnalyzer.java:
##########
@@ -45,29 +44,35 @@ public class JcsegAnalyzer implements Analyzer {
             "Complex"
     );
 
-    private static final JcsegTaskConfig CONFIG = new JcsegTaskConfig();
+    private static final SegmenterConfig CONFIG = new SegmenterConfig();
     private static final ADictionary DIC =
-            DictionaryFactory.createDefaultDictionary(new JcsegTaskConfig());
+        DictionaryFactory.createDefaultDictionary(CONFIG);
 
-    private int segMode;
+    private final ISegment.Type type;
 
     public JcsegAnalyzer(String mode) {
         if (!SUPPORT_MODES.contains(mode)) {
             throw new ConfigException(
                       "Unsupported segment mode '%s' for jcseg analyzer, " +
                       "the available values are %s", mode, SUPPORT_MODES);
         }
-        this.segMode = SUPPORT_MODES.indexOf(mode) + 1;
+
+        if (mode.equals("Simple")) {
+            this.type = ISegment.SIMPLE;
+        } else {
+            this.type = ISegment.COMPLEX;
+        }
     }
 
     @Override
     public Set<String> segment(String text) {
         Set<String> result = InsertionOrderUtil.newSet();
         try {
-            Object[] args = new Object[]{new StringReader(text), CONFIG, DIC};
-            ISegment seg = SegmentFactory.createJcseg(this.segMode, args);
-            IWord word = null;
-            while ((word = seg.next()) != null) {
+            ISegment segmentor = this.type.factory.create(CONFIG, DIC);
+            segmentor.reset(new StringReader(text));
+
+            IWord word;
+            while ((word = segmentor.next()) != null) {

Review Comment:
   warn: will the `segmentor.next()` throw exception if null? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to