This is an automated email from the ASF dual-hosted git repository.
hasan pushed a commit to branch CLEREZZA-1071-tutorial
in repository https://gitbox.apache.org/repos/asf/clerezza.git
The following commit(s) were added to refs/heads/CLEREZZA-1071-tutorial by this
push:
new fa983cf tutuorial module (#23)
fa983cf is described below
commit fa983cf18f5740b42f4f4dad99ab84e7a5a2e390
Author: Yusuf Karadag <[email protected]>
AuthorDate: Mon Aug 30 00:31:25 2021 +0200
tutuorial module (#23)
CLEREZZA-1071: Add tutorial module
---
pom.xml | 1 +
tutorial/pom.xml | 83 ++++++++++++++++++++++
.../org/apache/clerezza/tutorial/Example01.java | 41 +++++++++++
.../org/apache/clerezza/tutorial/Example02.java | 42 +++++++++++
.../org/apache/clerezza/tutorial/Example03.java | 43 +++++++++++
.../org/apache/clerezza/tutorial/example02.ttl | 3 +
.../org/apache/clerezza/tutorial/example03.ttl | 3 +
7 files changed, 216 insertions(+)
diff --git a/pom.xml b/pom.xml
index 8570d09..800cc35 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,6 +61,7 @@
<module>dataset</module>
<module>api.utils</module>
<module>jaxrs.rdf.providers</module>
+ <module>tutorial</module>
</modules>
<profiles>
diff --git a/tutorial/pom.xml b/tutorial/pom.xml
new file mode 100644
index 0000000..018a37e
--- /dev/null
+++ b/tutorial/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.clerezza.tutorial</groupId>
+ <artifactId>tutorial</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.6.0</version>
+ <executions>
+ <execution>
+ <id>first-example</id>
+ <configuration>
+
<mainClass>org.apache.clerezza.tutorial.Example01</mainClass>
+ </configuration>
+ </execution>
+ <execution>
+ <id>second-example</id>
+ <configuration>
+
<mainClass>org.apache.clerezza.tutorial.Example02</mainClass>
+ </configuration>
+ </execution>
+ <execution>
+ <id>third-example</id>
+ <configuration>
+
<mainClass>org.apache.clerezza.tutorial.Example03</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <name>Clerezza-Tutorials</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>api</artifactId>
+ <version>2.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>api-implementation</artifactId>
+ <version>2.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>representation</artifactId>
+ <version>2.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.30</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wymiwyg.clerezza</groupId>
+ <artifactId>rdf.jena.parser</artifactId>
+ <version>2.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wymiwyg.clerezza</groupId>
+ <artifactId>rdf.jena.serializer</artifactId>
+ <version>2.0.3</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/tutorial/src/main/java/org/apache/clerezza/tutorial/Example01.java
b/tutorial/src/main/java/org/apache/clerezza/tutorial/Example01.java
new file mode 100644
index 0000000..f06b692
--- /dev/null
+++ b/tutorial/src/main/java/org/apache/clerezza/tutorial/Example01.java
@@ -0,0 +1,41 @@
+package org.apache.clerezza.tutorial;
+
+import org.apache.clerezza.BlankNode;
+import org.apache.clerezza.Graph;
+import org.apache.clerezza.IRI;
+import org.apache.clerezza.Triple;
+import org.apache.clerezza.implementation.literal.PlainLiteralImpl;
+import org.apache.clerezza.implementation.TripleImpl;
+import org.apache.clerezza.implementation.in_memory.SimpleGraph;
+
+import java.util.Iterator;
+
+public class Example01 {
+
+ public static void main( String[] args ) {
+ BlankNode subject = new BlankNode();
+
+ IRI isA = new IRI( "http://clerezza.apache.org/2017/01/example#isA" );
+ IRI clerezzaUser = new IRI(
"http://clerezza.apache.org/2017/01/example#ClerezzaUser" );
+
+ IRI hasFirstName = new IRI(
"http://clerezza.apache.org/2017/01/example#hasFirstName" );
+ PlainLiteralImpl firstName = new PlainLiteralImpl( "Hasan" );
+
+ TripleImpl subjectType = new TripleImpl( subject, isA, clerezzaUser );
+ TripleImpl subjectFirstName = new TripleImpl( subject, hasFirstName,
firstName );
+
+ Graph myGraph = new SimpleGraph();
+ myGraph.add( subjectType );
+ myGraph.add( subjectFirstName );
+
+ Iterator<Triple> iterator = myGraph.filter( null, null, null );
+ Triple triple;
+ while ( iterator.hasNext() ) {
+ triple = iterator.next();
+ System.out.println( triple.getSubject().toString() );
+ System.out.println( triple.getPredicate().toString() );
+ System.out.println( triple.getObject().toString() );
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/tutorial/src/main/java/org/apache/clerezza/tutorial/Example02.java
b/tutorial/src/main/java/org/apache/clerezza/tutorial/Example02.java
new file mode 100644
index 0000000..be68e2d
--- /dev/null
+++ b/tutorial/src/main/java/org/apache/clerezza/tutorial/Example02.java
@@ -0,0 +1,42 @@
+package org.apache.clerezza.tutorial;
+
+import org.apache.clerezza.Graph;
+import org.apache.clerezza.Triple;
+import org.apache.clerezza.representation.Parser;
+import org.apache.clerezza.representation.SupportedFormat;
+import org.apache.clerezza.representation.UnsupportedFormatException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+public class Example02 {
+
+ private static final Logger logger = LoggerFactory.getLogger(
Example02.class );
+
+ public static void main( String[] args ) {
+
+ InputStream inputStream = Example02.class.getResourceAsStream(
"example02.ttl" );
+ Parser parser = Parser.getInstance();
+
+ try {
+ Graph graph = parser.parse( inputStream, SupportedFormat.TURTLE );
+
+ Iterator<Triple> iterator = graph.filter( null, null, null );
+ Triple triple;
+
+ while ( iterator.hasNext() ) {
+ triple = iterator.next();
+ logger.info( String.format( "%s %s %s",
+ triple.getSubject().toString(),
+ triple.getPredicate().toString(),
+ triple.getObject().toString()
+ ) );
+ }
+ } catch ( UnsupportedFormatException ex ) {
+ logger.warn( String.format( "%s is not supported by the used
parser", SupportedFormat.TURTLE ) );
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/tutorial/src/main/java/org/apache/clerezza/tutorial/Example03.java
b/tutorial/src/main/java/org/apache/clerezza/tutorial/Example03.java
new file mode 100644
index 0000000..efe44a1
--- /dev/null
+++ b/tutorial/src/main/java/org/apache/clerezza/tutorial/Example03.java
@@ -0,0 +1,43 @@
+package org.apache.clerezza.tutorial;
+
+import org.apache.clerezza.Graph;
+import org.apache.clerezza.rdf.jena.parser.JenaParserProvider;
+import org.apache.clerezza.rdf.jena.serializer.JenaSerializerProvider;
+import org.apache.clerezza.representation.Parser;
+import org.apache.clerezza.representation.Serializer;
+import org.apache.clerezza.representation.SupportedFormat;
+import org.apache.clerezza.representation.UnsupportedFormatException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+
+public class Example03 {
+
+ private static final Logger logger = LoggerFactory.getLogger(
Example03.class );
+
+ public static void main( String[] args ) {
+ InputStream inputStream = Example03.class.getResourceAsStream(
"example03.ttl" );
+ Parser parser = Parser.getInstance();
+ Graph graph;
+ try {
+ graph = parser.parse( inputStream, SupportedFormat.TURTLE );
+ } catch ( UnsupportedFormatException ex ) {
+ logger.warn( String.format( "%s is not supported by the used
parser", SupportedFormat.TURTLE ) );
+ return;
+ }
+
+ Serializer serializer = Serializer.getInstance();
+ try {
+ FileOutputStream outputStream = new FileOutputStream(
"/tmp/example03.rdf" );
+ serializer.serialize( outputStream, graph, SupportedFormat.RDF_XML
);
+ } catch ( FileNotFoundException ex ) {
+ logger.warn( ex.getMessage() );
+ } catch ( UnsupportedFormatException ex ) {
+ logger.warn( String.format( "%s is not supported by the used
serializer", SupportedFormat.RDF_XML ) );
+ }
+ }
+
+}
\ No newline at end of file
diff --git
a/tutorial/src/main/resources/org/apache/clerezza/tutorial/example02.ttl
b/tutorial/src/main/resources/org/apache/clerezza/tutorial/example02.ttl
new file mode 100644
index 0000000..9edaedd
--- /dev/null
+++ b/tutorial/src/main/resources/org/apache/clerezza/tutorial/example02.ttl
@@ -0,0 +1,3 @@
+@prefix ex: <http://clerezza.apache.org/2017/01/example#> .
+_:a ex:hasFirstName "Hasan" .
+_:a ex:isA ex:ClerezzaUser .
\ No newline at end of file
diff --git
a/tutorial/src/main/resources/org/apache/clerezza/tutorial/example03.ttl
b/tutorial/src/main/resources/org/apache/clerezza/tutorial/example03.ttl
new file mode 100644
index 0000000..9edaedd
--- /dev/null
+++ b/tutorial/src/main/resources/org/apache/clerezza/tutorial/example03.ttl
@@ -0,0 +1,3 @@
+@prefix ex: <http://clerezza.apache.org/2017/01/example#> .
+_:a ex:hasFirstName "Hasan" .
+_:a ex:isA ex:ClerezzaUser .
\ No newline at end of file