Author: hasan
Date: Sat Nov 11 20:52:06 2017
New Revision: 1814972
URL: http://svn.apache.org/viewvc?rev=1814972&view=rev
Log:
CLEREZZA-1017: Add Tutorial 2
Added:
clerezza/site/production/getting-started/tutorial/tutorial-02/
clerezza/site/production/getting-started/tutorial/tutorial-02/index.html
Modified:
clerezza/site/production/getting-started/tutorial/index.html
Modified: clerezza/site/production/getting-started/tutorial/index.html
URL:
http://svn.apache.org/viewvc/clerezza/site/production/getting-started/tutorial/index.html?rev=1814972&r1=1814971&r2=1814972&view=diff
==============================================================================
--- clerezza/site/production/getting-started/tutorial/index.html (original)
+++ clerezza/site/production/getting-started/tutorial/index.html Sat Nov 11
20:52:06 2017
@@ -83,6 +83,11 @@
<a href="tutorial-01/">Tutorial 1</a> -
Store Triples in a Simple Graph.
</div>
</li>
+ <li>
+ <div>
+ <a href="tutorial-02/">Tutorial 2</a> -
Import Triples from a File into a Simple Graph.
+ </div>
+ </li>
</ul>
</div>
</div>
Added: clerezza/site/production/getting-started/tutorial/tutorial-02/index.html
URL:
http://svn.apache.org/viewvc/clerezza/site/production/getting-started/tutorial/tutorial-02/index.html?rev=1814972&view=auto
==============================================================================
--- clerezza/site/production/getting-started/tutorial/tutorial-02/index.html
(added)
+++ clerezza/site/production/getting-started/tutorial/tutorial-02/index.html
Sat Nov 11 20:52:06 2017
@@ -0,0 +1,345 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link type="text/css" href="/style/style.css" rel="stylesheet"/>
+ <title>Tutorial 02 - Import Triples from a File into a Simple
Graph</title>
+ </head>
+ <body>
+ <div class="zz-header">
+ <div class="bar"></div>
+ <div class="logo">
+ <a href="http://clerezza.apache.org/" style="">
+ <img src="/images/logo.png" alt="logo"/>
+ </a>
+ </div>
+ </div>
+ <div class="column nav">
+ <ul>
+ <li class="top-nav-entry">
+ <div class="title">Documentation</div>
+ <ul class="nav-entries">
+ <li>
+ <a href="/getting-started/" class="active">Getting
Started</a>
+ </li>
+ <li>
+ <a href="/architecture/">The Apache Clerezza
Stack</a>
+ </li>
+ <li>
+ <a href="http://clerezza.apache.org/apidocs/"
target="_blank">API docs</a>
+ </li>
+ <li>
+ <a href="/faq/">FAQ</a>
+ </li>
+ </ul>
+ </li>
+ <li class="top-nav-entry">
+ <div class="title">Project Infos</div>
+ <ul class="nav-entries">
+ <li>
+ <a href="/downloads/">Downloads</a>
+ </li>
+ <li>
+ <a href="/contributing/">Contributing</a>
+ </li>
+ <li>
+ <a href="http://www.apache.org/licenses/"
target="_blank">License</a>
+ </li>
+ <li>
+ <a href="/mailinglists/">Mailing lists</a>
+ </li>
+ <li>
+ <a
href="http://issues.apache.org/jira/browse/CLEREZZA" target="_blank">Issue
Tracker</a>
+ </li>
+ <li>
+ <a
href="https://git-wip-us.apache.org/repos/asf?p=clerezza.git"
target="_blank">Source Repository</a>
+ </li>
+ </ul>
+ </li>
+ <li class="top-nav-entry">
+ <div class="title">Sponsorship</div>
+ <ul class="nav-entries">
+ <li>
+ <a href="/thanks/">Thanks</a>
+ </li>
+ <li>
+ <a
href="http://www.apache.org/foundation/sponsorship.html" target="_blank">Become
a Sponsor</a>
+ </li>
+ <li>
+ <a
href="http://www.apache.org/foundation/buy_stuff.html" target="_blank">Buy
Stuff</a>
+ </li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ <div class="zz-content">
+ <h1>Tutorial 02 - Import Triples from a File into a Simple
Graph</h1>
+ <div class='tx-content'>
+ <div>
+ <div xmlns="http://www.w3.org/1999/xhtml" class="column
one-column">
+ <p>
+ In this tutorial we are going to import triples
stored in a file into a graph.
+ </p>
+ <h2>Problem Definition</h2>
+ <p>
+ Given a file containing a set of triples in <a
href="https://www.w3.org/TR/turtle/">Turtle</a> serialization format
(text/turtle), an RDF Graph should be created and filled with the triples.
Assuming the content of the file is as follows, the program should log the
corresponding triples.
+ </p>
+ <div xmlns="http://www.w3.org/1999/xhtml"
class="tx-blockcode">
+@prefix ex: <http://clerezza.apache.org/2017/01/example#> .
+_:a ex:hasFirstName "Hasan" .
+_:a ex:isA ex:ClerezzaUser .
+ </div>
+ <h2>Solution</h2>
+ <p>
+ Apache Clerezza provides a Parser that can be
used to read files containing triples in various serialization format. The
Parser makes use of ParsingProvider services which implement the functionality
to parse files of specific data format. We are going to use a ParsingProvider
based on Jena Parser.
+ </p>
+ <p>
+ The programme listed below reads the file
example02.ttl, parses its content and stores the triples into a Graph. Then it
reads the newly created graph and logs the triples within the graph.
+ </p>
+ <div xmlns="http://www.w3.org/1999/xhtml"
class="tx-blockcode">
+ 1 package org.apache.clerezza.tutorial;
+ 2
+ 3 import org.apache.clerezza.commons.rdf.Graph;
+ 4 import org.apache.clerezza.commons.rdf.Triple;
+ 5 import org.apache.clerezza.rdf.core.serializedform.Parser;
+ 6 import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+ 7 import
org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException;
+ 8 import org.slf4j.Logger;
+ 9 import org.slf4j.LoggerFactory;
+ 10
+ 11 import java.io.InputStream;
+ 12 import java.util.Iterator;
+ 13
+ 14 public class Example02 {
+ 15
+ 16 private static final Logger logger =
LoggerFactory.getLogger(Example02.class);
+ 17
+ 18 public static void main(String[] args) {
+ 19 InputStream inputStream =
Example02.class.getResourceAsStream("example02.ttl");
+ 20 Parser parser = Parser.getInstance();
+ 21
+ 22 try {
+ 23 Graph graph = parser.parse(inputStream,
SupportedFormat.TURTLE);
+ 24
+ 25 Iterator<Triple> iterator =
graph.filter(null,null,null);
+ 26 Triple triple;
+ 27
+ 28 while (iterator.hasNext()) {
+ 29 triple = iterator.next();
+ 30 logger.info(String.format("%s %s %s",
+ 31 triple.getSubject().toString(),
+ 32 triple.getPredicate().toString(),
+ 33 triple.getObject().toString()
+ 34 ));
+ 35 }
+ 36 } catch (UnsupportedFormatException $ex) {
+ 37 logger.warn(String.format("%s is not supported by the used
parser", SupportedFormat.TURTLE));
+ 38 }
+ 39 }
+ 40 }
+ </div>
+ <p>
+ We will use maven for building the program. The
required POM file is as follows:
+ </p>
+ <div xmlns="http://www.w3.org/1999/xhtml"
class="tx-blockcode">
+ 1 <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ 3 <modelVersion>4.0.0</modelVersion>
+ 4 <groupId>org.apache.clerezza.tutorial</groupId>
+ 5 <artifactId>Example-02</artifactId>
+ 6 <packaging>jar</packaging>
+ 7 <version>1.0</version>
+ 8 <build>
+ 9 <plugins>
+ 10 <plugin>
+ 11 <groupId>org.apache.maven.plugins</groupId>
+ 12 <artifactId>maven-compiler-plugin</artifactId>
+ 13 <version>3.7.0</version>
+ 14 <configuration>
+ 15 <source>1.8</source>
+ 16 <target>1.8</target>
+ 17 </configuration>
+ 18 </plugin>
+ 19 <plugin>
+ 20 <groupId>org.codehaus.mojo</groupId>
+ 21 <artifactId>exec-maven-plugin</artifactId>
+ 22 <version>1.6.0</version>
+ 23 <executions>
+ 24 <execution>
+ 25 <goals>
+ 26 <goal>java</goal>
+ 27 </goals>
+ 28 </execution>
+ 29 </executions>
+ 30 <configuration>
+ 31
<mainClass>org.apache.clerezza.tutorial.Example02</mainClass>
+ 32 </configuration>
+ 33 </plugin>
+ 34 </plugins>
+ 35 </build>
+ 36 <name>Example-02</name>
+ 37 <url>http://maven.apache.org</url>
+ 38 <dependencies>
+ 39 <dependency>
+ 40 <groupId>org.apache.clerezza</groupId>
+ 41 <artifactId>rdf.core</artifactId>
+ 42 <version>1.0.1</version>
+ 43 </dependency>
+ 44 <dependency>
+ 45 <groupId>org.slf4j</groupId>
+ 46 <artifactId>slf4j-simple</artifactId>
+ 47 <version>1.7.25</version>
+ 48 </dependency>
+ 49 <dependency>
+ 50 <groupId>org.apache.clerezza</groupId>
+ 51 <artifactId>rdf.jena.parser</artifactId>
+ 52 <version>1.1.1</version>
+ 53 </dependency>
+ 54 </dependencies>
+ 55 </project>
+ </div>
+ <p>
+ The directory structure is simple as shown
below:
+ </p>
+ <div xmlns="http://www.w3.org/1999/xhtml"
class="tx-blockcode">
+ pom.xml
+ src/main/java/org/apache/clerezza/tutorial/Example02.java
+ src/main/resources/org/apache/clerezza/tutorial/example02.ttl
+ </div>
+ <p>
+ To build the jar, we should invoke:
+ </p>
+ <div xmlns="http://www.w3.org/1999/xhtml"
class="tx-blockcode">
+ mvn package
+ </div>
+ <p>
+ Running the programme can be done by invoking
+ </p>
+ <div xmlns="http://www.w3.org/1999/xhtml"
class="tx-blockcode">
+ mvn exec:java
+ </div>
+ <p>
+ The result of the programme execution shows the
log messages as expected.
+ </p>
+ <div xmlns="http://www.w3.org/1999/xhtml"
class="tx-blockcode">
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building Example-02 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ Example-02 ---
+SLF4J: Class path contains multiple SLF4J bindings.
+SLF4J: Found binding in
[jar:file:/home/hasan/.m2/repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
+SLF4J: Found binding in
[jar:file:/home/hasan/.m2/repository/org/slf4j/slf4j-log4j12/1.7.6/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
+SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
+SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
+[org.apache.clerezza.tutorial.Example02.main()] INFO
org.apache.clerezza.rdf.core.serializedform.Parser - constructing Parser
+[org.apache.clerezza.tutorial.Example02.main()] INFO
org.apache.clerezza.tutorial.Example02 -
<b>org.apache.clerezza.rdf.jena.commons.JenaBNodeWrapper@78d47560
<http://clerezza.apache.org/2017/01/example#hasFirstName>
"Hasan"^^<http://www.w3.org/2001/XMLSchema#string></b>
+[org.apache.clerezza.tutorial.Example02.main()] INFO
org.apache.clerezza.tutorial.Example02 -
<b>org.apache.clerezza.rdf.jena.commons.JenaBNodeWrapper@78d47560
<http://clerezza.apache.org/2017/01/example#isA>
<http://clerezza.apache.org/2017/01/example#ClerezzaUser></b>
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 0.928 s
+[INFO] Finished at: 2017-11-11T15:53:32+01:00
+[INFO] Final Memory: 9M/216M
+[INFO] ------------------------------------------------------------------------
+ </div>
+ <h2>Discussion</h2>
+ <p>
+ The maven POM file shows three libraries on
which the programme directly depends:
+ </p>
+ <ul>
+ <li>
+ org.apache.clerezza.rdf.core: contains
implementation of the Apache Clerezza Parser
+ </li>
+ <li>
+ org.apache.clerezza.rdf.jena.parser:
contains ParsingProvider service based on Jena Parser
+ </li>
+ <li>
+ org.slf4j.slf4j-simple: contains
implementation of the logger
+ </li>
+ </ul>
+ <p>
+ The core of the programme lies at line 20
(Parser instantiation) and 23 (parsing a stream of triples into a graph).
+ </p>
+ <p>
+ Note: Any comments and suggestions for improvements
are welcome. Please send your feedback to <a
href="mailto:[email protected]">[email protected]</a>
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="footer">
+ <div class="logos">
+ <img src="/images/feather.png"/>
+ <img src="/images/sw-vert-w3c.png"/>
+ <img src="/images/footer-logo.png"/>
+ </div>
+ <div class="divider"></div>
+ <div class="dark">
+ <div class="sitemap">
+ <div class="sitemap-title">Sitemap</div>
+ <div class="sitemap-content">
+ <div class="sitemap-column">
+ <div class="title">Documentation</div>
+ <ul>
+ <li>
+ <a href="/getting-started/">Getting
Started</a>
+ </li>
+ <li>
+ <a href="/architecture/">The Apache
Clerezza Stack</a>
+ </li>
+ <li>
+ <a
href="http://clerezza,apache.org/apidocs/" target="_blank">API docs</a>
+ </li>
+ <li>
+ <a href="/faq/">FAQ</a>
+ </li>
+ </ul>
+ </div>
+ <div class="sitemap-column">
+ <div class="title">Project Infos</div>
+ <ul>
+ <li>
+ <a href="/downloads/">Downloads</a>
+ </li>
+ <li>
+ <a href="/contributing/">Contributing</a>
+ </li>
+ <li>
+ <a href="http://www.apache.org/licenses/"
target="_blank">License</a>
+ </li>
+ <li>
+ <a href="mailinglists/">Mailing lists</a>
+ </li>
+ <li>
+ <a
href="http://issues.apache.org/jira/browse/CLEREZZA" target="_blank">Issue
Tracker</a>
+ </li>
+ <li>
+ <a
href="https://git-wip-us.apache.org/repos/asf?p=clerezza.git"
target="_blank">Source Repository</a>
+ </li>
+ </ul>
+ </div>
+ <div class="sitemap-column">
+ <div class="title">Sponsorship</div>
+ <ul>
+ <li>
+ <a href="/thanks/">Thanks</a>
+ </li>
+ <li>
+ <a
href="http://www.apache.org/foundation/sponsorship.html" target="_blank">Become
a Sponsor</a>
+ </li>
+ <li>
+ <a
href="http://www.apache.org/foundation/buy_stuff.html" target="_blank">Buy
Stuff</a>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div class="copyright">Apache Clerezza, Clerezza, Apache, the
Apache feather logo, and the Apache Clerezza project logo are trademarks of The
Apache Software Foundation.
+ <br></br>© 2011 The Apache Software Foundation.
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
\ No newline at end of file