Skip to content

Conversation

@aMahanna
Copy link
Member

@aMahanna aMahanna commented Jun 26, 2025

Test with:

pip install git+https://github.com/ArangoDB-Community/ArangoRDF@ressource-collection-name-and-migrate-edge-as-attributes

3 Changes:

  • Introduces resource_collection_name to the rdf_to_arangodb_by_pgt() method which proposes to replace some of the ArangoDB Collection Mapping Process with a simpler approach: store all RDF Resources in one ArangoDB Collection. This can be beneficial for those wanting to benefit from having a simpler ArangoDB Graph to manage.

  • Introduces migrate_edges_to_attributes() as a general PGT method. Similar to migrate_unknown_resources(), this function can be called after invoking rdf_to_arangodb_by_pgt() to transform Edges into Document Properties. For example, this method can be used to **convert all type edges into a _type property on each document`.

  • Refactor iri_collection_name to uri_map_collection_name: Due to risk of confusion between iri_collection_name and resource_collection_name, this parameter has been renamed to uri_map_collection_name. Functionality remains the same.

Example usage

from rdflib import Graph as RDFGraph

g = RDFGraph()
g.parse(
        data="""
        @prefix ex: <http://example.com/> .

        ex:Alice a ex:Person .
        ex:Alice a ex:Human .
        ex:Alice ex:name "Alice" .
        ex:Alice ex:age 25 .

        ex:Bob a ex:Person .
        ex:Bob a ex:Human .
        ex:Bob ex:name "Bob" .
        ex:Bob ex:age 30 .

        ex:Alice ex:friend ex:Bob .

        ex:ACME a ex:Organization .
        ex:ACME a ex:Company .
        """,
        format="turtle",
)

adbrdf.rdf_to_arangodb_by_pgt("MyGraph", g, resource_collection_name="Node")
# Result: Alice, Bob, and ACME will be placed under the "Node" Collection in ArangoDB


count = adbrdf.migrate_edges_to_attributes(
    graph_name="MyGraph", edge_collection_name="type"
)

assert count == 3

# Result: Alice, Bob, and ACME will now have a _type attribute on their documents
# Alice._type == ["Person", "Human"]
# Bob._type == ["Person", "Human"]
# ACME._type == ["Organization", "Company"]

count = adbrdf.migrate_edges_to_attributes(
    graph_name="MyGraph", edge_collection_name="friend"
)

assert count == 2

# Result: Alice and Bob now have a _friend attribute
# Alice._friend == ["Bob"]
# Bob._friend == [] ### <----- NOTE: Bob is not the Source of any `friend` edge, therefore the attribute is empty.
# To fix this, set `edge_direction` to ANY:

count = adbrdf.migrate_edges_to_attributes(
    graph_name="MyGraph", edge_collection_name="friend", edge_direction="ANY"
)

assert count == 2

# Alice._friend == ["Bob"]
# Bob._friend == ["Alice"]

@coveralls
Copy link

coveralls commented Jun 26, 2025

Pull Request Test Coverage Report for Build 16122510269

Details

  • 67 of 74 (90.54%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 94.955%

Changes Missing Coverage Covered Lines Changed/Added Lines %
arango_rdf/main.py 67 74 90.54%
Files with Coverage Reduction New Missed Lines %
arango_rdf/main.py 2 94.51%
Totals Coverage Status
Change from base Build 15759483469: 0.1%
Covered Lines: 1054
Relevant Lines: 1110

💛 - Coveralls

@aMahanna aMahanna changed the title new: resource_collection_name, migrate_edges_to_attributes, uri_map_collection_name new: resource_collection_name, migrate_edges_to_attributes(), uri_map_collection_name Jun 26, 2025
@aMahanna aMahanna merged commit 97e622d into main Jul 7, 2025
6 checks passed
@aMahanna aMahanna deleted the ressource-collection-name-and-migrate-edge-as-attributes branch July 7, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants