-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample.py
64 lines (53 loc) · 1.71 KB
/
example.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
from text2chem.regex_parser import RegExParser
from text2chem.parser_pipeline import ParserPipelineBuilder
from text2chem.preprocessing_tools.additives_processing import AdditivesProcessing
from text2chem.preprocessing_tools.chemical_name_processing import ChemicalNameProcessing
from text2chem.preprocessing_tools.mixture_processing import MixtureProcessing
from text2chem.preprocessing_tools.phase_processing import PhaseProcessing
from text2chem.postprocessing_tools.substitute_additives import SubstituteAdditives
mp = ParserPipelineBuilder() \
.add_preprocessing(AdditivesProcessing) \
.add_preprocessing(ChemicalNameProcessing) \
.add_preprocessing(PhaseProcessing) \
.add_preprocessing(MixtureProcessing)\
.add_postprocessing(SubstituteAdditives)\
.set_regex_parser(RegExParser)\
.build()
def run_test(testdata):
for data in testdata:
chem_name = data["material"]
output = data["parser_output"][0]
result = mp.parse(chem_name).to_dict()
if output != result:
print(chem_name)
"""
test formulas
"""
testdata_fn = "tests/formulas.json"
testdata = json.loads(open(testdata_fn).read())
run_test(testdata)
"""
test additives
"""
testdata_fn = "tests/additives.json"
testdata = json.loads(open(testdata_fn).read())
run_test(testdata)
"""
test chemical names
"""
testdata_fn = "tests/chemical_names.json"
testdata = json.loads(open(testdata_fn).read())
run_test(testdata)
"""
test mixtures: alloys, solid solutions, composites
"""
testdata_fn = "tests/mixtures.json"
testdata = json.loads(open(testdata_fn).read())
run_test(testdata)
"""
test phases
"""
testdata_fn = "tests/phases.json"
testdata = json.loads(open(testdata_fn).read())
run_test(testdata)