pylode 2.8.3__py2.py3-none-any.whl

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.
Files changed (63) hide show
  1. pyLODE-2.8.3.dist-info/LICENSE +643 -0
  2. pyLODE-2.8.3.dist-info/METADATA +772 -0
  3. pyLODE-2.8.3.dist-info/RECORD +63 -0
  4. pyLODE-2.8.3.dist-info/WHEEL +6 -0
  5. pyLODE-2.8.3.dist-info/entry_points.txt +3 -0
  6. pyLODE-2.8.3.dist-info/top_level.txt +1 -0
  7. pylode/__init__.py +5 -0
  8. pylode/cli.py +191 -0
  9. pylode/common.py +191 -0
  10. pylode/curies.py +2208 -0
  11. pylode/profiles/__init__.py +4 -0
  12. pylode/profiles/base.py +463 -0
  13. pylode/profiles/ontdoc.py +1283 -0
  14. pylode/profiles/prof.py +276 -0
  15. pylode/profiles/profile.py +135 -0
  16. pylode/profiles/vocpub.py +605 -0
  17. pylode/server.py +24 -0
  18. pylode/style/pylode.css +179 -0
  19. pylode/templates/agent.html +11 -0
  20. pylode/templates/agent.md +11 -0
  21. pylode/templates/namespaces.html +9 -0
  22. pylode/templates/namespaces.md +5 -0
  23. pylode/templates/ontdoc/class.html +121 -0
  24. pylode/templates/ontdoc/class.md +40 -0
  25. pylode/templates/ontdoc/classes.html +11 -0
  26. pylode/templates/ontdoc/classes.md +7 -0
  27. pylode/templates/ontdoc/document.html +42 -0
  28. pylode/templates/ontdoc/document.md +16 -0
  29. pylode/templates/ontdoc/metadata.html +127 -0
  30. pylode/templates/ontdoc/metadata.md +111 -0
  31. pylode/templates/ontdoc/named_individual.html +65 -0
  32. pylode/templates/ontdoc/named_individual.md +25 -0
  33. pylode/templates/ontdoc/named_individuals.html +11 -0
  34. pylode/templates/ontdoc/named_individuals.md +7 -0
  35. pylode/templates/ontdoc/properties.html +65 -0
  36. pylode/templates/ontdoc/properties.md +45 -0
  37. pylode/templates/ontdoc/property.html +129 -0
  38. pylode/templates/ontdoc/property.md +37 -0
  39. pylode/templates/orcid.html +19 -0
  40. pylode/templates/orcid.md +1 -0
  41. pylode/templates/prof/prof.html +38 -0
  42. pylode/templates/prof/prof.md +16 -0
  43. pylode/templates/prof/profile.html +90 -0
  44. pylode/templates/prof/profile.md +85 -0
  45. pylode/templates/prof/resource_descriptor.html +49 -0
  46. pylode/templates/prof/resource_descriptor.md +21 -0
  47. pylode/templates/vocpub/collection.html +51 -0
  48. pylode/templates/vocpub/collection.md +23 -0
  49. pylode/templates/vocpub/collections.html +11 -0
  50. pylode/templates/vocpub/collections.md +7 -0
  51. pylode/templates/vocpub/concept.html +115 -0
  52. pylode/templates/vocpub/concept.md +40 -0
  53. pylode/templates/vocpub/concept_hierarchy.html +80 -0
  54. pylode/templates/vocpub/concept_scheme.html +105 -0
  55. pylode/templates/vocpub/concept_scheme.md +102 -0
  56. pylode/templates/vocpub/concepts.html +9 -0
  57. pylode/templates/vocpub/concepts.md +7 -0
  58. pylode/templates/vocpub/taxonomy.html +42 -0
  59. pylode/templates/vocpub/taxonomy.md +17 -0
  60. pylode/tests/__init__.py +0 -0
  61. pylode/tests/test_ont_html_description.py +7 -0
  62. pylode/tests/test_skos.py +8 -0
  63. pylode/tests/tests_all.py +50 -0
