edu.umbc.cs.daml4jess
Class DjkToD4j

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

public class DjkToD4j
extends java.lang.Object

The main function is to convert the ordered-fact based DAMLJessKB rules/axioms into unordered-fact (template) based rules/axioms. E.g., from (PropertyValue daml#subClassOf my#SUV my#Car) to: (D4jRdfStatement (subject SUV) (predicate subClassOf) (object Car)) Efforts have been given to make the result rules readable and to keep the comments in place, but they may not look as good as desired. Note that if your rules file has tabs in it, it's recommended that you change them to spaces (e.g, using unix "pr" command). This converter does not attempt to retain tab related formating mainly because people may use different tab settings with their editor. Also Note that the template is not defined in the resulting file. A backup version of the old file will be saved, with an extension as configured (or default). A real parser could have been used to do the job more neatly but thought a simple piece of code might be sufficient - unfortunately it didn't quite turn out that way. This class is intended to be used as a utility, not quite designed to work with other classes.


Nested Class Summary
protected static class DjkToD4j.StatementInfo
          Internal class for statement information: old statement (before conversion) information and the new statement after conversion.
 
Field Summary
protected  java.lang.String backupExt_
           
protected  java.lang.String commentSym_
           
protected  int indentStep_
           
protected  java.lang.String newLine_
           
protected  java.lang.String object_
           
protected  java.lang.String oldHead_
           
protected  java.lang.String predicate_
           
protected  java.lang.String subject_
           
protected  java.lang.String tmplName_
           
 
Constructor Summary
DjkToD4j(java.util.Properties properties)
          Constructor, using the given configurations.
 
Method Summary
protected  void convert(java.lang.String fileName)
          Convert the jess rules in the given file into slot-based jess rules.
static void main(java.lang.String[] args)
          Main function.
protected  DjkToD4j.StatementInfo nextStatement(java.lang.String data, int startIndex)
          Locate the next statement to convert, convert it, and return the statement information.
protected  int nextStatementStart(java.lang.String data, int startIndex)
          Find the start index of next POSSIBLE statement.
protected  java.lang.String templatize(java.lang.String rulesData)
          Convert the jess rules in the given string into slot-based jess rules.
protected  java.lang.String templatizeStatment(java.lang.String oldStmt, int initIndent)
          This is where an old statement is converted to a new statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newLine_

protected java.lang.String newLine_

oldHead_

protected java.lang.String oldHead_

tmplName_

protected java.lang.String tmplName_

subject_

protected java.lang.String subject_

predicate_

protected java.lang.String predicate_

object_

protected java.lang.String object_

indentStep_

protected int indentStep_

backupExt_

protected java.lang.String backupExt_

commentSym_

protected java.lang.String commentSym_
Constructor Detail

DjkToD4j

public DjkToD4j(java.util.Properties properties)
Constructor, using the given configurations.

Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Main function. See the class description for more details. Usage: java [-Dconfig=] DjkToD4j ()*

java.lang.Exception

convert

protected void convert(java.lang.String fileName)
                throws java.io.IOException
Convert the jess rules in the given file into slot-based jess rules. A backup version of the old file will be saved. See the class Description for more details.

java.io.IOException

templatize

protected java.lang.String templatize(java.lang.String rulesData)
Convert the jess rules in the given string into slot-based jess rules. See the class Description for more details.


nextStatement

protected DjkToD4j.StatementInfo nextStatement(java.lang.String data,
                                               int startIndex)
Locate the next statement to convert, convert it, and return the statement information.

Returns:
the information for the next statement, if any. Return null if there is no statement to covnert.

nextStatementStart

protected int nextStatementStart(java.lang.String data,
                                 int startIndex)
Find the start index of next POSSIBLE statement. A possible start is an opening parenthesis, i.e., "(".

Returns:
the start index of the next POSSIBLE statement; return a negative number if nothing possible is found.

templatizeStatment

protected java.lang.String templatizeStatment(java.lang.String oldStmt,
                                              int initIndent)
This is where an old statement is converted to a new statement. See the class decription for more details.

Returns:
the new, templatized statement if templatizable; return null otherwise.