semsol / arc2

ARC RDF Classes for PHP
Other
332 stars 89 forks source link

Problem with insert data #88

Closed pietrobolcato closed 4 years ago

pietrobolcato commented 7 years ago

Hi

I'm trying to insert data into my RDF database using Arc2. This is my code:

<?php
include_once('semsol\ARC2.php');
$end = "http://localhost:7200/repositories/virtualcoach";
/* configuration */ 
$config = array(
  /* remote endpoint */
  'remote_store_endpoint' => $end,
);

/* instantiation */
$store = ARC2::getRemoteStore($config);
$q = "PREFIX vc: <http://www.fbk.eu/ontologies/2016/virtualcoach/v1#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?nome_rule (count(?nome_violazione) as ?conto) where { 
    ?nome_violazione vc:hasViolationUser vc:fb220550 .
    ?nome_violazione vc:hasViolationRule ?nome_rule .
} 
group by ?nome_rule";

$q2 = "PREFIX vc: <http://www.fbk.eu/ontologies/2016/virtualcoach/v1#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

INSERT DATA {
    vc:AnimalLipid_6666662 vc:amountNutrient 6666.66 . 
    vc:AnimalLipid_6666662 vc:unit  \"g\" .  
    vc:AnimalLipid_6666662 rdf:type vc:AnimalLipid .
    vc:AnimalLipid_6666662 rdf:type owl:NamedIndividual . 
}";
$rows = $store->query($q2);
print_r($rows);
?>

The first query, which is a select query, works like a charm. The second one, which is an insert data, is not working at all. My server is graphDB. How can I make it work? Where I'm wrong?

Thanks in advance.

k00ni commented 7 years ago

Hi! I guess, using INSERT DATA without a graph URI tells ARC2 to write into the default graph, which is currently not supported. But try INSERT INTO <http://your-target-graph> {.., described here.

pietrobolcato commented 7 years ago

First of all thanks for your kind answer! I tried this way:


<?php
include_once('semsol\ARC2.php');
$end = "http://localhost:7200/repositories/virtualcoach";
/* configuration */ 
$config = array(
  /* remote endpoint */
  'remote_store_endpoint' => $end,
);

/* instantiation */
$store = ARC2::getRemoteStore($config);

$q2 = "PREFIX vc: <http://www.fbk.eu/ontologies/2016/virtualcoach/v1#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

INSERT INTO <$end> {
    vc:AnimalLipid_6666662 vc:amountNutrient 6666.66 . 
    vc:AnimalLipid_6666662 vc:unit  \"g\" .  
    vc:AnimalLipid_6666662 rdf:type vc:AnimalLipid .
    vc:AnimalLipid_6666662 rdf:type owl:NamedIndividual . 
}";
$rows = $store->query($q2);
print_r($rows);

This is the error output:`

Array ( [query_type] => insert [result] => Array ( [errors] => Array ( [0] => 400 Bad Request "MALFORMED QUERY: Encountered " "insert" "INSERT "" at line 7, column 1. Was expecting one of: "base" ... "prefix" ......" [1] => missing stream in "getFormat" [2] => missing stream in "readStream" http://localhost:7200/repositories/virtualcoach ) ) [query_time] => 0.0067639350891113 )

Any idea? Thanks in advance again.

k00ni commented 6 years ago

Sorry for the late response!

Any luck solving this?

k00ni commented 4 years ago

I am closing this, because of no response. Please reopen, if the error persists.