Author: buildbot
Date: Wed Feb 19 22:16:02 2020
New Revision: 1056737
Log:
Staging update by buildbot for jena
Modified:
websites/staging/jena/trunk/content/ (props changed)
websites/staging/jena/trunk/content/tutorials/rdf_api.html
websites/staging/jena/trunk/content/tutorials/rdf_api_pt.html
Propchange: websites/staging/jena/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed Feb 19 22:16:02 2020
@@ -1 +1 @@
-1874059
+1874229
Modified: websites/staging/jena/trunk/content/tutorials/rdf_api.html
==============================================================================
--- websites/staging/jena/trunk/content/tutorials/rdf_api.html (original)
+++ websites/staging/jena/trunk/content/tutorials/rdf_api.html Wed Feb 19
22:16:02 2020
@@ -266,8 +266,7 @@ interface.</p>
<p>The code to create this graph, or model, is simple:</p>
-<blockquote>
- <pre><code>// some definitions
+<pre>// some definitions
static String personURI = "http://somewhere/JohnSmith";
static String fullName = "John Smith";
@@ -278,8 +277,8 @@ Model model = ModelFactory.createDefault
Resource johnSmith = model.createResource(personURI);
// add the property
- johnSmith.addProperty(VCARD.FN, fullName);</code></pre>
-</blockquote>
+johnSmith.addProperty(VCARD.FN, fullName);
+</pre>
<p>It begins with some constant definitions and then creates an empty Model
or model, using the <code>ModelFactory</code> method
<code>createDefaultModel()</code>
@@ -303,12 +302,9 @@ yourself.</p>
<p>The code to create the resource and add the property, can be more
compactly written in a cascading style:</p>
-<blockquote>
- <pre><code>Resource johnSmith =
+<p><pre>Resource johnSmith =
model.createResource(personURI)
- .addProperty(VCARD.FN, fullName);</code></pre>
-</blockquote>
-
+ .addProperty(VCARD.FN, fullName);</pre></p>
<p>Now let's add some more detail to the vcard, exploring some more features
of RDF and Jena.</p>
@@ -329,17 +325,14 @@ It is known as an <i><a href="#glos-blan
<p>The Jena code to construct this example, is again very simple. First
some declarations and the creation of the empty model.</p>
-<blockquote>
- <pre><code>// some definitions
+<p><pre>// some definitions
String personURI = "http://somewhere/JohnSmith";
String givenName = "John";
String familyName = "Smith";
-String fullName = givenName + " " + familyName;
-
-// create an empty Model
-Model model = ModelFactory.createDefaultModel();
-
-// create the resource
+String fullName = givenName + " " + familyName;</p>
+<p>// create an empty Model
+Model model = ModelFactory.createDefaultModel();</p>
+<p>// create the resource
// and add the properties cascading style
Resource johnSmith
= model.createResource(personURI)
@@ -347,9 +340,7 @@ Resource johnSmith
.addProperty(VCARD.N,
model.createResource()
.addProperty(VCARD.Given, givenName)
- .addProperty(VCARD.Family,
familyName));</code></pre>
-</blockquote>
-
+ .addProperty(VCARD.Family, familyName));</pre></p>
<p>The working code for this example can be found as <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial02.java">tutorial
2</a> in the /src-examples directory
of the Jena distribution.</p>
@@ -388,8 +379,7 @@ methods to the subject, predicate and ob
statements created and print them out. The complete code for this can be
found in <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial03.java">tutorial
3</a>.</p>
-<blockquote>
-<pre><code>// list the statements in the Model
+<pre>// list the statements in the Model
StmtIterator iter = model.listStatements();
// print out the predicate, subject and object of each statement
@@ -409,8 +399,7 @@ while (iter.hasNext()) {
}
System.out.println(" .");
-} </code></pre>
-</blockquote>
+} </pre>
<p>Since the object of a statement can be either a resource or a literal, the
<code>getObject()</code> method returns an
@@ -423,10 +412,10 @@ processes it accordingly.</p>
<p>When run, this program should produce output resembling:</p>
-<pre><code>http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N
413f6415-c3b0-4259-b74d-4bd6e757eb60 .
+<pre>http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N
413f6415-c3b0-4259-b74d-4bd6e757eb60 .
413f6415-c3b0-4259-b74d-4bd6e757eb60
http://www.w3.org/2001/vcard-rdf/3.0#Family "Smith" .
413f6415-c3b0-4259-b74d-4bd6e757eb60
http://www.w3.org/2001/vcard-rdf/3.0#Given "John" .
-http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN "John
Smith" .</code></pre>
+http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN "John
Smith" .</pre>
<p></p>
@@ -454,15 +443,11 @@ model in RDF XML form to the standard ou
very simple: <code>model.write</code> can take an <code>OutputStream</code>
argument.</p>
-<blockquote>
- <pre><code>// now write the model in XML form to a file
-model.write(System.out);</code></pre>
-</blockquote>
-
+<p><pre>// now write the model in XML form to a file
+model.write(System.out);</pre></p>
<p>The output should look something like this:</p>
-<blockquote>
- <pre><code><rdf:RDF
+<p><pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
@@ -474,9 +459,7 @@ model.write(System.out);</code></pre>
<vcard:Given>John</vcard:Given>
<vcard:Family>Smith</vcard:Family>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
-
+</rdf:RDF></pre></p>
<p></p>
<p>The RDF specifications specify how to represent RDF as XML. The RDF
@@ -518,12 +501,9 @@ invoked the standard 'dumb' writer. Jen
RDF/XML writer which can be invoked by specifying another argument to the
<code>write()</code> method call:</p>
-<blockquote>
- <pre><code>// now write the model in XML form to a file
+<p><pre>// now write the model in XML form to a file
model.write(System.out, "RDF/XML-ABBREV");
- </code></pre>
-</blockquote>
-
+ </pre></p>
<p>This writer, the so called PrettyWriter, takes advantage of features of
the RDF/XML abbreviated syntax to write a Model more compactly. It is also
able to preserve blank nodes where that is possible. It is however, not
@@ -531,12 +511,9 @@ suitable for writing very large Models,
acceptable. To write large files and preserve blank nodes, write in
N-Triples format:</p>
-<blockquote>
- <pre><code>// now write the model in N-TRIPLES form to a file
+<p><pre>// now write the model in N-TRIPLES form to a file
model.write(System.out, "N-TRIPLES");
- </code></pre>
-</blockquote>
-
+ </pre></p>
<p>This will produce output similar to that of tutorial 3 which conforms to
the N-Triples specification.</p>
@@ -548,34 +525,27 @@ we have provided <a href="sparql_data/vc
code will read it in and write it out. <em>Note that for this application to
run, the input file must be in the current directory.</em></p>
-<blockquote>
- <pre><code>
+<p><pre>
// create an empty model
- Model model = ModelFactory.createDefaultModel();
-
- // use the FileManager to find the input file
+ Model model = ModelFactory.createDefaultModel();</p>
+<p>// use the FileManager to find the input file
InputStream in = FileManager.get().open( inputFileName );
if (in == null) {
throw new IllegalArgumentException(
"File: " + inputFileName + " not found");
-}
-
-// read the RDF/XML file
-model.read(in, null);
-
-// write it to standard out
+}</p>
+<p>// read the RDF/XML file
+model.read(in, null);</p>
+<p>// write it to standard out
model.write(System.out);
- </code></pre>
-</blockquote>
-
+ </pre></p>
<p>The second argument to the <code>read()</code> method call is the URI which
will
be used for resolving relative URI's. As there are no relative URI
references in the test file, it is allowed to be empty. When run, <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial05.java">
tutorial 5</a> will produce XML output which
looks like:</p>
-<blockquote>
- <pre><code><rdf:RDF
+<p><pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
@@ -611,9 +581,7 @@ looks like:</p>
<vcard:FN>Becky Smith</vcard:FN>
<vcard:N rdf:nodeID="A3"/>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
-
+</rdf:RDF></pre></p>
<h2 id="ch-Prefixes">Controlling Prefixes</h2>
<h3>Explicit prefix definitions</h3>
@@ -623,7 +591,6 @@ prefix <code>vcard</code> and used that
uses only the full URIs, and not this shortened form, Jena provides ways
of controlling the namespaces used on output with its <i>prefix mappings</i>.
Here's a simple example.</p>
-<blockquote>
<pre>
<code>
Model m = ModelFactory.createDefaultModel();
@@ -646,12 +613,10 @@ Here's a simple example.</p>
m.write( System.out );
</code>
</pre>
-</blockquote>
<p>The output from this fragment is three lots of RDF/XML, with
three different prefix mappings. First the default, with no
prefixes other than the standard ones:</p>
-<blockquote>
<pre>
<code>
# -- no special prefixes defined
@@ -670,7 +635,6 @@ prefixes other than the standard ones:</
</rdf:RDF>
</code>
</pre>
-</blockquote>
<p>We see that the rdf namespace is declared automatically, since it
is required for tags such as <code><rdf:RDF></code> and
@@ -686,7 +650,8 @@ non-name character. The RDF/XML writer w
declarations into XML namespace declarations and use them in its
output:
-<blockquote>
+
+
<pre>
<code>
# -- nsA defined
@@ -705,13 +670,13 @@ output:
</rdf:RDF>
</code>
</pre>
-</blockquote>
+
The other namespace still gets the constructed name, but the nsA name
is now used in the property tags. There's no need for the prefix name
to have anything to do with the variables in the Jena code:
-<blockquote>
+
<pre>
<code>
# -- nsA and cat defined
@@ -730,7 +695,7 @@ to have anything to do with the variable
</rdf:RDF>
</code>
</pre>
-</blockquote>
+
Both prefixes are used for output, and no generated prefixes are needed.
@@ -744,7 +709,7 @@ Jena will remember the prefixes that wer
some file, with URL <b>file:/tmp/fragment.rdf</b> say. Then run the
code:
-<blockquote>
+
<pre>
<code>
Model m2 = ModelFactory.createDefaultModel();
@@ -752,7 +717,7 @@ m2.read( "file:/tmp/fragment.rdf" );
m2.write( System.out );
</code>
</pre>
-</blockquote>
+
You'll see that the prefixes from the input are preserved in the output.
All the prefixes are written, even if they're not used anywhere. You can
@@ -811,11 +776,11 @@ method is defined to return a Resource o
otherwise to create a new one. For example, to retrieve the John Smith
resource from the model read in from the file in tutorial 5:</p>
-<blockquote>
- <pre><code>// retrieve the John Smith vcard resource from the model
+
+ <pre>// retrieve the John Smith vcard resource from the model
Resource vcard = model.getResource(johnSmithURI);</code>
</pre>
-</blockquote>
+
<p>The Resource interface defines a number of methods for accessing the
properties of a resource. The <code>Resource.getProperty(Property
@@ -827,11 +792,11 @@ access the value of the property using o
return the object of the statement. For example to retrieve the
resource which is the value of the <code>vcard:N</code> property:</p>
-<blockquote>
- <pre><code>// retrieve the value of the N property
+
+ <pre>// retrieve the value of the N property
Resource name = (Resource) vcard.getProperty(VCARD.N)
- .getObject();</code></pre>
-</blockquote>
+ .getObject();</pre>
+
<p>In general, the object of a statement could be a resource or a literal, so
the application code, knowing the value must be a resource, casts the
@@ -840,30 +805,30 @@ type specific methods so the application
checking can be done at compile time. The code fragment above, can be
more conveniently written:</p>
-<blockquote>
- <pre><code>// retrieve the value of the N property
+
+ <pre>// retrieve the value of the N property
Resource name = vcard.getProperty(VCARD.N)
- .getResource();</code></pre>
-</blockquote>
+ .getResource();</pre>
+
<p>Similarly, the literal value of a property can be retrieved:</p>
-<blockquote>
- <pre><code>// retrieve the given name property
+
+ <pre>// retrieve the given name property
String fullName = vcard.getProperty(VCARD.FN)
- .getString();</code></pre>
-</blockquote>
+ .getString();</pre>
+
<p>In this example, the vcard resource has only one <code>vcard:FN</code> and
one <code>vcard:N</code> property. RDF permits a resource to repeat a
property; for example Adam might have more than one nickname. Let's give him
two:</p>
-<blockquote>
- <pre><code>// add two nickname properties to vcard
+
+ <pre>// add two nickname properties to vcard
vcard.addProperty(VCARD.NICKNAME, "Smithy")
- .addProperty(VCARD.NICKNAME, "Adman");</code></pre>
-</blockquote>
+ .addProperty(VCARD.NICKNAME, "Adman");</pre>
+
<p>As noted before, Jena represents an RDF Model as <em>set </em>of
statements, so adding a statement with the subject, predicate and object as
@@ -879,8 +844,8 @@ which will list them all. This method r
objects of type <code>Statement</code>. We can list the nicknames like
this:</p>
-<blockquote>
- <pre><code>// set up the output
+
+ <pre>// set up the output
System.out.println("The nicknames of \""
+ fullName + "\" are:");
// list the nicknames
@@ -889,8 +854,8 @@ while (iter.hasNext()) {
System.out.println(" " + iter.nextStatement()
.getObject()
.toString());
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>This code can be found in <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial06.java">
tutorial 6</a>.
The statement iterator <code>iter</code> produces each and every statement
@@ -900,11 +865,11 @@ so looping over it allows us to fetch ea
a string.
The code produces the following output when run:</p>
-<blockquote>
- <pre><code>The nicknames of "John Smith" are:
+
+ <pre>The nicknames of "John Smith" are:
Smithy
- Adman</code></pre>
-</blockquote>
+ Adman</pre>
+
<p>All the properties of a resource can be listed by using the
<code>listProperties()</code> method without an argument.
@@ -932,14 +897,14 @@ only vcard resources
will have <code>vcard:FN</code> property, and that in our data, all such
resources have such a property, then we can find all the vcards like this:</p>
-<blockquote>
- <pre><code>// list vcards
+
+ <pre>// list vcards
ResIterator iter = model.listSubjectsWithProperty(VCARD.FN);
while (iter.hasNext()) {
Resource r = iter.nextResource();
...
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>All these query methods are simply syntactic sugar over a primitive query
method <code>model.listStatements(Selector s)</code>. This method returns an
@@ -951,10 +916,10 @@ package <code>org.apache.jena.rdf.model<
necessary to use a specific class rather than an interface. The
<code>SimpleSelector</code> constructor takes three arguments:</p>
-<blockquote>
- <pre><code>Selector selector = new SimpleSelector(subject, predicate, object)
- </code></pre>
-</blockquote>
+
+ <pre>Selector selector = new SimpleSelector(subject, predicate, object)
+ </pre>
+
<p>This selector will select all statements with a subject that matches
<code>subject</code>, a predicate that matches <code>predicate</code> and an
@@ -964,28 +929,28 @@ equal resources or literals. (Two resour
or are the same blank node; two literals are the same if all their components
are equal.) Thus:</p>
-<blockquote>
- <pre><code>Selector selector = new SimpleSelector(null, null, null);
- </code></pre>
-</blockquote>
+
+ <pre>Selector selector = new SimpleSelector(null, null, null);
+ </pre>
+
<p>will select all the statements in a Model.</p>
-<blockquote>
- <pre><code>Selector selector = new SimpleSelector(null, VCARD.FN, null);
- </code></pre>
-</blockquote>
+
+ <pre>Selector selector = new SimpleSelector(null, VCARD.FN, null);
+ </pre>
+
<p>will select all the statements with VCARD.FN as their predicate, whatever
the subject or object. As a special shorthand,
-<blockquote><code>listStatements( S, P, O )
-</code></blockquote>
+<code>listStatements( S, P, O )
+</code>
is equivalent to
-<blockquote><code>listStatements( new SimpleSelector( S, P, O ) )
-</code></blockquote>
+<code>listStatements( new SimpleSelector( S, P, O ) )
+</code>
@@ -995,8 +960,8 @@ The following code, which can be found i
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial07.java">tutorial
7</a> lists the full names on all the
vcards in the database.</p>
-<blockquote>
- <pre><code>// select all the resources with a VCARD.FN property
+
+ <pre>// select all the resources with a VCARD.FN property
ResIterator iter = model.listSubjectsWithProperty(VCARD.FN);
if (iter.hasNext()) {
System.out.println("The database contains vcards for:");
@@ -1008,19 +973,19 @@ if (iter.hasNext()) {
} else {
System.out.println("No vcards were found in the database");
}
- </code></pre>
-</blockquote>
+ </pre>
+
<p>This should produce output similar to the following:</p>
-<blockquote>
- <pre><code>The database contains vcards for:
+
+ <pre>The database contains vcards for:
Sarah Jones
John Smith
Matt Jones
Becky Smith
- </code></pre>
-</blockquote>
+ </pre>
+
<p>Your next exercise is to modify this code to use <code>SimpleSelector
</code>instead of <code>listSubjectsWithProperty</code>.</p>
@@ -1029,15 +994,15 @@ if (iter.hasNext()) {
<code>SimpleSelector</code> can be subclassed and its selects method modified
to perform further filtering:</p>
-<blockquote>
- <pre><code>// select all the resources with a VCARD.FN property
+
+ <pre>// select all the resources with a VCARD.FN property
// whose value ends with "Smith"
StmtIterator iter = model.listStatements(
new SimpleSelector(null, VCARD.FN, (RDFNode) null) {
public boolean selects(Statement s)
{return s.getString().endsWith("Smith");}
- });</code></pre>
-</blockquote>
+ });</pre>
+
<p>This sample code uses a neat Java technique of overriding a method
definition inline when creating an instance of the class. Here the
@@ -1050,18 +1015,18 @@ applied to matching statements.</p>
<p>The full code can be found in <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial08.java">tutorial
8</a> and produces output like this:</p>
-<blockquote>
- <pre><code>The database contains vcards for:
+
+ <pre>The database contains vcards for:
John Smith
- Becky Smith</code></pre>
-</blockquote>
+ Becky Smith</pre>
+
<p></p>
<p>You might think that:</p>
-<blockquote>
- <pre><code>// do all filtering in the selects method
+
+ <pre>// do all filtering in the selects method
StmtIterator iter = model.listStatements(
new
SimpleSelector(null, null, (RDFNode) null) {
@@ -1071,15 +1036,15 @@ StmtIterator iter = model.listStatements
&& (object == null ||
s.getObject().equals(object)) ;
}
}
- });</code></pre>
-</blockquote>
+ });</pre>
+
<p>is equivalent to:</p>
-<blockquote>
- <pre><code>StmtIterator iter =
- model.listStatements(new SimpleSelector(subject, predicate,
object)</code></pre>
-</blockquote>
+
+ <pre>StmtIterator iter =
+ model.listStatements(new SimpleSelector(subject, predicate, object)</pre>
+
<p>Whilst functionally they may be equivalent, the first form will list all
the statements in the Model and test each one individually, whilst the second
@@ -1109,8 +1074,8 @@ one and the duplicate <code>vcard:FN</co
<p>Lets look at the code to do this (the full code is in <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial09.java">tutorial
9</a>) and see what happens.</p>
-<blockquote>
- <pre><code>// read the RDF/XML files
+
+ <pre>// read the RDF/XML files
model1.read(new InputStreamReader(in1), "");
model2.read(new InputStreamReader(in2), "");
@@ -1118,12 +1083,12 @@ model2.read(new InputStreamReader(in2),
Model model = model1.union(model2);
// print the Model as RDF/XML
-model.write(system.out, "RDF/XML-ABBREV");</code></pre>
-</blockquote>
+model.write(system.out, "RDF/XML-ABBREV");</pre>
+
<p>The output produced by the pretty writer looks like this:</p>
-<blockquote>
+
<pre><rdf:RDF
xmlns:rdf="<a
href="http://www.w3.org/1999/02/22-rdf-syntax-ns#">http://www.w3.org/1999/02/22-rdf-syntax-ns#</a>"
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
@@ -1140,8 +1105,8 @@ model.write(system.out, "RDF/XML-ABBREV"
<vcard:FN>John Smith</vcard:FN>
</rdf:Description>
</rdf:RDF></pre>
- <pre><code> </code></pre>
-</blockquote>
+ <pre> </pre>
+
<p>Even if you are unfamiliar with the details of the RDF/XML syntax, it
should be reasonably clear that the Models have merged as expected. The
@@ -1202,8 +1167,8 @@ container using the lower level methods.
<p align="left">Let's modify tutorial 8 to create this bag:</p>
-<blockquote>
- <pre><code>// create a bag
+
+ <pre>// create a bag
Bag smiths = model.createBag();
// select all the resources with a VCARD.FN property
@@ -1217,13 +1182,13 @@ StmtIterator iter = model.listStatements
// add the Smith's to the bag
while (iter.hasNext()) {
smiths.add(iter.nextStatement().getSubject());
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>If we write out this Model, it contains something like the following:</p>
-<blockquote>
- <pre><code><rdf:RDF
+
+ <pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
@@ -1233,16 +1198,16 @@ while (iter.hasNext()) {
<rdf:_1 rdf:resource='http://somewhere/JohnSmith/'/>
<rdf:_2 rdf:resource='http://somewhere/RebeccaSmith/'/>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
+</rdf:RDF></pre>
+
<p>which represents the Bag resource.</p>
<p>The container interface provides an iterator to list the contents of a
container:</p>
-<blockquote>
- <pre><code>// print out the members of the bag
+
+ <pre>// print out the members of the bag
NodeIterator iter2 = smiths.iterator();
if (iter2.hasNext()) {
System.out.println("The bag contains:");
@@ -1254,16 +1219,16 @@ if (iter2.hasNext()) {
}
} else {
System.out.println("The bag is empty");
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>which produces the following output:</p>
-<blockquote>
- <pre><code>The bag contains:
+
+ <pre>The bag contains:
John Smith
- Becky Smith</code></pre>
-</blockquote>
+ Becky Smith</pre>
+
<p>Executable example code can be found in <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial10.java">
tutorial 10</a>, which glues together the fragments above into a complete
@@ -1294,8 +1259,8 @@ parseType='Literal' attribute is used to
<p>In Jena, these attributes of a literal may be set when the literal is
constructed, e.g. in <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial11.java">tutorial
11</a>:</p>
-<blockquote>
- <pre><code>// create the resource
+
+ <pre>// create the resource
Resource r = model.createResource();
// add the property
@@ -1304,13 +1269,13 @@ r.addProperty(RDFS.label, model.createLi
.addProperty(RDFS.label, model.createLiteral("<em>chat</em>",
true));
// write out the Model
-model.write(system.out);</code></pre>
-</blockquote>
+model.write(system.out);</pre>
+
<p>produces</p>
-<blockquote>
- <pre><code><rdf:RDF
+
+ <pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'
>
@@ -1319,8 +1284,8 @@ model.write(system.out);</code></pre>
<rdfs:label xml:lang='fr'>chat</rdfs:label>
<rdfs:label
rdf:parseType='Literal'><em>chat</em></rdfs:label>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
+</rdf:RDF></pre>
+
<p>For two literals to be considered equal, they must either both be XML
literals or both be simple literals. In addition, either both must have no
@@ -1337,8 +1302,8 @@ are stored in the Model. For example, tr
simple literals, we can omit the <code>model.createLiteral</code>(...)
call):</p>
-<blockquote>
- <pre><code>// create the resource
+
+ <pre>// create the resource
Resource r = model.createResource();
// add the property
@@ -1346,14 +1311,14 @@ r.addProperty(RDFS.label, "11")
.addProperty(RDFS.label, 11);
// write out the Model
-model.write(system.out, "N-TRIPLE");</code></pre>
-</blockquote>
+model.write(system.out, "N-TRIPLE");</pre>
+
<p>The output produced is:</p>
-<blockquote>
- <pre><code>_:A... <http://www.w3.org/2000/01/rdf-schema#label> "11"
.</code></pre>
-</blockquote>
+
+ <pre>_:A... <http://www.w3.org/2000/01/rdf-schema#label> "11" .</pre>
+
<p>Since both literals are really just the string "11", then only one
statement is added.</p>
Modified: websites/staging/jena/trunk/content/tutorials/rdf_api_pt.html
==============================================================================
--- websites/staging/jena/trunk/content/tutorials/rdf_api_pt.html (original)
+++ websites/staging/jena/trunk/content/tutorials/rdf_api_pt.html Wed Feb 19
22:16:02 2020
@@ -227,21 +227,15 @@ Literais são exibidas em retângulo
<p>O código para criar este grafo, ou modelo, é simples:</p>
-<blockquote>
- <pre><code>// some definitions
+<p><pre>// some definitions
static String personURI = "http://somewhere/JohnSmith";
-static String fullName = "John Smith";
-
-// create an empty Model
-Model model = ModelFactory.createDefaultModel();
-
-// create the resource
-Resource johnSmith = model.createResource(personURI);
-
-// add the property
- johnSmith.addProperty(VCARD.FN, fullName);</code></pre>
-</blockquote>
-
+static String fullName = "John Smith";</p>
+<p>// create an empty Model
+Model model = ModelFactory.createDefaultModel();</p>
+<p>// create the resource
+Resource johnSmith = model.createResource(personURI);</p>
+<p>// add the property
+ johnSmith.addProperty(VCARD.FN, fullName);</pre></p>
<p>Ele começa com algumas definições de constantes e então cria um Model
vazio, usando o método <code>createDefaultModel()</code> de
<code>ModelFactory</code>
para criar um modelo na memória. Jena possui outras implementações da
interface Model, e.g. uma que usa banco de dados relacionais: esses tipos de
modelo são também disponibilizados a partir de ModelFactory.</p>
@@ -249,12 +243,9 @@ para criar um modelo na memória. Jena
<p>O código para criar o recurso e adicionar a propriedade pode ser escrito
de forma mais compacta usando um estilo cascata:</p>
-<blockquote>
- <pre><code>Resource johnSmith =
+<p><pre>Resource johnSmith =
model.createResource(personURI)
- .addProperty(VCARD.FN, fullName);</code></pre>
-</blockquote>
-
+ .addProperty(VCARD.FN, fullName);</pre></p>
<p>Os códigos desse exemplo podem ser encontrados no diretório /src-examples
no pacote de distribuição do Jena como <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial01.java">tutorial
1</a>. Como exercÃcio, pegue este código e modifique-o para criar um
próprio VCARD para você.</p>
<p>Agora vamos adicionar mais detalhes ao vcard, explorando mais recursos de
RDF e Jena.</p>
@@ -268,17 +259,14 @@ para criar um modelo na memória. Jena
<p>O código Jena para construir este exemplo é, novamente, muito simples.
Primeiro algumas declarações e a criação do modelo vazio.</p>
-<blockquote>
- <pre><code>// some definitions
+<p><pre>// some definitions
String personURI = "http://somewhere/JohnSmith";
String givenName = "John";
String familyName = "Smith";
-String fullName = givenName + " " + familyName;
-
-// create an empty Model
-Model model = ModelFactory.createDefaultModel();
-
-// create the resource
+String fullName = givenName + " " + familyName;</p>
+<p>// create an empty Model
+Model model = ModelFactory.createDefaultModel();</p>
+<p>// create the resource
// and add the properties cascading style
Resource johnSmith
= model.createResource(personURI)
@@ -286,9 +274,7 @@ Resource johnSmith
.addProperty(VCARD.N,
model.createResource()
.addProperty(VCARD.Given, givenName)
- .addProperty(VCARD.Family,
familyName));</code></pre>
-</blockquote>
-
+ .addProperty(VCARD.Family, familyName));</pre></p>
<p>Os códigos desse exemplo podem ser encontrados no diretório /src-examples
no pacote de distribuição do Jena como <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial02.java">tutorial
2</a>.</p>
<h2><a id="ch-Statements">Sentenças</a></h2>
@@ -313,8 +299,7 @@ que retorna a próxima sentença do
<p>Agora vamos usar essa interface para estender tutorial2 para listar todas
as sentenças criadas e imprimi-las. O código completo deste exemplo pode ser
encontrado em <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial03.java">tutorial
3</a>.</p>
-<blockquote>
-<pre><code>// list the statements in the Model
+<pre>// list the statements in the Model
StmtIterator iter = model.listStatements();
// print out the predicate, subject and object of each statement
@@ -334,18 +319,17 @@ while (iter.hasNext()) {
}
System.out.println(" .");
-} </code></pre>
-</blockquote>
+} </pre>
<p>Já que o objeto de uma sentença pode ser tanto um recurso quanto uma
literal, o método
<code>getObject()</code> retorna um objeto do tipo <code>RDFNode</code>, que
é uma superclasse comum de ambos <code>Resource</code> e <code>Literal</code>.
O objeto em si é do tipo apropriado, então o código usa
<code>instanceof</code> para determinar qual e processá-lo de acordo.</p>
<p>Quando executado, o programa deve produzir a saÃda:</p>
-<pre><code>http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N
anon:14df86:ecc3dee17b:-7fff .
+<pre>http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N
anon:14df86:ecc3dee17b:-7fff .
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Family
"Smith" .
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Given
"John" .
-http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN "John
Smith" .</code></pre>
+http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN "John
Smith" .</pre>
<p></p>
@@ -361,15 +345,11 @@ Group</a> definiu uma notação simi
<p>O Tutorial 3 criou um modelo e o escreveu no formato de triplas. <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial04.java">Tutorial
4</a> modifica o tutorial 3 para escrever o modelo na forma de RDF XML numa
stream de saÃda. O código, novamente, é muito simples:
<code>model.write</code> pode receber um <code>OutputStream</code> como
argumento.</p>
-<blockquote>
- <pre><code>// now write the model in XML form to a file
-model.write(System.out);</code></pre>
-</blockquote>
-
+<p><pre>// now write the model in XML form to a file
+model.write(System.out);</pre></p>
<p>A saÃda deve parecer com isso:</p>
-<blockquote>
- <pre><code><rdf:RDF
+<p><pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
@@ -381,9 +361,7 @@ model.write(System.out);</code></pre>
<vcard:Given>John</vcard:Given>
<vcard:Family>Smith</vcard:Family>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
-
+</rdf:RDF></pre></p>
<p></p>
<p>As especificações de RDF especificam como representar RDF como XML. A
sintaxe de RDF XML é bastante complexa. Recomendamos ao leitor dar uma olhada
no <a href="http://www.w3.org/TR/rdf-primer/">primer</a> sendo desenvolvido
pelo RDFCore WG para uma introdução mais detalhada. Entretanto, vamos dar uma
olhada rápida em como interpretar a saÃda acima.</p>
@@ -399,50 +377,37 @@ model.write(System.out);</code></pre>
<p>Jena possui uma interface extensÃvel que permite novos escritores para
diferentes linguagens de serialização RDF. Jena possuem também um escritor
RDF/XML mais sofisticado que pode ser invocado ao especificar outro argumento Ã
chamada de método
<code>write()</code>:</p>
-<blockquote>
- <pre><code>// now write the model in XML form to a file
+<p><pre>// now write the model in XML form to a file
model.write(System.out, "RDF/XML-ABBREV");
- </code></pre>
-</blockquote>
-
+ </pre></p>
<p>Este escritor, chamado também de PrettyWriter, ganha vantagem ao usar as
particularidades da sintaxe abreviada de RDF/XML ao criar um modelo mais
compacto. Ele também é capaz de preservar os blank nodes onde é possÃvel.
Entretanto, não é recomendável para escrever modelos muito grandes, já que
sua desempenho deixa a desejar. Para escrever grandes arquivos e preservar os
blank nodes, escreva no formato de N-Triplas:</p>
-<blockquote>
- <pre><code>// now write the model in XML form to a file
+<p><pre>// now write the model in XML form to a file
model.write(System.out, "N-TRIPLE");
- </code></pre>
-</blockquote>
-
+ </pre></p>
<p>Isso produzirá uma saÃda similar à do tutorial 3, que está em
conformidade com a especificação de N-Triplas.</p>
<h2><a id="ch-Reading RDF">Leitura de RDF</a></h2>
<p><a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial05.java">Tutorial
5</a> demonstra a leitura num modelo de sentenças gravadas num RDF XML. Com
este tutorial, nós teremos criado uma pequena base de dados de vcards na forma
RDF/XML. O código a seguir fará leitura e escrita. <em>Note que para esta
aplicação rodar, o arquivo de entrada precisa estar no diretório da
aplicação.</em></p>
-<blockquote>
- <pre><code>
+<p><pre>
// create an empty model
- Model model = ModelFactory.createDefaultModel();
-
- // use the FileManager to find the input file
+ Model model = ModelFactory.createDefaultModel();</p>
+<p>// use the FileManager to find the input file
InputStream in = FileManager.get().open( inputFileName );
if (in == null) {
throw new IllegalArgumentException(
"File: " + inputFileName + " not found");
-}
-
-// read the RDF/XML file
-model.read(in, null);
-
-// write it to standard out
+}</p>
+<p>// read the RDF/XML file
+model.read(in, null);</p>
+<p>// write it to standard out
model.write(System.out);
- </code></pre>
-</blockquote>
-
+ </pre></p>
<p>O segundo argumento da chamada de método <code>read()</code> é a URI que
será usada para resolver URIs relativas. Como não há referências URI
relativas no arquivo de teste, ele pode ser vazio. Quando executado, <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial05.java">
tutorial 5</a> produzirá uma saÃda XML como esta:</p>
-<blockquote>
- <pre><code><rdf:RDF
+<p><pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
@@ -478,16 +443,13 @@ model.write(System.out);
<vcard:FN>Becky Smith</vcard:FN>
<vcard:N rdf:nodeID="A3"/>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
-
+</rdf:RDF></pre></p>
<h2 id="ch-Prefixes">Controlando prefixos</h2>
<h3>Definições explÃcitas de prefixos</h3>
<p>Na sessão anterior, nós vimos que a saÃda XML declarou um prefixo
namespace<br />
<code>vcard</code> e o usou para abreviar URIs. Enquanto que RDF usa somente
URIs completas, e não sua forma encurtada, Jena provê formas de controlar
namespaces usados na saÃda com seu mapeamento de prefixos. Aqui vai um exemplo
simples.</p>
-<blockquote>
<pre>
<code>
Model m = ModelFactory.createDefaultModel();
@@ -510,10 +472,8 @@ model.write(System.out);
m.write( System.out );
</code>
</pre>
-</blockquote>
<p>A saÃda deste fragmento são três blocos de RDF/XML, com três diferentes
mapeamentos de prefixos. Primeiro o padrão, sem prefixos diferentes dos
padrões:</p>
-<blockquote>
<pre>
<code>
# -- no special prefixes defined
@@ -532,13 +492,13 @@ model.write(System.out);
</rdf:RDF>
</code>
</pre>
-</blockquote>
<p>Nós vimos que o namespace rdf é declarado automaticamente, já que são
requeridos para tags como <code><RDF:rdf></code> e
<code><rdf:resource></code>. Declarações de namespace são também
necessárias para o uso das duas propriedades P e Q, mas já que seus
namespaces não foram introduzidos no modelo, eles recebem nomes namespaces
inventados <code>j.0</code> e <code>j.1</code>.</p>
<p>O método <code>setNsPrefix(String prefix, String URI)</code>
declara que o namespace da <code>URI</code> deve ser abreviado por
<code>prefixos</code>. Jena requer que o <code>prefixo</code> seja um namespace
XML correto, e que o <code>URI</code> termine com um caractere sem-nome. O
escritor RDF/XML transformará essas declarações de prefixos em declarações
de namespaces XML e as usará nas suas saÃdas:
-<blockquote>
+
+
<pre>
<code>
# -- nsA defined
@@ -557,11 +517,11 @@ declara que o namespace da <code>URI</co
</rdf:RDF>
</code>
</pre>
-</blockquote>
+
O outro namespace ainda recebe o nome criado automaticamente, mas o nome nsA
é agora usado nas tags de propriedades. Não há necessidade de que o nome do
prefixo tenha alguma relação com as variáveis do código Jena:
-<blockquote>
+
<pre>
<code>
# -- nsA and cat defined
@@ -580,7 +540,7 @@ O outro namespace ainda recebe o nome cr
</rdf:RDF>
</code>
</pre>
-</blockquote>
+
Ambos os prefixos são usados na saÃda, e não houve a necessidade de
prefixos gerados automaticamente.
@@ -590,7 +550,7 @@ Assim como as declarações de prefi
<p>Pegue a saÃda produzida pelo fragmento anterior e cole-o dentro de algum
arquivo, com a URL <b>file:/tmp/fragment.rdf</b> say. E execute o código:
-<blockquote>
+
<pre>
<code>
Model m2 = ModelFactory.createDefaultModel();
@@ -598,7 +558,7 @@ m2.read( "file:/tmp/fragment.rdf" );
m2.write( System.out );
</code>
</pre>
-</blockquote>
+
Você verá que os prefixos da entrada são preservados na saÃda. Todos os
prefixos são escritos, mesmo se eles não forem usados em lugar algum. Você
pode remover um prefixo com <code>removeNsPrefix(String prefix)</code> se você
não o quiser na saÃda.
@@ -624,50 +584,50 @@ Você verá que os prefixos da entra
<p> Dada a URI de um recurso, o objeto do recurso pode ser recuperado de um
modelo usando o método <code>Model.getResource(String uri)</code>. Este
método é definido para retornar um objeto Resource se ele existir no modelo,
ou, caso contrário, criar um novo. Por exemplo, para recuperar o recurso Adam
Smith do modelo lido a partir do arquivo no tutorial 5:</p>
-<blockquote>
- <pre><code>// retrieve the John Smith vcard resource from the model
+
+ <pre>// retrieve the John Smith vcard resource from the model
Resource vcard = model.getResource(johnSmithURI);</code>
</pre>
-</blockquote>
+
<p>A interface Resource define numerosos métodos para acessar as propriedades
de um recurso. O método <code>Resource.getProperty(Property p)</code> acessa
uma propriedade do recurso. Este método não segue a convenção usual de Java
de acesso já que o tipo do objeto retorna é <code>Statement,</code> e não
<code>Property</code> como era de se esperar. Retornando toda a sentença
permite à aplicação acessar o valor da propriedade usando um de seus
métodos de acesso que retornam o objeto da sentença. Por exemplo, para
recuperar o recurso que é o valor da propriedade <code>vcard:N</code></p>
-<blockquote>
- <pre><code>// retrieve the value of the N property
+
+ <pre>// retrieve the value of the N property
Resource name = (Resource) vcard.getProperty(VCARD.N)
- .getObject();</code></pre>
-</blockquote>
+ .getObject();</pre>
+
<p>De modo geral, o objeto de uma sentença pode ser um recurso ou uma
literal, então a aplicação, sabendo que o valor precisar ser um recurso, faz
o cast do objeto retornado. Uma das coisas que Jena tenta fazer é fornecer
tipos especÃficos de métodos, então a aplicação não tem que fazer cast, e
checagem de tipos pode ser feita em tempo de compilação. O fragmento de
código acima poderia ser mais convenientemente escrito assim:</p>
-<blockquote>
- <pre><code>// retrieve the value of the FN property
+
+ <pre>// retrieve the value of the FN property
Resource name = vcard.getProperty(VCARD.N)
- .getResource();</code></pre>
-</blockquote>
+ .getResource();</pre>
+
<p>Similarmente, o valor literal de uma propriedade pode ser recuperado:</p>
-<blockquote>
- <pre><code>// retrieve the given name property
+
+ <pre>// retrieve the given name property
String fullName = vcard.getProperty(VCARD.FN)
- .getString();</code></pre>
-</blockquote>
+ .getString();</pre>
+
<p>Neste exemplo, o recurso vcard possui somente as propriedades
<code>vcard:FN</code> e <code>vcard:N</code>. RDF permite a um recurso repetir
uma propriedade; por exemplo, Adam pode ter mais de um apelido. Vamos dar dois
apelidos a ele:</p>
-<blockquote>
- <pre><code>// add two nickname properties to vcard
+
+ <pre>// add two nickname properties to vcard
vcard.addProperty(VCARD.NICKNAME, "Smithy")
- .addProperty(VCARD.NICKNAME, "Adman");</code></pre>
-</blockquote>
+ .addProperty(VCARD.NICKNAME, "Adman");</pre>
+
<p>Como notado anteriormente, Jena representa um modelo RDF como um conjunto
de sentenças, então, adicionar uma sentença com um sujeito, predicado e
objeto igual a um já existente não terá efeito. Jena não define qual do
dois apelidos será retornado. O resultado da chamada a
<code>vcard.getProperty(VCARD.NICKNAME)</code> é indeterminado. Jena vai
retornar um dos valores, mas não há garantia nem mesmo de que duas chamadas
consecutivas irá retornar o mesmo valor.</p>
<p>Se for possÃvel que uma propriedade ocorra mais de uma vez, então o
método Resource.listProperties(Property p) pode ser usado para retornar um
iterador para lista-las. Este método retorna um iterador que retorna objetos
do tipo <code>Statement</code>. Nós podemos listar os apelidos assim:</p>
-<blockquote>
- <pre><code>// set up the output
+
+ <pre>// set up the output
System.out.println("The nicknames of \""
+ fullName + "\" are:");
// list the nicknames
@@ -676,17 +636,17 @@ while (iter.hasNext()) {
System.out.println(" " + iter.nextStatement()
.getObject()
.toString());
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>Esse código pode ser encontrado em <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial06.java">
tutorial 6</a>. O iterador <code>iter</code> reproduz todas as sentenças com
sujeito <code>vcard</code> e predicado <code>VCARD.NICKNAME</code>, então,
iterar sobre ele permite recuperar cada sentença usando
<code>nextStatement()</code>, pegar o campo do objeto, e convertê-lo para
string. O código produz a seguinte saÃda quando executado:</p>
-<blockquote>
- <pre><code>The nicknames of "John Smith" are:
+
+ <pre>The nicknames of "John Smith" are:
Smithy
- Adman</code></pre>
-</blockquote>
+ Adman</pre>
+
<p>Todas as propriedades de um recurso podem ser listadas usando o método
<code>listProperties()</code> sem argumentos.
@@ -703,46 +663,46 @@ while (iter.hasNext()) {
<p><code>Model.listSubjectsWithProperty(Property p, RDFNode
o)</code><code></code> retornará um iterador sobre todos os recursos com
propriedade <code>p</code> de valor <code>o</code>. Se nós assumirmos que
somente recursos vcard terão a propriedade <code>vcard:FN</code> e que, em
nossos dados, todos esses recursos têm essa propriedade, então podemos
encontrar todos os vCards assim:</p>
-<blockquote>
- <pre><code>// list vcards
+
+ <pre>// list vcards
ResIterator iter = model.listSubjectsWithProperty(VCARD.FN);
while (iter.hasNext()) {
Resource r = iter.nextResource();
...
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>Todos esses métodos de consulta são acuçar sintático sobre o método
primitivo de consulta <code>model.listStatements(Selector s)</code>. Esse
método retorna um iterador sobre todas as sentenças no modelo 'selecionado'
por <code>s</code>. A interface de selector foi feita para ser extensÃvel, mas
por hora, só há uma implementação dela, a classe
<code>SimpleSelector</code> do pacote <code>org.apache.jena.rdf.model</code>.
Usar <code>SimpleSelector </code> é uma das raras ocasiões em Jena onde é
necessário usar uma classe especifica em vez de uma interface. O construtor de
<code>SimpleSelector</code> recebe três argumentos:</p>
-<blockquote>
- <pre><code>Selector selector = new SimpleSelector(subject, predicate, object)
- </code></pre>
-</blockquote>
+
+ <pre>Selector selector = new SimpleSelector(subject, predicate, object)
+ </pre>
+
<p>Esse selector vai selecionar todas as sentenças em que o sujeito casa com
<code>subject</code>, um predicado que casa com <code>predicate</code> e um
objeto que casa com <code>object</code>. Se <code>null</code> é passado para
algum dos argumentos, ele vai casar com qualquer coisa, caso contrário, ele
vai casar com os recursos ou literais correspondentes. (Dois recursos são
iguais se eles possuem o mesmo URI ou são o mesmo blank node; dois literais
são iguais se todos os seus componentes forem iguais.) Assim:</p>
-<blockquote>
- <pre><code>Selector selector = new SimpleSelector(null, null, null);
- </code></pre>
-</blockquote>
+
+ <pre>Selector selector = new SimpleSelector(null, null, null);
+ </pre>
+
<p>vai selecionar todas as sentenças do modelo.</p>
-<blockquote>
- <pre><code>Selector selector = new SimpleSelector(null, VCARD.FN, null);
- </code></pre>
-</blockquote>
+
+ <pre>Selector selector = new SimpleSelector(null, VCARD.FN, null);
+ </pre>
+
<p>vai selecionar todas as sentenças com o predicado VCARD.FN, independente
do sujeito ou objeto. Como um atalho especial,
-<blockquote><code>listStatements( S, P, O )
-</code></blockquote>
+<code>listStatements( S, P, O )
+</code>
é equivalente a
-<blockquote><code>listStatements( new SimpleSelector( S, P, O ) )
-</code></blockquote>
+<code>listStatements( new SimpleSelector( S, P, O ) )
+</code>
@@ -751,8 +711,8 @@ while (iter.hasNext()) {
O código a seguir, que pode ser encontrado em <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial07.java">tutorial
7</a> que lista os nomes completos de todos os vcards do banco de dados.</p>
-<blockquote>
- <pre><code>// select all the resources with a VCARD.FN property
+
+ <pre>// select all the resources with a VCARD.FN property
ResIterator iter = model.listSubjectsWithProperty(VCARD.FN);
if (iter.hasNext()) {
System.out.println("The database contains vcards for:");
@@ -764,19 +724,19 @@ if (iter.hasNext()) {
} else {
System.out.println("No vcards were found in the database");
}
- </code></pre>
-</blockquote>
+ </pre>
+
<p>Isso deve produzir uma saÃda similar a:</p>
-<blockquote>
- <pre><code>The database contains vcards for:
+
+ <pre>The database contains vcards for:
Sarah Jones
John Smith
Matt Jones
Becky Smith
- </code></pre>
-</blockquote>
+ </pre>
+
<p>Seu próximo exercÃcio é modificar o código para usar
<code>SimpleSelector
</code>em vez de <code>listSubjectsWithProperty</code>.</p>
@@ -784,33 +744,33 @@ if (iter.hasNext()) {
<p>Vamos ver como implementar um controle mais refinado sobre as sentenças
selecionadas.
<code>SimpleSelector</code> pode ser herdado ter seus selects modificado para
mais filtragens:</p>
-<blockquote>
- <pre><code>// select all the resources with a VCARD.FN property
+
+ <pre>// select all the resources with a VCARD.FN property
// whose value ends with "Smith"
StmtIterator iter = model.listStatements(
new SimpleSelector(null, VCARD.FN, (RDFNode) null) {
public boolean selects(Statement s)
{return s.getString().endsWith("Smith");}
- });</code></pre>
-</blockquote>
+ });</pre>
+
<p>Esse código usa uma técnica elegante de Java para sobrescrever a
definição de um método quando criamos uma instância da classe. Aqui, o
método <code>selects(...)</code> garante que o nome completo termine com
âSmithâ. Ã importante notar que a filtragem baseada nos argumentos
sujeito, predicado e objeto tem lugar antes que o método
<code>selects(...)</code> seja chamado, então esse teste extra só será
aplicado para casar sentenças.</p>
<p>O código completo pode ser encontrado no <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial08.java">tutorial
8</a> e produz uma saÃda igual a:</p>
-<blockquote>
- <pre><code>The database contains vcards for:
+
+ <pre>The database contains vcards for:
John Smith
- Becky Smith</code></pre>
-</blockquote>
+ Becky Smith</pre>
+
<p></p>
<p>Você pode imaginar que:</p>
-<blockquote>
- <pre><code>// do all filtering in the selects method
+
+ <pre>// do all filtering in the selects method
StmtIterator iter = model.listStatements(
new
SimpleSelector(null, null, (RDFNode) null) {
@@ -820,15 +780,15 @@ StmtIterator iter = model.listStatements
&& (object == null ||
s.getObject().equals(object))
}
}
- });</code></pre>
-</blockquote>
+ });</pre>
+
<p>é equivalente a:</p>
-<blockquote>
- <pre><code>StmtIterator iter =
- model.listStatements(new SimpleSelector(subject, predicate,
object)</code></pre>
-</blockquote>
+
+ <pre>StmtIterator iter =
+ model.listStatements(new SimpleSelector(subject, predicate, object)</pre>
+
<p>Embora possam ser funcionalmente equivalentes, a primeira forma vai listar
todas as sentenças do modelo e testar cada uma individualmente, a segunda
forma permite Ãndices mantidos pela implementação para melhor a perfomance.
Tente isso em modelos grandes e veja você mesmo, mas prepare uma chÃcara de
café antes.</p>
@@ -850,8 +810,8 @@ StmtIterator iter = model.listStatements
<p>Vamos ver o código (o código completo está em <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial09.java">tutorial
9</a>) e ver o que acontece.</p>
-<blockquote>
- <pre><code>// read the RDF/XML files
+
+ <pre>// read the RDF/XML files
model1.read(new InputStreamReader(in1), "");
model2.read(new InputStreamReader(in2), "");
@@ -859,12 +819,12 @@ model2.read(new InputStreamReader(in2),
Model model = model1.union(model2);
// print the Model as RDF/XML
-model.write(system.out, "RDF/XML-ABBREV");</code></pre>
-</blockquote>
+model.write(system.out, "RDF/XML-ABBREV");</pre>
+
<p>A saÃda produzida pelo PrettyWriter se assemelha a:</p>
-<blockquote>
+
<pre><rdf:RDF
xmlns:rdf="<a
href="http://www.w3.org/1999/02/22-rdf-syntax-ns#">http://www.w3.org/1999/02/22-rdf-syntax-ns#</a>"
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
@@ -881,8 +841,8 @@ model.write(system.out, "RDF/XML-ABBREV"
<vcard:FN>John Smith</vcard:FN>
</rdf:Description>
</rdf:RDF></pre>
- <pre><code> </code></pre>
-</blockquote>
+ <pre> </pre>
+
<p>Mesmo que você não seja familiarizado com os detalhes da sintaxe
RDF/XML, deve ser relativamente claro que os modelos foram unidos como esperado
A interseção e a diferença de modelos podem ser computados de maneira
semelhante, usando os métodos <code>.intersection(Model)</code> e
<code>.difference(Model)</code>; veja a documentação de
@@ -916,8 +876,8 @@ para mais detalhes.
<p align="left">Vamos modificar o tutorial 8 para criar essa bag:</p>
-<blockquote>
- <pre><code>// create a bag
+
+ <pre>// create a bag
Bag smiths = model.createBag();
// select all the resources with a VCARD.FN property
@@ -931,13 +891,13 @@ StmtIterator iter = model.listStatements
// add the Smith's to the bag
while (iter.hasNext()) {
smiths.add(iter.nextStatement().getSubject());
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>Se nós imprimirmos esse modelo, vamos obter algo do tipo:</p>
-<blockquote>
- <pre><code><rdf:RDF
+
+ <pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
@@ -947,15 +907,15 @@ while (iter.hasNext()) {
<rdf:_1 rdf:resource='http://somewhere/JohnSmith/'/>
<rdf:_2 rdf:resource='http://somewhere/RebeccaSmith/'/>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
+</rdf:RDF></pre>
+
<p>que representa o recurso Bag.</p>
<p>A interface do container fornece um iterador para listar o conteúdo do
container:</p>
-<blockquote>
- <pre><code>// print out the members of the bag
+
+ <pre>// print out the members of the bag
NodeIterator iter2 = smiths.iterator();
if (iter2.hasNext()) {
System.out.println("The bag contains:");
@@ -967,16 +927,16 @@ if (iter2.hasNext()) {
}
} else {
System.out.println("The bag is empty");
-}</code></pre>
-</blockquote>
+}</pre>
+
<p>que produz a seguinte saÃda:</p>
-<blockquote>
- <pre><code>The bag contains:
+
+ <pre>The bag contains:
John Smith
- Becky Smith</code></pre>
-</blockquote>
+ Becky Smith</pre>
+
<p>O código executável pode ser encontrado em <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial10.java">
tutorial 10</a>, que coloca esses fragmentos de código juntos num exemplo
completo.</p>
@@ -991,8 +951,8 @@ tutorial 10</a>, que coloca esses fragme
<p>Em Jena, esses atributos de uma literal podem ser setados quando a literal
é construÃda, e.g. no <a
href="https://github.com/apache/jena/tree/master/jena-core/src-examples/jena/examples/rdf/Tutorial11.java">tutorial
11</a>:</p>
-<blockquote>
- <pre><code>// create the resource
+
+ <pre>// create the resource
Resource r = model.createResource();
// add the property
@@ -1001,13 +961,13 @@ r.addProperty(RDFS.label, model.createLi
.addProperty(RDFS.label, model.createLiteral("<em>chat</em>",
true));
// write out the Model
-model.write(system.out);</code></pre>
-</blockquote>
+model.write(system.out);</pre>
+
<p>produz</p>
-<blockquote>
- <pre><code><rdf:RDF
+
+ <pre><rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'
>
@@ -1016,15 +976,15 @@ model.write(system.out);</code></pre>
<rdfs:label xml:lang='fr'>chat</rdfs:label>
<rdfs:label
rdf:parseType='Literal'><em>chat</em></rdfs:label>
</rdf:Description>
-</rdf:RDF></code></pre>
-</blockquote>
+</rdf:RDF></pre>
+
<p>Para que duas literais sejam consideradas iguais, elas devem ser ambas
literais XML ou ambas literais simples. Em adição a isso, ambas não devem
possuir tag de linguagem, ou se as tags de linguagem estiverem presentes, elas
devem ser iguais. Para simples literais strings, elas devem ser iguais.
Literais XML têm duas noções de igualdade. A noção simples é que as
condições anteriores são verdade e as strings também são iguais. A outra
noção é de que elas podem ser iguais se a canonização das strings forem
iguais.</p>
<p>As interfaces de Jena também suportam literais tipadas. A maneira antiga
(mostrada abaixo) trata literais tipadas como atalhos para strings: valores
tipados são convertidos por Java em strings, e essas strings são armazenadas
no modelo. Por exemplo, tente (observando que para literais simples, nós
podemos omitir a chamada code>model.createLiteral</code>(...)):</p>
-<blockquote>
- <pre><code>// create the resource
+
+ <pre>// create the resource
Resource r = model.createResource();
// add the property
@@ -1032,14 +992,14 @@ r.addProperty(RDFS.label, "11")
.addProperty(RDFS.label, 11);
// write out the Model
-model.write(system.out, "N-TRIPLE");</code></pre>
-</blockquote>
+model.write(system.out, "N-TRIPLE");</pre>
+
<p>A saÃda produzida é:</p>
-<blockquote>
- <pre><code>_:A... <http://www.w3.org/2000/01/rdf-schema#label> "11"
.</code></pre>
-</blockquote>
+
+ <pre>_:A... <http://www.w3.org/2000/01/rdf-schema#label> "11" .</pre>
+
<p>Já que ambas as literais são apenas a string ââ11â, então somente
uma sentença é adicionada</p>