commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [2/3] incubator-commonsrdf git commit: User guide: About Literal
Date Mon, 27 Apr 2015 16:11:30 GMT
User guide: About Literal

TODO: more outgoing links, show that the
getDataType() is an IRI, show lexical form, etc


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/4c5e9787
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/4c5e9787
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/4c5e9787

Branch: refs/heads/master
Commit: 4c5e9787952ff857775a7e0da873cc95117370c3
Parents: 33c0c43
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Apr 27 17:08:57 2015 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Apr 27 17:08:57 2015 +0100

----------------------------------------------------------------------
 src/site/markdown/userguide.md | 69 +++++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4c5e9787/src/site/markdown/userguide.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md
index 4c805c7..ce37d9a 100644
--- a/src/site/markdown/userguide.md
+++ b/src/site/markdown/userguide.md
@@ -512,11 +512,74 @@ be made about this string except that it is unique per blank node._
 
 ### Literal
 
-**TODO:** [Literal](apidocs/org/apache/commons/rdf/api/Literal.html)
+A [literal](http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal) in RDF
+is a value such as a string, number or a date. A `Literal` can only be used as
+_objects_ of a `Triple`
 
-### Types
+To create a [Literal](apidocs/org/apache/commons/rdf/api/Literal.html) instance
+from an `RDFTermFactory`, use
+[createLiteral](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createLiteral-java.lang.String-):
+
+```java
+Literal literal = factory.createLiteral("Hello world");
+System.out.println(literal);
+```
+
+> `"Hello world"`
+
+In RDF 1.1, a _plain literal_ as created above always have the type
+`http://www.w3.org/2001/XMLSchema#string`:
+
+```java
+System.out.println(literal.getDatatype());
+```
+
+> `<http://www.w3.org/2001/XMLSchema#string>`
+
+
+
+Literals may be created with an associated language tag:
+
+```java
+Literal inSpanish = factory.createLiteral("¡Hola, Mundo!", "es");
+System.out.println(inSpanish);
+```
+> `"¡Hola, Mundo!"@es`
+
+In RDF 1.1, a Literal with a language always have the
+type `http://www.w3.org/1999/02/22-rdf-syntax-ns#langString`:
+
+```java
+System.out.println(inSpanish.getDatatype());
+```
+
+> `<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>`
+
+A _typed literal_ has a datatype represented by an `IRI`:
+
+```java
+IRI xsdDouble = factory.createIRI("http://www.w3.org/2001/XMLSchema#double");
+Literal typedLiteral = factory.createLiteral("13.37", xsdDouble);
+System.out.println(typedLiteral);
+```
+
+> `"13.37"^^<http://www.w3.org/2001/XMLSchema#double>`
+
+
+#### Types
+
+The class [Types](apidocs/org/apache/commons/rdf/simple/Types.html), which is
+part of the _simple_ implementation, provides constants for the standard
+XML Schema datatypes, e.g. `xsd:dateTime` and `xsd:float`. Using `Types`,
+the above example can be simplified to:
+
+```java
+Literal typedLiteral = factory.createLiteral("13.37", Types.XSD_DOUBLE);
+````
+
+Note that the string returned from `Literal.ntriplesString()` will always
+contain the full IRI for the datatype:
 
-**TODO:** [Types](apidocs/org/apache/commons/rdf/simple/Types.html)
 
 ### Triple
 


Mime
View raw message