Skip to content

Commit 97e9116

Browse files
Merge pull request #20 from saezlab/feat/us3.2-graphblas-implementation
With this change, a user can choose if use Pronto or Graphblas as backend. Additionally, the load function has been unified to simplify the user experience.
2 parents 8e4a16d + 703f35d commit 97e9116

17 files changed

Lines changed: 7110 additions & 149 deletions

notebooks/_graphblas_experiments.ipynb

Lines changed: 712 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/graphblas_usecase_1.ipynb

Lines changed: 2257 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/query_graphblas.ipynb

Lines changed: 1846 additions & 0 deletions
Large diffs are not rendered by default.

ontograph/client.py

Lines changed: 279 additions & 89 deletions
Large diffs are not rendered by default.

ontograph/loader.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from functools import cached_property
1313

1414
import pronto
15+
from charset_normalizer import from_path
1516

1617
from ontograph.models import Ontology, CatalogOntologies
1718
from ontograph.downloader import (
@@ -155,6 +156,18 @@ def _extract_ontology_id(self, ontology: pronto.Ontology) -> str | None:
155156
)
156157
return None
157158

159+
def find_file_encoding(self, file: str | Path) -> str | None:
160+
"""Detect the encoding of a file.
161+
162+
Args:
163+
file (str | Path): Path to the file whose encoding should be detected.
164+
165+
Returns:
166+
str | None: The detected encoding, or None if it cannot be determined.
167+
"""
168+
result = from_path(file).best()
169+
return result.encoding
170+
158171
def _load_ontology(
159172
self, path_file: Path
160173
) -> tuple[pronto.Ontology, str | None]:
@@ -178,7 +191,9 @@ def _load_ontology(
178191

179192
logger.debug(f'Parsing ontology file with Pronto: {path_file}')
180193
try:
181-
ontology: pronto.Ontology = pronto.Ontology(path_file)
194+
ontology: pronto.Ontology = pronto.Ontology(
195+
path_file, encoding=self.find_file_encoding(path_file)
196+
)
182197
except (TypeError, ValueError) as e:
183198
error_msg = f'Failed to load ontology from {path_file}: {str(e)}'
184199
logger.exception(error_msg)

0 commit comments

Comments
 (0)