file-tag-parser 0.2.3__tar.gz
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.
- file_tag_parser-0.2.3/LICENSE +201 -0
- file_tag_parser-0.2.3/PKG-INFO +25 -0
- file_tag_parser-0.2.3/README.md +8 -0
- file_tag_parser-0.2.3/pyproject.toml +27 -0
- file_tag_parser-0.2.3/setup.cfg +4 -0
- file_tag_parser-0.2.3/src/file_tag_parser.egg-info/PKG-INFO +25 -0
- file_tag_parser-0.2.3/src/file_tag_parser.egg-info/SOURCES.txt +14 -0
- file_tag_parser-0.2.3/src/file_tag_parser.egg-info/dependency_links.txt +1 -0
- file_tag_parser-0.2.3/src/file_tag_parser.egg-info/requires.txt +3 -0
- file_tag_parser-0.2.3/src/file_tag_parser.egg-info/top_level.txt +1 -0
- file_tag_parser-0.2.3/src/ocvl/__init__.py +5 -0
- file_tag_parser-0.2.3/src/ocvl/io/__init__.py +5 -0
- file_tag_parser-0.2.3/src/ocvl/tags/__init__.py +5 -0
- file_tag_parser-0.2.3/src/ocvl/tags/file_tag_parser.py +132 -0
- file_tag_parser-0.2.3/src/ocvl/tags/json_format_constants.py +46 -0
- file_tag_parser-0.2.3/tests/test_file_tag_parser.py +57 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: file-tag-parser
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: A tag-based filename parser for imaging data.
|
|
5
|
+
Author-email: Rob F Cooper <robert.cooper@marquette.edu>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/OCVL/file-tag-parser
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: pandas>=2.0
|
|
14
|
+
Requires-Dist: parse>=1.2.0
|
|
15
|
+
Requires-Dist: parse-type>=0.6.4
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# file-tag-parser
|
|
19
|
+
A tag-based filename parser for imaging data.
|
|
20
|
+
|
|
21
|
+
This library is designed to make parsing of arbitrary filenames attainable and searchable via a pandas-based database.
|
|
22
|
+
Each filename can then be interpreted and/or manipulated for whatever processing and analysis is desired.
|
|
23
|
+
|
|
24
|
+
At the moment, the library is solely dedicated to the interpretation of complex filenames using
|
|
25
|
+
a "tagging system", to streamline their grouping and loading. This will likely be expanded in the future as needed.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# file-tag-parser
|
|
2
|
+
A tag-based filename parser for imaging data.
|
|
3
|
+
|
|
4
|
+
This library is designed to make parsing of arbitrary filenames attainable and searchable via a pandas-based database.
|
|
5
|
+
Each filename can then be interpreted and/or manipulated for whatever processing and analysis is desired.
|
|
6
|
+
|
|
7
|
+
At the moment, the library is solely dedicated to the interpretation of complex filenames using
|
|
8
|
+
a "tagging system", to streamline their grouping and loading. This will likely be expanded in the future as needed.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "file-tag-parser"
|
|
7
|
+
version = "0.2.3"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
description = "A tag-based filename parser for imaging data."
|
|
10
|
+
authors = [
|
|
11
|
+
{ name="Rob F Cooper", email="robert.cooper@marquette.edu" },
|
|
12
|
+
]
|
|
13
|
+
license = "Apache-2.0"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
requires-python = ">=3.9"
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"pandas>=2.0",
|
|
22
|
+
"parse>=1.2.0",
|
|
23
|
+
"parse-type>=0.6.4"
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/OCVL/file-tag-parser"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: file-tag-parser
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: A tag-based filename parser for imaging data.
|
|
5
|
+
Author-email: Rob F Cooper <robert.cooper@marquette.edu>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/OCVL/file-tag-parser
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: pandas>=2.0
|
|
14
|
+
Requires-Dist: parse>=1.2.0
|
|
15
|
+
Requires-Dist: parse-type>=0.6.4
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# file-tag-parser
|
|
19
|
+
A tag-based filename parser for imaging data.
|
|
20
|
+
|
|
21
|
+
This library is designed to make parsing of arbitrary filenames attainable and searchable via a pandas-based database.
|
|
22
|
+
Each filename can then be interpreted and/or manipulated for whatever processing and analysis is desired.
|
|
23
|
+
|
|
24
|
+
At the moment, the library is solely dedicated to the interpretation of complex filenames using
|
|
25
|
+
a "tagging system", to streamline their grouping and loading. This will likely be expanded in the future as needed.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/file_tag_parser.egg-info/PKG-INFO
|
|
5
|
+
src/file_tag_parser.egg-info/SOURCES.txt
|
|
6
|
+
src/file_tag_parser.egg-info/dependency_links.txt
|
|
7
|
+
src/file_tag_parser.egg-info/requires.txt
|
|
8
|
+
src/file_tag_parser.egg-info/top_level.txt
|
|
9
|
+
src/ocvl/__init__.py
|
|
10
|
+
src/ocvl/io/__init__.py
|
|
11
|
+
src/ocvl/tags/__init__.py
|
|
12
|
+
src/ocvl/tags/file_tag_parser.py
|
|
13
|
+
src/ocvl/tags/json_format_constants.py
|
|
14
|
+
tests/test_file_tag_parser.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ocvl
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import parse
|
|
6
|
+
from parse_type import TypeBuilder
|
|
7
|
+
|
|
8
|
+
from ocvl.tags.json_format_constants import DataTags, DataFormat, AcquisiTags, MetaTags
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FileTagParser():
|
|
12
|
+
|
|
13
|
+
json_dict = dict()
|
|
14
|
+
format_parsers = dict()
|
|
15
|
+
|
|
16
|
+
def __init__(self, format_dict=None):
|
|
17
|
+
# An optional parser for strings.
|
|
18
|
+
self.optional_parse = TypeBuilder.with_optional(lambda opt_str: str(opt_str))
|
|
19
|
+
|
|
20
|
+
for dataformat, form in format_dict.items():
|
|
21
|
+
self.format_parsers[dataformat] = parse.compile(form, {"s?":self.optional_parse})
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def from_json(cls, json_file, root_group=None):
|
|
26
|
+
with open(json_file, 'r') as config_json_path:
|
|
27
|
+
json_dict = json.load(config_json_path)
|
|
28
|
+
|
|
29
|
+
return cls.from_dataformat_dict(json_dict, json_file, root_group=root_group)
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def from_dataformat_dict(cls, json_dict_base=None, parse_path=None, root_group=None):
|
|
33
|
+
|
|
34
|
+
allFilesColumns = [AcquisiTags.DATASET, AcquisiTags.DATA_PATH, DataFormat.FORMAT_TYPE]
|
|
35
|
+
allFilesColumns.extend([d.value for d in DataTags])
|
|
36
|
+
|
|
37
|
+
cls.json_dict = json_dict_base
|
|
38
|
+
|
|
39
|
+
if root_group is not None:
|
|
40
|
+
sub_dict = json_dict_base.get(root_group)
|
|
41
|
+
else:
|
|
42
|
+
sub_dict = json_dict_base
|
|
43
|
+
|
|
44
|
+
cls.parser_extensions = ()
|
|
45
|
+
|
|
46
|
+
if sub_dict is not None and parse_path is not None:
|
|
47
|
+
form_dict = dict()
|
|
48
|
+
|
|
49
|
+
for format in DataFormat:
|
|
50
|
+
form = sub_dict.get(format)
|
|
51
|
+
|
|
52
|
+
if form is not None and isinstance(form, str):
|
|
53
|
+
form_dict[format] = form
|
|
54
|
+
|
|
55
|
+
cls.parser_extensions = cls.parser_extensions + (form[form.rfind(".", -5, -1):],) if form and form[form.rfind(".", -5,
|
|
56
|
+
-1):] not in cls.parser_extensions else cls.parser_extensions
|
|
57
|
+
|
|
58
|
+
metadata_form = None
|
|
59
|
+
metadata_params = None
|
|
60
|
+
if sub_dict.get(MetaTags.METATAG) is not None:
|
|
61
|
+
metadata_params = sub_dict.get(MetaTags.METATAG)
|
|
62
|
+
metadata_form = metadata_params.get(DataFormat.METADATA)
|
|
63
|
+
|
|
64
|
+
cls.parser_extensions = cls.parser_extensions + (metadata_form[metadata_form.rfind(".", -5, -1):],) if metadata_form and metadata_form[ metadata_form.rfind(".", -5, -1):] not in cls.parser_extensions else cls.parser_extensions
|
|
65
|
+
|
|
66
|
+
# Construct the parser we'll use for each of these forms
|
|
67
|
+
return cls(form_dict)
|
|
68
|
+
else:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
def parse_filename(self, file_string):
|
|
72
|
+
|
|
73
|
+
filename_tags = dict()
|
|
74
|
+
parsed_str = None
|
|
75
|
+
parser_used = None
|
|
76
|
+
|
|
77
|
+
for dataformat, parser in self.format_parsers.items():
|
|
78
|
+
parsed_str = parser.parse(file_string)
|
|
79
|
+
|
|
80
|
+
if parsed_str is not None:
|
|
81
|
+
parser_used = dataformat
|
|
82
|
+
break
|
|
83
|
+
|
|
84
|
+
if parsed_str is None:
|
|
85
|
+
return None, filename_tags
|
|
86
|
+
|
|
87
|
+
for formatstr in DataTags:
|
|
88
|
+
if formatstr in parsed_str.named:
|
|
89
|
+
if parsed_str[formatstr] is not None:
|
|
90
|
+
filename_tags[formatstr.value] = parsed_str[formatstr]
|
|
91
|
+
else:
|
|
92
|
+
filename_tags[formatstr.value] = ""
|
|
93
|
+
|
|
94
|
+
return parser_used, filename_tags
|
|
95
|
+
|
|
96
|
+
def parse_path(self, parse_path, recurse_me=False):
|
|
97
|
+
# Parse out the locations and filenames, store them in a hash table by location.
|
|
98
|
+
searchpath = Path(parse_path)
|
|
99
|
+
allFiles = list()
|
|
100
|
+
|
|
101
|
+
if recurse_me:
|
|
102
|
+
for ext in self.parser_extensions:
|
|
103
|
+
for path in searchpath.rglob("*" + ext):
|
|
104
|
+
format_type, file_info = self.parse_filename(path.name)
|
|
105
|
+
if format_type is not None:
|
|
106
|
+
file_info[DataFormat.FORMAT_TYPE] = format_type
|
|
107
|
+
file_info[AcquisiTags.DATA_PATH] = path
|
|
108
|
+
file_info[AcquisiTags.BASE_PATH] = path.parent
|
|
109
|
+
file_info[AcquisiTags.DATASET] = None
|
|
110
|
+
entry = pd.DataFrame.from_dict([file_info])
|
|
111
|
+
|
|
112
|
+
allFiles.append(entry)
|
|
113
|
+
else:
|
|
114
|
+
for ext in self.parser_extensions:
|
|
115
|
+
for path in searchpath.glob("*" + ext):
|
|
116
|
+
format_type, file_info = self.parse_filename(path.name)
|
|
117
|
+
if format_type is not None:
|
|
118
|
+
file_info[DataFormat.FORMAT_TYPE] = format_type
|
|
119
|
+
file_info[AcquisiTags.DATA_PATH] = path
|
|
120
|
+
file_info[AcquisiTags.BASE_PATH] = path.parent
|
|
121
|
+
file_info[AcquisiTags.DATASET] = None
|
|
122
|
+
entry = pd.DataFrame.from_dict([file_info])
|
|
123
|
+
|
|
124
|
+
allFiles.append(entry)
|
|
125
|
+
|
|
126
|
+
if allFiles:
|
|
127
|
+
return pd.concat(allFiles, ignore_index=True)
|
|
128
|
+
else:
|
|
129
|
+
return pd.DataFrame()
|
|
130
|
+
|
|
131
|
+
def get_dict(self):
|
|
132
|
+
return self.json_dict
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
class DataFormat(StrEnum):
|
|
4
|
+
FORMAT_TYPE = "Data_Type"
|
|
5
|
+
IMAGE = "image_format"
|
|
6
|
+
VIDEO = "video_format"
|
|
7
|
+
MASK = "mask_format"
|
|
8
|
+
METADATA = "metadata_format"
|
|
9
|
+
QUERYLOC = "queryloc_format"
|
|
10
|
+
|
|
11
|
+
# Will probably want to make a list of these corresponding to the version of the json files.
|
|
12
|
+
# This verson assumes that we don't have any naming collisions; e.g. these constants aren't used in the filenames.
|
|
13
|
+
class DataTags(StrEnum):
|
|
14
|
+
DATA_ID = "IDnum"
|
|
15
|
+
VIDEO_ID = "VidNum"
|
|
16
|
+
YEAR = "Year" # YYYY
|
|
17
|
+
MONTH = "Month" # MM
|
|
18
|
+
DAY = "Day" # DD
|
|
19
|
+
HOUR = "Hour"
|
|
20
|
+
MINUTE = "Minute"
|
|
21
|
+
SECOND = "Second"
|
|
22
|
+
EYE = "Eye"
|
|
23
|
+
RET_LOC_X = "LocX"
|
|
24
|
+
RET_LOC_Y = "LocY"
|
|
25
|
+
RET_LOC_Z = "LocZ"
|
|
26
|
+
FOV_WIDTH = "FOV_Width"
|
|
27
|
+
FOV_HEIGHT = "FOV_Height"
|
|
28
|
+
FOV_DEPTH = "FOV_Depth"
|
|
29
|
+
MODALITY = "Modality"
|
|
30
|
+
QUERYLOC = "QueryLoc"
|
|
31
|
+
|
|
32
|
+
class MetaTags(StrEnum):
|
|
33
|
+
METATAG = "metadata"
|
|
34
|
+
|
|
35
|
+
class AcquisiTags(StrEnum):
|
|
36
|
+
DATASET = "Dataset"
|
|
37
|
+
DATA_PATH = "Data_Path"
|
|
38
|
+
OUTPUT_PATH = "Output_Path"
|
|
39
|
+
VIDEO_PATH = "Video_Path"
|
|
40
|
+
IMAGE_PATH = "Image_Path"
|
|
41
|
+
QUERYLOC_PATH = "QueryLocation_Path"
|
|
42
|
+
BASE_PATH = "Base_Path"
|
|
43
|
+
MASK_PATH = "Mask_Path"
|
|
44
|
+
META_PATH = "Metadata_Path"
|
|
45
|
+
|
|
46
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from ocvl.tags.file_tag_parser import FileTagParser
|
|
6
|
+
from ocvl.tags.json_format_constants import DataFormat
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FileTagTestCase(unittest.TestCase):
|
|
10
|
+
def setUp(self):
|
|
11
|
+
self.test_json_fname = Path(os.path.dirname(__file__)).joinpath("json_ex/test_json.json")
|
|
12
|
+
|
|
13
|
+
self.test_preanalysis_nomatch_vid = "00-36828_20230324_OD_(4,0)_1x1_6385_760nm1_extract_reg_cropped_piped.avi"
|
|
14
|
+
self.test_preanalysis_match_vid = "00-36828_20230324_OD_(4,0)_1x1_6385_760nm1_vid.avi"
|
|
15
|
+
self.test_preanalysis_nomatch_mask = "00-36828_20230324_OD_(4,0)_1x1_6385_760nm1_piped.avi"
|
|
16
|
+
self.test_preanalysis_match_mask = "00-36828_20230324_OD_(4,0)_1x1_6385_760nm1_mask.avi"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_json_parser_init(self):
|
|
20
|
+
parse_me = FileTagParser.from_json(self.test_json_fname)
|
|
21
|
+
|
|
22
|
+
self.assertEqual(len(parse_me.format_parsers), 0, "Parser should be empty, since we aren't supplying a base json group.")
|
|
23
|
+
|
|
24
|
+
parse_me = FileTagParser.from_json(self.test_json_fname, root_group="preanalysis")
|
|
25
|
+
self.assertGreater(len(parse_me.format_parsers), 0,"Parser have more than 0 parsers available, since we are supplying a base json group.")
|
|
26
|
+
|
|
27
|
+
self.assertNotEqual(len(parse_me.json_dict), 0, "JSON should not be empty.")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_json_file_parsing(self):
|
|
31
|
+
|
|
32
|
+
parse_me = FileTagParser.from_json(self.test_json_fname, root_group="preanalysis")
|
|
33
|
+
self.assertGreater(len(parse_me.format_parsers), 0,"Parser have more than 0 parsers available, since we are supplying a base json group.")
|
|
34
|
+
|
|
35
|
+
used_parser, file_tags = parse_me.parse_filename(self.test_preanalysis_nomatch_vid)
|
|
36
|
+
self.assertIsNone(used_parser, f"This filename ({self.test_preanalysis_nomatch_vid}) should not match any parsers in this object.")
|
|
37
|
+
self.assertEqual(len(file_tags), 0, f"This filename ({self.test_preanalysis_nomatch_vid}) should not produce any matches with the parser")
|
|
38
|
+
|
|
39
|
+
used_parser, file_tags = parse_me.parse_filename(self.test_preanalysis_match_vid)
|
|
40
|
+
self.assertEqual(used_parser, DataFormat.VIDEO,f"This filename ({self.test_preanalysis_match_vid}) match the video format parser.")
|
|
41
|
+
self.assertEqual(len(file_tags), 11, f"This filename ({self.test_preanalysis_match_vid}) should produce 11 matches with the parser.")
|
|
42
|
+
print(f"SUCCESS: Used parser: {used_parser}")
|
|
43
|
+
print(f"Found tags: {file_tags}")
|
|
44
|
+
|
|
45
|
+
used_parser, file_tags = parse_me.parse_filename(self.test_preanalysis_nomatch_mask)
|
|
46
|
+
self.assertIsNone(used_parser, f"This filename ({self.test_preanalysis_nomatch_mask}) should not match any parsers in this object.")
|
|
47
|
+
self.assertEqual(len(file_tags), 0, f"This filename ({self.test_preanalysis_nomatch_mask}) should not produce any matches with the parser")
|
|
48
|
+
|
|
49
|
+
used_parser, file_tags = parse_me.parse_filename(self.test_preanalysis_match_mask)
|
|
50
|
+
self.assertEqual(used_parser, DataFormat.MASK,f"This filename ({self.test_preanalysis_match_mask}) should match the mask format parser.")
|
|
51
|
+
self.assertEqual(len(file_tags), 11, f"This filename ({self.test_preanalysis_match_mask}) produce 11 matches with the parser.")
|
|
52
|
+
print(f"SUCCESS: Used parser: {used_parser}")
|
|
53
|
+
print(f"Found tags: {file_tags}")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if __name__ == '__main__':
|
|
57
|
+
unittest.main()
|