folder-classifier 0.3.6__py3-none-any.whl → 0.3.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,71 +7,70 @@ from ray import serve
7
7
  from folder_classifier.dto import FolderClassificationRequest, FolderClassification
8
8
  from folder_classifier.util import build_folder, render_tree
9
9
 
10
- SYSTEM_PROMPT = """
11
- You are a strict text classifier.
12
- Output MUST be a single JSON object with exactly two keys: "category" and "reasoning".
13
- - "category" {"matter","other"} (lowercase).
14
- - "reasoning" 30 words, citing rule IDs (e.g., RC1+R7 or R1+R3) and up to two brief evidence tokens.
15
- - Do not include any double-quote (") characters inside the value of "reasoning"; use single quotes ' instead.
16
- - No backticks, no code fences, no extra text. Return one JSON object only.
17
- No step-by-step thinking. No extra keys. If unsure, choose "other".
10
+ SYSTEM_PROMPT = r"""
11
+ You are a strict text classifier. Provide a single JSON object with exactly two keys: "category" and "reasoning".
12
+ - "category": either "matter" or "other" (lowercase).
13
+ - "reasoning": 1–2 short explanation referencing the key rule(s) that decided it.
14
+ No markdown (no backticks or code blocks) or any extra text outside the JSON. No chain-of-thought explanations or extra keys. If uncertain, choose "other".
18
15
  """.strip()
19
16
 
20
- USER_PROMPT_TEMPLATE = """
21
- Classify the FOLDER TREE as "matter" or "other".
22
-
23
- Definitions
24
- - matter: The FOLDER TREE represents exactly one legal matter/container (one client/case/matter) AND includes at least one legal-work indicator.
25
- - other: Anything else, including:
26
- (a) the FOLDER TREE appears to contain multiple distinct matters (a container of matters), or
27
- (b) the ROOT NAME is a common subfolder/stage/type (e.g., "Correspondence", "Drafts", "Pleadings", "Court Documents", "Billing", "Evidence"), or
28
- (c) legal-work indicators are absent, or
29
- (d) there are zero files with extensions anywhere in the tree, or
30
- (e) contents are exclusively non-legal domains (finance/accounting/IT/admin) with no legal-work indicators, or
31
- (f) the ROOT NAME is non-matter-specific, including either:
32
- (f1) system/provenance roots (e.g., “CORTO Generated”, “Exports”, “Uploads”, “Dropbox Shared”, “OneDrive”, “SharePoint”, “Archive”, “Backup”, “Temp”, “Incoming”, “Outbox”, “Bulk Import”), or
33
- (f2) informal/placeholder roots lacking client/company/matter cues (e.g., “hello”, “test”, “misc”, “docs”, “files”, “images”, “new folder”, “untitled”, very short single tokens with no digits).
34
-
35
- Decision Rules (apply in order; case-insensitive)
36
- RC_container: Any indication the FOLDER TREE holds more than one distinct matter → category=other.
37
- Signals: ≥2 top-level subfolders with matter-like names (e.g., “<number> - <id>”, “<client> - <topic>”), even if those subfolders are empty; repetitive top-level matter-number patterns.
38
- R0_subfolder: ROOT NAME equals a common matter subfolder/stage/type → category=other.
39
- R7_files_present: Must contain ≥1 file with an extension (e.g., .pdf, .docx) anywhere; if none → category=other.
40
- R8_nonlegal_only: Strong non-legal domain signals and NO legal-work indicators (R2–R4 or R6) → other.
41
- • Finance/Accounting: BAS/IAS/GST/Tax Return, PAYG, payroll/timesheets/payslips, superannuation, Xero/MYOB/QuickBooks exports, GL/Trial Balance/Journals, bank statements, invoices/receipts, reconciliations, aged AR/AP, debtor/creditor lists, debtor collection schedules, AR “demand/reminder” letters in collections context.
42
- IT/Systems: backups, logs, source code, Git/DevOps, server/network/VPN, mailboxes, workspace/365 admin.
43
- Admin-only: generic receipts/vendor invoices/expenses without legal context.
44
- R9_non_matter_specific_rootname: Non-matter-specific ROOT NAME category=other.
45
- R9a_system_provenance: generated/export/import/shared/archive/backup/temp/uploads/downloads/platform names (Dropbox/OneDrive/SharePoint, etc.).
46
- R9b_placeholder_informal: informal/placeholder words with no client/company/matter cues (“hello”, “test”, “misc”, “docs”, “files”, “new folder”, “untitled”, short tokens without digits).
47
- R10_legal_filename_semantics: If files exist but **no filename** in the tree is legal-sounding (and R2–R4/R6 are absent) → category=other.
48
- Legal-sounding filename cues (non-exhaustive): agreement/contract/deed/will/affidavit/statement/brief/advice/retainer/engagement/costs disclosure/pleadings/statement of claim/defence/court form/subpoena/orders/judgment/undertaking/notice/settlement/consent orders/particulars/summons/witness statement/statutory declaration.
49
- Generic/non-informative basenames (e.g., “test.pdf”, “doc1.pdf”, “file.pdf”, “notes.pdf”, “scan.pdf”, “image001.pdf”) **do not** count as legal-sounding.
50
- R1_rootname: ROOT NAME resembles a single matter/container (matter/case/file number; client/surname/company; or a combination like “12345 Smith”, “Smith – Contract Dispute”, “Brown – Lease Review”).
51
- R2_initial_docs: Early-stage matter docs (cost agreement/disclosure, retainer/engagement, intake/onboarding).
52
- R3_legal_docs: Legal document types (agreement, contract, deed, will, affidavit, statement, advice, brief, pleadings, court forms, subpoena, orders, judgment, undertaking, notice of appeal, docket/case forms).
53
- R4_legal_subfolders: Typical legal subfolders (correspondence/emails, file notes/attendance notes, searches/certificates, court documents/evidence/disclosure/discovery, drafts/final/signed/executed, billing/invoices/time records).
54
- R5_support_filename_patterns: Supportive only (not decisive): versioning (v1/v2/v3), “final”, “executed”, “signed”, eight-digit dates (YYYYMMDD/DDMMYYYY).
55
- R6_jurisdiction: Court/jurisdiction/case references (generic court acronyms, registry references, docket patterns).
56
-
57
- Decision
58
- - If RC_container category=other (stop).
59
- - Else if R0_subfolder category=other (stop).
60
- - Else if NOT R7_files_present category=other (stop).
61
- - Else if R8_nonlegal_only → category=other (stop).
62
- - Else if R9_non_matter_specific_rootname → category=other (stop).
63
- - Else if R10_legal_filename_semantics category=other (stop).
64
- - Else if R1_rootname AND any of {R2, R3, R4, R6} AND no multi-matter signal → category=matter.
65
- (R5 is supportive only and cannot justify "matter" by itself.)
66
- - Else category=other.
67
-
68
- Normalization
69
- - “File with extension”: period + 1–5 char alphanumeric extension (e.g., .pdf, .docx). Ignore leading/trailing periods.
70
- - Treat hyphens/underscores as separators. Ignore extensions for semantic matching beyond presence. Tolerate minor typos.
71
-
72
- Output (JSON only; no prose before/after):
73
- {"category": "<matter|other>", "reasoning": "≤30 words citing R# and 1–2 evidence tokens>"}
74
-
17
+ USER_PROMPT_TEMPLATE = r"""
18
+ Task: Classify the root folder as 'matter' or 'other'.
19
+
20
+ Decision rules (apply in order):
21
+ 1) If there are no files with extension anywhere in the tree , classify as 'other'.
22
+ 2) If the root folder appears to be a container of multiple matters , classify as 'other'.
23
+ 3) If the root folder is or ends with a common subfolder name or descriptor found inside legal matters (e.g.,"Email", "Summons" "Emails", "Documents", "Correspondence", "Drafts", "Pleadings", "Court Documents", "Billing", or similar descriptive folder types), classify as 'other' even if it contains legal documents.
24
+ 4) If the root folder is a subfolder of a matter, classify as other
25
+ 5) If the root folder name matches any Matter Folder Naming Pattern and there is at least one file with an extension anywhere in the tree (including subfolders), and there is at least one file, subfolder, or filename that directly and unambiguously references a legal, client-matter, or professional context—for example, a legal document type, an initial or core legal document, clear legal terminology, a jurisdiction/court reference, the name of a law firm or legal/financial professional, or an activity specific to legal work—classify as 'matter'.
26
+ Do not classify as 'matter' if the folder only contains general business documents (e.g., invoices, estimates, generic correspondence) and there are no strong indicators of legal, client, or matter-related content as defined above
27
+ 6) If the root folder name very compellingly looks like a matter folder e.g (11206 - AcmeX Pty v Acme Corp), classify as 'matter' even if the documents are not initial/core/legal documents.
28
+ 7) If none of the above apply, classify as 'other'.
29
+
30
+ Matter Folder Naming Patterns (case-insensitive; separators like space, hyphen, underscore are fine):
31
+ • Matter number alone or combined with a client/surname/company (e.g., "12345", "12345 Smith", "Smith - Contract Dispute").
32
+ Client name/surname/company/business name, optionally with matter type or client reference (e.g., "Brown Lease Review", "Jones Family – Estate").
33
+ Common file-number prefixes/suffixes (e.g., "MAT-1234", "CLT001", "2025-0001", "ACME_2024_Lease").
34
+ Suggested regex-style hints (not strict requirements):
35
+ - Numeric ID: ^\d{4,}$
36
+ - Prefixed ID: ^(MAT|CLT|FILE|CASE|REF)[-_]?\d{3,}
37
+ - Name + type: ^[A-Za-z].*(Lease|Contract|Estate|Dispute|Sale|Acquisition|Conveyance|Family|Probate|Litigation).*
38
+
39
+ Initial or Core Documents (early-stage client docs):
40
+ File Cover Sheet
41
+ Cost Agreement / Costs Disclosure
42
+ Retainer Instructions / Engagement Letter
43
+ Onboarding Questionnaire / Client Intake Form
44
+
45
+ Legal Document Types (non-exhaustive):
46
+ Contract, Deed, Agreement, Will
47
+ Affidavit, Statement
48
+ Brief to Counsel, Advice
49
+ Court Forms, Pleadings, Subpoena, Orders, Judgment, Undertaking
50
+
51
+ Subfolder Indicators (often—but not always—present in matters):
52
+ Correspondence / Emails
53
+ • File Notes / Attendance Notes
54
+ • Searches / Certificates
55
+ Court Documents / Evidence / Disclosure / Discovery
56
+ Drafts / Final / Signed / Executed
57
+ Billing / Invoices / Time Records
58
+
59
+ File Naming Patterns (helpful signals):
60
+ Dates in YYYYMMDD or DDMMYYYY.
61
+ Legal terminology (e.g., "Letter to other side", "Draft_Affidavit_v3").
62
+ Versioning (v1, v2, Final, Executed, Signed).
63
+ Jurisdiction or court references (e.g., NSWSC, VCAT, Family Court, FCFCOA).
64
+
65
+ Definitions/assumptions:
66
+ "Document" = a file (e.g., .pdf, .docx, .rtf, .txt, .xlsx, .msg/.eml). Folders are not documents.
67
+ Treat "templates" or "precedents" as weak signals unless clearly client/matter-specific.
68
+ • Evaluate only the content shown in the tree—do not infer from outside knowledge.
69
+
70
+ Output format (JSON only, no extra text):
71
+ {"category": "<matter|other>", "reasoning": "<1–2 short explanation referencing the key rule(s) that decided it>"}
72
+ ROOT FOLDER:
73
+ {root_folder}
75
74
  FOLDER TREE:
76
75
  {folder_tree}
77
76
  """.strip()
