-
Notifications
You must be signed in to change notification settings - Fork 917
Expand file tree
/
Copy pathbuildtermlist.py
More file actions
executable file
·62 lines (51 loc) · 1.98 KB
/
buildtermlist.py
File metadata and controls
executable file
·62 lines (51 loc) · 1.98 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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Import standard python libraries
import argparse
import logging
import os
import sys
import typing
from typing import Any, Dict, List, Optional, Tuple, Union, Iterable, Sequence, Set, Callable, Generator
# Import schema.org libraries
if os.getcwd() not in sys.path:
sys.path.insert(1, os.getcwd())
import software.SchemaTerms.sdotermsource as sdotermsource
import software.SchemaTerms.sdoterm as sdoterm
import software.util.pretty_logger as pretty_logger
log: logging.Logger = logging.getLogger(__name__)
def generateTerms(tags: bool = False) -> Generator[str, None, None]:
for term in sdotermsource.SdoTermSource.getAllTerms(expanded=True):
if not isinstance(term, sdoterm.SdoTerm):
continue
label: str = ""
if tags:
if term.termType == sdoterm.SdoTermType.PROPERTY:
label = " p"
elif term.termType == sdoterm.SdoTermType.TYPE:
label = " t"
elif term.termType == sdoterm.SdoTermType.DATATYPE:
label = " d"
elif term.termType == sdoterm.SdoTermType.ENUMERATION:
label = " e"
elif term.termType == sdoterm.SdoTermType.ENUMERATIONVALUE:
label = " v"
yield term.id + label + "\n"
if __name__ == "__main__":
parser: argparse.ArgumentParser = argparse.ArgumentParser()
parser.add_argument(
"-t",
"--tagtype",
default=False,
action="store_true",
help="Add a termtype to name",
)
parser.add_argument("-o", "--output", required=True, help="output file")
args_parsed: argparse.Namespace = parser.parse_args()
filename: str = args_parsed.output
with pretty_logger.BlockLog(
logger=log, message=f"Writing term list to file {filename}"
):
with open(filename, "w", encoding="utf-8") as handle:
for term_line in generateTerms(tags=args_parsed.tagtype):
handle.write(term_line)