-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.py
More file actions
29 lines (26 loc) · 1.06 KB
/
driver.py
File metadata and controls
29 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Driver for ML component of MarkLogic Classifier.
import sys
import classifier as cfr
import os.path
# Params: ontology = stuff passed by frontend
# filepaths = list of filepaths to CSV files
# Returns: The classification metadata
# TODO: More clearly specify what metadata to return
def classify(ontology, filepaths):
# Verify parameters
if len(filepaths) == 0 or len(ontology) != 2:
print_usage()
raise ValueError("Bad arguments for Driver.classify")
for filepath in filepaths:
if not os.path.isfile(filepath):
raise FileNotFoundError(str(filepath) + " couldn't be found.")
my_classifier = cfr.Classifier(filepaths)
results_json = my_classifier.classify_ontology(ontology)
return results_json
# Print correct usage of application.
def print_usage():
print("""Classification module requires two parameters:
1) The given ontology as a JSON object.
Ex: ("myCategory", ["val1", "val2"])
2) One or more CSV filepaths.
Ex: ["file1.csv", "file2.csv"]""")