spotterbase.records package

Submodules

spotterbase.records.jsonld_support module

class spotterbase.records.jsonld_support.DefaultContexts

Bases: object

classmethod append(ctx: JsonLdContext)
classmethod get() list[JsonLdContext]
classmethod get_converter(record_class_resolver: RecordClassResolver | None = None) JsonLdRecordConverter
class spotterbase.records.jsonld_support.JsonLdContext(uri: Uri | None, namespaces: list[NameSpace], pred_infos: list[PredInfo], terms: list[tuple[str, Uri]])

Bases: object

This is a very crude implementation supporting only the necessary subset

export_to_json() dict
class spotterbase.records.jsonld_support.JsonLdRecordConverter(contexts: list[JsonLdContext], record_type_resolver: RecordClassResolver)

Bases: object

classmethod default() JsonLdRecordConverter
format_uri(uri: Uri) str
json_ld_to_record(json_ld, expect_non_root_record: bool = False) Record
record_to_json_ld(record: Record) dict[str, Any]
uri_from_str(string: str) Uri

spotterbase.records.rdf_to_jsonld module

spotterbase.records.rdf_to_jsonld.main()

spotterbase.records.record module

class spotterbase.records.record.AttrInfo(attr_name: 'str', pred_info: 'PredInfo', field_info: 'FieldInfo' = <spotterbase.records.record.FieldInfo object at 0x7eed12f489d0>, multi_field: 'bool' = False, literal_type: 'Optional[Uri]' = None)

Bases: object

attr_name: str
field_info: FieldInfo = <spotterbase.records.record.FieldInfo object>
literal_type: Uri | None = None
multi_field: bool = False
pred_info: PredInfo
class spotterbase.records.record.FieldInfo

Bases: object

class spotterbase.records.record.FieldKnownRecord(record_type: 'type[Record]')

Bases: FieldInfo

record_type: type[Record]
class spotterbase.records.record.FieldRecordSet(record_types: 'set[type[Record]]')

Bases: FieldInfo

record_types: set[type[Record]]
class spotterbase.records.record.PredInfo(uri: 'Uri', is_rdf_list: 'bool' = False, literal_type: 'Optional[Uri]' = None, is_reversed: 'bool' = False, json_ld_term: 'Optional[str]' = None, json_ld_type_is_id: 'bool' = False)

Bases: object

is_rdf_list: bool = False
is_reversed: bool = False
json_ld_term: str | None = None
json_ld_type_is_id: bool = False
literal_type: Uri | None = None
to_property_path() PropertyPath
uri: Uri
class spotterbase.records.record.Record(**kwargs)

Bases: object

check_attrs()
record_info: ClassVar[RecordInfo]
require_uri() Uri
to_triples(use_blanknode_if_no_uri: bool = False) Iterable[tuple[Uri | BlankNode, Uri, Uri | BlankNode | Literal]]
uri: Uri | None = None
class spotterbase.records.record.RecordInfo(record_type: Uri, attrs: list[AttrInfo], is_root_record: bool = False)

Bases: object

attrs: list[AttrInfo]
attrs_by_jsonld_term: dict[str, AttrInfo]
attrs_by_name: dict[str, AttrInfo]
attrs_by_uri: dict[Uri, AttrInfo]
is_root_record: bool
record_type: Uri
class spotterbase.records.record.RecordMeta(*args)

Bases: type

Metaclass for Record. Used for some basic checks.

record_info: RecordInfo

spotterbase.records.record_class_resolver module

class spotterbase.records.record_class_resolver.RecordClassResolver(record_types: Iterable[type[Record]] | None = None)

Bases: object

add(record_type: type[Record], overwrite: bool = False)
classmethod merged(*record_class_resolvers: RecordClassResolver) RecordClassResolver
record_class_iter() Iterator[type[Record]]

spotterbase.records.record_loading module

spotterbase.records.record_loading.load_all_records_from_graph(endpoint: SparqlEndpoint, graph: Uri, populator: Populator) Iterator[Record]
spotterbase.records.record_loading.load_all_records_transitively(uris: Iterable[Uri], populator: Populator) Iterator[Record]

spotterbase.records.record_to_python_source module

Code for generating the code that makes a record.

This is used in the documentation to show how to create a record in code.

spotterbase.records.record_to_python_source.record_to_python_source(record: Record) str

Generate the code that makes a record.

This is brittle and may not work for all records. It is intended for documentation purposes only.

spotterbase.records.sparql_populate module

class spotterbase.records.sparql_populate.Populator(endpoint: SparqlEndpoint | None = None, *, record_type_resolver: RecordClassResolver = DefaultRecordClassResolver, special_populators: dict[type[Record], list[Callable[[list[tuple[Record, RootUri]], PropertyPath, Populator], None]]] | None = None, chunk_size: int = 1000)

Bases: object

get_records(uris: Iterable[Uri], warn_if_initial_uri_unresolvable: bool = True) Iterator[Record]
class spotterbase.records.sparql_populate.RootUri

The RootUri of a record C is the Uri of the root record that C belongs to. The typical use case the following:

There is a root record R has a sub record C, which we want to populate. C might not have a URI associated with it. So to somehow reference it in SPARQL queries, we instead refer to R’s URI (the RootUri of C) and use a property path that leads from R to C.

alias of Uri

Module contents