Skip to content
Snippets Groups Projects
Commit 49987661 authored by weirdwizardthomas's avatar weirdwizardthomas
Browse files

Moved encoder from a separate file to be a part of document.py

parent df768bdb
No related branches found
No related tags found
No related merge requests found
import json
from json import JSONEncoder
 
 
class Document:
......@@ -8,3 +9,8 @@ class Document:
 
def to_json(self):
return json.dumps(self, default=lambda o: o.__dict__)
class Encoder(JSONEncoder):
def default(self, o: Document):
return o.__dict__
from json import JSONEncoder
from src.preprocessing.document import Document
class DocumentEncoder(JSONEncoder):
def default(self, o: Document):
return o.__dict__
import json
import os
import nltk
 
import nltk
from nltk import WordNetLemmatizer
 
from src.preprocessing.document import Document
from src.preprocessing.document_encoder import DocumentEncoder
from src import document
from src.document import Document
from src.preprocessing.word_prunner import WordPrunner
 
 
......@@ -17,7 +17,7 @@ def preprocess_folder(input_folder_path: str, output_persistence_path):
documents.append(preprocessor.read_file(input_folder_path + file))
 
with open(output_persistence_path, 'w') as file:
json.dump(documents, file, cls=DocumentEncoder)
json.dump(documents, file, cls=document.Encoder)
 
 
class Preprocessor:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment