edu.umbc.cs.daml4jess
Class D4jUtil

java.lang.Object
  |
  +--edu.umbc.cs.daml4jess.D4jUtil

public class D4jUtil
extends java.lang.Object

A set of Daml4Jess util methods.


Constructor Summary
D4jUtil()
           
 
Method Summary
static java.lang.String array2String(java.lang.Object[] array, int ipl)
          Convert the given object array to string, using default element separator: ", ".
static java.lang.String array2String(java.lang.Object[] array, int ipl, java.lang.String delim)
          Convert the given object array to string.
static java.lang.String buildAnonymousFact(java.lang.String value)
          Build an anonymous, ordered fact with the given value, in the form: ( )
static java.lang.String buildAsserts(java.lang.String facts)
          Construct a Jess "assert" statement with the given facts.
static java.lang.String buildDeffacts(java.lang.String facts)
          Construct a Jess "deffacts" statement with the given facts.
static java.lang.String buildRdfFact(java.lang.String subj, java.lang.String pred, java.lang.String obj)
          Build an RDF Jess fact with the given subject, predicate, and object.
static java.lang.String canonicalizeUri(java.lang.String uri)
          Canonicalize a resource URI (to be used to load the resource).
static java.lang.String dependencyFact(java.lang.String depId, java.lang.String seqId)
          create a dependency fact, a fact to be used as logical CE in Jess rule, so that when this fact is retracted, all facts asserted via the rule will automatically retracted.
static java.lang.String dependencyRule(java.lang.String ruleName, java.lang.String depFact, java.lang.String facts)
          create a dependency rule, with the given rule name, dependency fact, and the facts depending on the dependency fact and to be asserted.
static java.lang.String dependencyRuleName(java.lang.String depId, java.lang.String seqId)
          Create a dependency rule name with the given dependency id and sequenceid.
static java.lang.String dumpJessQueryResults(java.util.Iterator iter)
          Dump the given query results (in the iterator) to a string.
static java.lang.String factListToString(java.util.List facts)
          Convert a given list of facts into one string, a newline is inserted after each fact.
static java.lang.String getStackTrace(java.lang.Throwable t)
          Get the stack trace of the given throwable.
static java.lang.String getUniqueId(java.lang.String prefix)
          Generate a unique id with the given prefix.
static java.lang.String toJessQuery(java.lang.String queryName, java.lang.String[] args)
          Write the given query name and arguments into Jess run-query format, e.g., (run-query *)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

D4jUtil

public D4jUtil()
Method Detail

getUniqueId

public static java.lang.String getUniqueId(java.lang.String prefix)
Generate a unique id with the given prefix. The uniqueness is guaranteed for upto the number a long can express.


getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)
Get the stack trace of the given throwable.

Parameters:
t - the given throwable whose stack trace is to be retrieved.
Returns:
the stack trace of the given throwable.

array2String

public static java.lang.String array2String(java.lang.Object[] array,
                                            int ipl)
Convert the given object array to string, using default element separator: ", ".

Parameters:
array - the array to be converted to a string.
ipl - items per line. If ipl = 0, all items will be on one line.

array2String

public static java.lang.String array2String(java.lang.Object[] array,
                                            int ipl,
                                            java.lang.String delim)
Convert the given object array to string.

Parameters:
array - the array to be converted to a string.
ipl - items per line. If ipl = 0, all items will be on one line.
delim - the array item deliminator.

canonicalizeUri

public static java.lang.String canonicalizeUri(java.lang.String uri)
                                        throws D4jException
Canonicalize a resource URI (to be used to load the resource). For example, removing the trailing "#", or if a file name, canonicalize the file name (e.g, "/abc/../efg" to "file:/efg"). It first removes the trailing "#" if any; then check if it's a valid URL, and if not, treat it as a file name and canonicalize it.

Parameters:
uri - the uri to be "canonicalized".
Returns:
a "canonicalized" URI.
Throws:
D4jException - if the given uri can not be canonicalized.

buildRdfFact

public static java.lang.String buildRdfFact(java.lang.String subj,
                                            java.lang.String pred,
                                            java.lang.String obj)
Build an RDF Jess fact with the given subject, predicate, and object.


buildAnonymousFact

public static java.lang.String buildAnonymousFact(java.lang.String value)
Build an anonymous, ordered fact with the given value, in the form: ( )

Parameters:
value - the value of the only place in the fact.

buildDeffacts

public static java.lang.String buildDeffacts(java.lang.String facts)
Construct a Jess "deffacts" statement with the given facts.


buildAsserts

public static java.lang.String buildAsserts(java.lang.String facts)
Construct a Jess "assert" statement with the given facts.


dependencyFact

public static java.lang.String dependencyFact(java.lang.String depId,
                                              java.lang.String seqId)
create a dependency fact, a fact to be used as logical CE in Jess rule, so that when this fact is retracted, all facts asserted via the rule will automatically retracted.

Parameters:
depId - the dependency id.
seqId - the sequence id (number) with respect to the .

dependencyRuleName

public static java.lang.String dependencyRuleName(java.lang.String depId,
                                                  java.lang.String seqId)
Create a dependency rule name with the given dependency id and sequenceid.

Parameters:
depId - the dependency id.
seqId - the sequence id (number) with respect to the .

dependencyRule

public static java.lang.String dependencyRule(java.lang.String ruleName,
                                              java.lang.String depFact,
                                              java.lang.String facts)
create a dependency rule, with the given rule name, dependency fact, and the facts depending on the dependency fact and to be asserted.

Parameters:
ruleName - the dependency rule name.
depFact - the fact the given facts depend on.
facts - the facts to be asserted with dependency.

factListToString

public static java.lang.String factListToString(java.util.List facts)
Convert a given list of facts into one string, a newline is inserted after each fact.

Parameters:
facts - a list of facts.
Returns:
a string of the given facts.

dumpJessQueryResults

public static java.lang.String dumpJessQueryResults(java.util.Iterator iter)
Dump the given query results (in the iterator) to a string. Note that after calling this method, the iterator will be no longer usable!!! For debug use ONLY.

Parameters:
iter - the iterator of the query results.
Returns:
the result INFO, including the results, if any. return null if something is wrong.

toJessQuery

public static java.lang.String toJessQuery(java.lang.String queryName,
                                           java.lang.String[] args)
Write the given query name and arguments into Jess run-query format, e.g., (run-query *)

Parameters:
queryName - name of the query.
args - the argument list, if any.