org.w3c.rdf.util
Class RDFUtil

java.lang.Object
  |
  +--org.w3c.rdf.util.RDFUtil

public class RDFUtil
extends java.lang.Object

Useful utility methods.


Constructor Summary
RDFUtil()
           
 
Method Summary
static void add(Model m, Resource subject, Resource predicate, RDFNode object)
           
static void collectNamespaces(Model m, java.util.Collection target)
           
static void collectNamespaces(Resource r, java.util.Collection target)
           
static void collectNamespaces(Statement st, java.util.Collection target)
           
static void dumpModel(Model m, java.io.PrintStream ps, RDFSerializer s)
          Dumps the model in a serialized form.
static java.lang.String dumpModel(Model m, RDFSerializer s)
          Dumps the model in a serialized form in a string
static Statement get1(Model m)
          Returns the first triple of the model
static java.lang.String getLocalName(Resource r)
          Delivers the name out of the URI (without the namespace prefix).
static java.lang.String getNamespace(Resource r)
          Extracts the namespace prefix out of a URI.
static java.util.Hashtable getNodes(Model m)
           
static RDFNode getObject(Model r, Resource subject, Resource predicate)
           
static java.lang.String getObjectLiteral(Model r, Resource subject, Resource predicate)
          returns the literal value of the node reachable from subject via predicate
static Resource getObjectResource(Model r, Resource subject, Resource predicate)
           
static int getOrd(Resource r)
          Converts an ordinal property to an integer.
static Model getReachable(Resource r, Model m)
          returns a subgraph of "m" containing "r" and all nodes reachable from "r" via directed edges.
static java.util.Hashtable getResources(Model m)
           
static Statement[] getStatementArray(Model m)
          Collects the triples of a model into an array.
static java.util.Vector getStatementVector(Model m)
          Collects the triples of a model in a vector.
static Resource getSubject(Model r, Resource predicate, RDFNode object)
           
static java.lang.String guessName(java.lang.String uri)
          Delivers the name out of the URI (without the namespace prefix).
static java.lang.String guessNamespace(java.lang.String uri)
          Extracts the namespace prefix out of a URI.
static boolean isInstanceOf(Model r, Resource i, Resource cls)
           
static boolean isQualified(java.lang.String s)
          Tests if the URI is qualified, i.e.
static boolean isRDF(Resource r)
          Tests if the resource belongs to the RDF syntax/model namespace.
static boolean isRDF(java.lang.String uri)
          Tests if the URI belongs to the RDF syntax/model namespace.
static Resource noname(Model m)
          Creates a new unique unnamed resource.
static java.lang.String normalizeURI(java.lang.String uri)
           
static void parse(java.lang.String fileNameOrURL, RDFParser parser, Model model)
           
static void printStatements(Model m, java.io.PrintStream ps)
          Prints the triples of a model to the given PrintStream.
static Model removeNamespace(java.lang.String ns, Model m)
          Removes all triples which have something to do with the given namespace
static void saveModel(Model m, RDFSerializer s)
          tries to determine the file name from getSourceURI
static void saveModel(Model m, java.lang.String fileName, RDFSerializer s)
           
static boolean setUniqueObject(Model r, Resource subject, Resource predicate, RDFNode object)
          returns true if old triples from r were removed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RDFUtil

public RDFUtil()
Method Detail

noname

public static Resource noname(Model m)
                       throws ModelException
Creates a new unique unnamed resource.

getOrd

public static int getOrd(Resource r)
                  throws ModelException
Converts an ordinal property to an integer.

isQualified

public static boolean isQualified(java.lang.String s)
Tests if the URI is qualified, i.e. has a namespace prefix.

guessNamespace

public static java.lang.String guessNamespace(java.lang.String uri)
Extracts the namespace prefix out of a URI.

guessName

public static java.lang.String guessName(java.lang.String uri)
Delivers the name out of the URI (without the namespace prefix).

getNamespace

public static java.lang.String getNamespace(Resource r)
                                     throws ModelException
Extracts the namespace prefix out of a URI.

getLocalName

