commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r949426 - /websites/production/commonsrdf/content/userguide.html
Date Tue, 28 Apr 2015 02:10:51 GMT
Author: stain
Date: Tue Apr 28 02:10:51 2015
New Revision: 949426

Log:
Site checkin for project Commons RDF

Modified:
    websites/production/commonsrdf/content/userguide.html

Modified: websites/production/commonsrdf/content/userguide.html
==============================================================================
--- websites/production/commonsrdf/content/userguide.html (original)
+++ websites/production/commonsrdf/content/userguide.html Tue Apr 28 02:10:51 2015
@@ -342,7 +342,7 @@
   <maven.compiler.target>1.8</maven.compiler.target>
 </properties>
 </pre></div></div>
-<p>In the examples below we will use the <a href="apidocs/org/apache/commons/rdf/simple/package-summary.html"><i>simple</i>
implementation</a>, but the examples should be equally applicable to other implementations.
To add a dependency for the <i>simple</i> implementation, add to your <tt>&lt;dependencies&gt;</tt>:</p>
+<p>In the examples below we will use the <a href="apidocs/org/apache/commons/rdf/simple/package-summary.html"><i>simple</i>
implementation</a>, but the examples should be equally applicable to other <a href="implementations.html">implementations</a>.
To add a dependency for the <i>simple</i> implementation, add to your <tt>&lt;dependencies&gt;</tt>:</p>
 
 <div class="source">
 <div class="source">
@@ -362,21 +362,21 @@
 <pre>import org.apache.commons.rdf.api.*;
 import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
 // ...
-RDFTermFactory rdfTermFactory = new SimpleRDFTermFactory();
+RDFTermFactory factory = new SimpleRDFTermFactory();
 </pre></div></div>
 <p>Using the factory you can construct any <a href="apidocs/org/apache/commons/rdf/api/RDFTerm.html">RDFTerm</a>,
e.g. to create a <a href="apidocs/org/apache/commons/rdf/api/BlankNode.html">BlankNode</a>,
<a href="apidocs/org/apache/commons/rdf/api/IRI.html">IRI</a> and <a href="apidocs/org/apache/commons/rdf/api/Literal.html">Literal</a>:</p>
 
 <div class="source">
 <div class="source">
