se.kmr.scam.rdf.util
Class RDFUtil

java.lang.Object
  extended byse.kmr.scam.rdf.util.RDFUtil

public class RDFUtil
extends Object

Helper for RDF-operations.

NA means Non-Anonymous.
LI mean RDF.li stuff

Title:

Description:

Copyright: Copyright (c) 2002

Company:

Version:
$Revision $
Author:
jand
Created:
den 12 juli 2002

Field Summary
protected static org.apache.log4j.Category LOG
          Log4j-logger
 
Constructor Summary
RDFUtil()
           
 
Method Summary
static RDFNode getObject(Model m, RDFNode node)
          Fetch an RDF-Object
static RDFNode getObject(Model m, Resource res, Property prop)
          Fetch an RDF-Object
static Resource getResource(Model m, Property predicate, RDFNode object)
          Fetch a resource by predicate and object.
static Resource getResource(Model m, Resource res)
          Fetch a Resource.
static Resource getRoot(Model m)
          Fetch the "root" of a Model.
static Resource getRoot(Model m, Resource res)
          Backtrack to retrieve the NA-resource having res.
static boolean hasObject(Model m, RDFNode node)
          Check existance of an RDF-Object.
static boolean hasResource(Model m, Resource res)
          Check existance of a Resource.
static boolean isAnon(Resource res)
          Test if a Resource is anonymous.
static boolean isEmpty(Model m)
          Check if model is empty (contains no statements)
static boolean isFakeAnon(Resource res)
           
static List listAnonymous(Model m)
          List all anonymous subjects.
static List listLIObjects(Model m, Resource res)
          List ALL the (RDF.li) objects of a container-Resource.
static List listLIObjects(Model m, Resource res, boolean onlyResources)
          List the objects (RDF.li-resources) of a container-Resource.
static List listNASubjects(Model m)
          List all non-anonymous subjects.
static List listNASubjects(Model m, Property predicate, RDFNode object)
          List all non-anonymous subjects.
static List listNonLIObjects(Model m, Resource res)
          List ALL the non-RDF.li-objects.
static List listNonLIObjects(Model m, Resource res, boolean onlyResources)
          List the non-(RDF.li) objects.
static List listObjects(Model m, Resource subject, Property predicate)
          List ALL the objects.
static List listObjects(Model m, Resource subject, Property predicate, boolean onlyResources)
          List the objects.
static void main(String[] args)
           
static void remove(Model m, Statement stm)
          Remove a statement from a model.
static void replace(Model m, RDFNode orig, RDFNode node)
          Replace ALL occurences of orig with node.
