Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.1 #34

Merged
merged 20 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
97b64ea
pushing fix to edge case with only one subject that wasn't being flushed
alfredorubin96 Oct 25, 2023
97d62d6
Merge pull request #17 from neo4j-labs/fix/count_triples_not_refreshed
AleSim94 Oct 25, 2023
d988d20
added a new noteboook with the demo from the Nodes session
Oct 26, 2023
78d9e7e
changed the file name
Oct 26, 2023
f9398e6
small change for the password
Oct 26, 2023
aeb4d09
Merge pull request #18 from neo4j-labs/import-demo
AleSim94 Oct 26, 2023
237436a
set store as context-aware
jbarrasa Jan 22, 2024
80b6753
adding test for file format json-ld
alfredorubin96 Jan 22, 2024
a08adf2
fixing tests
alfredorubin96 Jan 22, 2024
5c3040d
Updated documentation
nielsdejong Jan 23, 2024
dcc8c87
Revert "Updated documentation"
nielsdejong Jan 23, 2024
cec2154
Updated documentation
nielsdejong Jan 23, 2024
e1f42c6
Merge pull request #22 from neo4j-labs/feature/docs
nielsdejong Jan 23, 2024
1b9ef06
Fix issue https://github.com/neo4j-labs/rdflib-neo4j/issues/28
ChristianTremblay Apr 5, 2024
31a171e
Merge pull request #29 from ChristianTremblay/master
alfredorubin96 Apr 5, 2024
fe49d5a
Ability to initialize the store with an existing driver object
nmervaillie Jul 7, 2024
f78e5c9
Merge pull request #31 from nmervaillie/sso-support
alfredorubin96 Jul 9, 2024
2215fc0
checking code and adding some small comments
alfredorubin96 Jul 10, 2024
ca1fb29
Merge pull request #33 from neo4j-labs/feat/testing-new-driver
alfredorubin96 Jul 11, 2024
3e932d4
bumping version to 1.1
alfredorubin96 Jul 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/getting_started.adoc

This file was deleted.

16 changes: 0 additions & 16 deletions docs/introduction.adoc

This file was deleted.

7 changes: 6 additions & 1 deletion docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
* xref:index.adoc[Introduction]
* xref:index.adoc[Introduction]
* xref:gettingstarted.adoc[Getting Started]
* xref:neo4jstore.adoc[Neo4j Store]
* xref:neo4jstoreconfig.adoc[Store Configuration]
* xref:examples.adoc[Examples]
* xref:contributing.adoc[Contributing]
17 changes: 17 additions & 0 deletions docs/modules/ROOT/pages/contributing.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

Contributions to the project are highly welcomed.
If you extend the library with custom functionality, consider creating a Pull Request on our GitHub repository.


We highly recommend to familiarize yourself with the RDFLib core library. You can https://github.com/RDFLib/rdflib/#getting-started[learn more here].


Contribution checklist:

- Find or create an https://github.com/neo4j-labs/rdflib-neo4j/issues[issue] on GitHub.
- Fork the repository, create your own feature branch starting from the `develop` branch.
- Document your code with docstrings or in the documentation (`docs` folder), if applicable.

## Feature Requests / Bugs
If you have a request for a feature, or have found a bug, creating an https://github.com/neo4j-labs/rdflib-neo4j/issues[issue on GitHub] is the best way to reach out.
149 changes: 149 additions & 0 deletions docs/modules/ROOT/pages/examples.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
= Examples

This page contains some code snippets with examples on using the library.

== Importing a TTL file
This a basic example for importing a single TTL file.
Insert your own database credentials for `AURA_DB_URI`, `AURA_DB_USERNAME`, `AURA_DB_PWD` to use this template.

[source,python]
----
from rdflib_neo4j import Neo4jStoreConfig
from rdflib_neo4j import HANDLE_VOCAB_URI_STRATEGY

# Get your Aura Db free instance here: https://neo4j.com/cloud/aura-free/#test-drive-section
AURA_DB_URI="your_db_uri"
AURA_DB_USERNAME="neo4j"
AURA_DB_PWD="your_db_pwd"

auth_data = {'uri': AURA_DB_URI,
'database': "neo4j",
'user': AURA_DB_USERNAME,
'pwd': AURA_DB_PWD}
from rdflib import Namespace

# Define your prefixes
prefixes = {
'neo4ind': Namespace('http://neo4j.org/ind#'),
'neo4voc': Namespace('http://neo4j.org/vocab/sw#'),
'nsmntx': Namespace('http://neo4j.org/vocab/NSMNTX#'),
'apoc': Namespace('http://neo4j.org/vocab/APOC#'),
'graphql': Namespace('http://neo4j.org/vocab/GraphQL#')
}
# Define your custom mappings
config = Neo4jStoreConfig(auth_data=auth_data,
custom_prefixes=prefixes,
handle_vocab_uri_strategy=HANDLE_VOCAB_URI_STRATEGY.IGNORE,
batching=True)
from rdflib_neo4j import Neo4jStore
from rdflib import Graph
file_path = 'https://raw.githubusercontent.com/neo4j-labs/neosemantics/3.5/docs/rdf/nsmntx.ttl'

graph_store = Graph(store=Neo4jStore(config=config))
graph_store.parse(file_path,format="ttl")
graph_store.close(True)
----

== Advanced Examples

=== Initialize Neo4jStore

[source,python]
----
from rdflib_neo4j import Neo4jStoreConfig, Neo4jStore, HANDLE_VOCAB_URI_STRATEGY
from rdflib import Namespace, Graph, URIRef, RDF, SKOS, Literal


# Define your custom prefixes
prefixes = {
'neo4ind': Namespace('http://neo4j.org/ind#'),
'neo4voc': Namespace('http://neo4j.org/vocab/sw#'),
}

# Neo4j connection credentials
auth_data = {'uri': 'your_neo4j_uri',
'database': 'neo4j',
'user': "neo4j",
'pwd': 'your_password'}

# Define your Neo4jStoreConfig
config = Neo4jStoreConfig(auth_data=auth_data,
custom_prefixes=prefixes,
handle_vocab_uri_strategy=HANDLE_VOCAB_URI_STRATEGY.IGNORE,
batching=False)

neo4j_store = Neo4jStore(config=config)
graph_store = Graph(store=neo4j_store)

----

=== Import by Reference URL

[source,python]
----
file_path = 'https://raw.githubusercontent.com/neo4j-labs/neosemantics/3.5/docs/rdf/nsmntx.ttl'
graph_store.parse(file_path,format="ttl")
----

=== Write Individual Triples

[source,python]
----
aura = URIRef("http://neo4j.com/voc/tech#AuraDB")

graph_store.add((aura, RDF.type, SKOS.Concept))
graph_store.add((aura, SKOS.prefLabel, Literal("AuraDB")))
graph_store.add((aura, SKOS.broader, URIRef("http://neo4j.org/ind#neo4j355")))

----

=== SPARQL Query with Batching

[source,python]
----
import requests
import urllib.parse

endpoint = "https://id.nlm.nih.gov/mesh/sparql"
sparql = """
PREFIX rdfs:
PREFIX meshv:
PREFIX mesh:
PREFIX rdf:

CONSTRUCT { ?s ?p ?o }
FROM
WHERE {
{
?s ?p ?o
filter(?s = mesh:D000086402 || ?o = mesh:D000086402)
}
union
{
mesh:D000086402 ?x ?s .
?s ?p ?o .
filter(?x != rdf:type && (isLiteral(?o) || ?p = rdf:type))
}
union
{
?s ?x mesh:D000086402 .
?s ?p ?o .
filter(isLiteral(?o|| ?p = rdf:type))
}
}
"""

# Define your Neo4jStoreConfig
config = Neo4jStoreConfig(auth_data=auth_data,
custom_prefixes=prefixes,
handle_vocab_uri_strategy=HANDLE_VOCAB_URI_STRATEGY.IGNORE,
batching=True)

neo4j_store = Neo4jStore(config=config)
graph_store = Graph(store=neo4j_store)

query_response = requests.get(endpoint, params = {"query": sparql , "format" : "TURTLE"})
graph_store.parse(data=query_response.text,format='ttl')
graph_store.close(commit_pending_transaction=True)

----
88 changes: 88 additions & 0 deletions docs/modules/ROOT/pages/gettingstarted.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
= Getting Started

This page describes how to get started with this library, and set up your first RDF import.

== Set up Neo4j
To configure your Neo4j Graph DB, the process is simplified: initialize the database by establishing a uniqueness constraint on Resources' URIs. You can achieve this by executing the following Cypher fragment:

[source,cypher]
----
CREATE CONSTRAINT n10s_unique_uri FOR (r:Resource) REQUIRE r.uri IS UNIQUE;
----
This constraint ensures the uniqueness of URIs for Resource nodes, streamlining the integration process. Alternatively, you can simply set `create=True` when attempting to open the store in your Python code, and it will create the constraint for you.

== Set up Python environment
`rdflib-neo4j` can be installed with Python's package management tool `pip`:

[source,shell]
----
$ pip install rdflib-neo4j
----

== Loading data
Now, seamlessly import RDF data into your Neo4j On-premise or Aura instance by establishing an RDFLib graph and employing it to parse your RDF data. Each individual triple undergoes transparent persistence within your Neo4j database(whether it is on Aura or on-premise). Here's a step-by-step guide to achieve this integration:

