Good day everyone!
I have an RDF file something like:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xml:lang="en"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:tool="https://www.toptools4learning.com/">
<rdf:Description rdf:about="YouTube">
<tool:rank>1</tool:rank>
<tool:reference rdf:resource="https://www.toptools4learning.com/"/>
<tool:type>learning</tool:type>
<tool:category>web-based</tool:category>
<tool:domain>any</tool:domain>
</rdf:Description>
<rdf:Description rdf:about="Wikipedia">
<tool:rank>11</tool:rank>
<tool:reference rdf:resource="https://www.toptools4learning.com/"/>
<tool:type>learning</tool:type>
<tool:category>web-based</tool:category>
<tool:domain>any</tool:domain>
</rdf:Description>
</rdf:RDF>
What I would like to do is I would like to implement a feature for my web application in PHP that would allow the user to upload an RDF File, and after clicking the submit button, it will generate the RDF graph of the uploaded file.
I was taking a look at EasyRDF tutorials, and in one of the tutorials it showed how to visualize an RDF graph by providing a valid URI:
<?php
require_once __dir__."/autoload.php";
require_once __DIR__."/html_tag_helper.php";
?>
<div style="margin: 10px">
<?= form_tag() ?>
URI: <?= text_field_tag('uri', ' ', array('size'=>80)) ?><br />
Format: <?= label_tag('format_html', 'HTML').' '.radio_button_tag('format', 'html', true) ?>
<?= label_tag('format_text', 'Text').' '.radio_button_tag('format', 'text') ?><br />
<?= submit_tag() ?>
<?= form_end_tag() ?>
</div>
<?php
if (isset($_REQUEST['uri'])) {
$graph = \EasyRdf\Graph::newAndLoad($_REQUEST['uri']);
if ($graph) {
if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'text') {
print "<pre>".$graph->dump('text')."</pre>";
} else {
$dump = $graph->dump('html');
print preg_replace_callback("/ href='([^#][^']*)'/", 'makeLinkLocal', $dump);
}
} else {
print "<p>Failed to create graph.</p>";
}
}
# Callback function to re-write links in the dump to point back to this script
function makeLinkLocal($matches)
{
$href = $matches[1];
return " href='?uri=".urlencode($href)."#$href'";
}
?>
My idea is the same but instead of URIs, I'd like to do this by uploading an RDF file. I saw a form tag helper from the Rails API called file_upload_tag()
, however I'm not quite sure how to work with it.
Any suggestions would be greatly appreciated!
My Answer:
Rate this post
4 of 5 based on 1992 votesComments