Skip to content

Commit

Permalink
now multival props behave as sets during the ingestion and added test…
Browse files Browse the repository at this point in the history
… to check the behaviour
  • Loading branch information
alfredorubin96 committed Sep 29, 2023
1 parent 3673b79 commit e9518a0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rdflib_neo4j/query_composers/NodeQueryComposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


def prop_query_append(prop):
return f"""n.`{prop}` = CASE WHEN COALESCE(param["{prop}"], NULL) IS NULL THEN n.{prop} ELSE COALESCE(n.`{prop}`,[]) + param["{prop}"] END"""
return f"""n.`{prop}` = CASE WHEN COALESCE(param["{prop}"], NULL) IS NULL THEN n.{prop} ELSE REDUCE(i=COALESCE(n.{prop},[]), val IN param["{prop}"] | CASE WHEN val IN i THEN i ELSE i+val END) END """



def prop_query_single(prop):
Expand Down
41 changes: 39 additions & 2 deletions test/integration/multival_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from test.integration.constants import LOCAL
from test.integration.constants import LOCAL, RDFLIB_DB
from rdflib import Graph, Namespace
from rdflib_neo4j.Neo4jStore import Neo4jStore
from rdflib_neo4j.config.Neo4jStoreConfig import Neo4jStoreConfig
Expand Down Expand Up @@ -41,7 +41,6 @@ def test_read_file_multival_with_strategy_no_predicates(neo4j_container, neo4j_d


def test_read_file_multival_with_strategy_and_predicates(neo4j_container, neo4j_driver):
"""Compare data imported with n10s procs and n10s + rdflib in single add mode for multivalues"""
"""Compare data imported with n10s procs and n10s + rdflib in single add mode for multivalues"""
auth_data = get_credentials(LOCAL, neo4j_container)

Expand Down Expand Up @@ -101,3 +100,41 @@ def test_read_file_multival_with_no_strategy_and_predicates(neo4j_container, neo
assert len(records_from_rdf_lib) == len(records)
for i in range(len(records)):
assert records_equal(records[i], records_from_rdf_lib[i])

def test_read_file_multival_array_as_set_behavior(neo4j_container, neo4j_driver):
"""When importing the data, if a triple will add the same value to a multivalued property it won't be added"""
auth_data = get_credentials(LOCAL, neo4j_container)

prefixes = {'music': Namespace('neo4j://graph.schema#')}

custom_mappings = []

multival_props = [("rdfs", "label")]
config = Neo4jStoreConfig(auth_data=auth_data,
custom_prefixes=prefixes,
custom_mappings=custom_mappings,
multival_props_names=multival_props,
handle_vocab_uri_strategy=HANDLE_VOCAB_URI_STRATEGY.IGNORE,
handle_multival_strategy=HANDLE_MULTIVAL_STRATEGY.ARRAY,
batching=False)

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

payload1 = """<http://dbpedia.org/resource/Cable_One> <http://dbpedia.org/property/name> "Sparklight"@en .\
<http://dbpedia.org/resource/Donald_E._Graham> <http://www.w3.org/2000/01/rdf-schema#label> "Donald Ernest. Graham II" .\
<http://dbpedia.org/resource/Cable_One> <http://dbpedia.org/ontology/owner> <http://dbpedia.org/resource/Donald_E._Graham> .\
<http://dbpedia.org/resource/Cable_One> <http://dbpedia.org/ontology/netIncome> "3.04391E8"^^<http://dbpedia.org/datatype/usDollar> .\
"""
payload2 = """ <http://dbpedia.org/resource/Donald_E._Graham> <http://www.w3.org/2000/01/rdf-schema#label> "Donald Ernest. Graham II" . """

payload3 = """ <http://dbpedia.org/resource/Donald_E._Graham> <http://www.w3.org/2000/01/rdf-schema#label> "Donald Ernest. Graham II" . """

for p in [payload1,payload2,payload3]:
graph_store.parse(data=p, format="ttl")

records, summary, keys = neo4j_driver.execute_query("MATCH (n) WHERE size(n.label) > 1 RETURN n",
database_=RDFLIB_DB)

assert len(records) == 0

x = 1

0 comments on commit e9518a0

Please sign in to comment.