org.ontoware.rdf2go.util
Class RDFTool

java.lang.Object
  extended by org.ontoware.rdf2go.util.RDFTool

public class RDFTool
extends java.lang.Object

RDFTool, a helper utility to cope with RDF in general. The accessor methods are also handled by the RDFReactor runtime.

This tool has been part of gnowsis.org.

Author:
Leo Sauermann (leo@gnowsis.com), 2003-2007, Max Völkel

Constructor Summary
RDFTool()
           
 
Method Summary
static Model copyModel(Model m)
           
static java.lang.String date2String(java.util.Date date)
          format the given date in a good date format: ISO 8601, using only the date and not the T seperator example: 2003-01-22 Timezone is ignored.
static java.lang.String dateTime2DateString(java.util.Date date)
          Deprecated. use date2String(Date)
static java.lang.String dateTime2String(java.util.Date date)
          format the given date in a good dateTime format: ISO 8601, using the T seperator and the - and : seperators accordingly. example: 2003-01-22T17:00:00
static Statement findStatement(Model model, ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object)
          find the first statement that fits the passed triple pattern and return it.
static java.text.DateFormat getDateFormat()
          format to express dates in ISO 8601.
static java.text.DateFormat getDateTimeFormat()
          get a DateFormat to format dates according to ISO 8601.
static java.lang.String getGoodLabel(Node o, Model source)
          Get the Displaylabel of a Node.
static java.lang.String getLabel(Node o)
          Get the label of a Node.
static java.lang.String getShortName(java.lang.String uri)
          The passed uri identifies something on the web, probably a namespace.
static Node getSingleValue(Model m, Resource res, URI pred)
          get the property pred of the resource res.
static Node getSingleValue(ModelSet m, Resource res, URI pred)
           
static java.lang.String getSingleValueString(Model m, Resource res, URI pred)
          read the values of a predicate of a resource.
static java.lang.String getSingleValueString(ModelSet modelset, Resource res, URI pred)
          read the values of a predicate of a resource.
static Syntax guessSyntax(java.lang.String filenname)
          guess the RDF syntax of a filename inspired by com.hp.hpl.jena.graph.impl.FileGraph#guessLang with the addition of toLowerCase
static java.lang.String modelToString(Model model)
          convert a model to a string RDF/XML for serialization
static java.lang.String modelToString(ModelSet modelset)
           
static java.lang.String modelToString(ModelSet modelset, Syntax syntax)
          convert a modelset to a string for serialization
static java.lang.String modelToString(Model model, Syntax syntax)
          convert a model to a string for serialization
static void setSingleValue(Model m, Resource res, URI pred, Node value)
          set the property pred of the resource res.
static void setSingleValue(Model m, Resource res, URI pred, java.lang.String value)
          set the property pred of the resource res.
static java.lang.String sha1sum(java.lang.String data)
          compute the sha1sum of a string (useful for handling FOAF data).
static java.util.Date string2Date(java.lang.String isodate)
          try to get a date out of a string.
static java.util.Date string2DateTime(java.lang.String date)
          format the given date in a good date format: ISO 8601, using only the date and not the T seperator example: 2003-01-22 This ignores timezones.
static Model stringToModel(java.lang.String rdfxml)
          convenience function to create a memModel from an RDF/XML-ABBREV stream
static Model stringToModel(java.lang.String string, Syntax syntax)
          convenience function to create a memModel from a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RDFTool

public RDFTool()
Method Detail

copyModel

public static Model copyModel(Model m)
Parameters:
m - the model to copy
Returns:
a copy of the model in a memory model

dateTime2DateString

public static java.lang.String dateTime2DateString(java.util.Date date)
Deprecated. use date2String(Date)

format the given date in a good date format: ISO 8601, using only the date and not the T seperator example: 2003-01-22 Timezone is ignored.

Parameters:
date -
Returns:
a formatted string.

dateTime2String

public static java.lang.String dateTime2String(java.util.Date date)
format the given date in a good dateTime format: ISO 8601, using the T seperator and the - and : seperators accordingly. example: 2003-01-22T17:00:00

Parameters:
date -
Returns:
a formatted string.

date2String

public static java.lang.String date2String(java.util.Date date)
format the given date in a good date format: ISO 8601, using only the date and not the T seperator example: 2003-01-22 Timezone is ignored.

Parameters:
date -
Returns:
a formatted string.

findStatement

public static Statement findStatement(Model model,
                                      ResourceOrVariable subject,
                                      UriOrVariable predicate,
                                      NodeOrVariable object)
find the first statement that fits the passed triple pattern and return it.

Parameters:
model - the model to search on
subject - subject
predicate - predicate
object - object
Returns:
a statement (the first found) or null, if nothing matched
Throws:
java.lang.RuntimeException - if the model throws an exception

getDateFormat

public static java.text.DateFormat getDateFormat()
format to express dates in ISO 8601. Timezone is ignored.

Returns:
the DateFormat to format dates (without time) according to ISO8601.

getDateTimeFormat

public static java.text.DateFormat getDateTimeFormat()
get a DateFormat to format dates according to ISO 8601. This ignored timezones.

Returns:
a dateformat.

getGoodLabel

public static java.lang.String getGoodLabel(Node o,
                                            Model source)
