-
Notifications
You must be signed in to change notification settings - Fork 0
HowToUse
This page provides a guide on how to use ocean-lib to define and execute aggregation queries over Event Knowledge Graphs (EKGs).
Clone the repository and install the library in editable mode:
git clone https://github.com/SaraPettinari/ocean-lib.git
cd ocean-lib
python3 -m venv .venv
source .venv/bin/activate
pip install -e .Place the file related to your dataset in a unique folder:
<dataset_name>/
├── main.py
├── ekg_config.yaml
└── log_config.yaml
-
main.pydefines the aggregation query -
ekg_config.yamlspecifies the connection to the Neo4j EKG and EKG conventions -
log_config.yamlmaps event and entity attributes
The file ekg_config.yaml defines how ocean-lib connects to the underlying Neo4j database and interprets entity types.
Configuration structure:
type_tag: "<TYPE_REF>"
entity_type_mode: "<label|property>"
neo4j:
URI: "<NEO4J_URI>"
username: "<USERNAME>"
password: "<PASSWORD>"Note
label = :Entity:EntityType property = :Entity (Type: 'EntityType')
The file log_config.yaml specifies how events and entities are mapped to the EKG.
Minimal configuration structure (if the dataset is already in Neo4j):
event_id: "<EVENT_ID_REF>"
event_activity: "<EVENT_ACTIVITY_REF>"
event_timestamp: "<EVENT_TIMESTAMP_REF>"
entity_id: "<ENTITY_ID_REF>"Important
If the dataset is not already stored in Neo4j, paths to CSV files and attribute types must be specified (see the repository README for full examples).
Aggregation queries are defined as a sequence of aggregation steps (AggrStep), combined into an AggrSpecification.
A typical query structure written in the main.py is shown below:
from ocean_lib import pipeline, AggrSpecification, AggrStep
from ocean_lib.aggregation_lib import AttrAggr, AggregationFunction
@pipeline(first_load=False)
def build_aggr_spec(log, ekg):
steps = [
AggrStep(
aggr_type="ENTITIES",
ent_type="playerId",
group_by=["role"],
where=None,
attr_aggrs=[]
),
AggrStep(
aggr_type="EVENTS",
ent_type=None,
where=None,
group_by=[log.event_activity],
attr_aggrs=[
AttrAggr(
name=log.event_timestamp,
function=AggregationFunction.MINMAX
)
]
)
]
return AggrSpecification(steps)Each AggrStep specifies:
-
the aggregation type (ENTITIES or EVENTS)
-
the entity type (if applicable)
-
grouping attributes
-
optional filtering conditions
-
optional attribute aggregation functions
To execute the aggregation pipeline, run:
cd <dataset_name>
python main.pyThe execution:
-
Loads the EKG (if required: @pipeline(first_load=True))
-
Applies the aggregation steps sequentially
-
Finalizes the aggregated EKG
-
Infers relationships between aggregated nodes
Depending on the configuration, the execution produces:
-
An aggregated EKG stored in Neo4j
-
Execution logs reporting processed nodes and execution times
-
Optional visualizations (e.g., via Neo4j Bloom)
© 2026 ocean-lib. All rights reserved.