1212from collections .abc import Iterable , Mapping
1313from functools import lru_cache
1414from pathlib import Path
15- from typing import Any , Literal
15+ from typing import TYPE_CHECKING , Any , Literal
1616
1717import bioregistry
18+ import curies
1819import pandas as pd
1920from bioregistry import NormalizedNamableReference as Reference
2021from bioregistry import manager
2526from .constants import CANONICAL , IRI_TO_PREFIX
2627from .relations import get_normalized_label , ground_relation , label_norm
2728
29+ if TYPE_CHECKING :
30+ import networkx as nx
31+
2832__all__ = [
2933 "Definition" ,
3034 "Edge" ,
@@ -55,7 +59,7 @@ def standardize(self) -> Self:
5559 """Standardize the data in this class."""
5660 raise NotImplementedError
5761
58- def raise_on_unstandardized (self ):
62+ def raise_on_unstandardized (self ) -> None :
5963 """Raise an exception if standarization has not occurred."""
6064 if not self .standardized :
6165 raise ValueError
@@ -215,7 +219,7 @@ class Meta(BaseModel, StandardizeMixin):
215219 subsets : list [str ] | None = None
216220 xrefs : list [Xref ] | None = None
217221 synonyms : list [Synonym ] | None = None
218- comments : list | None = None
222+ comments : list [ str ] | None = None
219223 version : str | None = None
220224 properties : list [Property ] | None = Field (None , alias = "basicPropertyValues" )
221225 deprecated : bool = False
@@ -303,7 +307,7 @@ def from_parsed(
303307 )
304308
305309
306- def _help_get_properties (self , predicate_iris : str | list [str ]) -> list [str ]:
310+ def _help_get_properties (self : Graph | Node , predicate_iris : str | list [str ]) -> list [str ]:
307311 if not self .meta :
308312 return []
309313 if isinstance (predicate_iris , str ):
@@ -330,12 +334,16 @@ class Node(BaseModel, StandardizeMixin):
330334 @property
331335 def prefix (self ) -> str | None :
332336 """Get the prefix for the node if it has been standardized."""
333- return self .reference and self .reference .prefix
337+ if self .reference :
338+ return self .reference .prefix
339+ return None
334340
335341 @property
336342 def identifier (self ) -> str | None :
337343 """Get the identifier for the node if it has been standardized."""
338- return self .reference and self .reference .identifier
344+ if self .reference is not None :
345+ return self .reference .identifier
346+ return None
339347
340348 def standardize (self ) -> Self :
341349 """Ground the node to a standard prefix and luid based on its id (URI)."""
@@ -536,17 +544,23 @@ def roots(self) -> list[str]:
536544 @property
537545 def license (self ) -> str | None :
538546 """Get the license of the ontology."""
539- return self ._get_property ("http://purl.org/dc/terms/license" )
547+ return self ._get_property (
548+ ["http://purl.org/dc/terms/license" , "http://purl.org/dc/elements/1.1/license" ]
549+ )
540550
541551 @property
542552 def title (self ) -> str | None :
543553 """Get the title of the ontology."""
544- return self ._get_property ("http://purl.org/dc/elements/1.1/title" )
554+ return self ._get_property (
555+ ["http://purl.org/dc/terms/title" , "http://purl.org/dc/elements/1.1/title" ]
556+ )
545557
546558 @property
547559 def description (self ) -> str | None :
548560 """Get the license of the ontology."""
549- return self ._get_property ("http://purl.org/dc/elements/1.1/description" )
561+ return self ._get_property (
562+ ["http://purl.org/dc/terms/description" , "http://purl.org/dc/elements/1.1/description" ]
563+ )
550564
551565 @property
552566 def version_iri (self ) -> str | None :
@@ -643,9 +657,9 @@ def standardize(
643657
644658 return self
645659
646- def _standardize_prefix (self ):
660+ def _standardize_prefix (self ) -> None :
647661 if not self .id :
648- return
662+ return None
649663 if self .id in IRI_TO_PREFIX :
650664 self .prefix = IRI_TO_PREFIX [self .id ]
651665 elif self .id .startswith ("http://purl.obolibrary.org/obo/" ):
@@ -656,10 +670,12 @@ def _standardize_prefix(self):
656670 self .id .removeprefix ("http://purl.obolibrary.org/obo/" )
657671 .removesuffix (suffix )
658672 .removesuffix ("_import" )
673+ .removesuffix ("_merged" )
659674 )
660675 if prefix != bioregistry .normalize_prefix (prefix ):
661676 tqdm .write (f"could not guess prefix from { self .id } " )
662677 return
678+ # FIXME check if clyh/clyh
663679 self .prefix = prefix
664680 return
665681
@@ -696,7 +712,9 @@ def get_xrefs(self) -> list[tuple[Reference, Reference, Reference]]:
696712 rv .append ((node .reference , xref .predicate , xref .value ))
697713 return rv
698714
699- def _get_edge_predicate_label (self , edge : Edge , ctn , require_label : bool = False ) -> str :
715+ def _get_edge_predicate_label (
716+ self , edge : Edge , ctn : Mapping [str , str ], require_label : bool = False
717+ ) -> str :
700718 if edge .predicate :
701719 label = get_normalized_label (edge .predicate .curie )
702720 if label :
@@ -870,7 +888,7 @@ def get_curie_to_name(self) -> Mapping[str, str]:
870888 node .curie : node .name for node in self .nodes if node .name and node .reference is not None
871889 }
872890
873- def get_networkx (self ):
891+ def get_networkx (self ) -> nx . MultiDiGraph :
874892 """Get a networkx multi-directional graph."""
875893 import networkx as nx
876894
@@ -902,7 +920,7 @@ def write_warned(path: str | Path) -> None:
902920
903921
904922@lru_cache (1 )
905- def _get_converter ():
923+ def _get_converter () -> curies . Converter :
906924 return bioregistry .manager .get_converter (include_prefixes = True )
907925
908926
@@ -933,7 +951,7 @@ def _get_reference(s: str, *, debug: bool = False) -> Reference | None: # noqa:
933951 if reference is not None :
934952 return reference
935953 if s not in WARNED :
936- logger .warning ("could not parse OBO internal relation: %s" , s )
954+ logger .debug ("could not parse OBO internal relation: %s" , s )
937955 WARNED [s ] += 1
938956
939957 if "upload.wikimedia.org" in s :
0 commit comments