{"record":{"id":"ef56aadac4e5ba7d","repo":"stanfordnlp/CoreNLP","slug":"only-support-settings-for-ctb-and-pk-now","errorCode":null,"errorMessage":"only support settings for CTB and PK now.","messagePattern":"only support settings for CTB and PK now\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/wordseg/ChineseSegmenterFeatureFactory.java","lineNumber":302,"sourceCode":"      (CTB/ASBC/HK/PK/MSR) POS information of each characters.\n      If a character falls into some function categories,\n      it is very likely there is a boundary.\n      A lot of Chinese function words belong to single characters.\n      This feature is also good for numbers and punctuations.\n      DE* are grouped into DE.\n    */\n    if (flags.useCTBChar2 || flags.useASBCChar2 || flags.useHKChar2\n        || flags.usePKChar2 || flags.useMSRChar2) {\n      String[] tagsets;\n      // the \"useChPos\" now only works for CTB and PK\n      if (flags.useChPos) {\n        if(flags.useCTBChar2) {\n          tagsets = new String[]{\"AD\", \"AS\", \"BA\", \"CC\", \"CD\", \"CS\", \"DE\", \"DT\", \"ETC\", \"IJ\", \"JJ\", \"LB\", \"LC\", \"M\",  \"NN\",  \"NR\", \"NT\", \"OD\", \"P\", \"PN\", \"PU\", \"SB\", \"SP\", \"VA\", \"VC\", \"VE\", \"VV\" };\n        } else if (flags.usePKChar2) {\n          //tagsets = new String[]{\"r\", \"j\", \"t\", \"a\", \"nz\", \"l\", \"vn\", \"i\", \"m\", \"ns\", \"nr\", \"v\", \"n\", \"q\", \"Ng\", \"b\", \"d\", \"nt\"};\n          tagsets = new String[]{\"2\",\"3\",\"4\"};\n        } else {\n          throw new RuntimeException(\"only support settings for CTB and PK now.\");\n        }\n      } else {\n        //logger.info(\"Using Derived features\");\n        tagsets = new String[]{\"2\",\"3\",\"4\"};\n      }\n\n      if (taDetector == null) {\n        taDetector = new TagAffixDetector(flags);\n      }\n      for (String tagset : tagsets) {\n        features.add(taDetector.checkDic(tagset + \"p\", charp) + taDetector.checkDic(tagset + \"i\", charp) + taDetector.checkDic(tagset + \"s\", charc) + taDetector.checkInDic(charp) + taDetector.checkInDic(charc) + tagset + \"prep-sufc\");\n        // features.add(\"|ctbchar2\");  // Added a constant feature several times!!\n      }\n    }\n\n    /*\n      In error analysis, we found English words and numbers are often separated.\n      Rule 1: isNumber feature: check if the current and previous char is a number.","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/wordseg/ChineseSegmenterFeatureFactory.java#L284-L320","documentation":"ChineseSegmenterFeatureFactory.featuresCpC builds character-level POS/dictionary features using a tagset that depends on the segmentation corpus flags. If neither useCTBChar2 nor usePKChar2 is enabled (and features were requested that need a tagset), the library cannot know which tag inventory to use and throws a RuntimeException at feature extraction time.","triggerScenarios":"Running the CRF Chinese segmenter with featuresCpC extraction while flags.useCTBChar2=false and flags.usePKChar2=false (e.g. no -sighanCorporaDict-style property set / properties loaded from a config that only enables base features).","commonSituations":"Users training or testing on ASBC, HK, or MSR corpora without setting useCTBChar2/usePKChar2; copying an old properties file that predates the CTB/PK flag options; invoking the feature factory programmatically with a partially populated SeqClassifierFlags.","solutions":["Set useCTBChar2=true (or usePKChar2=true) in the segmenter properties file before training/testing","If using Sighan corpora, pass the appropriate properties via -props so flags are loaded correctly","If supporting another corpus, modify featuresCpC to supply a tagset for that setting instead of falling into the else branch"],"exampleFix":"// before (Properties)\nser=edu.stanford.nlp.wordseg.ChineseSegmenterFeatureFactory\n// after\nser=edu.stanford.nlp.wordseg.ChineseSegmenterFeatureFactory\nuseCTBChar2=true","handlingStrategy":"validation","validationCode":"Properties p = new Properties();\np.load(new FileInputStream(propsFile));\nif (!Boolean.parseBoolean(p.getProperty(\"useCTBChar2\",\"false\")) &&\n    !Boolean.parseBoolean(p.getProperty(\"usePKChar2\",\"false\"))) {\n  throw new IllegalArgumentException(\"Set useCTBChar2 or usePKChar2 for ChineseSegmenterFeatureFactory\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  classifier = CRFClassifier.getClassifier(serializedClassifier, props);\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"CTB and PK\")) {\n    props.setProperty(\"useCTBChar2\", \"true\");\n    classifier = CRFClassifier.getClassifier(serializedClassifier, props);\n  } else throw e;\n}","preventionTips":["Always load a corpus-specific properties file (CTB or PK) rather than building SeqClassifierFlags by hand","Keep exactly one corpus char2 flag enabled in config","Add a startup sanity check that asserts one char2 flag is set before training/testing"],"tags":["java","chinese-segmentation","crf","configuration"],"backgroundTag":"invalid-config-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}