@@ -106,12 +105,15 @@ class FolderClassifier:
106
105
  def _to_chat_completion_request(self, request: FolderClassificationRequest) -> Dict[str, Any]:
107
106
  input_paths = request.items
108
107
  folder = build_folder(input_paths)
108
+ root_folder = folder.name
109
109
  folder_tree = render_tree(folder)
110
110
  chat_completion_request = {
111
111
  "model": self.model,
112
112
  "messages": [
113
113
  {"role": "system", "content": SYSTEM_PROMPT},
114
- {"role": "user", "content": USER_PROMPT_TEMPLATE.replace("{folder_tree}", folder_tree)}
114
+ {"role": "user", "content": USER_PROMPT_TEMPLATE.
115
+ replace("{root_folder}", root_folder).
116
+ replace("{folder_tree}", folder_tree)}
115
117
  ],
116
118
  "max_tokens": 1024,
117
119
  "temperature": 0.7,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: folder-classifier
3
- Version: 0.3.6
3
+ Version: 0.3.8
4
4
  Summary: Deploy folder classifier API to a Ray cluster
5
5
  Author: Crispin Almodovar
6
6
  Author-email:
@@ -1,10 +1,10 @@
1
1
  folder_classifier/__init__.py,sha256=k0YWZyUNe7myJiKeX0OaXtJ30_3EGE-vsZiAUbqa-3E,46
2
2
  folder_classifier/app.py,sha256=5eaniDWZFBvyI9UN4vOCc6TQwgyptAUVhRVgfrjp2F4,1259
3
- folder_classifier/classifier.py,sha256=yK154rXr-AEKZuf1d4YKhgbcCcPFK8nfuk4osd7XtLc,8820
3
+ folder_classifier/classifier.py,sha256=tTTu3B-vEtWaFeRMCKCpEcQJ1mo3GB5aDpi46HIB7j0,7223
4
4
  folder_classifier/deploy.py,sha256=06UAxz40IaP28e_RRohJoFwPUrWTaMquGbDylI-oHWA,424
5
5
  folder_classifier/dto.py,sha256=KRHEfXKlsIYkBySwHOlo4k5Z4J_F3eR3PeEdUAwj8lI,819
6
6
  folder_classifier/util.py,sha256=-Ptxkba5UzmhLrqoiiKZS3G56_cuAMkWlTyHcqdJkg0,3160
7
- folder_classifier-0.3.6.dist-info/METADATA,sha256=e4498y5SfYg3zXaG35qK78tWFwPQxoIvNgo17yK0NNQ,546
8
- folder_classifier-0.3.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- folder_classifier-0.3.6.dist-info/top_level.txt,sha256=36ugc9pEbNQ-mnzz4Ot2WVjY3t_LzAN6XOCjDFP4p4k,18
10
- folder_classifier-0.3.6.dist-info/RECORD,,
7
+ folder_classifier-0.3.8.dist-info/METADATA,sha256=VseLFnkWW-q2uO_F22MRJhuQcjkmxyv0qqi4MOmsSYc,546
8
+ folder_classifier-0.3.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ folder_classifier-0.3.8.dist-info/top_level.txt,sha256=36ugc9pEbNQ-mnzz4Ot2WVjY3t_LzAN6XOCjDFP4p4k,18
10
+ folder_classifier-0.3.8.dist-info/RECORD,,