Skip to content

Commit c1ad9f3

Browse files
authored
Merge pull request #217 from JaeTLDR/patch-1
fix utils.py to not load contents as file paths
2 parents 3f81c2f + f5894ba commit c1ad9f3

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

README.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,12 @@ Release Schedule
284284
:header: "Version", "Date", "Description"
285285
:widths: 15, 10, 30
286286

287-
**3.1.3**, **18 March 2024**, "Relax rdflib version constraint"
288-
**3.1.2**, **18 March 2024**, "Relax httpx version constraint"
289-
**3.1.1**, **19 February 2024**, "Fix release"
290-
**3.1.0**, **19 February 2024**, "Add supermodel mode - supports documenting profiles and modules"
291-
**3.0.5**, **27 April 2023**, "Minor patching"
287+
3.1.4, 6 April 2024, "Fix load_ontology function's detection of data input"
288+
3.1.3, 18 March 2024, "Relax rdflib version constraint"
289+
3.1.2, 18 March 2024, "Relax httpx version constraint"
290+
3.1.1, 19 February 2024, "Fix release"
291+
3.1.0, 19 February 2024, "Add supermodel mode - supports documenting profiles and modules"
292+
3.0.5, 27 April 2023, "Minor patching"
292293
3.0.4, 24 May 2022, "Use of Poetry"
293294
3.0.2, 24 May 2022, "Support for preformatted skos:example literals"
294295
3.0.1, 6 Jan 2022, "Direct HTML generation using dominate; easier to maintain and extend"

pylode/utils.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ def _get_prop_label(prop_iri: URIRef, back_onts: Graph) -> dict:
242242
return pl
243243

244244

245+
def _is_file(filepath: str) -> bool:
246+
try:
247+
if Path(filepath).is_file():
248+
return True
249+
return False
250+
except:
251+
return False
252+
253+
245254
def load_ontology(ontology: Union[Graph, Path, str]) -> Graph:
246255
"""Loads and ontology into an RDFLib Graph.
247256
@@ -251,8 +260,7 @@ def load_ontology(ontology: Union[Graph, Path, str]) -> Graph:
251260
if isinstance(ontology, str) and ontology.startswith("http"):
252261
return Graph().parse(location=ontology)
253262
elif isinstance(ontology, str):
254-
# see if it's a file path
255-
if Path(ontology).is_file():
263+
if _is_file(ontology):
256264
return Graph().parse(ontology)
257265
else: # it's data
258266
if ontology.startswith("[") or ontology.startswith("{"):

pylode/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.1.3"
1+
__version__ = "3.1.4"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pylode"
3-
version = "3.1.3a"
3+
version = "3.1.4a"
44
description = "An OWL ontology documentation tool using Python, based on LODE."
55
authors = ["Nicholas Car <[email protected]>"]
66
readme = "README.rst"

tests/test_utils.py

+31
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from rdflib.namespace import DCTERMS, OWL, RDF, RDFS, XSD
77
import pytest
88

9+
current_dir = Path(__file__).parent
10+
911

1012
# scope="session" so that this is reused without regeneration in this testing session
1113
@pytest.fixture(scope="session")
@@ -170,3 +172,32 @@ def test_prop_obj_pair_html(fix_ont, fix_load_background_onts, fix_get_ns):
170172
actual = de_space_html(pp.render(pretty=False))
171173

172174
assert actual == expected, f"Object HTML '{actual}' != '{expected}'"
175+
176+
177+
def test_load_ontology_data():
178+
data = """
179+
@prefix : <http://www.w3.org/ns/dx/prof/> .
180+
@prefix dc: <http://purl.org/dc/elements/1.1/> .
181+
@prefix dct: <http://purl.org/dc/terms/> .
182+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
183+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
184+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
185+
@prefix sdo: <https://schema.org/> .
186+
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
187+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
188+
@base <http://www.w3.org/ns/dx/prof> .
189+
190+
<http://www.w3.org/ns/dx/prof> rdf:type owl:Ontology .
191+
"""
192+
graph = load_ontology(data)
193+
assert len(graph)
194+
195+
196+
def test_load_ontology_file():
197+
filepath = current_dir / "prof.ttl"
198+
199+
graph = load_ontology(filepath)
200+
assert len(graph)
201+
202+
graph = load_ontology(str(filepath))
203+
assert len(graph)

0 commit comments

Comments
 (0)