Get the Displaylabel of a Node. For resources, the "rdfs:label" property is returned, if there is none, the url is shortened to a localname. If it is a Literal, return the Lexical Form. If it is null, returns null Results may vary.

Parameters:
o - the node to check
source - the model to ask
Returns:
a string representation of the node or null.

getLabel

public static java.lang.String getLabel(Node o)
Get the label of a Node. If it is a resource, return the local name (the last part of the URI). If it is a Literal, return the Lexical Form (the value). If it is null, returns null.

Parameters:
o - the node to check
Returns:
a string representation of the node or null.

getShortName

public static java.lang.String getShortName(java.lang.String uri)
The passed uri identifies something on the web, probably a namespace. To shorten this, parse the url for something like a localname. Returns the last string after a '#' or a '/'.

Parameters:
uri - a URI
Returns:
a short name for it, for display.

getSingleValue

public static Node getSingleValue(Model m,
                                  Resource res,
                                  URI pred)
get the property pred of the resource res. If there is none, return null. If there are mutliple, return any.

Parameters:
m - the model to read from
res - the resource
pred - the predicate to read
Returns:
the value or null

getSingleValue

public static Node getSingleValue(ModelSet m,
                                  Resource res,
                                  URI pred)

getSingleValueString

public static java.lang.String getSingleValueString(Model m,
                                                    Resource res,
                                                    URI pred)
read the values of a predicate of a resource. If a value exists, return a string representation of it. When multiple triples with this subject/predicate exist, choose one at random.

Parameters:
m - the model to read from
res - the resource
pred - the predicate to read
Returns:
a string representation of the value, or null. Literals are returned using their Value (not toString()).

getSingleValueString

public static java.lang.String getSingleValueString(ModelSet modelset,
                                                    Resource res,
                                                    URI pred)
read the values of a predicate of a resource. If a value exists, return a string representation of it. When multiple triples with this subject/predicate exist, choose one at random.

Parameters:
modelset - the model to read from
res - the resource
pred - the predicate to read
Returns:
a string representation of the value, or null. Literals are returned using their Value (not toString()).

guessSyntax

public static Syntax guessSyntax(java.lang.String filenname)
guess the RDF syntax of a filename inspired by com.hp.hpl.jena.graph.impl.FileGraph#guessLang with the addition of toLowerCase

Parameters:
filenname - the filename, we will look at the suffix after "."
Returns:
the guessed RDF syntax, fallback is RDF/XML

modelToString

public static java.lang.String modelToString(Model model)
convert a model to a string RDF/XML for serialization

Parameters:
model - the model to convert
Returns:

modelToString

public static java.lang.String modelToString(ModelSet modelset)

modelToString

public static java.lang.String modelToString(Model model,
                                             Syntax syntax)
convert a model to a string for serialization

Parameters:
model - the model to convert
syntax - the syntax to use
Returns:
a string of this model, according to the passed syntax

modelToString

public static java.lang.String modelToString(ModelSet modelset,
                                             Syntax syntax)
convert a modelset to a string for serialization

Parameters:
modelset - the model to convert
syntax - the syntax to use
Returns:
a string of this model, according to the passed syntax

setSingleValue

public static void setSingleValue(Model m,
                                  Resource res,
                                  URI pred,
                                  Node value)
set the property pred of the resource res. If it exists, change it. If it not exists, create it. If the passed value is null, delete the statement

Parameters:
m - the model to manipulate
res - the rsource
pred - the predicate to set
value - a value or null

setSingleValue

public static void setSingleValue(Model m,
                                  Resource res,
                                  URI pred,
                                  java.lang.String value)
set the property pred of the resource res. If it exists, change it. If it not exists, create it. If value is null, delete the triple.

Parameters:
m - the model to manipulate
res - the rsource
pred - the predicate to set
value - a string or null

sha1sum

public static java.lang.String sha1sum(java.lang.String data)
compute the sha1sum of a string (useful for handling FOAF data).

Parameters:
data - the string to parse
Returns:
the sha1sum as string.

string2Date

public static java.util.Date string2Date(java.lang.String isodate)
                                  throws java.text.ParseException
try to get a date out of a string. If this works, return it, otherwise return null. Btw: the namespace of dateTime is http://www.w3.org/2001/XMLSchema#dateTime Timezone is ignored.

Parameters:
isodate - the XSD date as string.
Returns:
a parsed date or null, if this breaks
Throws:
java.text.ParseException

string2DateTime

public static java.util.Date string2DateTime(java.lang.String date)
                                      throws java.text.ParseException
format the given date in a good date format: ISO 8601, using only the date and not the T seperator example: 2003-01-22 This ignores timezones.

Parameters:
date - the date-string to parse
Returns:
a formatted string.
Throws:
java.text.ParseException

stringToModel

public static Model stringToModel(java.lang.String rdfxml)
convenience function to create a memModel from an RDF/XML-ABBREV stream

Parameters:
rdfxml - the serialized form of the model
Returns:
a Model

stringToModel

public static Model stringToModel(java.lang.String string,
                                  Syntax syntax)
convenience function to create a memModel from a string

Parameters:
string - the string with the serialized model
syntax - the syntax to use
Returns:
the model that was serialised.


Copyright © 2005-2008 FZI - Forschungszentrum Informatik | Karlsruhe | Germany. All Rights Reserved.