Skip to content

Commit 4070123

Browse files
V0.0.5 (#25)
* [~] Fix path for properties * [~] Specify current directory * [~] Clean and fix external links * [~] Fix version and path posix
1 parent 8a9ba7e commit 4070123

11 files changed

Lines changed: 24 additions & 24 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ body:
3939
- type: input
4040
attributes:
4141
label: "ontodoc version:"
42-
placeholder: e.g., 0.0.4
42+
placeholder: e.g., 0.0.5
4343
validations:
4444
required: true

ontodoc/classes/Documentation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,18 @@ def generate(self):
5858
'version': self.version,
5959
'editionDate': datetime.date.today().strftime('%Y-%m-%d'),
6060
}
61+
6162
# Init ontology reader
6263
ontology = Ontology(self.graph, self.onto, self.templates, metadata)
6364
path = pathlib.Path(self.output)
6465

65-
66-
6766
# Generate pages
6867
if self.model == 'json':
6968
generate_page(json.dumps(ontology.__dict__, indent=2, cls=JSONOntoDocEncoder), f'{self.output}/ontology.json', add_signature=False)
7069
for c in ontology.classes:
7170
generate_page(json.dumps(c.__dict__, indent=2, cls=JSONOntoDocEncoder), f'{self.output}/class/{c.id}.json', add_signature=False)
7271
for p in chain(ontology.objectProperties, ontology.annotationProperties, ontology.datatypeProperties, ontology.functionalProperties):
73-
generate_page(json.dumps(p.__dict__, indent=2, cls=JSONOntoDocEncoder), f'{self.output}property/{p.id}.json', add_signature=False)
72+
generate_page(json.dumps(p.__dict__, indent=2, cls=JSONOntoDocEncoder), f'{self.output}/property/{p.id}.json', add_signature=False)
7473
elif self.model in ['markdown', 'gh_wiki']:
7574
if self.concatenate:
7675
page = ontology.__str__()
@@ -84,6 +83,7 @@ def generate(self):
8483
generate_page(path=path, node=n, footer=footer)
8584
else:
8685
raise Exception('Model not supported')
86+
8787
# Copy ontology file
8888
with open(f'{self.output}/ontology.ttl', mode='w', encoding='utf-8') as f:
8989
f.write(self.graph.serialize(format='ttl'))

ontodoc/classes/Generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, onto: Ontology, node: Node, template: Template, default_prope
2424
self.pagename = pagename
2525
else:
2626
self.pagename = (path / self.id).with_suffix('.md') if not onto.metadata.get('concatenate', False) else onto.pagename
27-
self.to_root_path = '../' * (len(self.pagename.parts) - 1)
27+
self.to_root_path = './' + '../' * (len(self.pagename.parts) - 1)
2828

2929
if onto.metadata.get('concatenate', False) and onto.onto_node != node:
3030
self.pagename = f"{self.pagename.as_posix()}#{self.id}"

