edu.umbc.cs.daml4jess
Class D4jRdf2Jess

java.lang.Object
  |
  +--edu.umbc.cs.daml4jess.D4jRdf2Jess
All Implemented Interfaces:
D4jLogger, com.hp.hpl.jena.rdf.arp.StatementHandler

public class D4jRdf2Jess
extends java.lang.Object
implements D4jLogger, com.hp.hpl.jena.rdf.arp.StatementHandler

This class is basically a rewrite of the DAMLJessFactCollector class. Loads an RDF resource using ARP parser and turn RDF statements into unordered Jess facts (templated). Basically each rdf statement is translated into a Jess fact. For anonymous nodes, an anonymous fact will be inserted (if flag is on) for each anonymous node. If an object (in an RDF statement) is a literal and the predicate is not "rdf:value", three more facts will be inserted: (1) give the literal a name and insert an anonymous fact (using the name). (2) the literal (referred using the name) has the type rdf:type, and (3) the literal (referred using the name) has the value of its string value.


Field Summary
protected  com.hp.hpl.jena.rdf.arp.ARP arp_
          The ARP RDF parser.
protected  java.lang.String defaultRdfXmlBase_
          Default RDF resource xml base.
protected  java.util.List facts_
          The list facts translated from RDF statements.
protected  java.util.List imports_
          The list of imported resources (if any) in the document.
protected  boolean insertAnonymous_
           
protected  D4jLogger logger_
           
 
Fields inherited from interface edu.umbc.cs.daml4jess.D4jLogger
LOG_LEVEL_BRIEF, LOG_LEVEL_ERR, LOG_LEVEL_INFO, LOG_LEVEL_VERBOSE, LOG_LEVEL_WARN, STDERR, STDIN, STDOUT
 
Constructor Summary
D4jRdf2Jess()
          Constructor.
 
Method Summary
 java.util.List getImports()
          Get the list of imported resources (by this document).
protected  java.lang.String getUniqueId(java.lang.String prefix)
          Generate a unique id with the default xml base (of the current resource being loaded), and the given prefix.
 java.util.List loadFromInputStream(java.io.InputStream istream, java.lang.String xmlBase)
          Load rdf resource from the given input stream.
 java.util.List loadFromReader(java.io.Reader reader, java.lang.String xmlBase)
          Load rdf resource from the given reader.
 java.util.List loadFromUri(java.lang.String rdfUrl)
          Load RDF data and convert it into Jess facts string.
 void log(java.lang.String msg, int level)
          Log the given message at the given level.
 void log(java.lang.String msg, java.lang.Throwable t, int level)
          Log the given message at the given level.
static void main(java.lang.String[] args)
          A simple test program which outputs RDF data as Jess facts.
 void setInsertAnonymous(boolean insertAnonymous)
          Set the flag of whether to insert (include) anonymous predicates (from the anonymous node).
 void setLogger(D4jLogger logger)
          Set the logger, which will be used for logging information.
 void statement(com.hp.hpl.jena.rdf.arp.AResource subj, com.hp.hpl.jena.rdf.arp.AResource pred, com.hp.hpl.jena.rdf.arp.ALiteral lit)
          Handling a RDF statement.
 void statement(com.hp.hpl.jena.rdf.arp.AResource subj, com.hp.hpl.jena.rdf.arp.AResource pred, com.hp.hpl.jena.rdf.arp.AResource obj)
          Handling a RDF statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

arp_

protected com.hp.hpl.jena.rdf.arp.ARP arp_
The ARP RDF parser.


facts_

protected java.util.List facts_
The list facts translated from RDF statements.


imports_

protected java.util.List imports_
The list of imported resources (if any) in the document.


defaultRdfXmlBase_

protected java.lang.String defaultRdfXmlBase_
Default RDF resource xml base. If an RDF resource specifies "xml:base", it will be used by the ARP parser (rather than the one passed to load(...)). If xml:base is not specified, it'll use the one passed in; if no xml base is passed in, it'll use "http://unknow.org". This defaultRdfXmlBase_ will always be set to the URI from which the RDF resource will be loaded, and pass to ARP as the xml base. If the RDF resource specifies xml:base, it'll overrides this default.


insertAnonymous_

protected boolean insertAnonymous_

logger_

protected D4jLogger logger_
Constructor Detail

D4jRdf2Jess

public D4jRdf2Jess()
Constructor.

Method Detail

setInsertAnonymous

public void setInsertAnonymous(boolean insertAnonymous)
Set the flag of whether to insert (include) anonymous predicates (from the anonymous node).


setLogger

public void setLogger(D4jLogger logger)
Set the logger, which will be used for logging information.


log

public void log(java.lang.String msg,
                int level)
Log the given message at the given level.

Specified by:
log in interface D4jLogger
Parameters:
msg - the message to be logged.
level - the log level of this message.
See Also:
for more details.

log

public void log(java.lang.String msg,
                java.lang.Throwable t,
                int level)
Log the given message at the given level.

Specified by:
log in interface D4jLogger
Parameters:
msg - the message to be logged.
level - the log level of this message.
t - a the throwable to be logged, can be null.
See Also:
for more details.

loadFromUri

public java.util.List loadFromUri(java.lang.String rdfUrl)
                           throws D4jException
Load RDF data and convert it into Jess facts string.

Parameters:
rdfUrl - Location to read RDF from. May be a filename or URL.
Returns:
the list of all facts converted from the rdf resource.
Throws:
D4jException - if anything goes wrong.

loadFromInputStream

public java.util.List loadFromInputStream(java.io.InputStream istream,
                                          java.lang.String xmlBase)
                                   throws D4jException
Load rdf resource from the given input stream.

Parameters:
xmlBase - the default xml base (if not specified in document).
istream - the input stream from which to load the document.
Returns:
the list of all facts converted from the rdf resource.
Throws:
D4jException - if anything goes wrong.

loadFromReader

public java.util.List loadFromReader(java.io.Reader reader,
                                     java.lang.String xmlBase)
                              throws D4jException
Load rdf resource from the given reader.

Parameters:
xmlBase - the default xml base (if not specified in data). Note that it will be canonicalized (if not yet).
Returns:
the list of all facts converted from the rdf resource.
Throws:
D4jException - if anything goes wrong.

getImports

public java.util.List getImports()
Get the list of imported resources (by this document).


statement

public void statement(com.hp.hpl.jena.rdf.arp.AResource subj,
                      com.hp.hpl.jena.rdf.arp.AResource pred,
                      com.hp.hpl.jena.rdf.arp.AResource obj)
Handling a RDF statement. See StatementHandler interface for details.

Specified by:
statement in interface com.hp.hpl.jena.rdf.arp.StatementHandler

statement

public void statement(com.hp.hpl.jena.rdf.arp.AResource subj,
                      com.hp.hpl.jena.rdf.arp.AResource pred,
                      com.hp.hpl.jena.rdf.arp.ALiteral lit)
Handling a RDF statement. See StatementHandler interface for details.

Specified by:
statement in interface com.hp.hpl.jena.rdf.arp.StatementHandler

getUniqueId

protected java.lang.String getUniqueId(java.lang.String prefix)
Generate a unique id with the default xml base (of the current resource being loaded), and the given prefix. The uniqueness is guaranteed for upto the number a long can express.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
A simple test program which outputs RDF data as Jess facts. Take a single argument, the location from which to read the RDF data.

java.lang.Exception