obographs 0.0.7__tar.gz → 0.0.9__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: obographs
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: A python data model for OBO Graphs
5
5
  Keywords: snekpack,cookiecutter
6
6
  Author: Charles Tapley Hoyt
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "obographs"
7
- version = "0.0.7"
7
+ version = "0.0.9"
8
8
  description = "A python data model for OBO Graphs"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -232,7 +232,7 @@ known-first-party = [
232
232
  docstring-code-format = true
233
233
 
234
234
  [tool.bumpversion]
235
- current_version = "0.0.7"
235
+ current_version = "0.0.9"
236
236
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(?:-(?P<release>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+(?P<build>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?"
237
237
  serialize = [
238
238
  "{major}.{minor}.{patch}-{release}+{build}",
@@ -184,6 +184,23 @@ class Graph(BaseModel):
184
184
  domainRangeAxioms: list[DomainRangeAxiom] = Field(default_factory=list) # noqa:N815
185
185
  propertyChainAxioms: list[PropertyChainAxiom] = Field(default_factory=list) # noqa:N815
186
186
 
187
+ def _get_property(self, predicate: str) -> str | None:
188
+ if self.meta is not None:
189
+ for prop in self.meta.basicPropertyValues or []:
190
+ if prop.pred == predicate and prop.val:
191
+ return prop.val
192
+ return None
193
+
194
+ @property
195
+ def name(self) -> str | None:
196
+ """Get the title."""
197
+ return self._get_property("http://purl.org/dc/terms/title")
198
+
199
+ @property
200
+ def version(self) -> str | None:
201
+ """Get the version."""
202
+ return self._get_property("http://www.w3.org/2002/07/owl#versionInfo")
203
+
187
204
  def standardize(
188
205
  self, converter: curies.Converter, *, strict: bool = False
189
206
  ) -> StandardizedGraph:
@@ -222,19 +239,31 @@ def get_id_to_edges(graph: Graph) -> dict[str, list[tuple[str, str]]]:
222
239
  # docstr-coverage:excused `overload`
223
240
  @overload
224
241
  def read(
225
- source: str | Path, *, timeout: TimeoutHint = ..., squeeze: Literal[False] = ...
242
+ source: str | Path,
243
+ *,
244
+ timeout: TimeoutHint = ...,
245
+ squeeze: Literal[False] = ...,
246
+ encoding: str = ...,
226
247
  ) -> GraphDocument: ...
227
248
 
228
249
 
229
250
  # docstr-coverage:excused `overload`
230
251
  @overload
231
252
  def read(
232
- source: str | Path, *, timeout: TimeoutHint = ..., squeeze: Literal[True] = ...
253
+ source: str | Path,
254
+ *,
255
+ timeout: TimeoutHint = ...,
256
+ squeeze: Literal[True] = ...,
257
+ encoding: str = ...,
233
258
  ) -> Graph: ...
234
259
 
235
260
 
236
261
  def read(
237
- source: str | Path, *, timeout: TimeoutHint = None, squeeze: bool = True
262
+ source: str | Path,
263
+ *,
264
+ timeout: TimeoutHint = None,
265
+ squeeze: bool = True,
266
+ encoding: str = "utf-8",
238
267
  ) -> Graph | GraphDocument:
239
268
  """Read an OBO Graph document.
240
269
 
@@ -244,6 +273,7 @@ def read(
244
273
  only has a single graph and return a :class:`Graph` object. If `true` and
245
274
  multiple graphs are received, will raise an error. Set this to `false` to return
246
275
  a GraphDocument containing all graphs.
276
+ :param encoding: The encoding to use for reading the graph
247
277
 
248
278
  :returns: A graph or graph document
249
279
 
@@ -264,10 +294,10 @@ def read(
264
294
  if not path.is_file():
265
295
  raise FileNotFoundError
266
296
  if path.suffix.endswith(".gz"):
267
- with gzip.open(path, mode="rt") as file:
297
+ with gzip.open(path, mode="rt", encoding=encoding) as file:
268
298
  graph_document = GraphDocument.model_validate(json.load(file))
269
299
  else:
270
- with path.open() as file:
300
+ with path.open(mode="rt", encoding=encoding) as file:
271
301
  graph_document = GraphDocument.model_validate(json.load(file))
272
302
  else:
273
303
  raise TypeError(f"Unhandled source: {source}")
@@ -4,11 +4,12 @@ from __future__ import annotations
4
4
 
5
5
  import logging
6
6
  from abc import ABC, abstractmethod
7
+ from collections.abc import Iterable
7
8
  from typing import Generic, TypeVar, cast
8
9
 
9
10
  import curies.preprocessing
10
11
  from curies import Converter, Reference, Triple, vocabulary
11
- from curies.vocabulary import SynonymScopeOIO
12
+ from curies.vocabulary import SynonymScopeOIO, has_title, owl_version_info
12
13
  from pydantic import BaseModel, Field
13
14
  from typing_extensions import Self
14
15
 
@@ -209,7 +210,7 @@ class StandardizedMeta(StandardizedBaseModel[Meta]):
209
210
  synonyms: list[StandardizedSynonym] | None = None
210
211
  comments: list[str] | None = None
211
212
  deprecated: bool = False
212
- version: str | None = None
213
+ version_iri: str | None = None
213
214
  properties: list[StandardizedProperty] | None = None
214
215
 
215
216
  @classmethod
@@ -272,7 +273,7 @@ class StandardizedMeta(StandardizedBaseModel[Meta]):
272
273
  xrefs=xrefs or None,
273
274
  synonyms=synonyms or None,
274
275
  comments=meta.comments,
275
- version=meta.version,
276
+ version_iri=meta.version,
276
277
  deprecated=meta.deprecated,
277
278
  properties=props or None,
278
279
  )
@@ -287,7 +288,7 @@ class StandardizedMeta(StandardizedBaseModel[Meta]):
287
288
  xrefs=[xref.to_raw(converter) for xref in self.xrefs] if self.xrefs else None,
288
289
  synonyms=[s.to_raw(converter) for s in self.synonyms] if self.synonyms else None,
289
290
  comments=self.comments,
290
- version=self.version, # TODO might need some kind of expansion?
291
+ version=self.version_iri,
291
292
  deprecated=self.deprecated,
292
293
  basicPropertyValues=[p.to_raw(converter) for p in self.properties]
293
294
  if self.properties
@@ -411,8 +412,11 @@ class StandardizedDomainRangeAxiom(StandardizedBaseModel[DomainRangeAxiom]):
411
412
  cls, obj: DomainRangeAxiom, converter: Converter, *, strict: bool = False
412
413
  ) -> Self | None:
413
414
  """Parse a raw object."""
415
+ predicate = _curie_or_uri_to_ref(obj.predicateId, converter, strict=strict)
416
+ if predicate is None:
417
+ return None
414
418
  return cls(
415
- predicate=_curie_or_uri_to_ref(obj.predicateId, converter, strict=strict),
419
+ predicate=predicate,
416
420
  domains=_parse_list(obj.domainClassIds, converter, strict=strict) or [],
417
421
  ranges=_parse_list(obj.rangeClassIds, converter, strict=strict) or [],
418
422
  all_values_from_edges=[
@@ -528,11 +532,11 @@ class StandardizedLogicalDefinition(StandardizedBaseModel[LogicalDefinition]):
528
532
  """Parse a raw object."""
529
533
  return cls(
530
534
  node=_curie_or_uri_to_ref(obj.definedClassId, converter, strict=strict),
531
- geni=_parse_list(obj.genusIds, converter, strict=strict),
532
- restrictions=[
535
+ geni=_parse_list(obj.genusIds, converter, strict=strict) or [],
536
+ restrictions=_schwoop(
533
537
  StandardizedExistentialRestriction.from_obograph_raw(r, converter, strict=strict)
534
538
  for r in obj.restrictions or []
535
- ],
539
+ ),
536
540
  meta=StandardizedMeta.from_obograph_raw(obj.meta, converter, strict=strict),
537
541
  )
538
542
 
@@ -577,22 +581,22 @@ class StandardizedGraph(StandardizedBaseModel[Graph]):
577
581
  for edge in graph.edges
578
582
  if (s_edge := StandardizedEdge.from_obograph_raw(edge, converter, strict=strict))
579
583
  ],
580
- equivalent_node_sets=[
584
+ equivalent_node_sets=_schwoop(
581
585
  StandardizedEquivalentNodeSet.from_obograph_raw(e, converter, strict=strict)
582
586
  for e in graph.equivalentNodesSets or []
583
- ],
584
- logical_definition_axioms=[
587
+ ),
588
+ logical_definition_axioms=_schwoop(
585
589
  StandardizedLogicalDefinition.from_obograph_raw(e, converter, strict=strict)
586
590
  for e in graph.logicalDefinitionAxioms or []
587
- ],
588
- property_chain_axioms=[
591
+ ),
592
+ property_chain_axioms=_schwoop(
589
593
  StandardizedPropertyChainAxiom.from_obograph_raw(e, converter, strict=strict)
590
594
  for e in graph.propertyChainAxioms or []
591
- ],
592
- domain_range_axioms=[
595
+ ),
596
+ domain_range_axioms=_schwoop(
593
597
  StandardizedDomainRangeAxiom.from_obograph_raw(e, converter, strict=strict)
594
598
  for e in graph.domainRangeAxioms or []
595
- ],
599
+ ),
596
600
  )
597
601
 
598
602
  def to_raw(self, converter: Converter) -> Graph:
@@ -623,12 +627,24 @@ class StandardizedGraph(StandardizedBaseModel[Graph]):
623
627
  @property
624
628
  def name(self) -> str | None:
625
629
  """Look up the name of the graph."""
626
- r = self._get_property(Reference(prefix="dcterms", identifier="title"))
630
+ r = self._get_property(has_title)
631
+ if isinstance(r, Reference):
632
+ raise TypeError
633
+ return r
634
+
635
+ @property
636
+ def version(self) -> str | None:
637
+ """Get the version."""
638
+ r = self._get_property(owl_version_info)
627
639
  if isinstance(r, Reference):
628
640
  raise TypeError
629
641
  return r
630
642
 
631
643
 
644
+ def _schwoop(x: Iterable[X | None]) -> list[X]:
645
+ return [y for y in x if y is not None]
646
+
647
+
632
648
  class StandardizedGraphDocument(StandardizedBaseModel[GraphDocument]):
633
649
  """A standardized graph document."""
634
650
 
@@ -12,7 +12,7 @@ __all__ = [
12
12
  "get_version",
13
13
  ]
14
14
 
15
- VERSION = "0.0.7"
15
+ VERSION = "0.0.9"
16
16
 
17
17
 
18
18
  def get_git_hash() -> str:
File without changes
File without changes