mirror of
https://github.com/Babibubebon/lodfe.git
synced 2024-09-23 01:34:21 +09:00
commit
e1a263b77a
7 changed files with 144 additions and 49 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Babibubebon
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -16,12 +16,11 @@ class ResourceController extends Controller
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* ResourceController constructor.
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
protected function getCurrentDatasetConfig($request) {
|
public function __construct()
|
||||||
$datasetName = explode('.', $request->route()[1]['as'])[1];
|
{
|
||||||
return config('datasets.' . $datasetName);
|
$this->middleware('dataset');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,28 +30,45 @@ class ResourceController extends Controller
|
||||||
*/
|
*/
|
||||||
protected function querySparql($request, $id)
|
protected function querySparql($request, $id)
|
||||||
{
|
{
|
||||||
$datasetConfig = $this->getCurrentDatasetConfig($request);
|
$client = new \EasyRdf_Sparql_Client($request->datasetConfig['endpoint']);
|
||||||
$client = new \EasyRdf_Sparql_Client($datasetConfig['endpoint']);
|
$query = <<<EOT
|
||||||
|
CONSTRUCT {
|
||||||
$resourceUri = str_replace('{id}', $id, $datasetConfig['resource_uri']);
|
<{$request->resourceUri}> ?p ?o .
|
||||||
$query = 'DESCRIBE <' . $resourceUri . '>';
|
?s ?ip <{$request->resourceUri}> .
|
||||||
|
}
|
||||||
|
WHERE {
|
||||||
|
<{$request->resourceUri}> ?p ?o .
|
||||||
|
?s ?ip <{$request->resourceUri}> .
|
||||||
|
}
|
||||||
|
EOT;
|
||||||
return $client->query($query);
|
return $client->query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param $id
|
||||||
|
* @return \Illuminate\View\View
|
||||||
|
*/
|
||||||
public function html(Request $request, $id)
|
public function html(Request $request, $id)
|
||||||
{
|
{
|
||||||
$graph = $this->querySparql($request, $id);
|
$graph = $this->querySparql($request, urldecode($id));
|
||||||
$subject = key($graph->toRdfPhp());
|
if ($graph->isEmpty()) {
|
||||||
$datasetConfig = $this->getCurrentDatasetConfig($request);
|
abort(404);
|
||||||
$dataUri = str_replace('{id}', $id, $datasetConfig['data_uri']);
|
}
|
||||||
|
|
||||||
return view('resource')->with([
|
return view('resource')->with([
|
||||||
'graph' => $graph,
|
'graph' => $graph,
|
||||||
'subject' => $subject,
|
'primaryTopic' => $request->resourceUri,
|
||||||
'dataUri' => $dataUri,
|
'dataUri' => $request->dataUri,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param $id
|
||||||
|
* @param $ext
|
||||||
|
* @return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory
|
||||||
|
*/
|
||||||
public function data(Request $request, $id, $ext)
|
public function data(Request $request, $id, $ext)
|
||||||
{
|
{
|
||||||
if (!in_array($ext, $this->acceptableFileExtensions)) {
|
if (!in_array($ext, $this->acceptableFileExtensions)) {
|
||||||
|
|
37
app/Http/Middleware/DatasetMiddleware.php
Normal file
37
app/Http/Middleware/DatasetMiddleware.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class DatasetMiddleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
if (!$request->route()) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
$datasetName = explode('.', $request->route()[1]['as'])[1];
|
||||||
|
$currentDatasetConfig = config('datasets.' . $datasetName);
|
||||||
|
|
||||||
|
$id = $request->route('id');
|
||||||
|
$resourceUri = str_replace('{id}', $id, $currentDatasetConfig['resource_uri']);
|
||||||
|
$dataUri = str_replace('{id}', $id, $currentDatasetConfig['data_uri']);
|
||||||
|
|
||||||
|
$request->merge([
|
||||||
|
'datasetConfig' => $currentDatasetConfig,
|
||||||
|
'resourceUri' => $resourceUri,
|
||||||
|
'dataUri' => $dataUri,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,6 +72,7 @@ $app->singleton(
|
||||||
|
|
||||||
$app->routeMiddleware([
|
$app->routeMiddleware([
|
||||||
'content_negotiation' => App\Http\Middleware\ContentNegotiatorMiddleware::class,
|
'content_negotiation' => App\Http\Middleware\ContentNegotiatorMiddleware::class,
|
||||||
|
'dataset' => App\Http\Middleware\DatasetMiddleware::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'version' => '1.1.0',
|
'version' => '1.2.0',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
34
resources/views/parts/row.blade.php
Normal file
34
resources/views/parts/row.blade.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@if($subject !== $primaryTopic)
|
||||||
|
is
|
||||||
|
@endif
|
||||||
|
<a href="{{ $predicate }}">{{ \EasyRdf_Namespace::shorten($predicate) ?? $predicate }}</a>
|
||||||
|
@if($subject !== $primaryTopic)
|
||||||
|
of
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul>
|
||||||
|
@if($subject === $primaryTopic)
|
||||||
|
@foreach($objects as $object)
|
||||||
|
<li>
|
||||||
|
@if($object['type'] === 'uri')
|
||||||
|
<a href="{{ $object['value'] }}">{{ $object['value'] }}</a>
|
||||||
|
@elseif($object['type'] === 'literal')
|
||||||
|
{{ $object['value'] }}
|
||||||
|
@if(isset($object['lang']))
|
||||||
|
<small>{{ '@'.$object['lang'] }}</small>
|
||||||
|
@endif
|
||||||
|
@if(isset($object['datatype']))
|
||||||
|
<small>^^{{ \EasyRdf_Namespace::shorten($object['datatype']) ?? $object['datatype'] }}</small>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
|
@else
|
||||||
|
<a href="{{ $subject }}">{{ $subject }}</a>
|
||||||
|
@endif
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
</tr>
|
|
@ -1,12 +1,12 @@
|
||||||
@extends('base')
|
@extends('base')
|
||||||
@section('title')
|
@section('title')
|
||||||
About: {{ $graph->label($subject) ?? $graph->getLiteral($subject, 'schema:name') }}
|
About: {{ $graph->label($primaryTopic) ?? $graph->getLiteral($primaryTopic, 'schema:name') }}
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<section>
|
<section>
|
||||||
<h1>@yield('title')</h1>
|
<h1>@yield('title')</h1>
|
||||||
<code class="h5">{{ $subject }}</code>
|
<code class="h5">{{ $primaryTopic }}</code>
|
||||||
|
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
|
@ -33,40 +33,26 @@
|
||||||
<th>Value</th>
|
<th>Value</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
<tbody>
|
||||||
@foreach($graph->toRdfPhp() as $subject => $predicateObjects)
|
@foreach($graph->toRdfPhp() as $subject => $predicateObjects)
|
||||||
@foreach($predicateObjects as $predicate => $objects)
|
@if($subject === $primaryTopic)
|
||||||
<tbody>
|
@foreach($predicateObjects as $predicate => $objects)
|
||||||
<tr>
|
@include('parts.row')
|
||||||
<td>
|
@endforeach
|
||||||
<a href="{{ $predicate }}">{{ \EasyRdf_Namespace::shorten($predicate) ?? $predicate }}</a>
|
@break
|
||||||
</td>
|
@endif
|
||||||
<td>
|
|
||||||
<ul>
|
|
||||||
@foreach($objects as $object)
|
|
||||||
<li>
|
|
||||||
@if($object['type'] === 'uri')
|
|
||||||
<a href="{{ $object['value'] }}">{{ $object['value'] }}</a>
|
|
||||||
@elseif($object['type'] === 'literal')
|
|
||||||
{{ $object['value'] }}
|
|
||||||
@if(isset($object['lang']))
|
|
||||||
<small>{{ '@'.$object['lang'] }}</small>
|
|
||||||
@endif
|
|
||||||
@if(isset($object['datatype']))
|
|
||||||
<small>^^{{ \EasyRdf_Namespace::shorten($object['datatype']) ?? $object['datatype'] }}</small>
|
|
||||||
@endif
|
|
||||||
@endif
|
|
||||||
</li>
|
|
||||||
@endforeach
|
|
||||||
</ul>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
|
|
||||||
@endforeach
|
|
||||||
@endforeach
|
@endforeach
|
||||||
|
@foreach($graph->toRdfPhp() as $subject => $predicateObjects)
|
||||||
|
@if($subject !== $primaryTopic)
|
||||||
|
@foreach($predicateObjects as $predicate => $objects)
|
||||||
|
@include('parts.row')
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<script type="application/ld+json">
|
<script type="application/ld+json">
|
||||||
{!! $graph->serialise('jsonld') !!}
|
{!! $graph->serialise('jsonld') !!}
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
Loading…
Reference in a new issue