How to use EasyRDF to save RDF Turtle file from SPARQL query

Sam Source

I am using EasyRDF lib and using this code.

I want similar code, but when user inputs SPARQL endpoint, I want to save some statistical information (i.e., number of triples, unique predicates/subjects) to a file with a pattern like --

dcterms:triples "12345"
dcterms:predicats "1234"

Form

 <form role="form" id="myform" method="post" >
 <div id="collapseOne-4" class="panel-collapse collapse in">
<div class="panel-body">
 <div class="form-group">
 <label>Title</label>
 <input type="text" class="form-control" placeholder="Title" id="title" name="title"  size="20" required>
 <label> Description</label>
 <textarea class="form-control" rows="3" placeholder=" Description " id="des" name="des"  size="200" required></textarea>
   <label>Endpoint</label>
     <input type="url" class="form-control" placeholder="Endpoint "  id="endpoint" name="endpoint" size="50"  required pattern="https?://.+"> 
<label>Total Number of Triples</label>
 <input type="text" id="triples" class="form-control" 
placeholder="Disabled input" disabled >
        </div>
</div>
</div>
</form>

and code for input data is

 <?php
 $myFile = "sample.ttl";
  if (isset($_POST['uri'])) {

    $graph = new \EasyRdf_Graph();
    $graph->addLiteral($_POST['uri'], 'dcterms:title', 
 $_POST['title']);
    $graph->addLiteral($_POST['uri'], 'dcterms:Description', 
 $_POST['des']);
    $graph->addLiteral($_POST['uri'], 'void:endpoint', 
$_POST['endpoint']);
$graph->addLiteral($_POST['uri'], 'void:triples', 
$_POST['triples']);
    $data = $graph->serialise($format);

  $fp = fopen ($myFile, "a"); 
    if ($fp) {
     fwrite ($fp, $data);
     fclose ($fp);
echo ("File written");
        }
    else {
echo ("File was not written");
    }


  }
    ?>

What I am not achieving yet is, what if from user-provided SPARQL endpoint at the same time (before submission) I collect some stats via SPARQL query and afterwards add in the same file (after submission)? My issue is how to bind the query below with the (user input) SPARQL endpoint in order to query and get and save the results.

             <?php
$result = $sparql->query(
    'SELECT (COUNT(*) AS ?triples) where { ?s ?p ?o  
}'
   );

  ?>

Currently output looks like this

  @prefix dcterms: <http://purl.org/dc/terms/> .
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
    @prefix void: <http://rdfs.org/ns/void#> .

 <http://www.mydataset.org>
   dcterms:title "MyDataset" ;
   dcterms:Description "This is dataset description" ;
   void:endpoint "http://abc.abc/sparql" ;
   void:triples ""

But what I want is

 <http://www.mydataset.org>
   dcterms:title "MyDataset" ;
   dcterms:Description "This is dataset description" ;
   void:endpoint "http://abc.abc/sparql" ;
   void::triples "12345"

Any help will be highly appreciated and thanks in advance.

phpsparqlrdfeasyrdf

Answers

comments powered by Disqus