-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path__main__.py
More file actions
70 lines (52 loc) · 2.06 KB
/
Copy path__main__.py
File metadata and controls
70 lines (52 loc) · 2.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
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
65
66
67
68
69
70
from __future__ import annotations
import argparse
from collections.abc import Sequence
from .model import concept_root, template
from .parser import parse
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="python -m ifcopenshell.mvd",
description="Inspect mvdXML or execute its generated SPARQL against an IFC-OWL file.",
)
parser.add_argument("mvdxml", help="Path to an mvdXML document")
parser.add_argument(
"ifcowl",
nargs="?",
help="Optional path to an IFC-OWL Turtle file; omit it to inspect the mvdXML",
)
return parser
def inspect_mvd(filename: str) -> None:
for item in parse(filename):
if isinstance(item, template):
print(item.name or item.entity)
_print_template(item)
continue
for concept in item.concepts():
print(concept.name)
print()
_print_template(concept.template())
print()
def _print_template(parsed_template: template) -> None:
def dump(rule, parents) -> None:
print(" " * len(parents), rule.tag, rule.attribute)
print("RootEntity", parsed_template.entity)
parsed_template.traverse(dump, with_parents=True)
print(" ".join(map(str, parsed_template.constraints)))
def execute_sparql(parsed_root: concept_root, mvdxml: str, ifcowl: str) -> None:
from . import sparql
sparql.derive_prefix(ifcowl)
inferred_ifcowl = sparql.infer_subtypes(ifcowl)
print(sparql.executor.run(parsed_root, mvdxml, inferred_ifcowl), end="")
def main(argv: Sequence[str] | None = None) -> int:
args = build_parser().parse_args(argv)
if args.ifcowl is None:
inspect_mvd(args.mvdxml)
return 0
roots = [item for item in parse(args.mvdxml) if isinstance(item, concept_root)]
if not roots:
raise ValueError(f"mvdXML document {args.mvdxml!r} contains no ConceptRoot")
for root in roots:
execute_sparql(root, args.mvdxml, args.ifcowl)
return 0
if __name__ == "__main__":
raise SystemExit(main())