ontodoc/classes/Ontology.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ def __init__(self, graph: Graph, onto_node: rdflib.Node, templates: dict[str, Te
2222
self.onto_prefix = [prefix for prefix, uriref in graph.namespace_manager.namespaces() if uriref.n3(graph.namespace_manager) == onto_node.n3(graph.namespace_manager)]
2323
self.onto_prefix = self.onto_prefix[0] if len(self.onto_prefix) > 0 else None
2424

25-
self.objectProperties = [Property(self, s, self.templates['property.md']) for s in self.graph.subjects(predicate=rdflib.RDF.type, object=rdflib.OWL.ObjectProperty) if type(s) == rdflib.URIRef and get_prefix(self.graph, s) == self.onto_prefix]
26-
self.datatypeProperties = [Property(self, s, self.templates['property.md']) for s in self.graph.subjects(predicate=rdflib.RDF.type, object=rdflib.OWL.DatatypeProperty) if type(s) == rdflib.URIRef and get_prefix(self.graph, s) == self.onto_prefix]
27-
self.annotationProperties = [Property(self, s, self.templates['property.md']) for s in self.graph.subjects(predicate=rdflib.RDF.type, object=rdflib.OWL.AnnotationProperty) if type(s) == rdflib.URIRef and get_prefix(self.graph, s) == self.onto_prefix]
28-
self.functionalProperties = [Property(self, s, self.templates['property.md']) for s in self.graph.subjects(predicate=rdflib.RDF.type, object=rdflib.OWL.FunctionalProperty) if type(s) == rdflib.URIRef and get_prefix(self.graph, s) == self.onto_prefix]
25+
[self.objectProperties, self.datatypeProperties, self.annotationProperties, self.functionalProperties] = [[Property(self, s, self.templates['property.md']) for s in self.graph.subjects(predicate=rdflib.RDF.type, object=object_type) if type(s) == rdflib.URIRef and get_prefix(self.graph, s) == self.onto_prefix] for object_type in [rdflib.OWL.ObjectProperty, rdflib.OWL.DatatypeProperty, rdflib.OWL.AnnotationProperty, rdflib.OWL.FunctionalProperty]]
26+
2927
self.classes = [Class(self, s, self.templates['class.md']) for s in self.graph.subjects(predicate=rdflib.RDF.type, object=rdflib.OWL.Class) if type(s) == rdflib.URIRef and get_prefix(self.graph, s) == self.onto_prefix]
3028

3129
self.update_internal_links()

ontodoc/classes/Property.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
class Property(Generic):
1414
def __init__(self, onto: Ontology, property_node: Node, template: Template):
15-
super().__init__(onto, property_node, template, PROPERTY, Path('property') if not onto.metadata.get('concatenate', False) else onto.pagename)
15+
super().__init__(onto, property_node, template, PROPERTY, Path('./property/') if not onto.metadata.get('concatenate', False) else onto.pagename)
1616

1717
g = onto.graph
1818

19-
self.range_link = compute_link(onto, property_node, self.range) if self.range else None
20-
self.domain_link = compute_link(onto, property_node, self.domain) if self.domain else None
19+
self.range_link = compute_link(onto, self, self.range) if self.range else None
20+
self.domain_link = compute_link(onto, self, self.domain) if self.domain else None
2121

2222
self.range_label = generate_clean_id_from_term(g, self.range) if self.range else None
2323
self.domain_label = generate_clean_id_from_term(g, self.domain) if self.domain else None

ontodoc/generate_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def generate_page(content: str = None, path: Path = None, node: Generic = None,
1111
path.parent.mkdir(parents=True, exist_ok=True)
1212
if content == None:
1313
content = node.__str__()
14-
with open(path, mode='w', encoding='utf-8') as f:
14+
with open(path.as_posix(), mode='w', encoding='utf-8') as f:
1515
f.write(content)
1616

1717
if footer:

ontodoc/templates/class.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ classDiagram
4848
{%- endif %} | {{triple.label if triple.label}} | {{triple.comment if triple.comment}} |
4949

5050
{%- if triple.range_link -%}
51-
<kbd>[{{triple.range_n3}}]({{class.to_root_path}}{{triple.range_link}})</kbd>
51+
<kbd>[{{triple.range_n3}}]({{triple.range_link}})</kbd>
5252
{%- else -%}
5353
<kbd>{{triple.range_n3}}</kbd>
5454
{%- endif %} |
@@ -58,7 +58,7 @@ classDiagram
5858
{%- if class.subclassof %}
5959
{%- for subclassof in class.subclassof %}
6060
{% if subclassof.triples|length %}
61-
### Inherited from <kbd>[**{{subclassof.label}}**](../{{subclassof.pagename}}.md)</kbd>
61+
### Inherited from <kbd>[**{{subclassof.label}}**](../{{subclassof.pagename}})</kbd>
6262
| Predicate | Label | Comment | Type |
6363
| -------------------------------- | -------------------------------- | ------------------------------------ | ---- |
6464
| {%- for triple in subclassof.triples | sort(attribute='n3') %} |
@@ -69,7 +69,7 @@ classDiagram
6969
{%- endif %} | {{triple.label if triple.label}} | {{triple.comment if triple.comment}} |
7070

7171
{%- if triple.range_link -%}
72-
<kbd>[{{triple.range_n3}}]({{class.to_root_path}}{{triple.range_link}})</kbd>
72+
<kbd>[{{triple.range_n3}}]({{triple.range_link}})</kbd>
7373
{%- else -%}
7474
<kbd>{{triple.range_n3}}</kbd>
7575
{%- endif %} |

ontodoc/templates/property.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# [{{onto.label}}]({{property.to_root_path}}{{onto.pagename}}) > {{property.id}}
2+
23
<a name="{{property.id}}"></a>
34
## {{property.label}}
45

@@ -10,14 +11,14 @@
1011

1112
{% if property.range -%}
1213
- Range : {%- if property.range_link -%}
13-
[{{property.range}}]({{property.to_root_path}}{{property.range_link}})
14+
[{{property.range}}]({{property.range_link}})
1415
{%- elif property.range%}
1516
<kbd>{{property.range}}</kbd>
1617
{%- endif %}{%- endif %}
1718

1819
{% if property.domain -%}
1920
- Domain : {%- if property.domain_link -%}
20-
[{{property.domain}}]({{property.to_root_path}}{{property.domain_link}})
21+
[{{property.domain}}]({{property.domain_link}})
2122
{%- elif property.domain -%}
2223
<kbd>{{property.domain}}</kbd>
2324
{%- endif %}{%- endif %}

ontodoc/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import TYPE_CHECKING
99
if TYPE_CHECKING:
1010
from ontodoc.classes.Ontology import Ontology
11+
from ontodoc.classes.Generic import Generic
1112
from ontodoc.ontology_properties import ONTOLOGY_PROP
1213

1314
def concat_templates_environment(default_env: Environment, custom_env: Environment = None):
@@ -70,7 +71,7 @@ def get_suffix(graph: Graph, n: Node):
7071
def generate_clean_id_from_term(graph: Graph, n: Node):
7172
return re.sub(r'[^a-zA-Z\-_0-9]+', '_', n.n3(namespace_manager=graph.namespace_manager).split(':')[-1])
7273

73-
def compute_link(onto: Ontology, current_node: Node, n: Node):
74+
def compute_link(onto: Ontology, current_node: Generic, n: Node):
7475
graph = onto.graph
7576
prefix = onto.onto_prefix
7677
if n and n.n3(graph.namespace_manager).startswith(prefix+':'):
@@ -79,8 +80,8 @@ def compute_link(onto: Ontology, current_node: Node, n: Node):
7980
type = get_object(graph, n, RDF.type)
8081
page_name = n.n3(graph.namespace_manager).split(prefix+':')[1]+'.md'
8182
if type and type in [RDFS.Class, OWL.Class]:
82-
return 'class/' + page_name
83-
return 'property/' + page_name
83+
return current_node.to_root_path + 'class/' + page_name
84+
return current_node.to_root_path + 'property/' + page_name
8485
return n.n3()
8586

8687
def serialize_subset(graph: Graph, n: Node):

ontodoc/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.4"
1+
__version__ = "0.0.5"

0 commit comments

Comments
 (0)