-<pre>BlankNode blankNode = factory.createBlankNode();
-IRI iri = factory.createIRI(&quot;http://example.com/name&quot;);
-Literal literal = factory.createLiteral(&quot;Alice&quot;);
+<pre>BlankNode aliceBlankNode = factory.createBlankNode();
+IRI nameIri = factory.createIRI(&quot;http://example.com/name&quot;);
+Literal aliceLiteral = factory.createLiteral(&quot;Alice&quot;);
 </pre></div></div>
 <p>You can also create a stand-alone <a href="apidocs/org/apache/commons/rdf/api/Triple.html">Triple</a>:</p>
 
 <div class="source">
 <div class="source">
-<pre>Triple triple = factory.createTriple(blankNode, iri, literal);
+<pre>Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);
 </pre></div></div>
 <p>The <a href="apidocs/org/apache/commons/rdf/api/RDFTermFactory.html">RDFTermFactory</a>
also contains more specific variants of some of the methods above, e.g. to create a typed
literal. </p>
 <p>Note that for any given implementation, <tt>RDFTerm</tt> instances need
not be created using a <tt>RDFTermFactory</tt>. More likely, implementation-specific
methods might create these objects as part of data parsing, storage lookup and queries.</p></div>
@@ -421,28 +421,31 @@ System.out.println(aliceLiteral.ntriples
 </blockquote>
 <p>This returns the <a class="externalLink" href="http://www.w3.org/TR/n-triples">N-Triples</a>
canonical form of the term, which can be useful both for debugging and simple serialization.</p>
 <p><i>Note: The <tt>.toString()</tt> of the <tt>simple</tt>
implementation used in some of these examples use <tt>ntriplesString()</tt> internally,
but Commons RDF places no such formal requirement on the <tt>.toString()</tt>
method. Clients that rely on a canonical N-Triples-compatible string should instead use <tt>ntriplesString()</tt>.</i></p>
-<p>As an example of using <tt>ntriplesString()</tt>, here is how one could
write a basic N-Triples-compatible serialization of a <a href="apidocs/org/apache/commons/rdf/api/Graph.html">Graph</a>:</p>
+<!-- Not relevant here
 
-<div class="source">
-<div class="source">
-<pre>public class NTriplesSerializer {
+As an example of using `ntriplesString()`, here is how one could write a basic
+N-Triples-compatible serialization of a
+[Graph](apidocs/org/apache/commons/rdf/api/Graph.html):
+
+```java
+public class NTriplesSerializer {
     public static String tripleAsString(Triple t) {
-        return t.getSubject().ntriplesString() + &quot; &quot; +
-               t.getPredicate().ntriplesString() + &quot; &quot; +
-               t.getObject().ntriplesString() + &quot; .&quot;;
+        return t.getSubject().ntriplesString() + " " +
+               t.getPredicate().ntriplesString() + " " +
+               t.getObject().ntriplesString() + " .";
     }
     public static void writeGraph(Graph graph, Path graphFile) throws Exception {
-        Stream&lt;CharSequence&gt; stream = graph.getTriples().map(NTriplesSerializer::tripleAsString);
-        Files.write(graphFile, stream::iterator, Charset.forName(&quot;UTF-8&quot;));
+        Stream<CharSequence> stream = graph.getTriples().map(NTriplesSerializer::tripleAsString);
+        Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
     }
 }
-</pre></div></div>
-<p>Example output:</p>
+```
 
-<blockquote>
-<p><tt>_:ef136d20-f1ee-3830-a54b-cd5e489d50fb &lt;http://example.com/name&gt;
&quot;Alice&quot; .</tt></p>
-<p><tt>&lt;http://example.com/bob&gt; &lt;http://example.com/name&gt;
&quot;Bob&quot; .</tt></p>
-</blockquote></div>
+Example output:
+
+> `_:ef136d20-f1ee-3830-a54b-cd5e489d50fb <http://example.com/name> "Alice" .`
+>
+> `<http://example.com/bob> <http://example.com/name> "Bob" .` --></div>
 <div class="section">
 <h3><a name="IRI"></a>IRI</h3>
 <p>An <a href="apidocs/org/apache/commons/rdf/api/IRI.html">IRI</a> is
a representation of an <a class="externalLink" href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">Internationalized
Resource Identifier</a>, e.g. <tt>http://example.com/alice</tt> or <tt>http://ns.example.org/vocab#term</tt>.</p>
@@ -515,7 +518,7 @@ System.out.println(iri.equals(factory.cr
 <div class="source">
 <div class="source">
 <pre>System.out.println(bnode.equals(bnode));
-System.out.println(bnode.equals(factory.createBlankNode()))
+System.out.println(bnode.equals(factory.createBlankNode()));
 </pre></div></div>
 
 <blockquote>
@@ -542,7 +545,7 @@ System.out.println(bnode.equals(factory.
 
 <div class="source">
 <div class="source">
-<pre>System.out.println(b1.equals(factory.createBlankNode(&quot;b1&quot;)))
+<pre>System.out.println(b1.equals(factory.createBlankNode(&quot;b1&quot;)));
 System.out.println(b1.equals(new SimpleRDFTermFactory().createBlankNode(&quot;b1&quot;)));
 </pre></div></div>
 
@@ -557,7 +560,7 @@ System.out.println(b1.equals(new SimpleR
 
 <div class="source">
 <div class="source">
-<pre>System.out.println(bnode.internalIdentifier())
+<pre>System.out.println(bnode.internalIdentifier());
 </pre></div></div>
 
 <blockquote>
@@ -624,8 +627,8 @@ literal</a> data type.
 <div class="source">
 <div class="source">
 <pre>IRI xsdDouble = factory.createIRI(&quot;http://www.w3.org/2001/XMLSchema#double&quot;);
-Literal typedLiteral = factory.createLiteral(&quot;13.37&quot;, xsdDouble);
-System.out.println(typedLiteral.ntriplesString());
+Literal literalDouble = factory.createLiteral(&quot;13.37&quot;, xsdDouble);
+System.out.println(literalDouble.ntriplesString());
 </pre></div></div>
 
 <blockquote>
@@ -637,7 +640,7 @@ System.out.println(typedLiteral.ntriples
 
 <div class="source">
 <div class="source">
-<pre>Literal typedLiteral = factory.createLiteral(&quot;13.37&quot;, Types.XSD_DOUBLE);
+<pre>Literal literalDouble2 = factory.createLiteral(&quot;13.37&quot;, Types.XSD_DOUBLE);
 </pre></div></div>
 <p>As the constants in <tt>Types</tt> are all instances of <tt>IRI</tt>,
they can also be used for comparisons:</p>
 
@@ -802,8 +805,9 @@ if (obj instanceof Literal) {
 <div class="source">
 <div class="source">
 <pre>IRI bob = factory.createIRI(&quot;http://example.com/bob&quot;);
+IRI nameIri = factory.createIRI(&quot;http://example.com/name&quot;);
 Literal bobName = factory.createLiteral(&quot;Bob&quot;);
-graph.add(bob, iri, bobName);
+graph.add(bob, nameIRI, bobName);
 </pre></div></div>
 <p>It is not necessary to check if a triple already exist in the graph, as the underlying
implementation will ignore duplicate triples.</p></div>
 <div class="section">
@@ -822,7 +826,7 @@ graph.add(bob, iri, bobName);
 
 <div class="source">
 <div class="source">
-<pre>System.out.println(graph.contains(null, iri, bobName));
+<pre>System.out.println(graph.contains(null, nameIri, bobName));
 </pre></div></div>
 
 <blockquote>
@@ -909,7 +913,7 @@ System.out.println(graph.contains(triple
 
 <div class="source">
 <div class="source">
-<pre>graph.remove(null, iri, null);
+<pre>graph.remove(null, nameIri, null);
 </pre></div></div>
 <p>To remove all triples, use <a href="apidocs/org/apache/commons/rdf/api/Graph.html#clear--">clear</a>:</p>
 



Mime
View raw message