static void replace(Model m, Resource subj, Property pred, RDFNode obj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static org.apache.log4j.Category LOG
Log4j-logger

Constructor Detail

RDFUtil

public RDFUtil()
Method Detail

hasResource

public static boolean hasResource(Model m,
                                  Resource res)
                           throws RDFException
Check existance of a Resource.

Parameters:
m - Model
res - Resource
Returns:
true if found
Throws:
RDFException - Description of the Exception

getResource

public static Resource getResource(Model m,
                                   Resource res)
                            throws RDFException
Fetch a Resource.

Parameters:
m - Model
res - Description of the Parameter
Returns:
Resource or null if not found
Throws:
RDFException - Description of the Exception

getResource

public static Resource getResource(Model m,
                                   Property predicate,
                                   RDFNode object)
                            throws RDFException
Fetch a resource by predicate and object.
Note: If multiple resources exist, the first one encountered will be returned.

Parameters:
m - Model
predicate - Predicate
object - Object
Returns:
Resource or null if not found
Throws:
RDFException

remove

public static void remove(Model m,
                          Statement stm)
                   throws RDFException
Remove a statement from a model. If the statement has an RDF.li property the Container-API will be used (reorder "children").

Parameters:
m - Model
stm - Statement
Throws:
RDFException

hasObject

public static boolean hasObject(Model m,
                                RDFNode node)
                         throws RDFException
Check existance of an RDF-Object.

Parameters:
m - Model
node - Object
Returns:
true if found
Throws:
RDFException - Description of the Exception

getObject

public static RDFNode getObject(Model m,
                                RDFNode node)
                         throws RDFException
Fetch an RDF-Object

Parameters:
m - Model
node - Object to fetch
Returns:
RDF-Object or null if not found
Throws:
RDFException

getObject

public static RDFNode getObject(Model m,
                                Resource res,
                                Property prop)
                         throws RDFException
Fetch an RDF-Object

Parameters:
m - Model
res - Subject
prop - Property
Returns:
RDF-Object or null if not found
Throws:
RDFException

getRoot

public static Resource getRoot(Model m)
                        throws RDFException
Fetch the "root" of a Model. A resource is considered to be the root if it does NOT appear as an Object in any Statement.

Parameters:
m - Model
Returns:
Root or null if not found
Throws:
RDFException

getRoot

public static Resource getRoot(Model m,
                               Resource res)
                        throws RDFException
Backtrack to retrieve the NA-resource having res. This will return res itself if it is NA.

Parameters:
m - Model
res - Resource
Returns:
NA-resource or null if none
Throws:
RDFException

listObjects

public static List listObjects(Model m,
                               Resource subject,
                               Property predicate,
                               boolean onlyResources)
                        throws RDFException
List the objects. subject and/or predicate can be null

Parameters:
m - Model
subject - Subject
predicate - Predicate
onlyResources - Select only objects of type Resource
Returns:
Collection of RDFNodes
Throws:
RDFException

listObjects

public static List listObjects(Model m,
                               Resource subject,
                               Property predicate)
                        throws RDFException
List ALL the objects. subject and/or predicate can be null

Parameters:
m - Model
subject - Subject
predicate - Predicate
Returns:
Collection of RDFNodes
Throws:
RDFException
See Also:
listObjects(Model, Resource, Property, boolean)

listLIObjects

public static List listLIObjects(Model m,
                                 Resource res,
                                 boolean onlyResources)
                          throws RDFException
List the objects (RDF.li-resources) of a container-Resource.

Parameters:
m - Model
res - Resource (parent)
onlyResources - Select only objects of type Resource
Returns:
Collection of RDFNodes
Throws:
RDFException - Description of the Exception

listLIObjects

public static List listLIObjects(Model m,
                                 Resource res)
                          throws RDFException
List ALL the (RDF.li) objects of a container-Resource.

Parameters:
m - Model
res - Resource
Returns:
Collection of RDFNodes
Throws:
RDFException
See Also:
listLIObjects(Model, Resource, boolean)

listNonLIObjects

public static List listNonLIObjects(Model m,
                                    Resource res,
                                    boolean onlyResources)
                             throws RDFException
List the non-(RDF.li) objects.

Parameters:
m - Model
res - Resource
onlyResources - Select only objects of type Resource
Returns:
Collection of RDFNodes
Throws:
RDFException

listNonLIObjects

public static List listNonLIObjects(Model m,
                                    Resource res)
                             throws RDFException
List ALL the non-RDF.li-objects.

Parameters:
m - Model
res - Resource
Returns:
Collection of RDFNodes
Throws:
RDFException
See Also:
listNonLIObjects(Model, Resource, boolean)

listNASubjects

public static List listNASubjects(Model m)
                           throws RDFException
List all non-anonymous subjects.

Parameters:
m - Model
Returns:
Collection of Resources
Throws:
RDFException - Description of the Exception

listNASubjects

public static List listNASubjects(Model m,
                                  Property predicate,
                                  RDFNode object)
                           throws RDFException
List all non-anonymous subjects.

Parameters:
m - Model
predicate - Predicate
object - Object
Returns:
Collection of Resources
Throws:
RDFException - Description of the Exception

listAnonymous

public static List listAnonymous(Model m)
                          throws RDFException
List all anonymous subjects.

Parameters:
m - Model
Returns:
Collection of Resources
Throws:
RDFException

isEmpty

public static boolean isEmpty(Model m)
                       throws RDFException
Check if model is empty (contains no statements)

Parameters:
m - Model
Returns:
true if empty
Throws:
RDFException

isAnon

public static boolean isAnon(Resource res)
                      throws RDFException
Test if a Resource is anonymous.
Note: Besides Jenas internal Resource.isAnon(), a Resource is also considered to be anonymous if its URI ends with "#A<number>". This is due to parsing problems(?) with anonymous resources and RDF/XML.

Parameters:
res - Resource
Returns:
true if anonymous
Throws:
RDFException

isFakeAnon

public static boolean isFakeAnon(Resource res)
                          throws RDFException
Throws:
RDFException

replace

public static void replace(Model m,
                           RDFNode orig,
                           RDFNode node)
                    throws RDFException
Replace ALL occurences of orig with node. Can be compared to performing a "rename" of an URI or Literal.

Parameters:
m - Model
orig - Original Node (Resource or Literal)
node - "New" Node (Resource or Literal)
Throws:
RDFException

replace

public static void replace(Model m,
                           Resource subj,
                           Property pred,
                           RDFNode obj)
                    throws RDFException
Throws:
RDFException

main

public static void main(String[] args)


Copyright © 2003 SCAM. All Rights Reserved.