PHP code example of your1 / laravel-sparql

1. Go to this page and download the library: Download your1/laravel-sparql library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

your1 / laravel-sparql example snippets


'connections' => [
    'sparql' => [
        'driver' => 'sparql',
        'endpoint' => env('SPARQL_ENDPOINT', 'http://localhost:3030/test/sparql'),

        // IMPORTANT: Specify your triple store implementation
        'implementation' => env('SPARQL_IMPLEMENTATION', 'fuseki'),  // fuseki|blazegraph|generic

        'auth' => [
            'type' => 'digest',
            'username' => env('SPARQL_USERNAME'),
            'password' => env('SPARQL_PASSWORD'),
        ],
        'namespaces' => [
            'schema' => 'http://schema.org/',
            'foaf' => 'http://xmlns.com/foaf/0.1/',
        ],
    ],
],

use LinkedData\SPARQL\Eloquent\Model;

class Person extends Model
{
    protected $connection = 'sparql';
    protected $table = 'http://schema.org/Person';

    protected $propertyUris = [
        'name' => 'http://schema.org/name',
        'email' => 'http://schema.org/email',
        'age' => 'http://schema.org/age',
    ];

    protected $fillable = ['name', 'email', 'age'];
    protected $casts = ['age' => 'integer'];
}

// Create
$person = new Person();
$person->id = 'http://example.com/person/1';
$person->name = 'John Doe';
$person->email = '[email protected]';
$person->save();

// Query
$adults = Person::where('age', '>', 18)->get();
$john = Person::where('name', 'John')->first();

// Update
$person->age = 31;
$person->save();

// Delete
$person->delete();

// Analytical queries (v1.2.3+)
use LinkedData\SPARQL\Query\Expression;

$labelStats = DB::connection('sparql')
    ->query()
    ->selectExpression('?language')
    ->selectExpression('(COUNT(?label) as ?count)')
    ->whereTriple('?concept', 'skos:inScheme', Expression::iri($schemeUri))
    ->whereTriple('?concept', 'skos:prefLabel', '?label')
    ->bind('COALESCE(LANG(?label), "no-lang")', '?language')
    ->groupBy('?language')
    ->get();