aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/apps/info.py
blob: 8cc6dca696a3d5911bcccd8b6d6e6823c0efc7e3 (plain)
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
71
72
73
74
"""

Part of the bsie module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# imports
import argparse
import sys
import typing

# bsie imports
from bsie.base import errors
from bsie.tools import builder
from bsie.utils.bsfs import URI

# exports
__all__: typing.Sequence[str] = (
    'main',
    )


## code ##

def main(argv):
    """Show information from BSIE."""
    parser = argparse.ArgumentParser(description=main.__doc__, prog='info')
    parser.add_argument('what', choices=('predicates', ),
        help='Select what information to show.')
    args = parser.parse_args(argv)

    # FIXME: Read reader/extractor configs from a config file
    # reader builder
    rbuild = builder.ReaderBuilder({})
    # extractor builder
    ebuild = builder.ExtractorBuilder([
        {'bsie.extractor.generic.path.Path': {}},
        {'bsie.extractor.generic.stat.Stat': {}},
        {'bsie.extractor.generic.constant.Constant': dict(
            tuples=[('http://bsfs.ai/schema/Entity#author', 'Me, myself, and I')],
            schema='''
                bse:author rdfs:subClassOf bsfs:Predicate ;
                    rdfs:domain bsfs:Entity ;
                    rdfs:range xsd:string ;
                    bsfs:unique "true"^^xsd:boolean .
                ''',
            )},
        ])
    # pipeline builder
    pbuild = builder.PipelineBuilder(
        URI('http://example.com/me/file#'), # not actually used
        rbuild,
        ebuild,
        )

    # build pipeline
    pipeline = pbuild.build()

    # show info
    if args.what == 'predicates':
        # show predicates
        for pred in pipeline.schema.predicates():
            print(pred.uri)
    else:
        # args.what is already checked by argparse
        raise errors.UnreachableError()


## main ##

if __name__ == '__main__':
    main(sys.argv[1:])

## EOF ##