mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-11 09:07:18 +01:00
removed matching model fields, automatic classifier reloading, added autmatic_classification field to matching model
This commit is contained in:
parent
30134034e2
commit
70bd05450a
8 changed files with 126 additions and 143 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import pickle
|
||||
|
||||
from documents.models import Correspondent, DocumentType, Tag
|
||||
|
|
@ -16,6 +17,18 @@ def preprocess_content(content):
|
|||
|
||||
class DocumentClassifier(object):
|
||||
|
||||
classifier_version = None
|
||||
|
||||
data_vectorizer = None
|
||||
|
||||
tags_binarizer = None
|
||||
correspondent_binarizer = None
|
||||
type_binarizer = None
|
||||
|
||||
tags_classifier = None
|
||||
correspondent_classifier = None
|
||||
type_classifier = None
|
||||
|
||||
@staticmethod
|
||||
def load_classifier():
|
||||
clf = DocumentClassifier()
|
||||
|
|
@ -23,15 +36,18 @@ class DocumentClassifier(object):
|
|||
return clf
|
||||
|
||||
def reload(self):
|
||||
with open(settings.MODEL_FILE, "rb") as f:
|
||||
self.data_vectorizer = pickle.load(f)
|
||||
self.tags_binarizer = pickle.load(f)
|
||||
self.correspondent_binarizer = pickle.load(f)
|
||||
self.type_binarizer = pickle.load(f)
|
||||
if self.classifier_version is None or os.path.getmtime(settings.MODEL_FILE) > self.classifier_version:
|
||||
print("reloading classifier")
|
||||
with open(settings.MODEL_FILE, "rb") as f:
|
||||
self.data_vectorizer = pickle.load(f)
|
||||
self.tags_binarizer = pickle.load(f)
|
||||
self.correspondent_binarizer = pickle.load(f)
|
||||
self.type_binarizer = pickle.load(f)
|
||||
|
||||
self.tags_classifier = pickle.load(f)
|
||||
self.correspondent_classifier = pickle.load(f)
|
||||
self.type_classifier = pickle.load(f)
|
||||
self.tags_classifier = pickle.load(f)
|
||||
self.correspondent_classifier = pickle.load(f)
|
||||
self.type_classifier = pickle.load(f)
|
||||
self.classifier_version = os.path.getmtime(settings.MODEL_FILE)
|
||||
|
||||
def save_classifier(self):
|
||||
with open(settings.MODEL_FILE, "wb") as f:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue