semsol / arc2

ARC RDF Classes for PHP
Other
331 stars 92 forks source link

adding the same triple into two graphs does not work #114

Open k00ni opened 6 years ago

k00ni commented 6 years ago

The following test code shows, that ARC2 does not seem to allow the same triple in different graphs. Is that right @semsol?

$store = \ARC2::getStore([...]);

$store->query(
    'INSERT INTO <http://graph1/> {<http://foo/1> <http://foo/2> <http://foo/3> . }'
);

$store->query(
    'INSERT INTO <http://graph2/> {<http://foo/1> <http://foo/2> <http://foo/3> . }'
);
$store->query(
    'INSERT INTO <http://graph2/> {<http://foo/4> <http://foo/5> <http://foo/6> . }'
);

// thats OK, 1 row
$res = $this->fixture->query('SELECT * FROM <http://graph1/> WHERE {?s ?p ?o.}');
echo count($res['result']['rows']);

// thats OK, 3 rows
$res = $this->fixture->query('SELECT * WHERE {?s ?p ?o.}');
echo count($res['result']['rows']);

// FAILED, got 1 row, expected 2
$res = $this->fixture->query('SELECT * FROM <http://graph2/> WHERE {?s ?p ?o.}');
echo count($res['result']['rows']);
cbinding commented 5 years ago

Hello, a modification of your second test (and your row count of 3) demonstrates the insertions are successful; ARC2 allows the same triple in different graphs:

$res = $store->query('SELECT * WHERE { GRAPH ?g {?s ?p ?o }}');  
print_r($res['result']['rows']);
// 3 rows are returned, also showing the graph associated with each triple 

However the query in the last test is indeed only returning the first of the two triples actually present in graph2.

Unfortunately I don't yet have a solution(!) but I am interested if you have any further information on this, as I have what I believe are similar issues for multiple 'LOAD' statements - the data is loaded to the triple store but only the data from the first 'LOAD' is actually visible in subsequent queries.

cbinding commented 5 years ago

After further testing I now have a solution for this issue, which also resolves the problems experienced with multiple 'LOAD' statements. In file ARC2_StoreLoadQueryHandler.php try changing line 228:

# old: 
if (false !== empty($binaryValue)) {
# new:
if (false == empty($binaryValue)) {

The code here is locating the ID for a previously inserted value, but I believe the condition logic here is incorrect - the ID is never found, so a value may get inserted multiple times with different IDs. This leads to the inconsistencies observed, where inserted/loaded data is present in the triple store but not retrieved.

k00ni commented 5 years ago

Unfortunately I don't yet have a solution(!) but I am interested if you have any further information on this [...]

Unfortunately no.

After further testing I now have a solution for this issue, which also resolves the problems experienced with multiple 'LOAD' statements.

Would you be OK with creating a test or two to reproduce the problem? And submit it as pull request, so that we can discuss the merge? That would be great.

cbinding commented 5 years ago

OK yes I will do, have set up a separate issue #122 (related to LOAD statements) but it should fix this issue also

k00ni commented 5 years ago

OK yes I will do

Nice to hear, looking for forward to it!