Skip to content

Commit

Permalink
/rdfDescribe の追加
Browse files Browse the repository at this point in the history
  • Loading branch information
miyacorata committed May 18, 2021
1 parent 125752c commit 3db9fd2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .idea/Lemonade.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions app/Http/Controllers/InfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Carbon\Carbon;
use Exception;
use ZipArchive;
use Illuminate\Support\Facades\Http;

class InfoController extends Controller
{
Expand Down Expand Up @@ -172,6 +173,25 @@ public function generateImeDic(){
return view('main.imedic', compact('dicString'));
}

public function rdfDescribe(string $resource = null){
if (is_null($resource)) abort(400, "リソースが指定されていません");

$turtle = http::get(config('lemonade.sparqlEndpoint'), [
'format' => 'turtle',
'query' => <<<SPARQL
PREFIX lilyrdf: <https://lily.fvhp.net/rdf/RDFs/detail/>
DESCRIBE lilyrdf:$resource
SPARQL
])->throw(function ($response, $e){
abort(502, "SPARQLエンドポイントが正しく応答しませんでした。");
})->body();

if(mb_strlen(trim(preg_replace('/^@prefix.+$/im','',$turtle))) === 0)
abort(404, "該当するリソースが存在しません");

return view('main.rdfDescribe', compact('turtle', 'resource'));
}

public function ed403(){
abort(403);
}
Expand Down
29 changes: 29 additions & 0 deletions resources/views/main/rdfDescribe.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@extends('app.layout', ['title' => 'RDF簡易参照'])

@section('head')
<meta name="robots" content="noindex">
<link rel=stylesheet href="//codemirror.net/lib/codemirror.css">
<script src="//codemirror.net/lib/codemirror.js"></script>
<script src="//codemirror.net/mode/turtle/turtle.js"></script>
@endsection

@section('main')
<main>
<h2>lilyrdf:{{ $resource }}</h2>
<label>
<textarea id="turtle" readonly>{{ $turtle ?? '' }}</textarea>
</label>
<script>
const cm = CodeMirror.fromTextArea(document.getElementById('turtle'), {
lineNumbers: true,
readOnly: true,
mode: 'text/turtle'
});
cm.setSize('100%','100%');
</script>
<p>
SPARQL endpoint : <a href="{{ config('lemonade.sparqlEndpoint') }}" target="_blank">{{ config('lemonade.sparqlEndpoint') }}</a><br>
Syntax highlight : <a href="https://codemirror.net/" target="_blank">CodeMirror</a>
</p>
</main>
@endsection
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

Route::get('/imedic', [InfoController::class, 'generateImeDic'])->name('imedic');

Route::get('/rdfDescribe/{resource}', [InfoController::class, 'rdfDescribe'])->name('rdfDescribe');

Route::middleware('throttle:30,1')->group(function (){
Route::get('/ogp/{type}/{title}.jpg', [OGPController::class, 'generate'])->name('ogp');
});
Expand Down

0 comments on commit 3db9fd2

Please sign in to comment.