// Step 1964: OperationClassifier // // t1: classify known text returns isKnown=true, confidence=1.0 // t2: classify unknown text returns isKnown=false, confidence=0.0 // t3: classify "serialize to JSON" -> serialization.json // t4: classify "matrix multiply" -> compute.matrix // t5: withDefaultTaxonomy() builds correctly; taxonomy() accessible #include "OperationClassifier.h" #include namespace ws = whetstone; static int p = 0, f = 0; #define T(n) { std::cout << " " << #n << "... "; } #define P() { std::cout << "PASS\n"; ++p; } #define F(m) { std::cout << "FAIL: " << m << "\n"; ++f; } #define C(c, m) if (!(c)) { F(m); return; } void t1() { T(known_text_returns_confidence_1); auto cls = ws::OperationClassifier::withDefaultTaxonomy(); auto r = cls.classify("serialize to JSON"); C(r.isKnown, "isKnown true"); C(r.confidence == 1.0f, "confidence 1.0"); C(!r.domain.empty(), "domain not empty"); C(r.domain != "unknown", "domain is not unknown"); P(); } void t2() { T(unknown_text_returns_confidence_0); auto cls = ws::OperationClassifier::withDefaultTaxonomy(); auto r = cls.classify("xyzzy frobble zogzog"); C(!r.isKnown, "isKnown false"); C(r.confidence == 0.0f, "confidence 0.0"); C(r.domain == "unknown", "domain is unknown"); P(); } void t3() { T(classify_json_text); auto cls = ws::OperationClassifier::withDefaultTaxonomy(); auto r = cls.classify("serialize to JSON"); C(r.domain == "serialization.json", "expected serialization.json, got " + r.domain); P(); } void t4() { T(classify_matrix_multiply_text); auto cls = ws::OperationClassifier::withDefaultTaxonomy(); auto r = cls.classify("matrix multiply on GPU"); C(r.domain == "compute.matrix", "expected compute.matrix, got " + r.domain); P(); } void t5() { T(withDefaultTaxonomy_and_taxonomy_accessor); auto cls = ws::OperationClassifier::withDefaultTaxonomy(); C(cls.taxonomy().domainCount() >= 40, ">=40 domains"); auto cats = cls.taxonomy().topLevelCategories(); C(cats.size() >= 6, ">=6 top-level categories"); // Classify a few more domains C(cls.classify("sql select query").domain == "db.query.sql", "sql"); C(cls.classify("compute sha256 hash").domain == "crypto.hash", "hash"); P(); } int main() { std::cout << "Step 1964: OperationClassifier\n"; t1(); t2(); t3(); t4(); t5(); std::cout << "\n" << p << "/" << (p + f) << " passed\n"; return f > 0 ? 1 : 0; }