public static java.lang.String getLocalName(Resource r)
                                     throws ModelException
Delivers the name out of the URI (without the namespace prefix).

isRDF

public static boolean isRDF(java.lang.String uri)
Tests if the URI belongs to the RDF syntax/model namespace.

isRDF

public static boolean isRDF(Resource r)
                     throws ModelException
Tests if the resource belongs to the RDF syntax/model namespace.

get1

public static Statement get1(Model m)
                      throws ModelException
Returns the first triple of the model

add

public static void add(Model m,
                       Resource subject,
                       Resource predicate,
                       RDFNode object)
                throws ModelException

setUniqueObject

public static boolean setUniqueObject(Model r,
                                      Resource subject,
                                      Resource predicate,
                                      RDFNode object)
                               throws ModelException
returns true if old triples from r were removed

getObjectLiteral

public static java.lang.String getObjectLiteral(Model r,
                                                Resource subject,
                                                Resource predicate)
                                         throws ModelException
returns the literal value of the node reachable from subject via predicate

getObjectResource

public static Resource getObjectResource(Model r,
                                         Resource subject,
                                         Resource predicate)
                                  throws ModelException

isInstanceOf

public static boolean isInstanceOf(Model r,
                                   Resource i,
                                   Resource cls)
                            throws ModelException

getObject

public static RDFNode getObject(Model r,
                                Resource subject,
                                Resource predicate)
                         throws ModelException

getSubject

public static Resource getSubject(Model r,
                                  Resource predicate,
                                  RDFNode object)
                           throws ModelException

printStatements

public static void printStatements(Model m,
                                   java.io.PrintStream ps)
                            throws ModelException
Prints the triples of a model to the given PrintStream.

dumpModel

public static void dumpModel(Model m,
                             java.io.PrintStream ps,
                             RDFSerializer s)
                      throws ModelException,
                             java.io.IOException,
                             SerializationException
Dumps the model in a serialized form.

dumpModel

public static java.lang.String dumpModel(Model m,
                                         RDFSerializer s)
                                  throws ModelException,
                                         java.io.IOException,
                                         SerializationException
Dumps the model in a serialized form in a string

getStatementVector

public static java.util.Vector getStatementVector(Model m)
                                           throws ModelException
Collects the triples of a model in a vector.

getStatementArray

public static Statement[] getStatementArray(Model m)
                                     throws ModelException
Collects the triples of a model into an array.

removeNamespace

public static Model removeNamespace(java.lang.String ns,
                                    Model m)
                             throws ModelException
Removes all triples which have something to do with the given namespace

getReachable

public static Model getReachable(Resource r,
                                 Model m)
                          throws ModelException
returns a subgraph of "m" containing "r" and all nodes reachable from "r" via directed edges. These edges are also included in the resulting model.

parse

public static void parse(java.lang.String fileNameOrURL,
                         RDFParser parser,
                         Model model)
                  throws java.io.IOException,
                         SAXException,
                         java.net.MalformedURLException,
                         ModelException

normalizeURI

public static java.lang.String normalizeURI(java.lang.String uri)

getResources

public static java.util.Hashtable getResources(Model m)
                                        throws ModelException

getNodes

public static java.util.Hashtable getNodes(Model m)
                                    throws ModelException

saveModel

public static void saveModel(Model m,
                             java.lang.String fileName,
                             RDFSerializer s)
                      throws java.io.FileNotFoundException,
                             java.io.IOException,
                             ModelException,
                             SerializationException

saveModel

public static void saveModel(Model m,
                             RDFSerializer s)
                      throws java.io.FileNotFoundException,
                             java.io.IOException,
                             ModelException,
                             SerializationException
tries to determine the file name from getSourceURI

collectNamespaces

public static void collectNamespaces(Resource r,
                                     java.util.Collection target)
                              throws ModelException

collectNamespaces

public static void collectNamespaces(Statement st,
                                     java.util.Collection target)
                              throws ModelException

collectNamespaces

public static void collectNamespaces(Model m,
                                     java.util.Collection target)
                              throws ModelException