You can import the data from an RDF document (for example link:https://github.com/jbarrasa/datasets/blob/master/rdf/music.nt[this one serialised using N-Triples]):

[source,python]
----
from rdflib_neo4j import Neo4jStoreConfig, Neo4jStore, HANDLE_VOCAB_URI_STRATEGY
from rdflib import Graph

# set the configuration to connect to your Aura DB
AURA_DB_URI="your_db_uri"
AURA_DB_USERNAME="neo4j"
AURA_DB_PWD="your_db_pwd"

auth_data = {'uri': AURA_DB_URI,
'database': "neo4j",
'user': AURA_DB_USERNAME,
'pwd': AURA_DB_PWD}

# Define your custom mappings & store config
config = Neo4jStoreConfig(auth_data=auth_data,
custom_prefixes=prefixes,
handle_vocab_uri_strategy=HANDLE_VOCAB_URI_STRATEGY.IGNORE,
batching=True)

file_path = 'https://github.com/jbarrasa/gc-2022/raw/main/search/onto/concept-scheme-skos.ttl'

# Create the RDF Graph, parse & ingest the data to Neo4j, and close the store(If the field batching is set to True in the Neo4jStoreConfig, remember to close the store to prevent the loss of any uncommitted records.)
neo4j_aura = Graph(store=Neo4jStore(config=config))
# Calling the parse method will implictly open the store
neo4j_aura.parse(file_path, format="ttl")
neo4j_aura.close(True)
----

The imported file contains a taxonomy of technologies extracted from Wikidata and serialised using SKOS.
After running the previous code fragment, your Aura DB/Neo4j DB should be populated with a graph like this one:

image::https://raw.githubusercontent.com/neo4j-labs/rdflib-neo4j/master/img/graph-view-aura.png[height="400"]

You can also write to the graph triple by triple like this:

[source,python]
----
import rdflib
from rdflib_neo4j import Neo4jStoreConfig, Neo4jStore, HANDLE_VOCAB_URI_STRATEGY
from rdflib import Graph, RDF, SKOS

# Set up your store config
config = Neo4jStoreConfig(auth_data=auth_data,
handle_vocab_uri_strategy=HANDLE_VOCAB_URI_STRATEGY.IGNORE,
batching=False)

# Create the graph and open the store
neo4j_aura = Graph(store=Neo4jStore(config=config))
neo4j_aura.open(config)

aura = rdflib.URIRef("http://neo4j.com/voc/tech#AuraDB")

neo4j_aura.add((aura, RDF.type, SKOS.Concept))
neo4j_aura.add((aura, SKOS.prefLabel, rdflib.Literal("AuraDB")))
neo4j_aura.add((aura, SKOS.broader, rdflib.URIRef("http://www.wikidata.org/entity/Q1628290")))
----

The previous fragment would add another node to the graph representing AuraDB as a concept related to Neo4j via `skos:narrower`, which in your AuraDB graph would look as follows:

image::https://raw.githubusercontent.com/neo4j-labs/rdflib-neo4j/master/img/graph-view-aura-detail.png[height="150"]
14 changes: 13 additions & 1 deletion docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
jsdhdfvjfdvfv
# RDFLib-Neo4j

The **rdflib-neo4j** project is a Python-based https://rdflib.readthedocs.io/en/stable/[RDFLib Store] backed by Neo4j.
You can use this library for high-performance RDF data ingestion into the Neo4j database.

This library works with all types of Neo4j deployments, whether on-premise or cloud-hosted (Neo4j Aura).

## Documentation

- To get started, see the link:quickstart[Quickstart] page.
- For details on the available Python classes, see the link:neo4jstore[Neo4j Store] page.
- Example code fragments are available under link:examples[Examples].
- If you want to contribute to this project, see link:contributing[Contributing].
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
== Neo4j Store
= Neo4j Store
[.procedures, opts=header]

This class is an implementation of the rdflib link:https://rdflib.readthedocs.io/en/stable/_modules/rdflib/store.html[Store class] that uses Neo4j as a backend. In this way it is possible to persist you RDF data directly in Neo4j, with the power of rdflib to process your data.

=== Object Initialization
== Constructor
|===
| Name | Type | Required | Default | Description
|config|Neo4jStoreConfig|True||Neo4jStoreConfig object that contains all the useful informations to initialize the store.
|config|Neo4jStoreConfig|True||Neo4jStoreConfig object that contains all the useful information to initialize the store.
|driver|Neo4jStoreConfig|False|None|A pre-built Neo4j driver object to use to connect to the database. You cannot specify both a driver and credentials in the Neo4jStoreConfig.
|===

== Functions
Expand Down
Loading
Loading