{"record":{"id":"3dd2164e18993bdd","repo":"stanfordnlp/CoreNLP","slug":"for-now-only-linear-classifiers-are-supported","errorCode":null,"errorMessage":"For now, only linear classifiers are supported","messagePattern":"For now, only linear classifiers are supported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/naturalli/ClauseSplitterSearchProblem.java","lineNumber":544,"sourceCode":"  }\n\n  /**\n   * Search, using the default weights / featurizer. This is the most common entry method for the raw search,\n   * though {@link ClauseSplitterSearchProblem#topClauses(double, int)} may be a more convenient method for\n   * an end user.\n   *\n   * @param candidateFragments The callback function for results. The return value defines whether to continue searching.\n   */\n  public void search(final Predicate<Triple<Double, List<Counter<String>>, Supplier<SentenceFragment>>> candidateFragments) {\n    if (!isClauseClassifier.isPresent()) {\n      search(candidateFragments,\n          new LinearClassifier<>(new ClassicCounter<>()),\n          HARD_SPLITS,\n          this.featurizer.orElse(DEFAULT_FEATURIZER),\n          1000);\n    } else {\n      if (!(isClauseClassifier.get() instanceof LinearClassifier)) {\n        throw new IllegalArgumentException(\"For now, only linear classifiers are supported\");\n      }\n      search(candidateFragments,\n          isClauseClassifier.get(),\n          HARD_SPLITS,\n          this.featurizer.get(),\n          1000);\n    }\n  }\n\n  /**\n   * Search from the root of the tree.\n   * This function also defines the default action space to use during search.\n   * This is NOT recommended to be used at test time.\n   *\n   * @see edu.stanford.nlp.naturalli.ClauseSplitterSearchProblem#search(Predicate)\n   *\n   * @param candidateFragments The callback function.\n   * @param classifier The classifier for whether an arc should be on the path to a clause split, a clause split itself, or neither.","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/naturalli/ClauseSplitterSearchProblem.java#L526-L562","documentation":"The search() method only supports ClauseSearcher implementations backed by a LinearClassifier. If an Optional-wrapped clause classifier was supplied whose runtime type is not LinearClassifier, an IllegalArgumentException is thrown. This is a deliberate capability restriction of the naturalli search implementation.","triggerScenarios":"Calling search() (directly or via topClauses/clauses/train) with an Optional<ClauseSearcher> containing a non-LinearClassifier, e.g. a custom ClauseSearcher subclass passed to ClauseSplitterSearchProblem.","commonSituations":"Plugging a custom classifier into ClauseSplitterSearchProblem; using an API that accepts any ClauseSearcher but whose search path only handles linear models.","solutions":["Pass a LinearClassifier instance (as produced by ClauseSplitter.train / ClauseSplitter.load) instead of a custom ClauseSearcher.","If a custom classifier is required, extend or adapt the search() method to support its type, or wrap its scoring in a LinearClassifier-compatible interface.","Check the classifier type before constructing the search problem and fail early with a clearer message."],"exampleFix":"// before\nsearchProblem.search(fragments, Optional.of(myCustomSearcher));\n// after\nLinearClassifierWrapper lc = new LinearClassifierWrapper(...); // train or load a linear classifier\nsearchProblem.search(fragments, Optional.of(lc));","handlingStrategy":"type-guard","validationCode":"if (classifierOpt.isPresent() && !(classifierOpt.get() instanceof LinearClassifier)) {\n  throw new IllegalArgumentException(\"search requires a LinearClassifier\");\n}","typeGuard":"boolean isLinear(ClauseSearcher c) { return c instanceof LinearClassifier; }","tryCatchPattern":"try {\n  problem.search(fragments, classifierOpt);\n} catch (IllegalArgumentException e) {\n  log.error(\"Non-linear clause classifier supplied\", e);\n}","preventionTips":["Only pass classifiers created by ClauseSplitter.train or ClauseSplitter.load","Avoid custom ClauseSearcher subclasses unless you also patch search()","Check the classifier type at configuration time, before search"],"tags":["unsupported-type","naturalli","clause-splitting","classifier"],"backgroundTag":"unsupported-operation","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"}