Validator¶
The Validator validates an instance of kgx.graph.base_graph.BaseGraph for Biolink Model compliance.
To validate a graph,
from kgx.validator import Validator
v = Validator()
v.validate(graph)
kgx.validator¶
-
class
kgx.validator.
MessageLevel
(value)[source]¶ Bases:
enum.Enum
Message level for validation reports
-
class
kgx.validator.
ValidationError
(entity: str, error_type: kgx.validator.ErrorType, message: str, message_level: kgx.validator.MessageLevel)[source]¶ Bases:
object
ValidationError class that represents an error.
- Parameters
entity (str) – The node or edge entity that is failing validation
error_type (kgx.validator.ErrorType) – The nature of the error
message (str) – The error message
message_level (kgx.validator.MessageLevel) – The message level
-
class
kgx.validator.
Validator
(verbose: bool = False)[source]¶ Bases:
object
Class for validating a property graph.
- Parameters
verbose (bool) – Whether the generated report should be verbose or not (default:
False
)
-
static
get_all_prefixes
(jsonld: Optional[Dict] = None) → set[source]¶ Get all prefixes from Biolink Model JSON-LD context.
It also sets
self.prefixes
for subsequent access.- Parameters
jsonld (Optional[Dict]) – The JSON-LD context
- Returns
A set of prefixes
- Return type
Optional[Dict]
-
static
get_required_edge_properties
() → list[source]¶ Get all properties for an edge that are required, as defined by Biolink Model.
- Returns
A list of required edge properties
- Return type
list
-
static
get_required_node_properties
() → list[source]¶ Get all properties for a node that are required, as defined by Biolink Model.
- Returns
A list of required node properties
- Return type
list
-
static
report
(errors: List[kgx.validator.ValidationError]) → List[source]¶ Prepare error report.
- Parameters
errors (List[ValidationError]) – List of kgx.validator.ValidationError
- Returns
A list of formatted errors
- Return type
List
-
validate
(graph: kgx.graph.base_graph.BaseGraph) → list[source]¶ Validate nodes and edges in a graph. TODO: Support strict mode
- Parameters
graph (kgx.graph.base_graph.BaseGraph) – The graph to validate
- Returns
A list of errors for a given graph
- Return type
list
-
static
validate_categories
(node: str, data: dict) → list[source]¶ Validate
category
field of a given node.- Parameters
node (str) – Node identifier
data (dict) – Node properties
- Returns
A list of errors for a given node
- Return type
list
-
static
validate_edge_predicate
(subject: str, object: str, data: dict) → list[source]¶ Validate
edge_predicate
field of a given edge.- Parameters
subject (str) – Subject identifier
object (str) – Object identifier
data (dict) – Edge properties
- Returns
A list of errors for a given edge
- Return type
list
-
static
validate_edge_properties
(subject: str, object: str, data: dict, required_properties: list) → list[source]¶ Checks if all the required edge properties exist for a given edge.
- Parameters
subject (str) – Subject identifier
object (str) – Object identifier
data (dict) – Edge properties
required_properties (list) – Required edge properties
- Returns
A list of errors for a given edge
- Return type
list
-
static
validate_edge_property_types
(subject: str, object: str, data: dict) → list[source]¶ Checks if edge properties have the expected value type.
- Parameters
subject (str) – Subject identifier
object (str) – Object identifier
data (dict) – Edge properties
- Returns
A list of errors for a given edge
- Return type
list
-
static
validate_edge_property_values
(subject: str, object: str, data: dict) → list[source]¶ Validate an edge property’s value.
- Parameters
subject (str) – Subject identifier
object (str) – Object identifier
data (dict) – Edge properties
- Returns
A list of errors for a given edge
- Return type
list
-
validate_edges
(graph: kgx.graph.base_graph.BaseGraph) → list[source]¶ Validate all the edges in a graph.
This method validates for the following, - Edge properties - Edge property type - Edge property value type - Edge label
- Parameters
graph (kgx.graph.base_graph.BaseGraph) – The graph to validate
- Returns
A list of errors for a given graph
- Return type
list
-
static
validate_node_properties
(node: str, data: dict, required_properties: list) → list[source]¶ Checks if all the required node properties exist for a given node.
- Parameters
node (str) – Node identifier
data (dict) – Node properties
required_properties (list) – Required node properties
- Returns
A list of errors for a given node
- Return type
list
-
static
validate_node_property_types
(node: str, data: dict) → list[source]¶ Checks if node properties have the expected value type.
- Parameters
node (str) – Node identifier
data (dict) – Node properties
- Returns
A list of errors for a given node
- Return type
list
-
static
validate_node_property_values
(node: str, data: dict) → list[source]¶ Validate a node property’s value.
- Parameters
node (str) – Node identifier
data (dict) – Node properties
- Returns
A list of errors for a given node
- Return type
list
-
validate_nodes
(graph: kgx.graph.base_graph.BaseGraph) → list[source]¶ Validate all the nodes in a graph.
This method validates for the following, - Node properties - Node property type - Node property value type - Node categories
- Parameters
graph (kgx.graph.base_graph.BaseGraph) – The graph to validate
- Returns
A list of errors for a given graph
- Return type
list
-
static
write_report
(errors: List[kgx.validator.ValidationError], outstream: TextIO) → None[source]¶ Write error report to a file
- Parameters
errors (List[ValidationError]) – List of kgx.validator.ValidationError
outstream (TextIO) – The stream to write to