Skip to content

neo4j module

Bibiana Rivadeneira edited this page Jun 21, 2023 · 2 revisions

neo4j module

General description

FLIXBUS SCRAPER <-------> neo4j module <--------> graph db module

(written in python)

It interacts with the flixbus scraper (left):

  • receives all flixbus routes available and loads them into the neo4j instance db (right)

Models

Location

A cypher point-like class based on Neo4J.

+--------------------------------------+
|             Location                 |
+--------------------------------------+
| - latitude: float | int              |
| - longitude: float | int             |
+--------------------------------------+
| + __post_init__(): void              |
| + __str__(): str                     |
+--------------------------------------+
  • latitude: (self explanatory)
  • longitude: (self explanatory)

__post_init__(): Performs validation checks on the latitude and longitude values.
__str__(): Returns a string representation of the location in the form of a Cypher point object, e.g. point({ longitude: 0.0, latitude: 0.0 })

Neo4jBase

Base class for neo4j like objects

+--------------------------------------+
|            Neo4jBase                  |
+--------------------------------------+
| + __str__(): str                      |
+--------------------------------------+

__str__(): Returns a string representation of the object, ready to be added in a Cypher query according to: https://neo4j.com/docs/api/python-driver/current/api.html#core-data-types
ready to be included into a query as follows:

  • None: 'Null'
  • bool: 'false'/'true' for False and True
  • datetime.datetime: https://neo4j.com/developer/cypher/dates-datetimes-durations/
    e.g. datetime("2019-06-01T18:40:32.142+0100")
  • datetime.timedelta: e.g. readingTime: {minutes: 3, seconds: 30}
  • str: add double quotes
  • iterable: (except str) applies transformations below to each element (array with same type of objects in cypher)
  • others: their str repr

BusStationNode

A Neo4jBase node model for bus stations, based on Neo4jBase.

+--------------------------------------+
|         BusStationNode               |
+--------------------------------------+
| - station_id: int                    |
| - city: StrictStr                    |
| - region: StrictStr                  |
| - location: Location                 |
| - id_for_reach: int                  |
| - node_type: StrictStr               |
| - service: StrictStr                 |
| - service_reachable_ids: list[int]   |
| - uuid_from_service: StrictStr       |
| - is_popular: bool                   |
+--------------------------------------+
  • station_id: The ID of the bus station (int).
  • city: The city where the bus station is located (StrictStr).
  • region: The region where the bus station is located (StrictStr).
  • location: The geographic location of the bus station (Location).
  • id_for_reach: The ID for reaching the bus station (int).
  • node_type: The type of the node (StrictStr, default: "bus_station").
  • service: The service associated with the bus station (StrictStr, default: "flixbus").
  • service_reachable_ids: List of IDs for services reachable from the bus station (list[int] or None).
  • uuid_from_service: The UUID associated with the bus station from the service (StrictStr or None).
  • is_popular: Indicates if the bus station is popular (bool, default: False).

Neo4JConn

Class for connecting with a Neo4j database instance.

+---------------------------------------+
|            Neo4JConn                  |
+---------------------------------------+
| - uri: StrictStr                      |
| - user_name: StrictStr                |
| - password: StrictStr                 |
| - db_name: StrictStr                  |
| - auth: tuple[str, str]               |
| - async_driver: AsyncDriverType       |
+---------------------------------------+
| + init_driver(): void                 |
| + __post_init__(): void               |
| + _close_driver(): Coroutine          |
| + execute_query(query: str): Coroutine|
+---------------------------------------+
  • uri: The URI of the Neo4j database (StrictStr).
  • user_name: The username for authentication (StrictStr).
  • password: The password for authentication (StrictStr).
  • db_name: The name of the database (StrictStr, default: "neo4j").
  • auth: Tuple containing the username and password for authentication (tuple[str, str]).
  • async_driver: The asynchronous driver for Neo4j (AsyncDriverType).

init_driver(): Initializes the Neo4j driver for connecting to
execute_query(): Execute an async given neo4j_graph query

TODO:

  • is popular query
  • result processing
  • custom query
Clone this wiki locally