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
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
| Android's Limits | Jun 04, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Linux Systems Administrator
- Introduction to MapReduce with Hadoop on Linux
- Senior Perl Developer
- Technical Support Rep
- Weechat, Irssi's Little Brother
- UX Designer
- One Tail Just Isn't Enough
- Android's Limits
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?




6 min 6 sec ago
54 min 2 sec ago
54 min 29 sec ago
3 hours 19 min ago
7 hours 30 min ago
7 hours 33 min ago
1 day 3 hours ago
1 day 4 hours ago
1 day 4 hours ago
1 day 7 hours ago