Ajax Timelines and the Semantic Web
Listing 18. Glue to Transform find Results to RDF
#!/usr/bin/perl
use POSIX;
use File::Basename;
use RDF::Redland;
$storage=new RDF::Redland::Storage(
"hashes", "test", "new='yes',hash-type='memory'");
$model=new RDF::Redland::Model($storage, "");
$rdfns = "http://witme.sf.net/rdf/filesystem/";
$/="\0";
while( <> ) {
$url=$_;
# remove pesky null char at end-of-string
chomp($url);
($dev, $ino, $mode, $nlink, $uid,$gid,$rdev,
$size,$atime,$mtime,$ctime) = lstat($_);
$model->add(
new RDF::Redland::URI( "${rdfns}${ino}" ),
new RDF::Redland::URI( "${rdfns}inode" ),
new RDF::Redland::LiteralNode( "$ino" ) );
$model->add(
new RDF::Redland::URI( "${rdfns}${ino}" ),
new RDF::Redland::URI( "${rdfns}url" ),
new RDF::Redland::LiteralNode( "$url" ) );
$model->add(
new RDF::Redland::URI( "${rdfns}${ino}" ),
new RDF::Redland::URI( "${rdfns}basename" ),
new RDF::Redland::LiteralNode(basename("$url")));
$model->add(
new RDF::Redland::URI( "${rdfns}${ino}" ),
new RDF::Redland::URI( "${rdfns}title" ),
new RDF::Redland::LiteralNode(
substr basename("$url"), 0, 25 ) );
$model->add(
new RDF::Redland::URI( "${rdfns}${ino}" ),
new RDF::Redland::URI( "${rdfns}mtime" ),
new RDF::Redland::LiteralNode( strftime(
"%Y-%m-%d %H:%M:%S", localtime($mtime)) ) );
$model->add(
new RDF::Redland::URINode( "${rdfns}${ino}" ),
new RDF::Redland::URINode( "${rdfns}size" ),
new RDF::Redland::LiteralNode( "$size" ) );
$model->add(
new RDF::Redland::URI( "${rdfns}${ino}" ),
new RDF::Redland::URI( "${rdfns}content" ),
new RDF::Redland::LiteralNode( "$url<br>" ) );
$desc = "<a href=\"${url}\">$url</a><br></br>"
. "<iframe src=\"${url}\" "
. "width=\"95%\" height=\"75%\"></iframe>";
$model->add(
new RDF::Redland::URI( "${rdfns}${ino}" ),
new RDF::Redland::URI( "${rdfns}description" ),
RDF::Redland::Node->new_xml_literal( $desc ) );
}
$model->sync();
print $model->to_string() , "\n";The SPARQL query is shown in Listing 19. The sparql2timeline.xsl can be reused from any of the above examples. The commands also are very similar, as shown in Listing 20. The evolution.html can be copied to filesystem.html and modified to include filesystem.json, and we have a new Timeline.
Listing 19. SPARQL to Query an RDF Store for Filesystem Data
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX fs: <http://witme.sf.net/rdf/filesystem/>
SELECT distinct ?uid ?title ?date ?description
WHERE {
?x fs:inode ?uid .
?x fs:title ?title .
?x fs:mtime ?date .
?x fs:description ?description .
}
ORDER BY DESC(?date)Listing 20. My File Modifications for This Week
$ find ~ -name ".*" -prune -o -name "*~" -prune \ -o -mtime -7 -print0 | \ ./find-to-rdf.pl >| filesystem.rdf $ java jena.sparql \ --data filesystem.rdf \ --query filesystem-to-timeline.rq \ --results xml >| filesystem.xml $ xsltproc sparql2timeline.xsl filesystem.xml \ | tr '\n' ' ' >| filesystem.json
Using RDF and SPARQL can be a great advantage when creating Timelines for new data sources. The sparql2timeline.xsl file can be reused to convert SPARQL query results to JSON. The two main things required are getting the data into RDF and the SPARQL query itself. I've touched on only some possibilities of SPARQL in this article. With SPARQL, it's easy to ensure that a value in the results matches a regular expression or has some other property, such as being between two dates. Results can come from multiple data sources using the UNION keyword. For example, it is easy to combine any of the above SPARQL queries into a single query to show multiple types of time events on a single Timeline.
Resources for this article: /article/9463.
Ben Martin has been working on filesystems for more than ten years. He is currently working toward a PhD at the University of Wollongong, Australia, combining Semantic Filesystems with Formal Concept Analysis to improve human-filesystem interaction.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Designing Electronics with Linux
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




7 hours 36 min ago
8 hours 10 min ago
9 hours 8 min ago
9 hours 59 min ago
14 hours 56 sec ago
17 hours 48 min ago
17 hours 56 min ago
20 hours 10 min ago
22 hours 40 min ago
1 day 8 hours ago