@@ -0,0 +1,63 @@
1
+ pylode/__init__.py,sha256=6i5ZH7ehVb_zv33sSaqx56EnlG5PJu--xw2DESnlOjU,220
2
+ pylode/cli.py,sha256=Uloty2FLHUwVnSYuuwi0fdv0w8-XGuCblhMZtmzXtCw,6152
3
+ pylode/common.py,sha256=ri3PtV_rmJ7XGNM4MuiFgT5xDAxdxMJTYQvF0yTVdO8,7461
4
+ pylode/curies.py,sha256=NsL9RSeF3Gco_So1c5VJz-TwKUy8iq0PxiPUzjgPWxw,117546
5
+ pylode/server.py,sha256=kXDLx2XlZ6NdKaYPuE7ZZ6JX7jvvEPLNKAzm-IbmVBg,793
6
+ pylode/profiles/__init__.py,sha256=6Mx0ej4KSfGdtb_wiNjCRZHffbhvaNmXyo1jLp1HXzU,100
7
+ pylode/profiles/base.py,sha256=_FJqsBGn-gSfFshZJQo97_PpUZaHlkgMXbXYZi13Zcs,18086
8
+ pylode/profiles/ontdoc.py,sha256=x1G5RBQM1SrCJb13M9gf7IKDq6oDrDTWBEkQCOIXa8g,54835
9
+ pylode/profiles/prof.py,sha256=BGfvP0540pb1Yz2ivHvJCF8nxMEp7T9kW5EvjEGnGTs,11910
10
+ pylode/profiles/profile.py,sha256=qCLtBzEYapaZKKAAeSVLsFeBXhTkjPJldVOfS03MuYo,5234
11
+ pylode/profiles/vocpub.py,sha256=9GX3PcjTvK4zl_x-0BLSC11-5Q0V2f9lOdEVWUYMS5w,25938
12
+ pylode/style/pylode.css,sha256=R0pqa-isdcFiSMORLp5LIfdM-3eYKsenzue84C9FMJA,3645
13
+ pylode/templates/agent.html,sha256=NTFTrA4Ji3CVnJAgw3JkL5WByIYmGSt0-wgUtDvg2kE,252
14
+ pylode/templates/agent.md,sha256=sYpnepaPTooYNX3JbFSdo6Rf_Dc8fN4vV6jw1np96EY,207
15
+ pylode/templates/namespaces.html,sha256=M-mDN1krRJWy2FAp9Vwcu5icPSfu0TM5Yfpeg1VQq8M,300
16
+ pylode/templates/namespaces.md,sha256=NgiCxkgNb1uIZlBKBIRI7xPWGKw0BYqTyj-X3t7A1xs,106
17
+ pylode/templates/orcid.html,sha256=o-2Z20AFnTqZZ92t7u-A_RofOYRh4LJaarKZznLwxBI,1905
18
+ pylode/templates/orcid.md,sha256=gwN-ODYXRi-JBMWmH9ES7gMRAC6kxvZuiVHc04k7pPE,7
19
+ pylode/templates/ontdoc/class.html,sha256=wJUQ_1yHpr-6moiVXz3mz7ShzEuPpTB-YkJN0tCFcFQ,3566
20
+ pylode/templates/ontdoc/class.md,sha256=0nQGvPbAOpuIaypsx8_Cs9H7huTri2PuLypcp-uFv6o,1284
21
+ pylode/templates/ontdoc/classes.html,sha256=f3i83ldj97wdbLnPCL-Sb8ye4V69CmpwMwSzqRP8H6g,347
22
+ pylode/templates/ontdoc/classes.md,sha256=RFZj1u9DQqylrmq0XW1Vz3hi0ATrZeW1RPUfo3UeYB4,139
23
+ pylode/templates/ontdoc/document.html,sha256=gUkGStgOzSos0cTw3ZjFYgAci0YksDzzL91u42rmECE,1656
24
+ pylode/templates/ontdoc/document.md,sha256=n2FlmqDQcUw2XgQRlvf4JBey4UH3-ZPj6kx2Dg70Vdo,376
25
+ pylode/templates/ontdoc/metadata.html,sha256=JrSxTuyX4Yd0kwMzQ2bWbVka2d8PrxCwP4FYMcOfGrs,4770
26
+ pylode/templates/ontdoc/metadata.md,sha256=K1uHUemo0Y10Xa_F2qzIDlvkYrb-51lgQ6yOj9B129c,2259
27
+ pylode/templates/ontdoc/named_individual.html,sha256=L6EMllxXtTl94YIRlOo8EGS1BYj78bblZT9VQEwqMcI,1833
28
+ pylode/templates/ontdoc/named_individual.md,sha256=Uz7xAiKQU0AQufi9N7CzKhVXZBj0hXr2muL_3J2yFn4,560
29
+ pylode/templates/ontdoc/named_individuals.html,sha256=5DIyP57yhcFZIQBwZWgp8dCnvgiwO_1TriJQuBoQztM,370
30
+ pylode/templates/ontdoc/named_individuals.md,sha256=szOSZQXQJFq6cpJd-H4Tjkd3cT3vi_q3qXnVJBUsJ0Y,153
31
+ pylode/templates/ontdoc/properties.html,sha256=Bgte2a-d8iusc5G8Otdev_3hGLrgAvp_ZIDh3LgBZIc,2080
32
+ pylode/templates/ontdoc/properties.md,sha256=n7-cUtWzQkX-2ZBTsn7XNp-UADc6y1_SMbfABsYTSUQ,980
33
+ pylode/templates/ontdoc/property.html,sha256=hllTJ5voVZP-4sBwnYaczV9Aa32ebnC6r9terZsj6dQ,4273
34
+ pylode/templates/ontdoc/property.md,sha256=4ZNR0Nl-NHzYbxNO4YN-_c58npsEl37G9Bh3fmMbkKo,1302
35
+ pylode/templates/prof/prof.html,sha256=hGY4UQfaKHMGLxfYAbvCtPbQ4yMWUGvAKfLzg0sc9Sg,1131
36
+ pylode/templates/prof/prof.md,sha256=blbh-rk_OWkGeliFQjz1hLP-bf_os7hqlDHx3AdHZcI,340
37
+ pylode/templates/prof/profile.html,sha256=HoS5qZmHWw32-vG2w1Je_XDxcxHbGnBKjYwdSVmdS2A,3557
38
+ pylode/templates/prof/profile.md,sha256=qnsv5H_I4HbegGY1dvnxIPRv6Ru76u0K1JRPEA92mJI,1684
39
+ pylode/templates/prof/resource_descriptor.html,sha256=d5Lbsl1tcXmHi0P4Bqu3fNUwpgWbYvBYvZzWyM6JmUg,1647
40
+ pylode/templates/prof/resource_descriptor.md,sha256=llvHezZwlMQy6Z79pFrCgwJvQbQOJIGKdZi_5upnsws,532
41
+ pylode/templates/vocpub/collection.html,sha256=oBF-NjxGV8X8XPiNDVEd7-LSBfmI6V3zre0Zo3Q_tO8,1591
42
+ pylode/templates/vocpub/collection.md,sha256=bcVJoifPBI5I_3P-UOelEKN3bBAxX3Mmw9lcP6Cmlh0,873
43
+ pylode/templates/vocpub/collections.html,sha256=T5iYEfieZ9YR-vHgbd7qdWKzOATM2Du00pfQsaHkX5g,400
44
+ pylode/templates/vocpub/collections.md,sha256=dsTyLK-CnhviHaf8jNEfdD7gflH_Ng9eaWKbiTXEXCM,191
45
+ pylode/templates/vocpub/concept.html,sha256=JCROzB9LnMhB3K2WHi3JN2siqOAxo4htXHup-dcSCu0,3670
46
+ pylode/templates/vocpub/concept.md,sha256=jpbGZuYnYRLs1xfGo9ICkkmdiA3Wb7bFIU85Fryg9r0,1609
47
+ pylode/templates/vocpub/concept_hierarchy.html,sha256=b9BTGN-toKq0EXd3eI0smn1J6IQopLumix9xyBNjuZY,2079
48
+ pylode/templates/vocpub/concept_scheme.html,sha256=75Edx-QbD6lmRXxOx3Fn5cZ7IxZtOtMXZcM-JH1h59g,4171
49
+ pylode/templates/vocpub/concept_scheme.md,sha256=jh690mXsiQDJpdLbDSPuISJSKp_LlJKyuu0eJEpgq-4,1916
50
+ pylode/templates/vocpub/concepts.html,sha256=PT5ogyuTby8wgNvyCy9tIF9rFMTiP14tlt2B-mAdT_k,307
51
+ pylode/templates/vocpub/concepts.md,sha256=dJSu1oZ7Dr_7faSeuQnehweHQEj95_gACITnPT4n9cg,160
52
+ pylode/templates/vocpub/taxonomy.html,sha256=oZTm5q0Oim_jtyxHoFNL8jd1F2J35owENp1UOiglldk,1097
53
+ pylode/templates/vocpub/taxonomy.md,sha256=LtbsBuOLWZiqcZOISVw6pSadsXftqBBuyiMg7hyyPe0,286
54
+ pylode/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
+ pylode/tests/test_ont_html_description.py,sha256=TGtdwSn7HjiK5wyPPXRj6oqSQlfoyBkZxmePgd9fes4,179
56
+ pylode/tests/test_skos.py,sha256=r_oBy6cjS-8v4yr8Y_qHhQvo8EqibAKcCMAHmEbpCX0,214
57
+ pylode/tests/tests_all.py,sha256=6w1njRCHH6TYOR6Oo5vCCaIUGn7YqTUdy0Jx-Rx7n4o,1578
58
+ pyLODE-2.8.3.dist-info/LICENSE,sha256=DOLbiwXyZgqIMYgF59FBHa0-beH9-Ars22dMstVAwCM,35262
59
+ pyLODE-2.8.3.dist-info/METADATA,sha256=lWfubz3_hvroDFAgzbtYWdvaZ1XhbM0W8uL0nVvDgx4,30581
60
+ pyLODE-2.8.3.dist-info/WHEEL,sha256=kGT74LWyRUZrL4VgLh6_g12IeVl_9u9ZVhadrgXZUEY,110
61
+ pyLODE-2.8.3.dist-info/entry_points.txt,sha256=ke39luhrWgy_H-OR1BMTarUmb0U5HD0qc9NCDeov2AM,44
62
+ pyLODE-2.8.3.dist-info/top_level.txt,sha256=abeq7Fnj2In1apCho3urrksoLurHqHeloZOV9KO0mss,7
63
+ pyLODE-2.8.3.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.34.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ pylode = pylode.cli:main
3
+
@@ -0,0 +1 @@
1
+ pylode
pylode/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from rdflib.plugin import register, Serializer
2
+ register("json-ld", Serializer, "rdflib_jsonld.serializer", "JsonLDSerializer")
3
+
4
+ from .common import *
5
+ from .profiles import OntDoc, Prof, VocPub, PROFILES, RDF_MEDIA_TYPES
pylode/cli.py ADDED
@@ -0,0 +1,191 @@
1
+ import argparse
2
+ import os
3
+ from os import path
4
+ import shutil
5
+ import sys
6
+ from os.path import dirname, realpath
7
+ sys.path.insert(0, dirname(dirname(realpath(__file__))))
8
+ from pylode import RDF_FILE_EXTENSIONS, MakeDocco
9
+
10
+
11
+ def is_valid_file(parser, arg):
12
+ try:
13
+ return open(arg, "r")
14
+ except:
15
+ parser.error("The file %s does not exist!" % arg)
16
+
17
+
18
+ # used to capture graph parsing and content errors
19
+ class RdfGraphError(Exception):
20
+ pass
21
+
22
+
23
+ def main(args=None):
24
+ # read the input ontology file into a graph
25
+ parser = argparse.ArgumentParser()
26
+ overarching_group = parser.add_mutually_exclusive_group()
27
+ inputs_group = overarching_group.add_mutually_exclusive_group()
28
+
29
+ inputs_group.add_argument(
30
+ "-i",
31
+ "--inputfile",
32
+ help="The RDF ontology file you wish to generate HTML for. "
33
+ "Must be in either Turtle, RDF/XML, JSON-LD or N-Triples formats indicated by the file type extensions:"
34
+ "{} respectively.".format(", ".join(RDF_FILE_EXTENSIONS)),
35
+ type=lambda x: is_valid_file(parser, x),
36
+ )
37
+
38
+ inputs_group.add_argument(
39
+ "-u",
40
+ "--url",
41
+ help="The RDF ontology you wish to generate HTML for, online. "
42
+ "Must be an absolute URL that can be resolved to RDF, preferably via Content Negotiation.",
43
+ )
44
+
45
+ overarching_group.add_argument(
46
+ "-lp",
47
+ "--listprofiles",
48
+ help="This flag, if used, must be the only flag supplied. It will cause the program to list all the ontology"
49
+ " documentation profiles that it supports, indicating both their URI and their short token for use with the"
50
+ " -p (--profile) flag when creating HTML documentation",
51
+ action="store_true",
52
+ )
53
+
54
+ parser.add_argument(
55
+ "-p",
56
+ "--profile",
57
+ help="A profile - a specified information model - for an ontology. You can indicate this via the profile's URI"
58
+ "or its token. The list of profiles - URIs and their corresponding tokens - supported by pyLODE, can be "
59
+ "found by running the program with the flag -lp or --listprofiles.",
60
+ default="ontdoc",
61
+ )
62
+
63
+ parser.add_argument(
64
+ "-c",
65
+ "--css",
66
+ help="Whether (true) or not (false) to copy the default CSS file to the output directory.",
67
+ choices=["true", "false"],
68
+ default="false",
69
+ )
70
+
71
+ parser.add_argument(
72
+ "-xc",
73
+ "--excludecss",
74
+ help="Whether (true) or not (false) to exclude the standard pyLODE CSS content from an HTML file output.",
75
+ choices=["true", "false"],
76
+ default="false",
77
+ )
78
+
79
+ parser.add_argument(
80
+ "-q",
81
+ "--getcuriesonline",
82
+ help="Whether (true) or not (false) to look up CURIEs for unknown namespaces using http://prefix.cc.",
83
+ choices=["true", "false"],
84
+ default="false",
85
+ )
86
+
87
+ parser.add_argument(
88
+ "-o",
89
+ "--outputfile",
90
+ help="A name you wish to assign to the output file. Will be postfixed with .html/.md if not already added. If "
91
+ "no output file is given, output will be printed to screen",
92
+ default=None
93
+ )
94
+
95
+ parser.add_argument(
96
+ "-f",
97
+ "--outputformat",
98
+ help="The output format of the documentation.",
99
+ choices=["html", "md"],
100
+ default="html",
101
+ )
102
+
103
+ parser.add_argument(
104
+ "-v",
105
+ "--version",
106
+ help="The version of this copy of pyLODE.",
107
+ action="store_true"
108
+ )
109
+
110
+ args = parser.parse_args()
111
+
112
+ if args.listprofiles:
113
+ print(MakeDocco.list_profiles())
114
+ exit()
115
+ elif args.version:
116
+ from pylode import __version__
117
+ print(__version__)
118
+ exit()
119
+ elif args.inputfile or args.url:
120
+ if args.excludecss == "true":
121
+ exclude_css = True
122
+ else:
123
+ exclude_css = False
124
+
125
+ # args are present so getting RDF from input file or uri into an rdflib Graph
126
+ if args.inputfile:
127
+ h = MakeDocco(
128
+ input_data_file=args.inputfile,
129
+ outputformat=args.outputformat,
130
+ profile=args.profile,
131
+ exclude_css=exclude_css
132
+ )
133
+ elif args.url:
134
+ h = MakeDocco(
135
+ input_uri=args.url,
136
+ outputformat=args.outputformat,
137
+ profile=args.profile,
138
+ exclude_css=exclude_css
139
+ )
140
+ else:
141
+ # we have neither an input file or a URI supplied
142
+ parser.error(
143
+ "Either an input file or a url is required to access the ontology's RDF"
144
+ )
145
+
146
+ if args.profile:
147
+ if not MakeDocco.is_supported_profile(args.profile):
148
+ parser.error("The profile you requested, '{}', is not supported. "
149
+ "Please choose from those given by List Profiles (-lp)".format(args.profile))
150
+ else:
151
+ parser.error("An ontology source (-i/--inputfile or -u/--url) is required")
152
+
153
+ # here we have a parsed graph from either a local file or a URI
154
+
155
+ # set up output directories and resources
156
+ main_dir = path.dirname(path.realpath(__file__))
157
+ style_dir = path.join(main_dir, "style")
158
+ if h.publication_dir == "":
159
+ h.publication_dir = "."
160
+ os.makedirs(h.publication_dir, exist_ok=True)
161
+
162
+ # include CSS
163
+ if args.css == "true":
164
+ shutil.copyfile(
165
+ path.join(style_dir, "pylode.css"), path.join(h.publication_dir, "style.css")
166
+ )
167
+
168
+ if args.outputfile is not None:
169
+ output_file_name = (
170
+ args.outputfile if args.outputfile else "doc.html"
171
+ )
172
+
173
+ if args.outputformat == "html":
174
+ if not output_file_name.endswith(".html"):
175
+ output_file_name += ".html"
176
+ elif args.outputformat == "md":
177
+ if not output_file_name.endswith(".md"):
178
+ output_file_name += ".md"
179
+
180
+ # generate the HTML doc
181
+ h.document(destination=output_file_name)
182
+
183
+ print("Finished. {} documentation in {}".format(args.profile, output_file_name))
184
+ else:
185
+ print(h.document())
186
+
187
+
188
+ if __name__ == "__main__":
189
+ import sys
190
+
191
+ main(sys.argv[1:])
pylode/common.py ADDED
@@ -0,0 +1,191 @@
1
+ from os import path
2
+ import requests
3
+ from rdflib import util, Graph
4
+
5
+ VERSION = "2.8.3"
6
+ APP_DIR = path.dirname(path.realpath(__file__))
7
+ TEMPLATES_DIR = path.join(path.dirname(path.realpath(__file__)), "templates")
8
+ STYLE_DIR = path.join(path.dirname(path.realpath(__file__)), "style")
9
+ RDF_FILE_EXTENSIONS = [".rdf", ".owl", ".ttl", ".n3", ".nt", ".json"]
10
+ RDF_SERIALIZER_MAP = {
11
+ "text/turtle": "turtle",
12
+ "text/n3": "n3",
13
+ "application/n-triples": "nt",
14
+ "application/ld+json": "json-ld",
15
+ "application/rdf+xml": "xml",
16
+ # Some common but incorrect mimetypes
17
+ "application/rdf": "xml",
18
+ "application/rdf xml": "xml",
19
+ "application/json": "json-ld",
20
+ "application/ld json": "json-ld",
21
+ "text/ttl": "turtle",
22
+ "text/turtle;charset=UTF-8": "turtle",
23
+ "text/ntriples": "nt",
24
+ "text/n-triples": "nt",
25
+ "text/plain": "nt", # text/plain is the old/deprecated mimetype for n-triples
26
+ }
27
+
28
+
29
+ from .profiles import OntDoc, Prof, VocPub, PROFILES
30
+
31
+
32
+ class MakeDocco:
33
+ def __init__(self, input_data_file=None, input_uri=None, data=None, outputformat="html", exclude_css=False, get_curies_online=False, profile="ontdoc"):
34
+ """This class receives all of the variables needed to specify how to make documentation from an input RDF source
35
+
36
+ :param input_data_file: An RDF file
37
+ :type input_data_file: path (string)
38
+ :param input_uri: A URI resolving to RDF data
39
+ :type input_uri: A URI (string)
40
+ :param data: RDF data
41
+ :type data: Python varaible (string)
42
+ :param outputformat: The desired output format form the list of supported formats (currently either "html" (default) or "md" for Markdown
43
+ :type outputformat: string (one of "html" or "md")
44
+ :param exclude_css: Whether (True, default) or not (False) to include styling CSS within HTML outputs (as oposed to producing a separate style.css file)
45
+ :type exclude_css: boolean
46
+ :param get_curies_online: Whether (True) or not (False, default) to search prefix.cc online for additional URI prefixes
47
+ :type get_curies_online: boolean
48
+ :param profile: When document profile, from a supported set, to use. Currently supported is "ontdoc" (profile of OWL) or "skosp" (profile of SKOS). See `list_profiles()` for full list of profiles.
49
+ :type profile: string (one of "ontdoc" or "skosp")
50
+ """
51
+ self.profile_selected = profile
52
+
53
+ if outputformat not in ["html", "md"]:
54
+ self.outputformat = "html"
55
+ else:
56
+ self.outputformat = outputformat
57
+
58
+ self.exclude_css = exclude_css
59
+ self.get_curies_online = get_curies_online
60
+
61
+ if profile not in PROFILES.keys():
62
+ print("The profile you've selected, {}, is not recognised so the default profile, {} is being used. "
63
+ "Known profiles are: {}".format(profile, "ontdoc", ", ".join(PROFILES.keys())))
64
+ self.profile_selected = "ontdoc"
65
+ else:
66
+ self.profile_selected = profile
67
+
68
+ # shared variables
69
+ if input_data_file is not None:
70
+ self._parse_input_data_file(input_data_file)
71
+ elif input_uri is not None:
72
+ self._parse_input_uri(input_uri)
73
+ elif data is not None:
74
+ self._parse_data(data)
75
+ else:
76
+ raise Exception("You must supply either an input file or a URI for your ontology's RDF")
77
+
78
+ def _parse_input_data_file(self, input_data_file):
79
+ if hasattr(input_data_file, "name"):
80
+ file_name = str(input_data_file.name)
81
+ elif input_data_file is not None:
82
+ file_name = str(input_data_file)
83
+
84
+ if not file_name.endswith(tuple(RDF_FILE_EXTENSIONS)):
85
+ raise Exception(
86
+ "If supplying an input RDF file, it must end with one of the following file type extensions: {}."
87
+ .format(
88
+ ", ".join(RDF_FILE_EXTENSIONS)
89
+ )
90
+ )
91
+ else:
92
+ fmt = (
93
+ "json-ld"
94
+ if file_name.endswith(".json") or file_name.endswith(".jsonld")
95
+ else util.guess_format(file_name)
96
+ )
97
+
98
+ self.G = Graph().parse(file_name, format=fmt)
99
+ self.source_info = (file_name, fmt)
100
+ self.publication_dir = path.dirname(file_name)
101
+
102
+ def _parse_input_uri(self, uri):
103
+ r = requests.get(
104
+ uri, headers={"Accept": ", ".join(RDF_SERIALIZER_MAP.keys())}
105
+ )
106
+ # get RDF format from Media Type
107
+ media_type = r.headers.get("Content-Type").split(";")[0] # splitting off any ;charset=...
108
+ if RDF_SERIALIZER_MAP.get(media_type):
109
+ fmt = RDF_SERIALIZER_MAP.get(media_type)
110
+ else:
111
+ fmt = (
112
+ "json-ld"
113
+ if media_type == "application/ld+json"
114
+ or media_type == "application/json"
115
+ else None
116
+ )
117
+
118
+ if fmt is None:
119
+ raise Exception(
120
+ "Could not parse the supplied URI. The RDF format could not be determined from Media Type "
121
+ "({} was given) or from a file extension".format(media_type)
122
+ )
123
+
124
+ self.G = Graph().parse(data=r.text, format=fmt)
125
+ self.source_info = (uri, fmt)
126
+ self.publication_dir = path.join(
127
+ path.dirname(path.realpath(__file__)), "output_files"
128
+ )
129
+
130
+ def _parse_data(self, data):
131
+ self.G = Graph().parse(data=data, format="turtle")
132
+ self.source_info = ("input.ttl", "turtle")
133
+ self.publication_dir = path.dirname(path.realpath(__file__))
134
+
135
+ @classmethod
136
+ def list_profiles(cls):
137
+ s = ""
138
+ for k, v in PROFILES.items():
139
+ s += "{}: {}\n".format(k, v)
140
+
141
+ return s
142
+
143
+ @classmethod
144
+ def is_supported_profile(cls, profile_key):
145
+ is_supported = False
146
+ for k, v in PROFILES.items():
147
+ if profile_key == k or profile_key == v.uri:
148
+ is_supported = True
149
+
150
+ return is_supported
151
+
152
+ def document(self, destination=None):
153
+ if self.profile_selected == "prof":
154
+ p = Prof(
155
+ self.G,
156
+ self.source_info,
157
+ outputformat=self.outputformat,
158
+ exclude_css=self.exclude_css,
159
+ default_language="en",
160
+ get_curies_online=self.get_curies_online
161
+ )
162
+ elif self.profile_selected == "vocpub":
163
+ p = VocPub(
164
+ self.G,
165
+ self.source_info,
166
+ outputformat=self.outputformat,
167
+ exclude_css=self.exclude_css,
168
+ default_language="en",
169
+ get_curies_online=self.get_curies_online
170
+ )
171
+ else:
172
+ p = OntDoc(
173
+ self.G,
174
+ self.source_info,
175
+ outputformat=self.outputformat,
176
+ exclude_css=self.exclude_css,
177
+ default_language="en",
178
+ get_curies_online=self.get_curies_online
179
+ )
180
+
181
+ if destination is not None:
182
+ doc = p.generate_document()
183
+ try:
184
+ with open(destination, "w") as f:
185
+ f.write(doc)
186
+ except Exception as e:
187
+ print(e)
188
+ raise Exception("The file you specified as 'destination' could not be written to. You specified {}.".format(destination))
189
+
190
+ else:
191
+ return p.generate_document()