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.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
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
| 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 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Home, My Backup Data Center
- What's the tweeting protocol?
- New Products
- One Hand Slapping
- RSS Feeds
- Readers' Choice Awards
Enter to Win an Adafruit Prototyping Pi Plate 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 Prototyping Pi Plate 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
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




6 hours 38 min ago
9 hours 10 min ago
10 hours 28 min ago
11 hours 2 min ago
11 hours 25 min ago
16 hours 13 min ago
17 hours 43 sec ago
18 hours 34 min ago
20 hours 11 min ago
22 hours 8 min ago